#!/bin/csh -bf # # gp.addstapos # # Script to add station site position to sta_info/sta_pos. # J.L. Svarc # January 4 1995 # Based on script written by Nancy King addstasvec. # # Purpose: This script is designed to search a directory # for rinex files. Station positions are extracted # from the header information. A copy of the original # sta_pos file is made. Script then checks to see # if station position already exists. # If not, new station position is added. # # Modifications: # 1995/10/13 whp Convert to gp.addstapos. # 1995/10/12 whp Script now converts name to lower case # before it looks for it in StationList. # 1997/01/15 whp Now uses four character code from file name # instead of information from MARKER NAME in rinex file. # Define station info directory # ----------------------------- set Prefix = "sta_info" set StationList = /attic/StationList # cp -f $Prefix/sta_pos $Prefix/sta_pos_old/sta_pos.old.$$ rm -f sta_pos.$$ >& /dev/null # SEARCH FOR RINEX FILES IN JPL FORMAT # ------------------------------------ set numfiles = `ls *.rnx | wc -l ` if ($numfiles == 0) then echo " " echo "gp.addstapos: No RINEX observation files found in this directory." echo "gp.addstapos: Check file names for proper format" echo " " exit 1 else set filesearch="" set filesearch=($filesearch *.rnx) shift filesearch endif # SEARCH FOR STA_ID AND ADD IF NECESSARY # -------------------------------------- foreach file ($filesearch) set base=`basename $file` set sta1 = `echo $base | awk '{print substr($1,8,4) }'` # First find station in NameTrans # ------------------------------- set sta2 = `echo $sta1 | gp.NameTransLookup` set NumEntries = `echo $sta2 | wc -l` if ($NumEntries != 1) then echo gp.addstapos: More or less than one entry for $sta1 in NameTrans exit 1 else set sta = `echo $sta2 | tr '[a-z]' '[A-Z]'` endif # If that's okay, look for station in sta_pos # If it isn't there, try to add it. # --------------------------------- set NumEntries = `grep "^ $sta" $Prefix/sta_pos | wc -l` if ($NumEntries == 0) then echo gp.addstapos: Trying to add entry for --$sta1-- to sta_pos file set stalc = `echo $sta | tr '[A-Z]' '[a-z]'` set FoundPosition = "None" set present = `grep "^$stalc" $StationList | awk '{print $1}' | wc -l` if ($present == 0) then echo "gp.addstapos: WARNING WARNING WARNING " echo "gp.addstapos: --$stalc-- not found in StationList" else set xyz = `grep "^$stalc" $StationList | awk '{print $4,$5,$6}'` if ($xyz[1] == "NA") then echo "gp.addstapos: WARNING WARNING WARNING " echo "gp.addstapos: --$stalc-- coordinates not found in StationList" else set FoundPosition = "StationList" endif endif if ($FoundPosition == "None") then set xyz = `grep 'APPROX POSITION XYZ' $file | awk '{print $1,$2,$3}'` if ($xyz[1] == "NA") then echo "gp.addstapos: WARNING WARNING WARNING " echo "gp.addstapos: --$stalc-- coordinates not found in Rinex hdr" else set FoundPosition = "Rinex" endif endif switch ($FoundPosition) case "StationList": set xyz = `grep "^$stalc" $StationList | awk '{print $4,$5,$6}'` breaksw case "Rinex": set xyz = `grep 'APPROX POSITION XYZ' $file | awk '{print $1,$2,$3}'` breaksw case "None": echo "gp.addstapos: WARNING WARNING WARNING " echo "gp.addstapos: --$stalc-- coordinates not found anywhere" exit 2 endsw set xpos = $xyz[1] while (`echo $xpos | awk '{print (length($1))}'` < 13) set xpos = ${xpos}0 end set ypos = $xyz[2] while (`echo $ypos | awk '{print (length($1))}'` < 13) set ypos = ${ypos}0 end set zpos = $xyz[3] while (`echo $zpos | awk '{print (length($1))}'` < 12) set zpos = ${zpos}0 end set string1 = "00:00: 0.00 9999999.00" set string2 = "0.00000000e+00 0.00000000e+00 0.00000000e+00" set string3 = `date '+%Y %m %d'` set string4 = " gp.addstapos" echo " "$sta" 1985 01 01 "$string1" "$xpos" "$ypos" "$zpos" "$string2 $string3 $string4 >> sta_pos.$$ else set xyz = `grep "^ $sta" $Prefix/sta_pos | awk '{print substr($0,43,48)}'` endif # End else clause of No entry in sta_pos end # End foreach loop on rinex files # If new line exists, append to sta_pos file # ------------------------------------------ if (-e sta_pos.$$) then mv -f $Prefix/sta_pos $Prefix/sta_pos.old cat sta_pos.$$ $Prefix/sta_pos.old > $Prefix/sta_pos rm -f sta_pos.$$ $Prefix/sta_pos.old endif exit