$if not setglobal debug $offlisting offinclude * The GAMS code contained in this file was originally written by * Tom Rutherford, published at http://www.mpsge.org/gnuplot/gnuplot.htm * and was slightly adapted by Torbjoren Jansson *----------------------------------------------------------------------------- * GAMS Source Code (resides in the ldir directory): Generic Plotting Routine *----------------------------------------------------------------------------- *----------------------------------------------------------------------------- * Declarations: *----------------------------------------------------------------------------- $if not declared gp__1 alias(gp__1,gp__2,*); $if not declared gp_row set gp_row(*), gp_col(*); $if not declared gp_r parameter gp_r(*); $if not declared gp_rr alias (gp_rr,gp_row); $if not declared gp_inp file gp_inp /gnuplot.plt/; $if not declared gp_data file gp_data /gnuplot.dat/; $if not declared gp_na scalar gp_na /na/; $if not declared gp_count scalar gp_count, gp_counter; *TJ $if not setglobal GPSTYLE $setlocal GPSTYLE with lines * If no arguments, this is solely for intialization: $if a%1 == a $exit $if declared %1 $goto declared $error PLOT ERROR: Identfier %1 is not declared. $exit $label declared $if defined %1 $goto defined $error PLOT ERROR: identfier %1 is not defined. $exit $label defined $if not setglobal domain $setglobal domain $if not setglobal series $setglobal series $if not "%2"=="" $setglobal domain %2 $onuni $if dimension 1 %1 $goto start1 $if not "%3"=="" $setglobal series %3 $if dimension 2 %1 $goto getsets $if not %series%=="" $goto getsets $error PLOT error: series must be specified for multidimensional plots $exit * Extract row and column labels: $label start1 gp_row(gp__1)$%1(gp__1) = yes; $label getsets $if not dimension 1 %1 $goto arraysets $if "%domain%"=="" gp_row(gp__1)$abs(%1(gp__1)) = yes; $if not "%domain%"=="" gp_row(%domain%) = yes; $goto checkx $label arraysets $if not "%domain%"=="" $goto getseries $if %series%=="" gp_row(gp__1)$sum(gp__2, abs(%1(gp__1,gp__2))) = yes; $if not %series%=="" gp_row(gp__1)$sum(%series%, abs(%1(gp__1,%series%))) = yes; $label getseries $if "%series%"=="" gp_col(gp__2)$sum(gp__1, abs(%1(gp__1,gp__2))) = yes; $if not "%domain%"=="" gp_row(%domain%) = yes; $if not dimension 2 %1 $goto checkx $if not "%series%"=="" gp_col(%series%) = yes; * See if xvalue has been specified: $label checkx $if setglobal xvalue $goto xvalue * 1. No X parameter array has been specified assign unit values: gp_count = 1; loop(gp_row, gp_r(gp_row) = gp_count; gp_count = gp_count + 1; ); $goto write $label xvalue * If the plotted item is single dimensional, skip * we must assume that xvalue is a parameter: $if partype %xvalue% $goto xparam $if dimension 2 %1 $goto xcolumn $error PLOT ERROR: Cannot find parameter %xvalue% (xvalue). $exit * 2. X parameter values are in the data array: $label xcolumn gp_r(gp_row) = %1(gp_row,"%xvalue%"); gp_col("%xvalue%") = no; $goto write * 3. X values are in a separate array: $label xparam $if partype %xvalue% $goto gotparam $abort Unrecognized symbol specified as xvalue in plot call: %xvalue% $label gotparam gp_r(gp_row) = %xvalue%(gp_row); $label write put gp_inp; gp_inp.lw = 0; gp_inp.nr = 0; gp_inp.nd = 0; gp_inp.nw = 6; put 'set title "',%1.ts,'"'/; $if not setglobal xvalue put 'set xrange [1:',card(gp_row),']'/; gp_inp.nd = 3; gp_inp.nw = 12; $if setglobal xvalue put 'set xrange [',(smin(gp_row,gp_r(gp_row))),':',(smax(gp_row,gp_r(gp_row))),']'/; $if not setglobal labels $goto options put 'set xtics ('; gp_inp.nd = 3; gp_inp.nw = 12; gp_count = 0; gp_counter = 0; loop(gp_row, gp_count=gp_count+1; if (%labels%(gp_row), gp_counter = gp_counter + 1; if (gp_counter gt 1, put ',';); $if not setglobal xvalue put '\'/' "',%labels%.te(gp_row),'" ',gp_count; $if setglobal xvalue put '\'/' "',%labels%.te(gp_row),'" ',%xvalue%(gp_row); ); ); put ')'/; * Pass through any user-specified options: $label options put 'set data style lines'/; * Permit user-override of up to 10 GNUPLOT features: $if setglobal gp_opt0 put "%gp_opt0%"/; $if setglobal gp_opt1 put "%gp_opt1%"/; $if setglobal gp_opt2 put "%gp_opt2%"/; $if setglobal gp_opt3 put "%gp_opt3%"/; $if setglobal gp_opt4 put "%gp_opt4%"/; $if setglobal gp_opt5 put "%gp_opt5%"/; $if setglobal gp_opt6 put "%gp_opt6%"/; $if setglobal gp_opt7 put "%gp_opt7%"/; $if setglobal gp_opt8 put "%gp_opt8%"/; $if setglobal gp_opt9 put "%gp_opt9%"/; $if setglobal gp_opt10 put "%gp_opt10%"/; $if setglobal gp_opt11 put "%gp_opt11%"/; $if setglobal gp_opt12 put "%gp_opt12%"/; $if setglobal gp_opt13 put "%gp_opt13%"/; $if setglobal gp_opt14 put "%gp_opt14%"/; $if setglobal gp_opt15 put "%gp_opt15%"/; $if setglobal gp_opt16 put "%gp_opt16%"/; $if setglobal gp_opt17 put "%gp_opt17%"/; $if setglobal gp_opt18 put "%gp_opt18%"/; $if setglobal gp_opt19 put "%gp_opt19%"/; gp_inp.nd = 0; gp_inp.nw = 6; gp_data.nw = 16; gp_data.nd = 8; gp_data.nr = 2; $if dimension 2 %1 $goto twodimen $if not dimension 1 %1 $goto multidim * A. Plot a vector. put 'set nokey'/; put 'plot "gnuplot.dat" using 1:2 "%lf%lf"'/; *.putclose /; putclose /'quit'/; loop(gp_row, put gp_data, gp_r(gp_row); if (%1(gp_row) eq gp_na, put gp_data, ' '; else put gp_data, %1(gp_row); ); put /; ); put //; $goto putclose $label twodimen * B. Plot a two-dimensional array. gp_count=1; put 'plot '; loop(gp_col, if (gp_count gt 1, put ',';); gp_inp.nw = 0 put '\'/' "gnuplot.dat" index ',(gp_count-1):0:0, ' using 1:2 "%lf%lf" title "',gp_col.te(gp_col),'" %GPSTYLE%'; gp_inp.nw = 6; gp_count = gp_count + 1; ); *.putclose /; putclose /'quit'/; loop(gp_col, loop(gp_row, put gp_data, gp_r(gp_row); if (%1(gp_row,gp_col) eq gp_na, put gp_data, ' '; else put gp_data, %1(gp_row,gp_col); ); put /; ); put //; ); $goto putclose $label multidim * C. Plot a multi-dimensional array gp_count=1; put 'plot '; loop(%series%, if (gp_count gt 1, put ',';); gp_inp.nw = 0 put '\'/' "gnuplot.dat" index ',(gp_count-1):0:0, ' using 1:2 "%lf%lf" title "',%series%.te(%series%),'"'; gp_inp.nw = 6; gp_count = gp_count + 1; ); *.putclose /; putclose //'quit'/; loop(%series%, loop(gp_row, put gp_data, gp_r(gp_row); if (%1(gp_row,%series%) eq gp_na, put gp_data, ' '; else put gp_data, %1(gp_row,%series%); ); put /; ); put //; ); $label putclose putclose; * We are done with the row and column sets. Clean them * out so that they can be used a second time: gp_row(gp__1) = no; gp_col(gp__2) = no; $offuni $if not setglobal batch $set batch no * Change 3/7/00 by tfr * Documentation states that gnuplot can be anywhere on * the PATH. *.$if %batch%=="yes" execute '%gams.sdir%wgnuplot gnuplot.plt'; *.$if %batch%=="no" execute '%gams.sdir%wgnuplot gnuplot.plt -'; * Change 3/17/00 by tfr: use new version of GNUPLOT gp371w32 * Change 18/11/06 by TJ: GnuPlot is now called wgnuplot.exe $if %batch%=="yes" execute 'wgnuplot gnuplot.plt'; *$if %batch%=="yes" execute 'wgnupl32 gnuplot.plt'; $if %batch%=="no" execute 'wgnuplot gnuplot.plt -'; *$if %batch%=="no" execute 'wgnupl32 gnuplot.plt -';