#!/usr/local/bin/perl -w # # CreateObsDateFile # # This script stores useful versions of the # observation date in a file for access by # other scripts. # # 1995/08/07 Created by W. Prescott # 1995/08/11 Modified by N.E. King to # use input date of the form yyyymmdd, # include JPL date, # add date strings for /attic directory names, # fix bug in calculation of day+1, at end of month, # re-write month-boundary calculations, # change daym2 to daym1 in both name and function, # rename input string (was date, now datelong), # re-do comments. # 1995/08/12 Modified by N.E. King to # check input argument string for length & char type, # check input year/month/day, # check for leap year, # handle special cases of Jan 1 and Dec 31, # add comments. # 1995/08/14 whp Added output for day - 2. # 1995/12/1-3 whp Converted to use cal2sec and perl. # 1996/11/14 whp Decimal year calculation ignored leap year # Added accounting for leap year and modified # DecYr so that it refers to 12 noon. # 1997/01/13 whp Added -f to rm to suppress error message. # All variables are written to the file "SaveObsDate" # They can be extracted with the command # # set XXX = `grep YYY SaveObsDate | awk '{print $2}'` # or # setenv XXX `grep YYY SaveObsDate | awk '{print $2}'` # or # open (Hdl,"SaveObsDate"); # @UUU = grep /YYY/,; # @VVV = split /[ \n\t]+/,$UUU[0]; # $XXX = $VVV[1]; # # where XXX is the destination name and # YYY is the variable name at the bottom of the script. # (without the "$"). # # XXX and YYY may need not be the same unshift (@INC,"/goa/local/gp_dir"); require gp_utils; &gp_utils::setEnviron; # Process command line # -------------------- if ($#ARGV == -1) { print "\n"; print "Usage: CreateObsDateFile yyyymmdd\n"; print "\n"; exit 1; } # Check and parse input argument # ------------------------------ $datelong = $ARGV[0]; $datelong = &gp_utils::untaint($datelong); if (length($datelong) != 8) { print "CreateObsDateFile:", "Argument does not have 8 characters.\n"; print "Usage: CreateObsDateFile yyyymmdd\n"; print " Script stops.\n"; exit 1; } ($numcheck=$datelong) =~ tr/0-9//d; if ($numcheck ne "") { print "CreateObsDateFile:", "Argument contains non-numeric characters.\n"; print "Usage: CreateObsDateFile yyyymmdd\n"; print " Script stops.\n"; exit 2; } # Pick apart input date # --------------------- $dateshort = substr($datelong,2,6); $yymm = substr($datelong,2,4); $yrobs = substr($datelong,2,2); $longyr = substr($datelong,0,4); $moobs = substr($datelong,4,2); $dayobs = substr($datelong,6,2); $hour = "00"; $minute = "00"; # Set J2000 date # -------------- system ("cal2sec $longyr $moobs $dayobs $hour $minute > temp1.seconds"); open (HDL,"temp1.seconds"); $sec = ; $sec = &gp_utils::untaint($sec); $sec = sprintf ("%16.5f",$sec); close (HDL); $secdm1 = $sec - 86400; $secdm2 = $secdm1 - 86400; $secdp1 = $sec + 86400; system ("sec2cal $sec > temp2.seconds"); system ("sec2cal $secdm1 >> temp2.seconds"); system (`sec2cal $secdm2 >> temp2.seconds`); system (`sec2cal $secdp1 >> temp2.seconds`); system (`/bin/csh -bf /goa/bin/sec2doy $sec >> temp2.seconds`); system (`sec2gpsws $sec >> temp2.seconds`); open (HDL,"temp2.seconds"); $CheckDate = ; $Datedm1 = ; $Datedm2 = ; $Datedp1 = ; $Datedoy = ; $Dategpsweeksec = ; close (HDL); # system ("rm temp?.seconds"); # Check that date is valid # ------------------------ ($CDyyyy,$CDmm,$CDdd) = split(' ',$CheckDate,5); if (length($CDmm) == 1) {$CDmm = "0$CDmm";} if (length($CDdd) == 1) {$CDdd = "0$CDdd";} if ($datelong ne "$CDyyyy$CDmm$CDdd") { print "CreateObsDateFile: Input date invalid.", "$datelong ?=? $CDyyyy$CDmm$CDdd\n"; print " Script stops.\n"; exit 3; } # Define month names # ------------------ @months = ("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"); # Set JPL date, hour, minute, and hypenated date strings # ------------------------------------------------------ $monthobs = $months[$moobs-1]; $datejpl = $yrobs.$monthobs.$dayobs; $ymdobs = "$longyr-$moobs-$dayobs"; $dmyobs = "$dayobs-$monthobs-$longyr"; # Convert yymmmdd (ie:93sep16) to julian day of year # -------------------------------------------------- @fields = split(' ',$Datedoy); $doy = $fields[1]; while (length($doy) < 3) {$doy="0$doy";} # Decimal year # ------------ $NoDaysYear = 365; if ($longyr%4 == 0 && $longyr%400 != 0) {$NoDaysYear = 366;} $decyr = $longyr + ($doy-0.5)/$NoDaysYear; $decyr = sprintf ("%9.4f",$decyr); # Month name of day +/- 1 # ----------------------------------------------------------------------- if ($moobs == "01") { $mom1 = "12"; $mop1 = "02"; } else { $mom1 = $moobs-1; if (length($mom1) == 1) {$mom1 = "0$mom1";} } if ($moobs == "12") { $mom1 = "11"; $mop1 = "01"; } else { $mop1 = $moobs+1; if (length($mop1) == 1) {$mop1 = "0$mop1";} } # Calculate values for obs date-1 # ------------------------------- ($lgyrdm1,$modm1,$daym1) = split(' ',$Datedm1,5); $shyrdm1 = substr($lgyrdm1,2,2); if (length($modm1) == 1) {$modm1 = "0$modm1";} if (length($daym1) == 1) {$daym1 = "0$daym1";} $monthdm1 = $months[$modm1-1]; # Calculate values for obs date-2 # ------------------------------- ($lgyrdm2,$modm2,$daym2) = split(' ',$Datedm2,5); if (length($modm2) == 1) {$modm2 = "0$modm2";} if (length($daym2) == 1) {$daym2 = "0$daym2";} $monthdm2 = $months[$modm2-1]; # Calculate values for obs date+1 # ------------------------------- ($lgyrdp1,$modp1,$dayp1) = split(' ',$Datedp1,5); $shyrdp1 = substr($lgyrdp1,2,2); if (length($modp1) == 1) {$modp1 = "0$modp1";} if (length($dayp1) == 1) {$dayp1 = "0$dayp1";} $monthdp1 = $months[$modp1-1]; $dmym2 = $daym2."-".$monthdm2."-".$lgyrdm2; $dmym1 = $daym1."-".$monthdm1."-".$lgyrdm1; $dmyp1 = $dayp1."-".$monthdp1."-".$lgyrdp1; # GPS week and day-of-week calculations # ------------------------------------- ($gpsweekobs,$dayofweekobs) = split(' ',$Dategpsweeksec,4); $dayofweekobs /= 86400; $dayofweekm1 = $dayofweekobs-1; $gpsweekdm1 = $gpsweekobs; $dayofweekp1 = $dayofweekobs+1; $gpsweekdp1 = $gpsweekobs; if ($dayofweekm1 < 0) { --$gpsweekdm1; $dayofweekm1 = 6; } if ($dayofweekp1 > 6) { ++$gpsweekdp1; $dayofweekp1 = 0; } # Save for future reruns # ------------------------------------------------ system ("rm -f SaveObsDate"); open (HDL,">SaveObsDate"); print (HDL "datelong $datelong\n"); # yyyymmdd print (HDL "dateshort $dateshort\n"); # yymmdd print (HDL "datejpl $datejpl\n"); # yyMMMdd, where MMM is alpha month print (HDL "yrobs $yrobs\n"); # yy print (HDL "shyrdm1 $shyrdm1\n"); # yy for preceding day print (HDL "shyrdp1 $shyrdp1\n"); # yy for succeeding day print (HDL "longyr $longyr\n"); # yyyy print (HDL "lgyrdm1 $lgyrdm1\n"); # yyyy for preceding day print (HDL "lgyrdp1 $lgyrdp1\n"); # yyyy for succeeding day print (HDL "yymm $yymm\n"); # yymm, for use in /attic pathnames print (HDL "moobs $moobs\n"); # mm print (HDL "modm1 $modm1\n"); # mm for previous day print (HDL "modp1 $modp1\n"); # mm for succeeding day print (HDL "mom1 $mom1\n"); # moobs-1, with leading zero if necessary print (HDL "mop1 $mop1\n"); # moobs+1, with leading zero if necessary print (HDL "monthobs $monthobs\n"); # month of observation, alpha form print (HDL "monthdm2 $monthdm2\n"); # month of pre-previous day, alpha form print (HDL "monthdm1 $monthdm1\n"); # month of previous day, alpha form print (HDL "monthdp1 $monthdp1\n"); # month of next day, alpha form print (HDL "dayobs $dayobs\n"); # dd print (HDL "daym2 $daym2\n"); # dd-2, going into previous month if necessary print (HDL "daym1 $daym1\n"); # dd-1, going into previous month if necessary print (HDL "dayp1 $dayp1\n"); # dd+1, going into next month if necessary print (HDL "hour $hour\n"); # hour = 0 print (HDL "minute $minute\n"); # minute = 0 print (HDL "ymdobs $ymdobs\n"); # yyyy-mm-dd print (HDL "dmyobs $dmyobs\n"); # dd-MMM-yyyy, where MMM is alpha month print (HDL "dmym2 $dmym2\n"); # date of pre-previous day, in dd-MMM-yyyy format print (HDL "dmym1 $dmym1\n"); # date of previous day, in dd-MMM-yyyy format print (HDL "dmyp1 $dmyp1\n"); # date of next day, in dd-MMM-yyyy format print (HDL "doy $doy\n"); # Julian day print (HDL "decyr $decyr\n"); # Decimal year print (HDL "sec $sec\n"); # J2000 print (HDL "gpsweekobs $gpsweekobs\n"); # GPS week print (HDL "dayofweekobs $dayofweekobs\n"); # day of GPS week (0-6 for Sun-Sat) print (HDL "gpsweekdm1 $gpsweekdm1\n"); # GPS week of previous day print (HDL "dayofweekm1 $dayofweekm1\n"); # day of GPS week, for previous day print (HDL "gpsweekdp1 $gpsweekdp1\n"); # GPS week of next day print (HDL "dayofweekp1 $dayofweekp1\n"); # day of GPS week, for next day close (HDL); exit;