function satlan_prc
% SATLAN_PRC - Autmated function to convert argos message from stordats to text data files
% First it creates a 7***.out file from the argos messages then
% This wrapper only processes files that contain data occuring within the last 14 days

% Brian Schlining
% 26 Mar 1999

Files = getfname('\\tsunami.shore.mbari.org\oasis\eqpac\satpac\7*.*');


[r c] = size(Files);
for i = 1:r
   FileName = deblank(Files(i,:));
   FileIn = ['\\tsunami.shore.mbari.org\oasis\eqpac\satpac\' FileName];
   FileOut = ['\\tsunami.shore.mbari.org\oasis\eqpac\stordat\' FileName '.out'];
   FileFTP = ['\\tsunami.shore.mbari.org\oasis\eqpac\pete\realtimeprc\ftp_nasa\' FileName '.ftp'];
   try
      a = satlan2out(FileIn,FileOut,1);
      % Create the name of FileOut
      % 1. Parse out the calibration file, which contains the stordat #
      %    Do this by finding the first non-zero number, take it and the next two values
      j = min(find(abs(a.CalibrationFile) >= 49 & abs(a.CalibrationFile) <= 57));
      s1 = a.CalibrationFile(j:j+2);
      s2 = round(nanmedian(a.Lat));
      if s2 < 0
         s2 = sprintf('%02is',abs(s2));
         %s2 = [num2str(abs(s2)) 's'];
      elseif s2 > 0
         s2 = sprintf('%02in',abs(s2));
         %s2 = [num2str(s2) 'n'];
      else
         s2 = sprintf('%02i_',abs(s2));
         %s2 = [num2str(s2) '_'];
      end

      s3 = round(nanmedian(a.Lon));
      if s3 > 180
         s3 = (360 - s3)*-1;
      end

      if s3 < 0
         s3 = sprintf('%03iw',abs(s3));
         %s3 = [num2str(abs(s3)) 'w'];
      elseif s3 > 0
         s3 = sprintf('%03ie',abs(s3));
         %s3 = [num2str(s3) 'e'];
      else
         s3 = sprintf('%03i_',abs(s3));
         %s3 = [num2str(s3) '_'];
      end

      x = readout(FileOut);

      if (nanmax(x.TIME_TAG) >= (now-14))    % Only write files that have recieved data within the last 14 days
         [Year Month Day] = datevec(nanmin(x.TIME_TAG));
         s4 = sprintf('%04i%02i', Year, Month);
         %s4 = [num2str(Year) num2str(Month)];
         FTPName = ['stor' s1 '_' s2 s3 '_' s4];
         FileFTP = ['\\tsunami.shore.mbari.org\oasis\eqpac\pete\realtimeprc\ftp_nasa\' FTPName '.ftp'];
         satlan_write(FileOut,FileFTP,a);
         pc2unix(FileFTP);
         fprintf(1,'(SATLAN_PRC): Wrote file %s\n', FileFTP);
      else
         fprintf(1,'(SATLAN_PRC): File %s was not written. No current data was found\n', FileFTP);
      end

   catch
      fclose all;
      fprintf(1,'(SATLAN_PRC): Unable to process %s\n', FileIn);

   end

end


