#!/usr/local/bin/perl # # File: GetAnts # # Creates a list of rinex and svec antenna types and instrument heights # # Page Stites 01/04/2000 # # interpretation of arguments unless ( ($#ARGV == 0) || ( ($ARGV[0] eq "-r") && ( $#ARGV == 2) ) ) { print "Usage: GetAnts -l --> lists information from rinex header and sta_svec file\n"; print " GetAnts -r yyyy mm --> rewrites rinex header information for yyyy, mm\n"; exit 1; } # Variables useful to the entire program: $StaSvec = "/goa/sta_info/sta_svec"; $nosend = "/closet/GPS/nosend"; $jsvantennafile = "/closet/GPS/AntennaTable"; $kjwantennafile = "/closet/GPS/KJWAntList"; $kjwreceiverfile = "/closet/GPS/KJWRecList"; $receiverfile = "/closet/GPS/ReceiverTable"; $antcode = "ANT #"; $reccode = "REC #"; # Index variables for navigating through rinex directory structure: @days = ("01", "02", "03", "04", "05", "06", "07", "08", "09", 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31); # Main Program @screened = &ReadFile(NOSEND, $nosend); %JSVAntennas = &ReadFiletoHash(JSVANTENNAS, $jsvantennafile); @KJWAntennas = &ReadFile(KJWANTENNAS, $kjwantennafile); @KJWReceivers = &ReadFile(KJWRECEIVERS, $kjwreceiverfile); %Receivers = &ReadFiletoHash(RECEIVERS, $receiverfile); if ($ARGV[0] eq "-l") { $dest = "/closet/GPS/antinfo.991220"; $source = "/GPSdata/rinex"; open(OUT, ">>$dest") or die "Couldn't open $dest: $!\n"; print OUT "Ant. SN Rinex Ant. Svec Ant. IGS Code (kjw) IGS Code (js) Station Date\n"; @years = (1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999); @months = ("01", "02", "03", "04", "05", "06", "07", "08", "09", 10, 11, 12); } elsif ($ARGV[0] eq "-r") { if ( $#ARGV == 0 ) { print "Please supply yyyy and mm as arguments when using the -r option\n"; exit 2; } @years = ("$ARGV[1]"); @months = ("$ARGV[2]"); $source = "/closet/GPS/working/rinex"; } else { print "Improper arguments -- aborting execution\n"; exit 3; } foreach $year (@years) { $yy = substr($year, 2, 2); foreach $mm (@months) { foreach $dd (@days) { $searchpath = "$year/$yy$mm/$yy$mm$dd"; %allfiles = (); &ExtractCodes; &FilterFiles; &OpenSvec; &FindAnts; } } } if ($ARGV[0] eq "-l") { close(OUT) } print "\a\a\a"; # Subroutine: ExtractCodes # Usage: &Extractcodes; # Comments: extractes 4 letter station codes from filenames sub ExtractCodes { @contents = (); @contents = `ls $source/$searchpath`; foreach $name (@contents) { chomp $name; $code = substr($name, 0, 4); push(@codes, $code); $allfiles{$name} = $code; } } # Subroutine: ReadFile # Usage: @array = &ReadFile(HANDLE, $filename); # Comments: creates an array of the contents of a file sub ReadFile { ($filehandle, $filename) = @_; local @filecontents = (); open($filehandle, "< $filename") or die "Couldn't read file $filename: $!\n"; while (<$filehandle>) { chomp; push(@filecontents, $_); } close($filehandle); return @filecontents; } # Subroutine: ReadFiletoHash # Usage: %hash = &ReadFiletoHash(HANDLE, $filename); # reads contents of files into a hash after padding the keys of the hash for later use. sub ReadFiletoHash { ($filehandle, $filename) = @_; local %filehash = (); open($filehandle, "< $filename") or die "Couldn't read file $filename: $!\n"; while (<$filehandle>) { chomp; ($left, $right) = split(':', $_); $left = &Pad($left, r); $filehash{$left} = $right; } close($filehandle); return %filehash; } # Subroutine: FilterFiles # Usage: &FilterFiles; # Commments: filters continuous data out of file list sub FilterFiles { while(($key, $value) = each(%allfiles)) { chomp $key; chomp $value; $value = lc($value); foreach $item (@screened) { if (($item eq $value) || ((substr($key, 0, 4) eq "Read"))) { delete($allfiles{$key}); } } } } # Subroutine: OpenSvec # Usage: &OpenSvec; # Comments: opens sta_svec file and writes contents into an array. sub OpenSvec { open(STASVECHDL, "<$StaSvec") or die "Couldn't open $StaSvec: $!\n"; undef @SvecLinesTemp; while () { push(@SvecLinesTemp,$_); } close(STASVECHDL); @SvecLines = sort(@SvecLinesTemp); } # Subroutine: FindAnts # Usage: &FindAnts; # Comments: Extracts and prints antenna types, instrument heights, receiver types, and dates. sub FindAnts { while(($file, $stacode) = each(%allfiles)) { $test = substr($file, 13, 1); if ($test eq "o") { @RinLines = `zcat $source/$searchpath/$file | head -50`; @antline = grep { m/ANT #/ } @RinLines; @hiline = grep { m/DELTA/ } @RinLines; @recline = grep { m/REC #/ } @RinLines; @dateline = grep { m/TIME OF FIRST OBS/ } @RinLines; @waveline = grep { m/WAVELENGTH/ } @RinLines; chomp $antline[0]; chomp $hiline[0]; chomp $recline[0]; chomp $dateline[0]; chomp $waveline[0]; ($rinantsn) = split(' ', $antline[0]); $rinant = substr($antline[0], 20, 20); $rinhi = substr($hiline[0], 8, 6); $rinrec = substr($recline[0], 20, 20); ($rinrecsn) = split(' ', $recline[0]); ($junk, $rinwave) = split(' ', $waveline[0]); ($rinyy, $rinmo, $rindd, $rinhh, $rinmm, $rinss) = split(' ', $dateline[0]); $rinss = int($rinss); while (length($rinmo) < 2) { $rinmo = "0$rinmo" } while (length($rindd) < 2) { $rindd = "0$rindd" } while (length($rinhh) < 2) { $rinhh = "0$rinhh" } while (length($rinmm) < 2) { $rinmm = "0$rinmm" } while (length($rinss) < 2) { $rinss = "0$rinss" } $rindate = "$rinyy$rinmo$rindd$rinhh$rinmm$rinss"; @Matches = grep { /^ $stacode/i } @SvecLines; foreach $line (@Matches) { # extract svec information $staname2 = substr($line,1,4); $year2 = substr($line,11,4); $month2 = substr($line,16,2); $day2 = substr($line,19,2); $hour2 = substr($line,22,2); $minutes2 = substr($line,25,2); $secs2 = substr($line,28,5); $duration2 = substr($line,34,12); $antenna2 = substr($line,47,9); $hi2 = substr($line,94,7); $svecdate1 = "$year2$month2$day2$hour2$minutes2$secs2"; $stasvecstart = &CallCal2Sec($year2, $month2, $day2, $hour2, $minutes2, $secs2); $stasvecendtime = $stasvecstart + $duration2; $svecdate2 = &CallSec2Cal($stasvecendtime); if (($rindate >= $svecdate1) && ($rindate <= $svecdate2) && ($ARGV[0] eq "-l")) { $flag = " "; $shortdate = substr($file, 4, 8); $antenna2 = &Pad($antenna2, r); $jsvigs = &Pad($JSVAntennas{$antenna2}, a); foreach $entry (@KJWAntennas) { ($sn, $longsn, $igs, $stdate, $enddate) = split(':', $entry); if ( ($sn == $rinantsn) && ($shortdate >= $stdate) && ($shortdate <= $enddate) ) { if ( !($igs eq "unknown ") ) { $kjwigs = &Pad($igs, a) } else { $kjwigs = $igs } if ( !($kjwigs eq $jsvigs) ) { $flag = '!' } } } if ( !(($hi2 - $rinhi) == 0) ) { $flag = "!" } print OUT " $rinantsn $rinant $antenna2 $kjwigs $flag $jsvigs $stacode $shortdate\n"; } } if ($ARGV[0] eq "-r") { `uncompress "$source/$searchpath/$file"`; $shortdate = substr($file, 4, 8); $file = substr($file, 0, (length($file) -2)); foreach $recentry (@KJWReceivers) { ($recsn, $longrecsn) = split (':', $recentry); if ($recsn == $rinrecsn) { $rinrecsn = &Pad($rinrecsn, r); $longrecsn = &Pad($longrecsn, r); $ln = int(`sed -n /"$reccode"/= "$source/$searchpath/$file"`); `overwrite "$source/$searchpath/$file" sed "$ln"sm"$rinrecsn"m"$longrecsn"m "$source/$searchpath/$file"`; } } unless ( $Receivers{$rinrec} eq () ) { $newrec = &Pad($Receivers{$rinrec}, r); $ln = int(`sed -n /"$reccode"/= "$source/$searchpath/$file"`); `overwrite "$source/$searchpath/$file" sed "$ln"sm"$rinrec"m"$newrec"m "$source/$searchpath/$file"`; } foreach $antentry (@KJWAntennas) { ($antsn, $longantsn, $igsant, $antstdate, $antenddate) = split (':', $antentry); if ( ($antsn == $rinantsn) && ($shortdate >= $antstdate) && ($shortdate <= $antenddate) ) { if ( !( ($igsant eq "unknown ") || ($igsant eq "TRIMBLE 4000 SSE ") || ($igsant eq "unknown Ashtech ") ) ) { $igsant = &Pad($igsant, a) } $rinantsn = &Pad($rinantsn, r); $longantsn = &Pad($longantsn, r); $ln = int(`sed -n /"$antcode"/= "$source/$searchpath/$file"`); `overwrite "$source/$searchpath/$file" sed "$ln"sm"$rinant"m"$igsant"m "$source/$searchpath/$file"`; `overwrite "$source/$searchpath/$file" sed "$ln"sm"$rinantsn"m"$longantsn"m "$source/$searchpath/$file"`; } } `compress "$source/$searchpath/$file"`; } } elsif (($test eq "n") || ($test eq "a")) { next } else { if ($ARGV[0] eq "-l") { open (COMMENTED, ">>commented.991108"); print COMMENTED "$file\n"; close(COMMENTED); } next; } } } # Procedure CallCal2Sec # --------------------- # Convert yyyy mm dd to seconds sub CallCal2Sec { local($year,$month,$day,$hour,$minutes,$secs) = @_; $Seconds = `cal2sec $year $month $day $hour $minutes $secs`; $Seconds = int($Seconds); return($Seconds); } # Procedure CallSec2Cal # --------------------- # Converts seconds to yyyy mm dd hh mm ss sub CallSec2Cal { local ($Secs) = @_; local ($yyyy, $mo, $dd, $hh, $mm, $ss); $Date = `sec2cal $Secs`; ($yyyy, $mo, $dd, $hh, $mm, $ss) = split(' ', $Date); $ss = int($ss); while (length($mo) < 2) { $mo = "0$mo"; } while (length($dd) < 2) { $dd = "0$dd"; } while (length($hh) < 2) { $hh = "0$hh"; } while (length($mm) < 2) { $mm = "0$mm"; } while (length($ss) < 2) { $ss = "0$ss"; } $return = "$yyyy$mo$dd$hh$mm$ss"; } # Subroutine: Pad # Usage: $string1 = &Pad($string2, [ar]); # pads the string to 20 characters sub Pad { ($string, $option) = @_; if ($option eq "r") { while (length($string) < 20) { $string = "$string "; } } elsif ($option eq "a") { while (length($string) < 16) { $string = "$string "; } $string = $string . 'NONE'; } return $string; }