Script en Perl per processar la sortida del hardware per fer ampero-voltimetrias de CH-Instruments
my ($dtmp,$gp_prefs,$dirname,$datafile,$ln,$line,$seg,$seg2,$segnum,$id,$plot,$title);
$dtmp= "temp";
$seg = $ARGV[1]+1;
$seg2 = $seg + 2;
print "\nLoading preferences...\n";
{ local $/ = undef; local *FILE; open FILE, ""; $gp_prefs = ; close FILE };
if ($#ARGV > -1) { $dirname = $ARGV[0]; }
else { die "No directory specified.\n"; };
opendir(DIR, $dirname) or die "can't opendir $dirname: $!";
while (defined($datafile = readdir(DIR))) {
next if $datafile =~ /^\.\.?$/;
next if $datafile !~ /\.txt$/;
$datafile =~ sopen (INP, "< $dirname/$datafile\0") || die "couldn't open $datafile for reading.\n";
mkdir $dtmp || die "Couldn't create temp directory.";
open (GPT, ">$dtmp/plot.gp") ||
die "couldn't open temporary files for writing.\n";
print "Extracting cycle ". ($seg - 1) ." from file: $datafile\n";
print GPT $gp_prefs;
print GPT "\nplot ";
while () {
if (/^Segment $seg:/ ... /^Segment $seg2:/) {
open (DAT, ">> $dtmp/$datafile-c$seg.dat");
print DAT "$_";
close (DAT);
};
};
close (INP);
$title = $datafile;
$title !~ s/\.txt//;
$plot.="\'$dtmp/$datafile-c$seg.dat\' using 1:2:3 title \"$title\" w l,";
}
closedir(DIR);
print GPT substr($plot, 0, -1);
close (GPT);
print "Creating graph...\n";
@args = ("gnuplot", "$dtmp/plot.gp");
system(@args) == 0
or die "system @args failed: $?";
print "Cleaning scratch files and directories\n";
`rm -fr $dtmp`;