if [ -n "$LOUD1b" ]; then if [[ $LOUD1b != off ]] ; then set -x fi fi if [ -n "$LOUDsat" ]; then if [[ $LOUDsat != off ]] ; then set -x fi fi ########### set -x ########### if (( $# < 3 )) ; then echo "Script window_orbits requires 6 arguments." echo "Usage: window_orbits dirstem filestem begdate begtime enddate endtime" echo "(1) dirstem is the portion of the data directory preceding the" echo " 6 or 8 digit year, month, and day." echo "(2) filestem is the the first portion of the filename." echo "(3) begdate is a 6 or 8 digit string of the form [YY]YYMMDD." echo "(4) begtime is a 4-digit string of the form HHMM." echo "(5) enddate is a 6 or 8 digit string of the form [YY]YYMMDD." echo "(6) endtime is a 4-digit string of the form HHMM." exit 255 fi if (( ${#3} != 6 && ${#3} != 8 )) ; then echo "begdate is not in form YYMMDD or YYYYMMDD." exit 254 fi if (( ${#4} != 4 )) ; then echo "begtime is not in form HHMM." exit 254 fi if (( ${#5} != 6 && ${#5} != 8 )) ; then echo "enddate is not in form YYMMDD or YYYYMMDD." exit 254 fi if (( ${#6} != 4 )) ; then echo "endtime is not in form HHMM." exit 254 fi # SAG: Following typeset added for frost/snow so that possible # leading zero in var jdayb will not be treated as octal value. typeset -LZ7 jdayb set +A DAYSBEFORE 0 31 59 90 120 151 181 212 243 273 304 334 IYR=$(($3/10000)) MON=$(($3/100-100*$IYR)) IDA=$(($3-10000*$IYR-100*$MON)) if (( $IYR < 21 )) ; then IYR=$((2000+$IYR)) elif (( $IYR < 100 )) ; then IYR=$((1900+$IYR)) fi LEAP=$(($IYR/4*4)) LEAP100=$(($IYR/100*100)) LEAP400=$(($IYR/400*400)) if (( $LEAP == $IYR && $MON > 2 )) ; then if (( $LEAP100 != $IYR || $LEAP400 == $IYR )) ; then LEAP=1 else LEAP=0 fi else LEAP=0 fi MONSUB=$(($MON-1)) DOY=$((${DAYSBEFORE[$MONSUB]}+$IDA+$LEAP)) BJULDAT=$(($IYR*1000+$DOY)) # SAG: BHR changed to deal with leading zero arithmetic #BHR=$(($4/100)) BHR=$( expr $4 / 100 ) BYMD=$((10000*$IYR+100*$MON+$IDA)) BYMDH=$(echo "100*$BYMD+$BHR \n quit" | bc) IYR=$(($5/10000)) MON=$(($5/100-100*$IYR)) IDA=$(($5-10000*$IYR-100*$MON)) if (( $IYR < 21 )) ; then IYR=$((2000+$IYR)) elif (( $IYR < 100 )) ; then IYR=$((1900+$IYR)) fi LEAP=$(($IYR/4*4)) LEAP100=$(($IYR/100*100)) LEAP400=$(($IYR/400*400)) if (( $LEAP == $IYR && $MON > 2 )) ; then if (( $LEAP100 != $IYR || $LEAP400 == $IYR )) ; then LEAP=1 else LEAP=0 fi else LEAP=0 fi MONSUB=$(($MON-1)) DOY=$((${DAYSBEFORE[$MONSUB]}+$IDA+$LEAP)) EJULDAT=$(($IYR*1000+$DOY)) # SAG: EHR changed to deal with leading zero arithmetic #EHR=$(($6/100)) EHR=$( expr $6 / 100 ) EYMD=$((10000*$IYR+100*$MON+$IDA)) EYMDH=$(echo "100*$EYMD+$EHR \n quit" | bc) BDATEM1=$(/nwprod/util/exec/ndate -24 $BYMDH) BYYMMDDM1=$(echo "$BDATEM1/100 \n quit" | bc) yyyymmddlist="$BYYMMDDM1 $BYMD" if (( $3 != $5 )) ; then BDATEP1=$(/nwprod/util/exec/ndate +24 $BYMDH) BYYMMDDP1=$(echo "$BDATEP1/100 \n quit" | bc) EDATEM1=$(/nwprod/util/exec/ndate -24 $EYMDH) EYYMMDDM1=$(echo "$EDATEM1/100 \n quit" | bc) if (( $BYYMMDDP1 == $EYYMMDDM1 )) ; then yyyymmddlist="$yyyymmddlist $BYYMMDDP1" fi yyyymmddlist="$yyyymmddlist $EYMD" fi for yyyymmdd in $yyyymmddlist ; do if [[ ! -d $1/$yyyymmdd/mobsbfr ]] ; then yyyymmdd=$(($yyyymmdd%1000000)) if [[ ! -d $1/$yyyymmdd/mobsbfr ]] ; then continue fi fi for file in $(ls $1/$yyyymmdd/mobsbfr/$2*) ; do jdayb=$(echo $file | cut -d"." -f4 | cut -c2-) if (( $jdayb < 21000 )) ; then jdayb=$(($jdayb+2000000)) elif (( $jdayb < 100000 )) ; then jdayb=$(($jdayb+1900000)) fi btime=$(echo $file | cut -d"." -f5 | cut -c2-) etime=$(echo $file | cut -d"." -f6 | cut -c2-) if (( $btime > $etime )) ; then jdaye=$(($jdayb+1)) jyre=$(($jdaye/1000)) jdoye=$(($jdaye-1000*$jyre)) if (( $jdoye > 366 )) ; then jyre=$(($jyre+1)) jdaye=$((1000*$jyre+1)) elif (( $jdoye == 366 )) ; then leap=$(($jyre/4*4)) leap100=$(($jyre/100*100)) leap400=$(($jyre/400*400)) if (( $leap != $jyre )) ; then jyre=$(($jyre+1)) jdaye=$((1000*$jyre+1)) elif (( $leap100 == $jyre && $leap400 != $jyre )) ; then jyre=$(($jyre+1)) jdaye=$((1000*$jyre+1)) fi fi else jdaye=$jdayb fi begorbit=$(echo "10000*$jdayb+$btime \n quit" | bc) endorbit=$(echo "10000*$jdaye+$etime \n quit" | bc) begwindo=$(echo "10000*$BJULDAT+$4 \n quit" | bc) endwindo=$(echo "10000*$EJULDAT+$6 \n quit" | bc) if [[ $begorbit < $begwindo && $endorbit < $begwindo ]] ; then continue elif [[ $begorbit < $endwindo || $endorbit < $endwindo ]] ; then echo $file fi done done