#CreateAndPopulateAmazonDirStructure_Inventory_LDFR_20230619.plx # PROJECT $project='inv'; $amazondir='C:\\epa\\moves\\amazon20130603'; $year=2021; $vers='20231110'; $nonroad_counties="RepCos_2021_Inventory_20231110.txt"; #$scen=''; # BATCHSIZE -- NUMBER OF COUNTIES PER BATCH $batchsize=1; print "project = $project\n"; print "amazondir = $amazondir\n"; print "year = $year\n"; print "vers = $vers\n"; print "nonroad_counties = $nonroad_counties\n"; print "batchsize = $batchsize\n"; # 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 $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"; $zmhdb='2021nei_month_hour_for_nonroad_met'; $cdbdir="C:\\EPA_MOVES_5-19\\On-road\\$year\\InputDatabases\\CDBs_2021_20231108\\"; # MOVES driver output $runspectemplate_evp="samplerunspecs\\INV_MVS4_CY${year}_JulyOnly_evap.mrs"; $runspectemplate_starts="samplerunspecs\\INV_MVS4_CY${year}_allMonths_starts.mrs"; $runspectemplate_other="samplerunspecs\\INV_MVS4_CY${year}_JanJulOnly_nonevap_nonstart.mrs"; print "cdbdir = $cdbdir\n"; print "case = $case\n"; print "casevers = $casevers\n"; print "casepath = $casepath\n"; print "casedbs = $casedbs\n"; print "dbdir = $dbdir\n"; print "zmhdb = $zmhdb\n"; print "runspectemplate_evp = $runspectemplate_evp\n"; print "runspectemplate_starts = $runspectemplate_starts\n"; print "runspectemplate_other = $runspectemplate_other\n"; `md $casepath`; `md $casedbs`; # COPY CASE-LEVEL DATABASES foreach $xxx( "$dbdir $zmhdb", "$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`; } } open(nrcos1,"$nonroad_counties"); # COUNTY $cntycount=0; $batchno=0; foreach $xxx() { if(substr($xxx,0,1) eq '#'){next;} ($cntyfips,$sdb,$cdb)=split(/,/,$xxx); chomp($cdb); $state=substr($cdb,1,2); print "state = $state\n"; $cntycount=$cntycount+1; print "cntyfips, sdb, cdb = $cntyfips, $sdb, $cdb\n"; # First element of batch print "cntycount = $cntycount\n"; if($cntycount%$batchsize==1 or $batchsize==1){ $batchno = $batchno+1; $batch=$casevers."_batch".sprintf("%04d",$batchno); $batchpath="$casepath\\$batch"; $batchdbs="$batchpath\\databases"; print "mod=1: cntycount = $cntycount\n"; print "mod=1: cntyfips= $cntyfips\n"; print "mod=1: batchno = $batchno\n"; print "mod=1: batch = $batch\n"; print "mod=1: batchpath = $batchpath\n"; print "mod=1: batchdbs = $batchdbs\n"; # Create folder batchpath and transfer batch-specific databases. # Create folder batchdatabases and transfer batch-specific databases. `md $batchpath`; `md $batchdbs`; } print "cntycount = $cntycount\n"; print "cntyfips= $cntyfips\n"; print "batchno = $batchno\n"; print "batch = $batch\n"; print "batchpath = $batchpath\n"; print "batchdbs = $batchdbs\n"; # Create batch county or state level databases folder and copy CDBs or SDBs if($sdb ne ''){ `xcopy $cdbdir\\$sdb $batchdbs\\$sdb /I/S/Y/D/Q`; } if($cdb ne ''){ `xcopy $cdbdir\\$cdb $batchdbs\\$cdb /I/S/Y/D/Q`; } # JOB $jobcount=0; foreach $xxx ( "evp $runspectemplate_evp", "start $runspectemplate_starts", "other $runspectemplate_other", ) { ($runspectype,$runspectemplate)=split(/ /,$xxx); print "runspectype = $runspectype\n"; print "runspectemplate = $runspectemplate\n"; $jobcount=$jobcount+1; if($runspectype eq 'evp'){ $job="c".sprintf("%05d",$cntyfips)."_${year}_${runspectype}"; $jobpath="$batchpath\\$job"; print "job = $job\n"; print "jobpath = $jobpath\n"; `md $jobpath`; # Create jobdatabases folder and copy jobdatabases `md $jobpath\\databases`; #if($sdb ne ''){ # `xcopy $cdbdir\\$sdb $jobpath\\databases\\$sdb /I/S/Y/D/Q`; #} #if($cdb ne ''){ # `xcopy $cdbdir\\$cdb $jobpath\\databases\\$cdb /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. open (in1,"$runspectemplate"); open (out1,">$jobpath\\$job.mrs"); while () { # SET COUNTY if (m/geographicselection type="COUNTY"/){ s//; } # SET OUTPUT DB if (m/outputdatabase/){ s/databasename=".*description/databasename="standardoutput" description/; } # SET CDB if (m/scaleinputdatabase/){ s/databasename=".*description/databasename="$cdb" description/; } # Replace databaseselections block if (m//){ print out1; $indbs=1; # zonemonthhour print out1 " \n"; # fuels # print out1 " \n"; #if($sdb ne ''){ # print out1 " \n"; #} #if($cdb ne ''){ # print out1 " \n"; #} # OTAQ database with Construction and Agricultural surrogates and populations # print out1 " \n"; # rhoffdb #if ($rhoffdb ne ''){ # print out1 " \n"; #} # 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;} } if ($lev==1){ print out1 " \n"; } 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); } # ENDIF for RunSpec Type 'evp' if($runspectype eq 'start'){ $monthcount=0; foreach $month( '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', ){ $monthcount=$monthcount+1; print "month = $month\n"; $job="c".sprintf("%05d",$cntyfips)."_${year}_${month}_${runspectype}"; $jobpath="$batchpath\\$job"; print "job = $job\n"; print "jobpath = $jobpath\n"; `md $jobpath`; # Create jobdatabases folder and copy jobdatabases `md $jobpath\\databases`; #if($sdb ne ''){ # `xcopy $cdbdir\\$sdb $jobpath\\databases\\$sdb /I/S/Y/D/Q`; #} #if($cdb ne ''){ # `xcopy $cdbdir\\$cdb $jobpath\\databases\\$cdb /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. open (in1,"$runspectemplate"); open (out1,">$jobpath\\$job.mrs"); while () { # SET COUNTY if (m/geographicselection type="COUNTY"/){ s//; } # SET MONTH if (m/month id="1"/){ s/1/$month/; } # SET OUTPUT DB if (m/outputdatabase/){ s/databasename=".*description/databasename="standardoutput" description/; } # SET CDB if (m/scaleinputdatabase/){ s/databasename=".*description/databasename="$cdb" description/; } # Replace databaseselections block if (m//){ print out1; $indbs=1; # zonemonthhour print out1 " \n"; # fuels # print out1 " \n"; #if($sdb ne ''){ # print out1 " \n"; #} #if($cdb ne ''){ # print out1 " \n"; #} # OTAQ database with Construction and Agricultural surrogates and populations # print out1 " \n"; # rhoffdb #if ($rhoffdb ne ''){ # print out1 " \n"; #} # 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;} } if ($lev==1){ print out1 " \n"; } 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); } # END MONTH loop for RunSpec Type 'start' } # ENDIF for RunSpec Type 'start' if($runspectype eq 'other'){ $monthcount=0; foreach $month( '1', '7', ){ $monthcount=$monthcount+1; print "month = $month\n"; $job="c".sprintf("%05d",$cntyfips)."_${year}_${month}_${runspectype}"; $jobpath="$batchpath\\$job"; print "job = $job\n"; print "jobpath = $jobpath\n"; `md $jobpath`; # Create jobdatabases folder and copy jobdatabases `md $jobpath\\databases`; #if($sdb ne ''){ # `xcopy $cdbdir\\$sdb $jobpath\\databases\\$sdb /I/S/Y/D/Q`; #} #if($cdb ne ''){ # `xcopy $cdbdir\\$cdb $jobpath\\databases\\$cdb /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. open (in1,"$runspectemplate"); open (out1,">$jobpath\\$job.mrs"); while () { # SET COUNTY if (m/geographicselection type="COUNTY"/){ s//; } # SET MONTH if (m/month id="1"/){ s/1/$month/; } # SET OUTPUT DB if (m/outputdatabase/){ s/databasename=".*description/databasename="standardoutput" description/; } # SET CDB if (m/scaleinputdatabase/){ s/databasename=".*description/databasename="$cdb" description/; } # Replace databaseselections block if (m//){ print out1; $indbs=1; # zonemonthhour print out1 " \n"; # fuels # print out1 " \n"; #if($sdb ne ''){ # print out1 " \n"; #} #if($cdb ne ''){ # print out1 " \n"; #} # OTAQ database with Construction and Agricultural surrogates and populations # print out1 " \n"; # rhoffdb #if ($rhoffdb ne ''){ # print out1 " \n"; #} # 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;} } if ($lev==1){ print out1 " \n"; } 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); } # END MONTH loop for RunSpec Type 'other' } # ENDIF for RunSpec Type 'other' } # 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 close(nrcos1);