Initializing help system before first use

Reading several arrays from a single table

If two or more data arrays have the same index sets, then their values may be defined in a single spreadsheet range/database table, such as the following table where the first two columns hold the indices and the last two colums the data entries for two arrays:

Products Mach Cost Duration
prod1 1 1.2 3
prod1 3 2.4 2
prod2 3 3 1
prod2 2   2
prod4 1 4 5
prod4 4 3.2 2
prod3 3 5.7 2
prod3 4 2.9 8
prod3 1 3  

Notice that in this table not all entries are defined for every array.

The following Mosel model multicol.mos reads the data from the range ProdData into two array, COST and DUR. For every array only those entries that are specified in the input data will actually be defined:

model "Multiple data columns"
 uses "mmodbc"

 declarations
  PRODUCTS: set of string
  MACH: range
  COST: dynamic array(PRODUCTS,MACH) of real
  DUR: dynamic array(PRODUCTS,MACH) of integer
 end-declarations

 initializations from "mmodbc.odbc:multicol.sqlite"
  [COST,DUR] as 'ProdData'
 end-initializations

 writeln(COST); writeln(DUR)

end-model 

The SQL version of this model is as follows:

 SQLconnect('multicol.sqlite')
 setparam("SQLverbose",true)
 SQLexecute("select * from ProdData ", [COST,DUR])
 SQLdisconnect 

If we wish to read data from a different database, also defining the table ProdData, we again simply need to adapt the filename or the connection string to the database name.

To use the excel driver with a data range definition that includes the header line the option skiph needs to be employed.

 initializations from "mmsheet.excel:multicol.xls"
  [COST,DUR] as 'skiph;ProdData'
 end-initializations