# CreateAndPopulateAmazonDirStructureSmokeMoves_LDFR_20230615.plx # PROJECT $project='rates'; $zmhproj='2021'; $amazondir='C:\\epa\\moves\\amazon20130603'; $year=2021; $vers=20231108; $repcdblist="RepCos_2021_20231108.txt"; #$scen=''; # CASE #$case="$project-$year-$scen"; # for when the case includes a scen & year #$case="$project"; # for when the case does not include a scen & year $case="$project-$year"; # for when the case does not include a scen #$case="$project-$scen"; $casevers="${case}-$vers"; $casepath="c:\\EPA_MOVES_5-19\\On-road\\$year\\AmazonStructure\\$casevers"; $casedbs="$casepath\\databases_$casevers"; $dbdir="c:\\EPA_MOVES_5-19\\On-road\\$year\\InputDatabases"; $runspecgenyear=2021; # This can be different from $year # As of MOVES4, rhoff is done via the default database (truncated noxHumidityAdjust table) #$rhoffdb='nonoxadj_moves3'; $cdbdir="c:\\EPA_MOVES_5-19\\On-road\\$year\\InputDatabases\\CDBs_2021_20231108"; # MOVES driver output # The runspecs have same names as the base year+significant editing below. # Zonemonthhour is the same as base year. $zmhoutput="c:\\EPA_MOVES_5-19\\On-road\\$zmhproj\\SmokeMovesRunSpecGenerator_${zmhproj}\\${zmhproj}_zmh"; $rdrunspectemplate="samplerunspecs\\RD_Main_MVS4_$year.mrs"; # Main RD run has everything except Evaps and Refueling $rerunspectemplate="samplerunspecs\\RD_EvRf_MVS4_$year.mrs"; # New RD run has only Evaps & Refueling on roads 2,3,4,5 $rprunspectemplate="samplerunspecs\\RP_MVS4_$year.mrs"; $rvrunspectemplate="samplerunspecs\\RV_MVS4_$year.mrs"; print "project = $project\n"; print "amazondir = $amazondir\n"; print "dbdir = $dbdir\n"; #print "scen = $scen\n"; print "year = $year\n"; print "runspecgenyear = $runspecgenyear\n"; print "vers = $vers\n"; #print "rhoffdb = $rhoffdb\n"; print "repcdblist = $repcdblist\n"; print "cdbdir = $cdbdir\n"; print "case = $case\n"; print "casevers = $casevers\n"; print "casepath = $casepath\n"; print "casedbs = $casedbs\n"; print "zmhoutput = $zmhoutput\n"; print "rdrunspectemplate = $rdrunspectemplate\n"; print "rerunspectemplate = $rerunspectemplate\n"; print "rprunspectemplate = $rprunspectemplate\n"; print "rvrunspectemplate = $rvrunspectemplate\n"; `mkdir $casepath`; `mkdir $casedbs"`; # COPY CASE-LEVEL DATABASES foreach $xxx( #"$dbdir $rhoffdb", "$dbdir\\LEV lev_06_20220824", "$dbdir\\LEV lev_09_20220824", "$dbdir\\LEV lev_10_20220824", "$dbdir\\LEV lev_23_20220824", "$dbdir\\LEV lev_24_20220824", "$dbdir\\LEV lev_25_20220824", "$dbdir\\LEV lev_34_20220824", "$dbdir\\LEV lev_36_20220824", "$dbdir\\LEV lev_41_20220824", "$dbdir\\LEV lev_42_20220824", "$dbdir\\LEV lev_44_20220824", "$dbdir\\LEV lev_50_20220824", "$dbdir\\LEV lev_53_20220824", "$dbdir\\LEV nlev_09_20220824", "$dbdir\\LEV nlev_10_20220824", "$dbdir\\LEV nlev_11_20220824", "$dbdir\\LEV nlev_24_20220824", "$dbdir\\LEV nlev_33_20220824", "$dbdir\\LEV nlev_34_20220824", "$dbdir\\LEV nlev_42_20220824", "$dbdir\\LEV nlev_44_20220824", "$dbdir\\LEV nlev_51_20220824", ){ ($dbpath,$db)=split(/ /,$xxx); print "dbpath = $dbpath\n"; print "db = $db\n"; print "Case-level DB = $db\n"; if (-d "$casedbs\\$db") { print 'Line '.__LINE__.". DB $db already exists; not copied.\n"; } else { # Include only mysql tables by specifying the extensions `xcopy $dbpath\\$db\\*.frm $casedbs\\$db /I/S/Y/D/Q`; `xcopy $dbpath\\$db\\*.MYD $casedbs\\$db /I/S/Y/D/Q`; `xcopy $dbpath\\$db\\*.MYI $casedbs\\$db /I/S/Y/D/Q`; } } # COUNTY $cntycount=0; open(cdb1,"$repcdblist"); foreach $xxx() { if(substr($xxx,0,1) eq '#'){next;} $cntycount=$cntycount+1; print "cntycount = $cntycount\n"; #if($cntycount>1){last;} # Limit to one county for diagnostics if(substr($xxx,0,1) eq '#'){next;} #($cnty,$cdbvers,$janrvpbin,$julrvpbin)=split(/ /,$xxx); ($cnty,$cdbvers)=split(/ /,$xxx); chomp($cnty); chomp($cdbvers); # COUNTY DATABASE: $cdb="c${cnty}y${year}_$cdbvers"; $state=substr($cnty,0,2); print "cnty = $cnty\n"; print "cdbvers = $cdbvers\n"; print "cdb = $cdb\n"; print "state = $state\n"; $monthcount=0; foreach $month( '1', '7' ){ $monthcount=$monthcount+1; #if($monthcount>1){last;} # Diagnostic limit to one month print "month = $month\n"; #if($month==1){$rvpbin=$janrvpbin} #elsif($month==7){$rvpbin=$julrvpbin} $batchzmh="${zmhproj}_${cnty}_$month"; #$batchzmh="${project}_${cnty}_$month"; # Normally OK #$batchzmh="nei2016v2_${cnty}_$month"; # Needed for Pre-RFS 2016 #$batchzmh="nei2011v2_${cnty}_$month"; #$batchzmh="2007pfbase2007_${cnty}_$month"; # Needed for 2007PF $batch="${casevers}_${cnty}_$month"; $batchpath="$casepath\\$batch"; $batchdbs="$batchpath\\databases"; print "month = $month\n"; #print "rvpbin = $rvpbin\n"; print "batchzmh = $batchzmh\n"; print "batch = $batch\n"; print "batchpath = $batchpath\n"; print "batchdbs = $batchdbs\n"; # Create folder batchpath and transfer batch-specific databases. # Create folder batchdatabases and transfer batch-specific databases. # Commented out if already done. `md $batchpath`; `md $batchdbs`; # LEV $lev=0; foreach $st( '06','09','10','23','24','25','34','36','41','42','44','50','53', ){ if($state eq $st){$lev=1;} } # NLEV $nlev=0; foreach $st( '09','10','11','24','33','34','42','44','51', ){ if($state eq $st){$nlev=1;} } # STATE-WIDE VMT AND POP #$stvmtpop=0; #foreach $st('01','04','05','06','08','12','18','19','20','21','22','28','30','31', # '32','35','36','38','39','40','41','46','47','48','54','56', # ){ # if($state eq $st){$stvmtpop=1;} #} # COPY BATCH COUNTY-LEVEL DATABASES if (-d "$batchdbs\\$cdb") { print 'Line '.__LINE__.". DB $cdb already exists; not copied.\n"; } else { `xcopy $cdbdir\\$cdb $batchdbs\\$cdb /I/S/Y/D/Q`; } # JOB $jobcount=0; $zmhpath="$zmhoutput\\${zmhproj}_${cnty}_${month}"; print "zmhpath = $zmhpath\n"; foreach $zmhdb (`dir /b $zmhpath`) { print "zmhdb = $zmhdb\n"; $jobcount=$jobcount+1; #if($jobcount>1){last;} # Limit to one job for diagnostics chomp($zmhdb); $zmhdb=lc($zmhdb); # Convert to lower case $ratetype=substr($zmhdb,0,2); print "ratetype = $ratetype\n"; # DETERMINE THE NUMBER OF HOURS NEEDED IN RD RUNSPECS # The reason for this is to not repeat temperatures unnecessarily. if($ratetype eq 'rd'){ ($a1,$a2,$a3,$a4,$tlow,$thigh,$a7)=split(/_/,$zmhdb); # Eliminate initial t or tn if(substr($tlow,0,2) eq 'tn'){ $tlow=substr($tlow,2,10); # Eliminate inital tn $tlow=-1.*$tlow; # Re-establish sign } else {$tlow=substr($tlow,1,10);} # Eliminate initial t $rdendhour=($thigh-$tlow)/5+1; print "thigh, tlow, rdendhour = $thigh, $tlow, $rdendhour\n"; $runspectemplate=$rdrunspectemplate; } elsif($ratetype eq 'rv') {$runspectemplate=$rvrunspectemplate;} elsif($ratetype eq 'rp') {$runspectemplate=$rprunspectemplate;} else {die "Unknown ratetype $ratetype\n";} # Peel off the trailing _zmh: # Make job lower case and substitute tn for t- $job05=substr($zmhdb,0,-4); $job05=lc($job05); $_=$job05; s/t-/tn/; $job05=$_; s/_${runspecgenyear}_/_${year}_/; $job=$_; $jobpath="$batchpath\\$job"; if($ratetype eq 'rd'){ $job21=substr($zmhdb,3,-4); $job21="re_${job21}"; $job21=lc($job21); $_=$job21; s/t-/tn/; $job21=$_; s/_${runspecgenyear}_/_${year}_/; $job2=$_; $jobpath2="$batchpath\\$job2"; } print "zmhdb = $zmhdb\n"; print "job05 = $job05\n"; print "jobpath = $jobpath\n"; if($ratetype eq 'rd'){ print "job2 = $job2\n"; print "jobpath2 = $jobpath2\n"; `md $jobpath2`; `md $jobpath2\\databases`; } `md $jobpath`; # Create jobdatabases folder and copy jobdatabases `md $jobpath\\databases`; `xcopy $zmhoutput\\$batchzmh\\$zmhdb $jobpath\\databases\\$zmhdb /I/S/Y/D/Q`; if($ratetype eq 'rd'){ `xcopy $jobpath\\databases\\$zmhdb $jobpath2\\databases\\$zmhdb /I/S/Y/D/Q`; } # EDIT RUNSPECS INTO APPROPRIATE DIRECTORY # Input database name has been commented out for increased flexibility. # It is blank in the moves driver script output, and # we could change the database without having to re-jar the job. if (-f "$jobpath\\$job.mrs") { print "runspec $jobpath\\$job.mrs already exists.\n"; } else { open (in1,"$runspectemplate"); open (out1,">$jobpath\\$job.mrs"); #if($ratetype eq 'rd'){ # open (out2,">$jobpath2\\$job2.mrs"); #} $inpp=0; # inside pollutantprocessassociations block $inveh=0; # inside onroadvehicleselections block while () { # SET COUNTY if (m/geographicselection type="COUNTY"/){ s//; } # SET MONTH if (m/month id="1"/){ s/1/$month/; } # SET CDB if (m/scaleinputdatabase/){ s/databasename=".*description/databasename="$cdb" description/; } if($ratetype eq 'rd'){ s/endhour id="24"/endhour id="$rdendhour"/; } if (m/outputdatabase/){ s/databasename=".*description/databasename="standardoutput" description/; } if (m/scenarioid/){ s/scenarioid=".*"/scenarioid="$job"/; } # Replace databaseselections block if (m//){ print out1; $indbs=1; # zonemonthhour print out1 " \n"; # rhoffdb #if ($rhoffdb ne ''){ # print out1 " \n"; #} # LEV if ($lev==1){ print out1 " \n"; } # NLEV if ($nlev==1){ print out1 " \n"; } #if($ratetype eq 'rd'){ #print out2; #$indbs=1; ## zonemonthhour # print out2 " \n"; ## rhoffdb # if ($rhoffdb ne ''){ # print out2 " \n"; #} ## LEV # if ($lev==1){ # print out2 " \n"; #} ## NLEV # if ($nlev==1){ # print out2 " \n"; # } # } next; # Go to next line without printing if still in databaseselections } if (m/<\/databaseselections>/){ $indbs=0; print out1; next; } #if($ratetype eq 'rd'){ # if (m/<\/databaseselections>/){ # $indbs=0; # print out2; # next; # } #} if ($indbs) {next;} # Go to next line without printing if still in databaseselections print out1; # if($ratetype eq 'rd'){ # print out2; #} } close(in1); close(out1); #if($ratetype eq 'rd'){ # close(out2); #} } # ELSE # EDIT NEW RD EVAP & REFUELING ONLY RUNSPECS INTO APPROPRIATE RE* DIRECTORY if($ratetype eq 'rd'){ $runspectemplate=$rerunspectemplate; if (-f "$jobpath2\\$job2.mrs") { print "runspec $jobpath2\\$job2.mrs already exists.\n"; } else { open (in1,"$runspectemplate"); open (out1,">$jobpath2\\$job2.mrs"); $inpp=0; # inside pollutantprocessassociations block $inveh=0; # inside onroadvehicleselections block while () { # SET COUNTY if (m/geographicselection type="COUNTY"/){ s//; } # SET MONTH if (m/month id="1"/){ s/1/$month/; } # SET CDB if (m/scaleinputdatabase/){ s/databasename=".*description/databasename="$cdb" description/; } if($ratetype eq 'rd'){ s/endhour id="24"/endhour id="$rdendhour"/; } if (m/outputdatabase/){ s/databasename=".*description/databasename="standardoutput" description/; } if (m/scenarioid/){ s/scenarioid=".*"/scenarioid="$job"/; } # Replace databaseselections block if (m//){ print out1; $indbs=1; # zonemonthhour print out1 " \n"; # rhoffdb #if ($rhoffdb ne ''){ # print out1 " \n"; #} # LEV if ($lev==1){ print out1 " \n"; } # NLEV if ($nlev==1){ print out1 " \n"; } next; # Go to next line without printing if still in databaseselections } if (m/<\/databaseselections>/){ $indbs=0; print out1; next; } if ($indbs) {next;} # Go to next line without printing if still in databaseselections print out1; } close(in1); close(out1); } # ELSE } # JOB } # JARJOBS FOR EACH BATCH open(out2,">jarjobs.bat"); print out2 "call pushd $amazondir\n"; print out2 "call setenv\n"; print out2 "call ant -Dcmd=\"jarjobs batchdir $batchpath\" job\n"; print out2 "call popd\n"; close(out2); `call jarjobs.bat`; } # COUNTY } # MONTH close(cdb1);