Initializing help system before first use

Reading 3-dimensional arrays


Type: Programming
Rating: 2 (easy-medium)
Description: This example shows how to read a 3-dimensional array from an excel file (threedimarr.mos) and from a generic spreadsheet (threedimarr5.mos).
File(s): threedimarr.mos, threedimarr2.mos, threedimarr3.mos, threedimarr4.mos, threedimarr5.mos, threedimarr6.mos
Data file(s): threedim.csv, threedim.xls, threedim.xlsx, threedim.mdb, threedim.sqlite

threedimarr.mos
(!*******************************************************
   Mosel Example Problems 
   ======================

   file threedimarr.mos
   ````````````````````
   Reading 3-dimensional arrays.
   - Using 'initializations from' with the odbc driver -
       
   (c) 2010 Fair Isaac Corporation
       author: S. Heipcke, July 2010, rev. Jan. 2014
*******************************************************!)

model ThreeDimArr
 uses "mmodbc"

 parameters
  CSTR = "threedim.mdb"        ! Use Access database `threedim.mdb'
!  CSTR = 'threedim.sqlite'    ! Use SQLite database `threedim.sqlite' directly
                               ! Use SQLite database `threedim.sqlite' via ODBC
!  CSTR = 'DSN=sqlite;DATABASE=threedim.sqlite'
 end-parameters

 declarations
  I: range
  J: set of string
  K = 1..5	              ! The last index set must be defined in the model
  A: dynamic array(I,J,K) of real
 end-declarations

 initializations from 'mmodbc.odbc:debug;noindex;' + CSTR
  A as 'Tab_23'
 end-initializations

 writeln("A: ")
 forall(i in I, j in J, k in K | exists(A(i,j,k)))
  writeln("A(", i, ",", j, ",", k, "): ", A(i,j,k))

end-model



threedimarr2.mos
(!*******************************************************
   Mosel Example Problems 
   ======================

   file threedimarr2.mos
   `````````````````````
   Reading 3-dimensional arrays.
   - Using SQL commands -
       
   (c) 2014 Fair Isaac Corporation
       author: S. Heipcke, Jan. 2014
*******************************************************!)

model "ThreeDimArr (SQL)"
 uses "mmodbc", "mmsystem"

 parameters
!  CSTR = "threedim.xls"      ! Use Excel spreadsheet `threedim.xls'
  CSTR = "threedim.mdb"       ! Use Access database `threedim.mdb' 
!  CSTR = 'threedim.sqlite'   ! Use SQLite database `threedim.sqlite' directly
                              ! Use SQLite database `threedim.sqlite' via ODBC
!  CSTR = 'DSN=sqlite;DATABASE=threedim.sqlite'
 end-parameters

 declarations
  I: range
  J: set of string
  K = 1..5	              ! The last index set must be defined in the model
  A: dynamic array(I,J,K) of real
  Idx3: text
 end-declarations

 SQLconnect(CSTR)
 
 setparam("SQLndxcol", false) ! Partially indexed data
 
 forall(k in K) Idx3+= (", Index3_"+k )
 SQLexecute("select Index1, Index2" + Idx3 + " from Tab_23", A)
 SQLdisconnect

 writeln("A: ")
 forall(i in I, j in J, k in K | exists(A(i,j,k)))
  writeln("A(", i, ",", j, ",", k, "): ", A(i,j,k))

  
end-model



threedimarr3.mos
(!*******************************************************
   Mosel Example Problems 
   ======================

   file threedimarr3.mos
   `````````````````````
   Reading 3-dimensional arrays.
   - Using 'initializations from' with Excel -
       
   (c) 2010 Fair Isaac Corporation
       author: S. Heipcke, July 2010, rev. Apr. 2014
*******************************************************!)

model "ThreeDimArr (Excel)"
 uses "mmsheet", "mmodbc"

 declarations
  I: range
  J: set of string
  K = 1..5	              ! The last index set must be defined in the model	
  A,B: dynamic array(I,J,K) of real
 end-declarations

 initializations from 'mmsheet.excel:partndx;threedim.xls'
  A as 'Tab_23'
 end-initializations

 writeln("A: ")
 forall(i in I, j in J, k in K | exists(A(i,j,k)))
  writeln("A(", i, ",", j, ",", k, "): ", A(i,j,k))

 (!
 initializations from 'mmodbc.odbc:debug;partndx;threedim.xls'
  B as 'Tab23odbc'
 end-initializations

 writeln("B: ")
 forall(i in I, j in J, k in K | exists(B(i,j,k)))
  writeln("B(", i, ",", j, ",", k, "): ", B(i,j,k))
!)
end-model



threedimarr4.mos
(!*******************************************************
   Mosel Example Problems 
   ======================

   file threedimarr4.mos
   `````````````````````
   Reading 3-dimensional arrays.
   - Using OCI statements -
       
   (c) 2014 Fair Isaac Corporation
       author: S. Heipcke, Jan. 2014
*******************************************************!)

model "ThreeDimArr (OCI)"
 uses "mmoci", "mmsystem"

 parameters
  DB="myname/mypassword@dbname"     ! Login to Oracle database (not provided)
  CNCT="mmoci.oci:debug;"+DB
 end-parameters

 declarations
  I: range
  J: set of string
  K = 1..5	              ! The last index set must be defined in the model
  A: dynamic array(I,J,K) of real
  Idx3: text
 end-declarations

 setparam("OCIdebug",true)
 OCIlogon(DB)
 
 setparam("OCIndxcol", false) ! Partially indexed data

 forall(k in K) Idx3+= (", Index3_"+k )
 OCIexecute("select Index1, Index2" + Idx3 + " from Tab_23", A)
 OCIlogoff

 writeln("A: ")
 forall(i in I, j in J, k in K | exists(A(i,j,k)))
  writeln("A(", i, ",", j, ",", k, "): ", A(i,j,k))
 
end-model



threedimarr5.mos
(!*******************************************************
   Mosel Example Problems 
   ======================

   file threedimarr5.mos
   `````````````````````
   Reading 3-dimensional arrays.
   - Using 'initializations from' with the xls/xlsx driver -
       
   (c) 2012 Fair Isaac Corporation
       author: S. Heipcke, Dec. 2012, rev. Apr. 2014
*******************************************************!)

model "ThreeDimArr (generic spreadsheet)"
 uses "mmsheet"

 parameters
  CSTR1= 'mmsheet.xls:threedim.xls'
  CSTR2= 'mmsheet.xlsx:threedim.xlsx'
 end-parameters

 declarations
  I: range
  J: set of string
  K = 1..5	              ! The last index set must be defined in the model
  A,B,C: dynamic array(I,J,K) of real
 end-declarations

 initializations from CSTR1
  A as 'partndx;Tab_23'
 end-initializations

 writeln("A: ")
 forall(i in I, j in J, k in K | exists(A(i,j,k)))
  writeln("A(", i, ",", j, ",", k, "): ", A(i,j,k))

 initializations from CSTR2
  B as 'partndx;Tab_23'
 end-initializations

 writeln("B: ")
 forall(i in I, j in J, k in K | exists(B(i,j,k)))
  writeln("B(", i, ",", j, ",", k, "): ", B(i,j,k))

! Using explicit cell addresses instead of a named range:
 initializations from CSTR1
  C as 'partndx;[Sheet1$A3:G8]'
 end-initializations

 writeln("C: ")
 forall(i in I, j in J, k in K | exists(C(i,j,k)))
  writeln("C(", i, ",", j, ",", k, "): ", C(i,j,k))
  
end-model



threedimarr6.mos
(!*******************************************************
   Mosel Example Problems 
   ======================

   file threedimarr6.mos
   `````````````````````
   Reading 3-dimensional arrays.
   - Using 'initializations from' with the csv driver -
       
   (c) 2012 Fair Isaac Corporation
       author: S. Heipcke, Dec. 2012, rev. Apr. 2014
*******************************************************!)

model "ThreeDimArr (CSV)"
 uses "mmsheet"

 parameters
  CSTR= 'mmsheet.csv:threedim.csv'
 end-parameters

 declarations
  I: range
  J: set of string
  K = 1..5	              ! The last index set must be defined in the model
  A: dynamic array(I,J,K) of real
 end-declarations

 initializations from CSTR
  A as 'partndx;[A3:G8]'
 end-initializations

 writeln("A: ")
 forall(i in I, j in J, k in K | exists(A(i,j,k)))
  writeln("A(", i, ",", j, ",", k, "): ", A(i,j,k))
  
end-model



© 2001-2020 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.