#!/usr/local/bin/perl # # gp.UpdateRes # # Script to add new entries to WRMS file # overwriting existing entries if necessary. # (Adapted from gp.UpdateXYZ) # # wrms file format: tab-delimited # # Entry (tab between each field after first three) # ----- # yyyy Year # mm Month # dd Day # # nn P(reliminary) or F(inal) flag # yyy.ffff Year and fractional year # nnn Day of year (sometimes called julian day) # xx.yy N residual (mm) # xx.yy E residual (mm) # xx.yy U residual (mm) # free format Comment including date processed # # W. Prescott 10 February 1997 # # Modifications: # 1997/02/10 whp Adapted from gp.UpdateXYZ # 2001/01/31 whp Ignore first character in output line # from transform residual file $ENV{PATH} = "/bin:/usr/bin:/goa/local/gp_dir"; $ENV{SHELL} = "/bin/sh"; $ENV{IFS} = "" if $ENV{IFS} ne ""; # Check number of arguments. # ------------------------- if ($#ARGV < 0) { print "Usage: gp.UpdateRes takes two argument\n"; print " the name of the transform output file and\n"; print " the name of the stacov file\n"; print " e.g. gp.UpdateRes transform.log filename.stacov\n"; exit 1; } $TransformLogName = $ARGV[0]; $StacovName = $ARGV[1]; print ("gp.UpdateRes:\n"); # Define useful path names # ------------------------ $Path = "/GPSdata/postprocess/res"; # Get solution date from SaveObsDate # -------------------------------------------- open (DateHdl, "SaveObsDate") || die "gp.UpdateRes: SaveObsDate not found"; @Line = grep (/datelong/,); ($skip,$datelong) = split(' ',$Line[0],3); seek (DateHdl,0,0); @Line = grep (/decyr/,); ($skip,$decyr) = split(' ',$Line[0],3); seek (DateHdl,0,0); @Line = grep (/doy/,); ($skip,$doy) = split(' ',$Line[0],3); close (DateHdl); # Find type of orbit used for this solution # ----------------------------------------- open (OrbitHdl, "ProcessFlags"); while () { ($abbrev,$value) = split(" ",$_); $Options{$abbrev} .= $value; } close (OrbitHdl); $Flag = $Options{"OrbitType"}; if ($Flag eq "") {$Flag = "F";} # Open transform log # ------------------ open (TLHdl, $TransformLogName); undef @TransformLines; while () { push(@TransformLines,$_); } close (TLHdl); print(@TransformLines); # Find relevant lines in transform log # ------------------------------------ for ($i = 0; $i < $#TransformLines; ++$i) { if (substr($TransformLines[$i],1,8) eq "POSITION") { $StartPt = $i + 2; last; } } for ($i = $StartPt; $i <= $#TransformLines; ++$i) { if (substr($TransformLines[$i],1,4) eq "WRMS") { $StopPt = $i; last; } } # Save relevant values from transform log # --------------------------------------- undef %NorthResidual; undef %EastResidual; undef %UpResidual; for ($i = $StartPt; $i <= $StopPt; ++$i) { ($TempStaName,$NR,$ER,$UR) = split(' ',substr($TransformLines[$i],1)); ($StaName = $TempStaName) =~ tr/A-Z/a-z/; $NorthResidual{$StaName} = $NR; $EastResidual{$StaName} = $ER; $UpResidual{$StaName} = $UR; } # Store residuals for each station in transform log # ------------------------------------------------- foreach $StaName (sort(keys NorthResidual)) { # Open old residual file # ---------------------- $Fullname = "$Path/$StaName.res"; open (ResHdl, $Fullname); # Read contents # ------------- undef %Residuals; while () { $DateKey = substr($_,0,8); $Residuals{$DateKey} = $_; } close (ResHdl); # Add current solution (or replace old one) # ----------------------------------------- # Get current time and date # ------------------------- $DateTimeString = `CurrTimeDate.pl`; $Comment = "Updated:$DateTimeString-by-gp.UpdateRes from $StacovName"; # Create tab-delimited string # --------------------------- $String = sprintf("%8.8s \t %2.2s \t %8.4f \t %3d \t ", $datelong,$Flag,$decyr,$doy); $String .= sprintf("%7.2f \t %7.2f \t %7.2f \t ", $NorthResidual{$StaName}, $EastResidual{$StaName}, $UpResidual{$StaName}); $String .= sprintf("%s\n", $Comment); $Residuals{$datelong} = $String; # Save updated wrms file # --------------------- open (ResHdl, ">$Fullname.new") || die "gp.UpdateRes: Can't open $Fullname.new"; foreach $DateKey (sort(keys %Residuals)) { print (ResHdl $Residuals{$DateKey}); } close (ResHdl); if (-e "$Fullname.new") { system ("mv -f $Fullname.new $Fullname");} } # End loop on stations in transform log file.