Download revision 2014b

Transcript
CHAPTER 19. PRINTING—THE STAND-ALONE (SA-06) MODULERWD Nickalls
267
the program (using the system() command), writing appropriate comments to the
logfile as we go.
#[processdata.pl]
...
## check we are in the correct directory
print (logfile "the current dir is: \n");
$thisdir=cwd; ## grab the current working dir
print (logfile $thisdir,"\n");
## now call fields2PDATA.pl
$perlprog="fields2PDATA.pl";
print (logfile "CALLing program <",$perlprog,">");
if (-e $perlprog) {print "\n CALLing program ", $perlprog,"\n";
print (logfile "... OK...done\n");
system("perl ./"."$perlprog")}
else{print "...ERROR: can’t find file <$perlprog>\n";
print (logfile " ** ERROR: can’t find file <$perlprog>\n")};
c Determine the start-time
The first thing the fields2PDATA.pl script does is to determine the start-time by
reading the time associated with the first data point in each of the .binlog files in the
/fields/ directory, and selecting the earliest as defining the working start-time. Armed
with a working start-time, we can then determine an ‘elapsed-time’ for each data-event.
In practice these times are expressed as so-called Unix-time (seconds since 1st Jan
1970).
Each line of a typical .binlog file is a comma-separated data-pair, where the first
item is the Unix time, and the second item is the parameter value. An example of a
typical sat.binlog structure is as follows (sat.binlog).
## sat.binlog
1071580231,92
1071580236,92
1071580241,93
1071580246,93.5
1071580251,93
1071580256,93
1071580261,92.5
1071580266,92
...
...
The fields2PDATA.pl script starts by determining the earliest data entry time for
each of the .binlog files, and then setting this earliest time as the $starttimeunix
variable.
It does this by reading only the first Unix-time entry in each of the .binlog files
(reading each filename from an array of all such filenames), and determining the earliest
time. It also writes comments to the logfile so we can check its progress if we need to
investigate any errors.
#[fields2PDATA.pl]