# Demonstrating automatic control of a sequence with Perl # Stanley Humphries, Field Precision, Copyright 2008 # Find the potential of a floating line electrode using the # energy method # --------------------- # Section A: set up control parameters $VMin = 2000.0; $VMax = 10000.0; $NStep = 20; $dV = ($VMax-$VMin)/$NStep; $FilePrefix = "perl_demo"; # --------------------- # --------------------- # Section B: generate the mesh file (MOU) $status = system("c:/fieldp/tricomp/mesh",$FilePrefix); if ($status==0) { print "Mesh file created successfully\n"; } else { print "Error in mesh file creation\n"; exit; } # --------------------- # --------------------- # Section C: loop of potential values $FileNameIn = $FilePrefix . ".EIN"; for ($n=0;$n<($NStep+1);$n++) { $V = $VMin + $n*$dV; # --------------------- # Create the temporary script file with the current voltage open (InFile,"<",$FileNameIn); if ($n < 10) { $FileNameOut = $FilePrefix . "0" . $n . ".EIN"; $EFilePrefix = $FilePrefix . "0" . $n } else { $FileNameOut = $FilePrefix . $n . ".EIN"; $EFilePrefix = $FilePrefix . $n } open (OutFile,">",$FileNameOut); while () { $Line = $_; $Line =~ s/@/$V/; print OutFile $Line; } close InFile; close OutFile; # --------------------- # Generate the electrostatic solution $status = system("c:/fieldp/tricomp/estat",$EFilePrefix); # --------------------- # Erase the temporary script unlink($FileNameOut); } # --------------------- # --------------------- # Section D: run an EStat analysis script to calculate field energy $status = system("c:/fieldp/tricomp/estat","PERL_DEMO.SCR"); # --------------------- # --------------------- # Section E: abstract the information open (InFile,"<","perl_demo.dat"); open (OutFile,">","summary.dat"); $V = $VMin; while () { $Line = $_; if (m/Energy:/s) { print OutFile "Voltage: $V $Line"; $V = $V + $dV; } } close InFile; close OutFile; # --------------------- # --------------------- # Section F: clear the directory @filenames = glob("*.ELS"); unlink @filenames; @filenames = glob("*.EOU"); unlink @filenames; # --------------------- exit;