#### UNIX Script Documentation Block # # Script name: ingest_gross_window_orbits # # JIF contact: Keyser org: NP22 date: 2006-05-12 # # Abstract: Checks to see if a file is within the specified time window. # # Script history log: # ????-??-?? Bert Katz Original version for implementation. # 2006-05-12 D. Keyser Improved documentation and comments. Handles new # DDS machine ozone filenames with YYDDD in qualifier # 5 (rather than 4), btime in qualifier 6 (rather than # 5) and etime in qualifier 7 (rather than 6) (still # works for TOVS filenames with YYDDD, btime and etime # in qualifier 4, 5 and 6, respectively). # # Usage: # ingest_gross_window_orbits filename > # # Script parameters: (1) filename (complete path) # (2) earliest_time {in hours before (-) or after (+) # current time} - optional, if not specified defaults # to -48 # (3) latest_time {in hours before (-) or after (+) # current time} - optional, if not specified defaults # to +6 (note: if this is present, script parameter 2 # must also be present) # # Modules and files referenced: # scripts : none # data cards : none # executables: none # # Remarks: Invoked by the ush scripts ingest_script_1b.sh, # ingest_script_atovs1b.sh and ingest_script_o3.sh. Returns "NONO" to # standard output if file is outside specified time limits. Returns file's # starting YYYYMMDD to standard output if file is within specified time # limits. # # Condition codes: # 0 - no problem encountered # > 0 - some problem encountered # Specifically: 255 - ZERO arguments passed in (expects 1 argument) or file # is outside specified time limits # # Attributes: # Language: aix unix script # Machine: NCEP CCS #### set -aux if [ $# -eq 0 ] ; then echo echo "Script ingest_gross_window_orbits requires 1 argument." echo echo "Usage: ingest_gross_window_orbits filename >" echo "(1) filename is the complete path AND entire filename." echo "(2) window_lim1 is earliest window limit, in hours before(-)/after(+)" echo " the current time." echo "(3) window_lim2 is latest window limit, in same form as window_lim1." echo " If unspecified, window_lim1 is -48 and window_lim2 is +6." echo echo "Returns NONO to standard output if file is outside specified time \ limits." echo echo "Returns files's starting YYYYMMDD to standard output if file is \ within specified time limits." echo exit 255 fi set +A DAYSBEFORE 0 31 59 90 120 151 181 212 243 273 304 334 # SAG: The following line was added for frost/snow so that these variables # would not contain leading zeros. # ------------------------------------------------------------------------- typeset -LZ yyddd if (( $# == 1 )) ; then set $1 -48 6 elif (( $# == 2 )) ; then if (( $2 >= 0 )) ; then set $1 $2 -48 else set $1 $2 +6 fi fi if [ $2 -gt $3 ] ; then BEGACCEPT=$($utilexec/ndate $3) ENDACCEPT=$($utilexec/ndate $2) else BEGACCEPT=$($utilexec/ndate $2) ENDACCEPT=$($utilexec/ndate $3) fi first_q4=$(echo $1 | cut -d"." -f4 | cut -c1) if [ $first_q4 = D ]; then yyddd=$(echo $1 | cut -d"." -f4 | cut -c2-) else first_q5=$(echo $1 | cut -d"." -f5 | cut -c1) if [ $first_q5 = D ]; then yyddd=$(echo $1 | cut -d"." -f5 | cut -c2-) else echo NONO exit 255 fi fi IYR=$(($yyddd/1000)) DOY=$(($yyddd-1000*$IYR)) if (( $IYR < 21 )) ; then IYR=$(($IYR+2000)) elif (( $IYR < 100 )) ; then IYR=$(($IYR+1900)) fi first_q5=$(echo $1 | cut -d"." -f5 | cut -c1) if [ $first_q5 = S ]; then btime=$(echo $1 | cut -d"." -f5 | cut -c2-) else first_q6=$(echo $1 | cut -d"." -f6 | cut -c1) if [ $first_q6 = S ]; then btime=$(echo $1 | cut -d"." -f6 | cut -c2-) else echo NONO exit 255 fi fi first_q6=$(echo $1 | cut -d"." -f6 | cut -c1) if [ $first_q6 = E ]; then etime=$(echo $1 | cut -d"." -f6 | cut -c2-) else first_q7=$(echo $1 | cut -d"." -f7 | cut -c1) if [ $first_q7 = E ]; then etime=$(echo $1 | cut -d"." -f7 | cut -c2-) else echo NONO exit 255 fi fi # If either $btime or $etime is not numerically equal to zero (i.e., it is # not equal to the string '0000'), remove any possible leading zeroes so the # value will not be defined as an octal in any arithmetic evaluations (cannot # do this if $btime or $etime numerically equals zero because its value will # then be undefined) # --------------------------------------------------------------------------- [ $btime -ne 0 ] && typeset -LZ btime [ $etime -ne 0 ] && typeset -LZ etime set +A DAYSBEFORE 0 31 59 90 120 151 181 212 243 273 304 334 365 LPYR=$(($IYR/4*4)) LPYR100=$(($IYR/100*100)) LPYR400=$(($IYR/400*400)) MON=1 byymmdd=0 while (( $byymmdd == 0 )) ; do if (( $MON < 2 || $LPYR != $IYR )) ; then LEAP=0 else if (( $LPYR100 != $IYR || $LPYR400 == $IYR )) ; then LEAP=1 else LEAP=0 fi fi if (( $DOY <= $((${DAYSBEFORE[$MON]}+$LEAP)) )) ; then MONSUB=$(($MON-1)) if (( $MONSUB < 2 )) ; then LEAP=0 fi DOM=$(($DOY-${DAYSBEFORE[$MONSUB]}-$LEAP)) byymmdd=$((10000*$IYR+100*$MON+$DOM)) fi MON=$(($MON+1)) done eyymmdd=$byymmdd if (( $btime > $etime )) ; then eyymmdd00=$($utilexec/ndate 24 ${byymmdd}00) eyymmdd=$(echo $eyymmdd00 | cut -c1-8) fi bhr=$(($btime/100)) ehr=$(($etime/100)) begorbit=$(echo "100*$byymmdd+$bhr \n quit" | bc) endorbit=$(echo "100*$eyymmdd+$ehr \n quit" | bc) if [[ $begorbit < $BEGACCEPT && $endorbit < $BEGACCEPT ]] ; then echo "NONO" elif [[ $begorbit < $ENDACCEPT || $endorbit < $ENDACCEPT ]] ; then echo $byymmdd else echo "NONO" fi exit 0