#!/usr/local/bin/perl # # ListStaCovFiles from archive contents # and from DataList. # # 1996/10/01 W. Prescott # # Go through directories on archive # For each date: # Extract list of all stacov files found # Adapted from RebuildDataList # # Mods: # 19961209 whp Changed input defaults. Now if there are no # command line arguments, the procedure uses # a hard-wired start date and current stop date. print("ListStaCovFiles: Starting\n"); system("date"); # Check for input start & stop dates # ---------------------------------- if ($#ARGV != 1) { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); if (length($hour) < 2) {$hour = "0".$hour;} if (length($min) < 2) {$min = "0".$min;} if (length($sec) < 2) {$sec = "0".$sec;} ++$mon; if (length($mon) < 2) {$mon = "0".$mon;} if (length($mday) < 2) {$mday = "0".$mday;} $Start = "19890101"; $Stop = "19$year$mon$mday"; } else { $Start = $ARGV[0]; $Stop = $ARGV[1]; } print ("ListStaCovFiles:\nListing all stacov files from $Start to $Stop\n"); # Define paths # ------------ $Prefix = "/GPSdata"; $ArchiveList = ">StaCovs.Archive.$$"; $DataListList = ">StaCovs.DataList.$$"; $DataList = "/attic/DataList"; # Look at archive first # ---------------------- print("ListStaCovFiles: Reading archive\n"); open (Hdl,$ArchiveList); # Loop through dates # ------------------ $StartSec = &CallCal2Sec($Start); $StopSec = &CallCal2Sec($Stop); for ($i = $StartSec; $i <= $StopSec; $i = $i+86400) { ($yyyy,$mm,$dd) = &CallSec2Cal($i); $yy = substr($yyyy,2,2); $DayDirectory = $yyyy."/".$yy.$mm."/".$yy.$mm.$dd; $ArchiveSolutions = $Prefix."/solutions/".$DayDirectory; # print( "ListStaCovFiles: Processing $DayDirectory\n"); opendir(CurrentDir,$ArchiveSolutions); @StaCovFiles = grep(/.*stacov.*/,readdir(CurrentDir)); for (@StaCovFiles) { $Name = &RemoveDotZ($_); $fullpathname = $ArchiveSolutions."/".$Name; print("$fullpathname\n"); print (Hdl $Name,"\n"); } } close (Hdl); # Now look at DataList # -------------------- ### print("ListStaCovFiles: Reading DataList\n"); ### open (OutHdl,$DataListList); ### open (InHdl,$DataList); ### ### while () { ### $Line = $_; ### next if index($Line,"stacov") eq -1; ### @Field = split(/\t/,$Line); ### $Name = &RemoveDotZ($Field[12]); ### print (OutHdl $Name,"\n"); ### } ### close (OutHdl); ### close (InHdl); # Sort and remove duplicates # -------------------------- system("sort -u StaCovs.Archive.$$ > StaCovs.Archive "); system("sort -u StaCovs.DataList.$$ > StaCovs.DataList "); system("rm StaCovs.Archive.$$ StaCovs.DataList.$$ "); system("date"); print("ListStaCovFiles: Finished\n"); exit; # Procedure CallCal2Sec # --------------------- # Convert yyyymmdd to seconds sub CallCal2Sec { local($Date) = @_; $yyyy = substr($Date,0,4); $mm = substr($Date,4,2); $dd = substr($Date,6,2); system ("cal2sec $yyyy $mm $dd > Date.$$"); open (DateHdl, "Date.$$"); read (DateHdl, $Seconds, 16384); close (DateHdl); system ("rm Date.$$"); $Seconds = int($Seconds); } # Procedure CallSec2Cal # --------------------- # Convert seconds to yyyymmdd sub CallSec2Cal { local($Seconds) = @_; local ($yyyy,$mm,$dd); system ("sec2cal $Seconds > Date.$$"); open (DateHdl, "Date.$$"); read (DateHdl, $Date, 16384); close (DateHdl); system ("rm Date.$$"); ($yyyy,$mm,$dd) = split(' ',$Date); while (length ($mm) < 2) {$mm = "0$mm";} while (length ($dd) < 2) {$dd = "0$dd";} @Return = ($yyyy,$mm,$dd); } # Procedure RemoveDotZ # --------------------- # Remove trailing .Z sub RemoveDotZ { local ($InName) = @_; $LenName = length($InName); if (substr($InName, $LenName-2,2) eq ".Z") { $OutName = substr($InName,0,$LenName-2); } else { $OutName = $InName; } $Return = $OutName; }