gdxmrw_iwgdx01_init.gms : Writing data into a indexed GDX file with IWGDX

Description

Initialization: Write "iwgdx01.m".

The program demonstrates writing data into a indexed GDX
file with IRGDX in Matlab.

Intended use: interactive Matlab session

Contributor: Toni Lastusilta


Category : GAMS Data Utilities library


Main file : gdxmrw_iwgdx01_init.gms   includes :  gdxmrw_iwgdx01_init.gms

$Title Writing data into a indexed GDX file with IWGDX

$ontext
Initialization: Write "iwgdx01.m".

The program demonstrates writing data into a indexed GDX
file with IRGDX in Matlab.

Intended use: interactive Matlab session

Contributor: Toni Lastusilta

$offtext


*Write Matlab program
$onecho > iwgdx01.m
% Writing data to a indexed GAMS Data eXchange (GDX) file
% by using IWGDX in Matlab.

% Write empty GDX file test1.gdx
iwgdx('test1');

% Write GDX file test2.gdx
a2=[1 2;0 4];
a3=sparse(3,2);
a3(1,1)=2;
a3(1,2)=4;
a3(2,2)=8;
iwgdx('test2','a2','a3')

% Test pass by reference writing test3.gdx
clear;
randMat = rand(5000);
if exist('test3.gdx')
  delete test3.gdx;
end
tic;
iwgdx('test3','randMat'); % slower
t1 = toc
delete test3.gdx;
tic;
iwgdx('test3','randMat',randMat); % faster
t2 = toc

% Write GDX file pp.gdx
d0 = pi;
p1 = d0;
d1 = pi*ones(3,1);
p2 = d1;
d2 = pi*ones(3,3,1);
% Compare Dim and NRecs for (d0,p1), (d1,p2) and (d2,p3)
iwgdx('pp','d0','p1:1','d1','p2:2','d2','p3:3',d2);
gdxWhos('pp');
% See pp.gdx in the GAMSIDE
if ispc system('start gamside pp.gdx'); end

% Write GDX file pp2.gdx
vec0=0;vec1=2;vec2=[3:4];
mat0=0;mat1=2;mat2=[3:4];
% Vectors and matrices with zero, one and two elements
iwgdx('pp2','vec0:1','vec1:1','vec2:1','mat0:2','mat1:2','mat2:2');
gdxWhos('pp2');

open iwgdx01.m
$offecho


*Call Matlab
$set WHICH which
$if not %system.filesys% == UNIX $set WHICH where
$call %WHICH% matlab
$ifThen errorLevel 1
$clearError
$abort.noerror 'Matlab is not available!';
$else
$call.Async matlab -r "cd %GAMS.cdir%;iwgdx01" -nosplash -nodisplay
$endIf