Macro Sample

this page demonstrates how to use the Plot macro language to import a custom data file and automatically apply style attributes to the document.

Our sample data file (download) contains the dollar exchange rate in DM and has the following format:

 19710104 36434
 19710105 36450
 19710106 36439
 19710107 36433
 19710108 36424
 19710111 36414
 19710112 36416
 19710113 36402
 19710114 36390
 ...

The first column is the date formated as YYYYMMDD and the second the dollar exchanged rate (rate*10000). Our script needs to convert the time string to a time values which is known by Plot, convert the exchange rate and apply graphic attributes. The import is made with a inline Perl script followed by some Plot macro commands to apply the style:

 delete all

 PERL
 use Time::Local;
 open(IN,$file); 
 while(<IN>) {
   if (/(\d\d\d\d)(\d\d)(\d\d)\s*(.*)$/) {
     $t=timelocal(0,0,0,$3,$2-1,$1-1900);
     $data[0][$n][0]=$t-978307200.0;		
     $data[0][$n][1]=$4/10000;		
     $n++;	
   }
 }
 close(IN);
 PERL

 browse
 perlimport $file

 aformat 1 2
 atext 2 'Dollar Exchanged Rate (DM)'
 atext 1 'Date'
 atickdist 2 0.1
 atextfont all Helvetica-Bold 18
 anumfont all Helvetica 12
 asetticks all no
 asetminticks all no
 aminsteps 2 2
 asetgrid 2 yes
 agridwidth 2 0.3
 asetgrid 1 yes
 agridwidth 1 0.3
 atextoffset all 15
 adecplaces 2 2
 adecplacesauto 2 no
 rescale
 upscale 0 25
 bcolor 0.7 0 0 all

The result look as follows:


Dollar Exchange Rate Sample