#!/usr/bin/perl use FileHandle; use File::Basename; use Getopt::Long; use List::Util qw(first max maxstr min minstr reduce shuffle sum); $npoly = 1; #default offset polynomial order $novr = 2; #default MLI oversampling factor $rlks = 1; $azlks = 1; $rpos = "-"; $azpos = "-"; $rflag = 0; $sc = 0.8; $exp = 0.4; $mflg = 0; #turn on generation MLI-1 in the geometry of MLI-2 by default $cflg = 0; $thres_mli = 0.15; #cross-correlation threshold for accepting MLI offset measurement $rwinm = 256; #MLI range patch size $azwinm = 256; #MLI azimuth patch size $patch = 1024; #init_offsetm patch size $uflag = 0; #do not run in update mode by default GetOptions ('e=f' => \$exp, 's=f' => \$sc, 'm' => \$mflg, 'c' => \$cflg, 'n=i' => \$npoly,'t=f' => \$thres_mli,'u' => \$uflag); if (($#ARGV + 1) < 8){die < [rflag] [rlks] [azlks] [rpos] [azpos] [patch] [thres_mli] MLI_tab (input) two-column list of MLI filenames and MLI parameter filenames (including paths) (text) ref_MLI (input) reference MLI (including path) ref_MLI_par (input) ISP image parameter file of the reference MLI (including path) DEM_rdc (input) DEM in Range-Doppler Coordinates with width and height as described in the MLI_par MLI_dir (input) directory containing MLI parameter files, same the same width and height as DEM_rdc. RMLI_dir directory to contain the resampled MLIs, lookup tables, ISP image parameter files, and log files RMLI_tab (output) RMLI_tab file for the resampled MLI files mode processing modes: 0: Generate lookup table and resample MLI-1 image into the geometry of MLI-2 optional: resample MLI-1 image into the geometry of MLI-2, with -m option, required for mode 1. 1: Refine lookup table based on measured offsets between MLI-1 resampled to the geometry of MLI-2 (optional) 2: Resample MLI-2 to the geometry of the reference MLI using lookup table 3: Create DIFF parameter files for MLI resampling refinement, measure offsets, and calculate the MLI residual offset fit polynomials 4: Resample MLI images using lookup table and refinement polynomials determined in mode 3 and generate RMLI_tab rflag flag for interative refinement of the resampled MLI: 0: Resample and measure residual range and azimuth offsets (default) 1: Interatively improve range and azimuth offset polynomials then measure residual offsets rlks number of range looks for initial MLI offset estimation (enter - for default: $rlks) azlks number of azimuth looks for initial MLI offset estimation (enter - for default: $azlks) rpos center of patch for initial MLI offset estimation range (samples) (enter - for default: image center) azpos center of patch for initial MLI offset estimation azimuth (lines) (enter - for default: image center) patch patch size for initial MLI offset estimate (enter - for default: $patch) thres_mli cross-correlation threshold to accept the MLI offset estimates (enter - for default: $thres_mli) -m (option) generate MLI-1 in geometry of MLI-2, required for optional refinement of lookup table using MLI-1 and MLI-2 -n npoly (option) number of terms in the range and azimuth offset polynomials (npoly: 1,3,4,6) (default: $npoly) -t thres (option) cross-correlation threshold to accept an MLI offset measurement (default: $thres_mli) -s scale (option) set image display scale factor (default: $sc) -e exp (option) set image display exponent (default: $exp) -c (option) clean up, delete intermediate results -u (option) update flag, coregister only new MLI scenes that have not yet been resampled EOS open(MLI_TAB, "<$ARGV[0]") or die "\nERROR $0: table of MLI images and parameter files does not exist: $ARGV[0]\n\n"; print "SLC_tab table of SLC images and parameter files: $ARGV[0]\n"; $ref_MLI = $ARGV[1]; $ref_MLI_par = $ARGV[2]; $dem_rdc = $ARGV[3]; $mli_dir = $ARGV[4]; $rmli_dir = $ARGV[5]; $RMLI_tab = $ARGV[6]; $mode = $ARGV[7]; ($mode >= 0 && $mode <= 4) or die "\nERROR $0: invalid mode for script: $mode\n\n"; print "$0 mode: $mode\n"; if($#ARGV >= 8){$rflag = $ARGV[8];} if($#ARGV >= 9){$rlks = $ARGV[9];} if($#ARGV >= 10){$azlks = $ARGV[10];} if($#ARGV >= 11){$rpos = $ARGV[11];} if($#ARGV >= 12){$azpos = $ARGV[12];} if($#ARGV >= 13){$patch = $ARGV[13];} if($#ARGV >= 14){$thres_mli = $ARGV[14];} printf "reference MLI: $ref_MLI\n"; printf "reference MLI parameter file: $ref_MLI_par\n"; printf "resampled MLI directory: $rmli_dir\n"; printf "DEM in range-Doppler coordinates: $dem_rdc\n"; printf "MLI data directory: $mli_dir\n"; printf "output table for resampled MLIs: $RMLI_tab\n\n"; -e $ref_MLI or die "\nERROR $0: reference SLC does not exist: $ref_MLI\n"; -e $ref_MLI_par or die "\nERROR $0: ISP image parameter file of the reference MLI does not exist: $ref_MLI_par\n"; -d $mli_dir or die "\nERROR $0: directory containing MLI images and parameter files does not exist: $mli_dir\n"; -e $dem_rdc or die "\nERROR $0: DEM in range doppler coordinates does not exist: $dem_rdc\n"; unless (-d $rmli_dir){ print "creating resampled MLI directory: $rmli_dir\n"; (mkdir $rmli_dir) or die "ERROR $0: non-zero exit status, could not create SLC data directory $rmli_dir\n"; } $log = "$rmli_dir/MLI_resamp_lt_all"."_$mode".".log"; open(LOG,">$log") or die "ERROR $0: cannot open log file: $log\n"; LOG->autoflush; print LOG "$0 @ARGV\n\n"; #print command line that was used $time = localtime; print LOG "*** $0 processing start: $time ***\n"; print "*** $0 processing start: $time ***\n"; print "log file: $log\n"; my ($s1, $dir1, $ext1) = fileparse($ref_MLI, qr/\.[^.]*/); #extension is the last bit after the last period $ref_id = $s1; $ref_mli = "$rmli_dir/$s1.rmli"; $ref_par = "$rmli_dir/$s1.rmli.par"; close LOG; unless (-e $ref_mli) { #copy reference mli and mli parameter file if they do not yet exist execute("cp $ref_MLI $ref_mli",$log); } unless (-e $ref_par){ execute("cp $ref_MLI_par $ref_par",$log); } @mli1_width = extract_param($ref_MLI_par,"range_samples:"); @mli1_lines = extract_param($ref_MLI_par,"azimuth_lines:"); @mli1_rlks = extract_param($ref_MLI_par,"range_looks:"); @mli1_azlks = extract_param($ref_MLI_par,"azimuth_looks:"); execute("raspwr $ref_mli $mli1_width[1] 1 0 1 1 $sc $exp", $log); open(LOG,">>$log") or die "ERROR $0: cannot open log file: $log\n"; LOG->autoflush; $nrpm = min(int($mli1_width[1]/($rwinm/2) + 0.5), 128); #number of range and azimuth patches for MLI matching if ($nrpm < 16) { $nrpm = 16; } $nazpm = min(int($mli1_lines[1]/($azwinm/2) + 0.5), 128); if ($nazpm < 16) { $nazpm = 16; } if ($rpos eq "-") { $rpos = int($mli1_width[1]/2); } if ($azpos eq "-") { $azpos = int($mli1_lines[1]/2); } ($s1, $dir1, $ext1) = fileparse($ref_MLI_par, qr/\.[^.]*/); #extension is the last bit after the last period $ref_MLI = $dir1."/".$s1; $time = localtime; print "resampled RMLI data directory: $rmli_dir\n"; print "reference MLI: $ref_MLI\n"; print "reference MLI parameters: $ref_MLI_par\n"; print "reference MLI range samples: $mli1_width[1] azimuth lines: $mli1_lines[1]\n"; print "MLI range patch size: $rwinm azimuth patch size: $azwinm\n"; print "number of MLI range patches: $nrpm azimuth patches: $nazpm\n"; print "cross-correlation threshold to accept MLI offset measurement: $thres_mli\n"; print "output RMLI_tab file: $RMLI_tab\n"; ($rflag == 0) or print "rflag = 1: measuring offsets relative to the resampled MLI to improve the offset model\n"; print "reference MLI range looks: $mli1_rlks[1] azimuth looks: $mli1_azlks[1]\n"; if ($mode == 1) { print "initial MLI offset patch center coordinates range: $rpos azimuth: $azpos\n"; print "initial MLI offset patch size: $patch\n"; print "MLI range patch size: $rwinm azimuth patch size: $azwinm\n"; print "number of MLI range patches: $nrpm azimuth patches: $nazpm\n"; print "cross-correlation threshold to accept MLI offset measurement: $thres_mli\n"; } print LOG "resampled RMLI data directory:$rmli_dir\n"; print LOG "reference MLI: $ref_MLI\n"; print LOG "reference MLI parameters: $ref_MLI_par\n"; print LOG "reference MLI range samples: $mli1_width[1] azimuth lines: $mli1_lines[1]\n"; print LOG "MLI range patch size: $rwinm azimuth patch size: $azwinm\n"; print LOG "number of SLC range patches: $nrpm azimuth patches: $nazpm\n"; print LOG "cross-correlation threshold to accept MLI offset measurement: $thres_mli\n"; print LOG "output RMLI_tab file: $RMLI_tab\n"; ($rflag == 0) or print LOG "rflag = 1: measuring offsets relative to the resampled MLI to improve the offset model\n"; print LOG "reference MLI range looks: $mli1_rlks[1] azimuth looks: $mli1_azlks[1]\n"; if ($mode == 1) { print LOG "initial MLI offset patch center coordinates range: $rpos azimuth: $azpos\n"; print LOG "initial MLI offset patch size: $patch\n"; print LOG "MLI range patch size: $rwinm azimuth patch size: $azwinm\n"; print LOG "number of MLI range patches: $nrpm azimuth patches: $nazpm\n"; print LOG "cross-correlation threshold to accept MLI offset measurement: $thres_mli\n"; } if ($uflag == 1) { printf "update flag: %d resampling newly added SLCs\n",$uflag; printf LOG "update flag: %d resampling newly added SLCs\n",$uflag; } else { printf "update flag: %d resampling all MLIs\n",$uflag; printf LOG "update flag: %d resampling all MLIs\n",$uflag; } close LOG; open(OFFINP, ">create_diff_par.in") or die "ERROR $0: cannot create file with inputs to create_diff_par: create_diff_par.in\n"; print OFFINP "MLI offset parameters\n0 0\n$nrpm $nazpm\n$rwinm $azwinm\n$thres_mli\n0\n"; close OFFINP; $k = 0; LINE: while () { #read lines of processing list file $time = localtime; chomp $_; #remove new line from record next LINE if /^$/; #skip blank lines in processing list next LINE if /^#/; #skip comments in processing list @fields = split; #extract the scene identifier and other parameters on the line if present $mli2 = $fields[0]; $mli2_par = $fields[1]; -e $mli2_par or die "ERROR $0: ISP image parameter file does not exist for mli2: $mli2_par\n"; -e $mli2 or die "ERROR $0: mli2 image file does not exist: $mli2\n"; my ($s2, $dir2, $ext2) = fileparse($mli2, qr/\.[^.]*/); #extension is the last bit after the last period $rmli = "$rmli_dir/$s2.rmli"; $rmli_par = "$rmli_dir/$s2.rmli.par"; $mli2_id = $s2; $mli1_par = $ref_MLI_par; $mli2 = "$mli_dir/$mli2_id.mli"; unless (-e $mli2){ $mli2 = "$mli_dir/$mli2_id.rmli"; } $mli2_par = "$mli_dir/$mli2_id.mli.par"; unless (-e $mli2_par){ $mli2_par = "$mli_dir/$mli2_id.rmli.par"; } @mli2_width = extract_param($mli2_par,"range_samples:"); @mli2_lines = extract_param($mli2_par,"azimuth_lines:"); if($ref_id eq $mli2_id){ #if MLI-2 is the reference scene, jump to the next scene next; } $k = $k + 1; $id = $ref_id."_".$mli2_id; $diff_par = "$rmli_dir/$id.diff_par"; #offset parameter file for offset parameters between MLI data $lt0 = "$rmli_dir/$id.lt0"; #initial lookup table $lt1 = "$rmli_dir/$id.lt1"; #refined lookup table $offs = "$rmli_dir/$id.offs"; #MLI offsets $ccp = "$rmli_dir/$id.ccp"; #cross-correlation for resampled MLI offsets $coffs = "$rmli_dir/$id.coffs"; #culled offsets $offs_lt0 = "$rmli_dir/$id"."_lt0.offs"; #binary MLI offsets $coffs_lt0 = "$rmli_dir/$id"."_lt0.coffs"; #culled binary MLI offsets $ccp_lt0 = "$rmli_dir/$id"."_lt0.ccp"; #cross-correlation for MLI offsets $mli1_lt0 = $rmli_dir."/".$id."_lt0.mli"; #reference MLI-1 resampled into geometry of MLI-2 $diff_par_lt0 = $rmli_dir."/".$id."_lt0.diff_par"; $diff_par_lt0_in = $diff_par_lt0.".in"; $log = "$rmli_dir/".$id."_resamp_lt.log"; print "\n*** MLI #$k ref. MLI: $ref_mli MLI-2: $mli2 start time: $time ***\n"; print "MLI_resamp_lt_all log file: $log\n"; print "resampled RMLI data directory: $rmli_dir\n"; print "reference MLI: $ref_mli\n"; print "reference MLI parameters: $ref_par\n"; print "MLI-2: $mli2\n"; print "MLI-2 parameter file: $mli2_par\n"; print "MLI-2 range samples: $mli2_width[1] azimuth lines: $mli2_lines[1]\n"; print "MLI DIFF_par parameter file: $diff_par\n"; if ($mode == 1){ print "MLI-2: $mli2\n" ; print "MLI-2 parameter file: $mli2_par\n"; print "MLI-2 range samples: $mli2_width[1]\n"; print "initial MLI offset looks range: $rlks azimuth: $azlks\n"; print "lookup table refinement DIFF_par: $diff_par_lt0\n"; print "reference MLI image resampled into geometry of MLI-2: $mli1_lt0\n"; print "cross-correlation threshold for MLI offsets: $thres_mli\n"; print "initial lookup table: $lt0\n"; print "refined lookup table using MLI image offset model: $lt1\n"; } open(LOG,">>$log") or die "ERROR $0: cannot open SLC_interp_lt_all log file: $log\n"; print LOG "MLI_resamp_lt_all log file: $log mode: $mode\n"; print LOG "resampled RMLI data directory: $rmli_dir\n"; print LOG "reference MLI: $ref_mli\n"; print LOG "reference MLI parameters: $ref_par\n"; print LOG "reference MLI: $ref_MLI\n"; print LOG "reference MLI parameters: $ref_MLI_par\n"; print LOG "MLI-2: $mli2\n"; print LOG "MLI-2 parameter file: $mli2_par\n"; print LOG "MLI-2 range samples: $mli2_width[1] azimuth lines: $mli2_lines[1]\n"; print LOG "MLI DIFF_par parameter file: $diff_par\n"; if ($mode == 1){ print LOG "MLI-2: $mli2\n" ; print LOG "MLI-2 parameter file: $mli2_par\n"; print LOG "MLI-2 range samples: $mli2_width[1]\n"; print LOG "initial MLI offset looks range: $rlks azimuth: $azlks\n"; print LOG "lookup table refinement DIFF_par: $diff_par_lt0\n"; print LOG "reference MLI image resampled into geometry of MLI-2: $mli1_lt0\n"; print LOG "cross-correlation threshold for MLI offsets: $thres_mli\n"; print LOG "initial lookup table: $lt0\n"; print LOG "refined lookup table using MLI image offset model: $lt1\n"; } close LOG; if($mode == 0){ if ($mflg == 1) { if ((-e $lt0) and (-e $mli1_lt0) and ($uflag == 1)){ next LINE; } } else { if ((-e $lt0) and ($uflag == 1)){ next LINE; } } print "\nmode 0: Generate lookup table (MLI-2 into geometry of MLI-1), with option -m: resample MLI-1 image into the geometry of MLI-2\n"; execute("rdc_trans $ref_MLI_par $dem_rdc $mli2_par $lt0", $log); if($mflg == 1){ #resample reference MLI image into the geometry of MLI-2 execute("geocode $lt0 $ref_MLI $mli1_width[1] $mli1_lt0 $mli2_width[1] $mli2_lines[1] 0 0 - -", $log); execute("raspwr $mli1_lt0 $mli2_width[1] 1 0 1 1 $sc $exp", $log); } } if ($mode == 1){ if ((-e $lt1) and (-e $diff_par_lt0) and ($uflag == 1)){ next LINE; } print "\nmode 1: Refine lookup table values based on measured offsets between MLI-1 resampled to the geometry of MLI-2\n"; -e $mli1_lt0 or die "\nERROR: missing resampled MLI-1 in MLI-2 geometry, generate these images running mode 0 using the -m option\n"; print "creating DIFF/GEO parameter file: $diff_par_lt0\n"; if(-e $diff_par_lt0){ print "deleting $diff_par_lt0\n"; unlink $diff_par_lt0; #delete existing DIFF/GEO offset parameter file } open(DPAR, "> $diff_par_lt0_in") or die "ERROR $0: cannot create file with inputs to create_diff_par: $diff_par_lt0_in\n\n"; print DPAR "$id\n0 0\n$nrpm $nazpm\n$rwinm $azwinm\n$thres_mli\n"; close DPAR; execute("create_diff_par $mli2_par - $diff_par_lt0 1 < $diff_par_lt0_in", $log); printf("\n"); execute("init_offsetm $mli1_lt0 $mli2 $diff_par_lt0 $rlks $azlks $rpos $azpos - - $thres_mli $patch", $log); execute("offset_pwrm $mli1_lt0 $mli2 $diff_par_lt0 $offs_lt0 $ccp_lt0 - - - 2 - - $thres_mli", $log); execute("offset_fitm $offs_lt0 $ccp_lt0 $diff_par_lt0 $coffs_lt0 - $thres_mli $npoly", $log); @rpolym = extract_param($diff_par_lt0,"range_offset_polynomial:"); @azpolym = extract_param($diff_par_lt0,"azimuth_offset_polynomial:"); print "\nMLI offset refinement polynomials:\n"; print "@rpolym\n"; print "@azpolym\n\n"; execute("gc_map_fine $lt0 $mli1_width[1] $diff_par_lt0 $lt1", $log); } if ($mode == 2){ if ((-e $rmli) and (-e $rmli_par) and ($uflag == 1)){ next LINE; } print "\nmode 2: Resample MLI-2 into the geometry of the reference MLI using the lookup table\n"; if (-e $lt1) { execute("MLI_interp_lt $mli2 $ref_par $mli2_par $lt1 $ref_MLI_par $mli2_par - $rmli $rmli_par", $log); } else { print "NOTE: Refined lookup table derived from MLI offsets (mode 1) does not exist, using initial lookup table: $lt0\n"; execute("MLI_interp_lt $mli2 $ref_par $mli2_par $lt0 $ref_MLI_par $mli2_par - $rmli $rmli_par", $log); } execute("raspwr $rmli $mli1_width[1] 1 0 1 1 $sc $exp", $log); } if ($mode == 3){ if ((-e $diff_par) and ($uflag == 1)){ next LINE; } print "\nmode 3: Create offset parameter files for MLI resampling refinement, measure offsets, and calculate the MLI offset fit polynomials\n"; if (-e $diff_par) { print "deleting $diff_par\n"; unlink $diff_par; } execute("create_diff_par $ref_par $mli2_par $diff_par 1 < create_diff_par.in",$log); print "\n"; execute("offset_pwrm $ref_mli $rmli $diff_par $offs $ccp - - - $novr - - $thres_mli", $log); execute("offset_fitm $offs $ccp $diff_par $coffs - $thres_mli $npoly", $log); @rpoly = extract_param($diff_par,"range_offset_polynomial:"); @azpoly = extract_param($diff_par,"azimuth_offset_polynomial:"); print "\nMLI offset polynomials:\n"; print "@rpoly\n"; print "@azpoly\n\n"; } if($mode == 4){ #now apply refinement from offset parameter file $diff_par2 = "$rmli_dir/$id"."_2.diff_par"; $offs2 = "$rmli_dir/$id"."_2.offs"; #binary offsets $coffs2 = "$rmli_dir/$id"."_2.coffs"; #culled offsets $ccp2 = "$rmli_dir/$id"."_2.ccp"; if ((-e $diff_par2) and (-e $rmli) and (-e $rmli_par) and ($uflag == 1)){ next LINE; } print "\nmode 4: Resample MLI-2 images using the lookup table and refinement polynomials determined in mode 3, and generate the RMLI_tab\n"; if (-e $lt1) { execute("MLI_interp_lt $mli2 $ref_par $mli2_par $lt1 $mli1_par $mli2_par $diff_par $rmli $rmli_par", $log); } else { print "NOTE: refined lookup table derived from MLI offsets (mode 1) does not exist, using initial lookup table: $lt0\n"; execute("MLI_interp_lt $mli2 $ref_par $mli2_par $lt0 $mli1_par $mli2_par $diff_par $rmli $rmli_par", $log); } execute("create_diff_par $ref_par $rmli_par $diff_par2 1 < create_diff_par.in",$log); printf("\n"); execute("offset_pwrm $ref_mli $rmli $diff_par2 $offs2 $ccp2 - - - $novr - - $thres_mli", $log); execute("offset_fitm $offs2 $ccp2 $diff_par2 $coffs2 - $thres_mli $npoly", $log); @rpoly2 = extract_param($diff_par2,"range_offset_polynomial:"); @azpoly2 = extract_param($diff_par2,"azimuth_offset_polynomial:"); print "\nRMLI residual offset polynomials:\n"; print "@rpoly2\n"; print "@azpoly2\n\n"; open(LOG,">>$log") or die "ERROR $0: cannot open SLC_interp_lt_all log file: $log\n"; LOG->autoflush; printf LOG "residual offset polynomials 1:\n"; print LOG "\n@rpoly2\n"; print LOG "@azpoly2\n\n"; close LOG; if($rflag == 1){ for($j = 1; $j <= 6; $j += 1){ $rpoly3[$j] = $rpoly[$j] + $rpoly2[$j]; $azpoly3[$j] = $azpoly[$j] + $azpoly2[$j]; } $sv1 = sprintf "%.5f %12.5e %12.5e %12.5e %12.5e %12.5e",$rpoly3[1], $rpoly3[2], $rpoly3[3], $rpoly3[4]. $rpoly3[5], $rpoly3[6],; $sv2 = sprintf "%.5f %12.5e %12.5e %12.5e %12.5e %12.5e",$azpoly3[1], $azpoly3[2], $azpoly3[3], $azpoly3[4], $azpoly3[5], $azpoly3[6]; execute("set_value $diff_par2 $diff_par2 \"range_offset_polynomial\" \"$sv1\"", $log); execute("set_value $diff_par2 $diff_par2 \"azimuth_offset_polynomial\" \"$sv2\"", $log); #resample again after offset polynomial refinement and measure residual offsets if (-e $lt1) { execute("MLI_interp_lt $mli2 $ref_par $mli2_par $lt1 $mli1_par $mli2_par $diff_par2 $rmli $rmli_par", $log); } else { execute("MLI_interp_lt $mli2 $ref_par $mli2_par $lt0 $mli1_par $mli2_par $diff_par2 $rmli $rmli_par", $log); } execute("offset_pwrm $ref_mli $rmli $diff_par2 $offs2 $ccp2 - - - $novr - - $thres_mli", $log); execute("offset_fitm $offs2 $ccp2 $diff_par2 $coffs2 - $thres_mli $npoly", $log); @rpoly2 = extract_param($diff_par2,"range_offset_polynomial:"); @azpoly2 = extract_param($diff_par2,"azimuth_offset_polynomial:"); printf "\nresidual offset polynomials 2:\n"; print "\n@rpoly2\n"; print "@azpoly2\n"; open(LOG,">>$log") or die "ERROR $0: cannot open SLC_interp_lt_all log file: $log\n"; LOG->autoflush; printf LOG "residual offset polynomials 2:\n"; print LOG "\n@rpoly2\n"; print LOG "@azpoly2\n"; close LOG; print "\n"; } execute("raspwr $rmli $mli1_width[1] 1 0 1 1 $sc $exp", $log); } $time = localtime; open(LOG,">>${log}") or die "\nERROR $0: cannot open log file: $log\n"; print LOG "*** ref. MLI: $ref_mli MLI-2: $mli2 END: $time ***\n"; close LOG; print "*** ref. MLI: $ref_mli MLI-2: $mli2 END: $time ***\n"; #delete files created during the processing and create output RMLI_tab file if ($cflg == 1) { print "deleting $offs, $coffs, $ccp\n"; unlink $offs if -e $offs; unlink $offs2 if -e $offs2; unlink $coffs if -e $coffs; unlink $coffs2 if -e $coffs2; unlink $ccp if -e $ccp; unlink $ccp2 if -e $ccp2; if ($mflg == 1){ print "deleting $offs_lt0, $coffs_lt0, $ccp_lt0, $mli1_lt0"; unlink $offs_lt0 if -e $offs_lt0; unlink $coffs_lt0 if -e $coffs_lt0; unlink $ccp_lt0 if -e $ccp_lt0; unlink $mli1_lt0 if -e $mli1_lt0; } } } if ($mode == 2 || $mode == 4){ execute("mk_tab $rmli_dir rmli rmli.par $RMLI_tab", $log); } $time = localtime; $log = "$rmli_dir/MLI_resamp_lt_all"."_$mode".".log"; open(LOG,">>${log}") or die "\nERROR $0: cannot open log file: $log\n"; print "\n*** $0 mode: $mode COMPLETED: $time ***\n"; print LOG "\n*** $0 mode: $mode COMPLETED: $time ***\n\n"; close LOG; exit 0; sub execute{ my ($command, $log) = @_; if (-e $log){open(LOG,">>$log") or die "\nERROR $0: cannot open log file: $log\n";} else {open(LOG,">$log") or die "\nERROR $0: cannot open log file: $log\n";} LOG->autoflush; print "$command\n"; print LOG ("\n${command}\n"); close LOG; $exit = system("$command 1>> $log"); $exit == 0 or die "ERROR $0: non-zero exit status: $command\n" } sub extract_param{ my ($infile,$keyword) = @_; open(PAR_IN,$infile) || die "\nERROR extract_param: cannot open parameter file: $infile\n"; while(){ chomp; @tokens = split; if($tokens[0] eq $keyword){close PAR_IN; return @tokens;} } close PAR_IN; die "\nERROR $0: keyword $keyword not found in file: $infile\n"; }