Quantcast
Channel: Yet Another Math Programming Consultant
Viewing all articles
Browse latest Browse all 809

GAMS: Undocumented PUT formats

$
0
0

The GAMS documentation mentions f.nr=1 (standard notation) and f.nr=2 (scientific notation) for formatting numeric items using the PUT statement. There are however a few more. Here we print values using different formats:


       f.nr=1       f.nr=2       f.nr=3       f.nr=4
1.201.20E+001.20000000001.2
1.231.23E+001.23450000001.2345
123450000.001.23E+08123450000.00123450000
0.001.20E-070.00000012001.2E-7
0.001.23E-070.00000012351.2345E-7


It looks like formats 3 and 4 are inspired by SAS PUT formats f12.10 and best12.10.

References

  1. Dictionary of formats, https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/p0z62k899n6a7wn1r5in6q5253v1.htm


Appendix: GAMS code


set
   i  
'values'   /i1*i5/
   fmt
'formats'  /'f.nr=1'*'f.nr=4'/
;

parameter p(i) 'test values'/
  
i1  1.2
  
i2  1.2345
  
i3  1.2345e8
  
i4  1.2e-7
  
i5  1.2345e-7
/;

*
* write all values in all formats
*

file f /put.txt/;
* right align text
f.lj = 1;
put f;
* write headers
loop(fmt,
  
put fmt.tl:13
);
put /;
* write values
loop(i,
  
loop(fmt,
     
put'':0;
      f.nr=
ord(fmt);
     
put p(i);
   );
  
put /;
);


Viewing all articles
Browse latest Browse all 809

Trending Articles