#!/usr/local/bin/perl # # DataToAttic.mDates # # 1995/11/22 W. Prescott # # Go through directories on mraw and mrinex local directories # For each file: # Run CreateObsDateFile # Move file to raw or rinex # Run DataToAttic.pl # # Mods: # 1996/04/05 whp Change call to DataToAttic for compatibility. # 1996/10/04 whp Add ability to putaway solutions. # 2000/01/04 whp Fixed y2k bug in handling raw file date conversion. # Raw: # bcsun195.306.Z # ecsun195.306.Z # scsun195.306.Z # shatc195.305.Z # bprnc195.306.Z # Rinex: # csun19951031ao.Z # lp1x19951106ao.Z # pbl12060.95o.Z # pbl13060.95o.Z # prh319951102ao.Z # Solutions: # sss.ttt.yyyymmdd.stacov.ttt.Z print("DataToAttic.mDates: Starting\n"); system("date"); $PutAway = "PutAway"; # Check that raw and rinex exist and are empty. # --------------------------------------------- foreach $Dir ("raw","rinex","solutions") { if (-e $Dir) { opendir(HDL,$Dir); @List = grep (!/^\.\.?$/,readdir(HDL)); close (HDL); if ($#List != -1) { print ("DataToAttic.mDates: $Dir isn't empty.\n", "Do you want to delete contents?\n"); ($Input = substr(,0,1)) =~ y/A-Z/a-z/; if ($Input eq "y") { system ("rm $Dir/*"); } else { print( "DataToAttic.mDates: Terminating\n"); exit 2; } } } else { mkdir ($Dir,0775); } } # Get file listing # ---------------- opendir(PAHDL,$PutAway); foreach $FileName (grep (!/^\.\.?$/,readdir(PAHDL))) { print( "DataToAttic.mDates: Processing $FileName\n"); ($RawOrRinex,$yyyy,$yy,$mm,$dd) = &ParseName($FileName); if ($RawOrRinex eq "raw") { system ("cp $PutAway/$FileName raw/$FileName"); } elsif ($RawOrRinex eq "rinex") { system ("cp $PutAway/$FileName rinex/$FileName"); } elsif ($RawOrRinex eq "solutions") { system ("cp $PutAway/$FileName solutions/$FileName"); } else { print( "DataToAttic.mDates:", "Type of $FileName not recognized\n"); next; } system ("CreateObsDateFile $yyyy$mm$dd"); system ("echo Y | DataToAttic.pl"); system ("rm raw/* rinex/* solutions/* SaveObsDate"); } closedir(PAHDL); system("date"); print("DataToAttic.mDates: Finished\n"); # Procedure ParseName # ------------------- # Calculate yyyy,yy,mm,dd and filetype from filename sub ParseName { local($FileName) = @_; $RawOrRinex = "neither"; $yyyy = 0; $yy = 0; $mm = 0; $dd = 0; $Last3Char = substr($FileName,-3,3); if ($Last3Char eq "o.Z" || $Last3Char eq "n.Z") { $RawOrRinex = "rinex"; if ( substr($FileName,8,1) eq "." ) { $yy = substr($FileName,9,2); if ($yy < 80) { $yyyy = "20$yy"; } else { $yyyy = "19$yy"; } $doy = substr($FileName,4,3); ($mm,$dd) = &CallDoy2Cal($yyyy,$doy); } else { $yy = substr($FileName,6,2); $yyyy = substr($FileName,4,4); $mm = substr($FileName,8,2); $dd = substr($FileName,10,2); } return ($RawOrRinex,$yyyy,$yy,$mm,$dd); } $FirstChar = substr($FileName,0,1); $yy = substr($FileName,6,2); if ($yy < 80) { $yyyy = "20$yy"; } else { $yyyy = "19$yy"; } $doy = substr($FileName,9,3); if (length($FileName) == 14 && ($FirstChar eq "b" || $FirstChar eq "e" || $FirstChar eq "s") && ($doy >=1 && $doy <=366) && ($yy >= 0 && $yy<=99) ) { $RawOrRinex = "raw"; ($mm,$dd) = &CallDoy2Cal($yyyy,$doy); return ($RawOrRinex,$yyyy,$yy,$mm,$dd); } $Position = index($FileName,"stacov"); if ($Position > -1) { $Date = substr($FileName,$Position-9,8); $yyyy = substr($Date,0,4); $yy = substr($Date,2,2); $mm = substr($Date,4,2); $dd = substr($Date,6,2); $RawOrRinex = "solutions"; return ($RawOrRinex,$yyyy,$yy,$mm,$dd); } @Return = ($RawOrRinex,$yyyy,$yy,$mm,$dd); } # Procedure CallDoy2Cal # --------------------- # Convert yyyy doy to yyyy mm dd sub CallDoy2Cal { local($yyyy,$doy) = @_; system ("doy2cal $yyyy $doy > Date.$$"); open (DateHdl, "Date.$$"); read (DateHdl, $Date, 16384); close (DateHdl); system ("rm Date.$$"); ($Dummy1,$Dummy2,$yyyy,$mm,$dd) = split(" ",$Date,7); if (length($mm) < 2 ) {$mm = "0$mm";} if (length($dd) < 2 ) {$dd = "0$dd";} @Return = ($mm,$dd); }