Input of Matrices to Vam Files¶
There are four commands to introduce into the default Vam file a matrix from an ASCII file. The first two use different input formats to put matrices into the Vam file. The other two put data into packed matrix files, in which the cells that are zero in all years have been eliminated to conserve space.
The first, and most used, command is matin. It has the form
It also is possible to introduce a matrix that is in a spreadsheet by a “Copy” and “Paste” operation into the window created by the show command described below. While this route may be a quick expedient, if the Vam file is changed and the process has to be repeated, it quickly loses its appeal.
The second command for reading matrices is solely for conversion of models previously built with the Slimforp program. If you are not converting a model from Slimforp, ignore this command. Its form is
- matin5 <matrix_name> <year> [<width> <decs> <IndexWidth>]
It is followed by a matrix in the punch5 format used in Slimforp. The end of the matrix is signaled either by a ‘;’ in the first space on a line or by the end of the file. For those not familiar with the punch5 format, it is a fixed length format with 5 matrix entries to a line, each entry of the form “<row> <col> <number>”. One possible format in Fortran would be (5X,5(2I3,F9.5)). In this case, <width> = 9, <decs> = 5, and <IndexWidth> = 3.
Here is a sample from the beginning of an A matrix:
matin5 am 1977 9 5 3
# A-matrix for 1977. 83 rows and 83 columns.
AM 1 1 0.245790 1 4 0.000220 1 8 0.000410 1 9 0.281300 1 10 0.058360
AM 1 11 0.002070 1 12 0.005680 1 13 0.000380 1 15 0.001700 1 16 0.003060
AM 1 22 0.089770 1 24 0.000070 1 48 0.001210 1 49 0.000130 1 50 0.000030
Packed Matrices
There are two special commands for introducing data for a “packed” matrix. Packed matrices become important in models with many sectors, in which the matrices – especially the various bridge matrices – often are very sparse; that is, they have relatively few non-zero elements. Interdyme has the ability to carry the matrices in a packed form in which only the non-zero elements are stored. In most places in G7, the packed matrix can be used interchangeably with the “full” matrix. For example, in the index, lint, and show commands described below, either full or packed matrix names can be used without needing to remember which kind of matrix is being used. For the input of data, however, there is a special format for packed matrices. Moreover, packed matrices are not included in the Vam file. Only the file name of the packed matrix is in the Vam file; the actual data are stored in a special binary file for which we use the extension .PMX. This separation of the .PMX from the Vam file was done because (a) the .PMX files are fairly big and (b) they often do not change at all between various alternative runs of the model. Thus, we might have five runs of the model, each with its own Vam file but all with the same PMX files. The savings in disk space over having five copies of the .PMX files could be substantial.
The first command for introducing data into packed matrices assumes that the elimination of the zero elements already has been done, as likely is the case if the matrix comes from Inforum programs for updating a matrix. The second command reads the matrix in full rectangular form and eliminates the zeroes itself. The result is the same in either case. The first command is:
- pmatin <matrix_name> <packed_matrix_filename>
where <matrix_name> is the name of a matrix in the VAM.CFG file which must have the letter ‘p’ in the “lags” position. The <packed_matrix_filename> is name the file name of the .PMX file. (The .PMX should be included in the specified name.)
The format of the data that follow is:
<year>
<row> <num_non-zero_elements>
<col1> <element1> <col2> <element2> ...
For example
pmatin bm bm.pmx
1985
1 5 # row 1 has 5 non-zero elements
1 .656 7 .352 11 .038 23 .019 27 .218
3 2 # row 3 has 2 non-zero elements
7 .098 51 .923
.... ;
If the matrix is available for several years, the data for all years should be introduced with only one pmatin command, with each year’s data preceded by the number of the year. It is essential that the year numbers not be abbreviated; use “1987” please, not “87”. If a cell is non-zero in any year for which there is data, the packed matrix will have a place reserved for it in all years. To signify the end of the data, provide a ‘;’.
- pmatin1 <matrix_name> <packed_matrix_filename>
An alternative way to introduce data into packed matrices is the pmatin1 command. The format is just like that of the pmatin command except that the data should be arranged in rectangular rows and columns like the matin command.
For example, if you wish to treat as a packed matrix a 3 x 3 matrix known as B in the Vam file, you can introduce it with the pmatin1 command as follows:
pmatin1 B B.pmx
1995
1 0 0
5 0 1
6 2 0
1996
1.5 0 0
6 0 2
7 3 1
Note that in the above example, only those cells that are zero in all years will be left out of the packed matrix. Cell (3,3) will actually be stored, since it has a non-zero value in 1996. As with the pmatin command, you should put of the data for all years you want to read in the same file, and use only one pmatin1 command per matrix.
pmfile <matrix_name> <packed_matrix_filename>
Although packed matrix files often do not change between runs, they may. If, for example, we wished to study the effects of changes in the A matrix and the A matrix was packed, then we would need two different .PMX files. If the original was called AM.PMX, then to create the alternative, say, AMALT.PMX, we would go to the DOS prompt via File | DOS and do
copy am.pmx amalt.pmx
copy hist.vam vamalt.vam
Then from G7’s command box type
vam vamalt b
dvam b
pmfile am amalt.pmx
This pmfile command both will assign AMALT.PMX to be used whenever the am matrix is referenced and will put “AMALT.PMX” into AMALT.VAM as the name of the file to be used for the packed am matrix.
- pmmode { “simple”| “advanced” }
Note that the <packed_matrix_filename> setting is limited to 30 characters, including any path specification. Sometimes more than one vam bank is loaded in G7, where the vam banks include packed matrix files with the same name but that are stored in different locations. Sometimes it is not convenient to reset the link for each vam bank using the pmfile command, or perhaps inclusion of a full path specification would be needed to distinguish between the files but the full specification exceeds the limit of 30 characters. In such cases, it might be useful to specify a link to each packed matrix file relative to the placement of the corresponding vam bank. By default, G7 will assume that the packed matrix file is in the current working directory, or, if a relative path is specified, that the specification is relative to the current location. This behavior can be controlled with the pmmode command. The pmmode simple command corresponds to the default behavior. The “advanced” mode instructs G7 to attempt to find PMX files in the same location as the corresponding vam bank, or if a relative path is specified for the PMX file, the root location should be the location of the parent vam bank.