function Aux = satlan3(CalFile, InFile, OutFile) % SATLAN3 - Convert raw binary satlantic files to processed text files % % Use As: Aux = satlan3(CalFile, InFile, OutFile) % Inputs: CalFile = Name of calibration file, if empty satlan3 searches for it. % InFile = name of binary satlantic to read (from satlan2) (default = sat_data.raw) % OutFile = Name of file to write to (default = sat_data.out) % Ouputs: Aux = auxillary data structure used by satlan_write % % Satlan3 can automatically look for serial numbers with in the InFile and % select the most recent version of the calibration file. TO use this feature try: % satlan3([], InFile, OutFile) or % satlan3(\\tsunami.shore.mbari.org\calfiles\, InFile, OutFile) % % Requires: AUTOCON.EXE (DOS executable), GETFNAME % Brian Schlining % 19 Mar 1999 if nargin < 3 OutFile = 'sat_data.out'; if nargin < 2 InFile = 'sat_data.raw'; end end if ~nargin CalFile = []; end [CalPath CalFilename CalExt] = fileparts(CalFile); % Get the correct calfile if nargin < 1 | isempty(CalFilename) fid = fopen(InFile,'r','b'); if fid == -1 error(['Unable to read file ' InFile]) end % Bytes 13:20 contain the ascii serial number of the first record % Skip over to byte 7 to start reading status = fseek(fid, 7, 'bof'); if status == -1 fclose(fid); error(['Input File, ' InFile ', is not a satlantic binary data file']) end % Read all the serial numbers in the file (sometimes there is more than one) % Each record is 36 bytes long with the serial numbers written as ascii between % bytes 13 and 20 (4 ascii digits). OK = 1; n = 1; while OK SNBuffer = max(fscanf(fid,'%4d')); if ~isempty(SNBuffer) SN(n) = SNBuffer; else SN(n) = 0; end status = fseek(fid, 36, 'cof'); OK = status + 1; end fclose(fid); % Find the serial number that occurs most often within the file SNums = unique(SN); for i = 1:length(SNums) j(i) = find(SN == SNums(i)); end i = min(find(j == max(j))); % use min in case two serial numbers occur with equal frequency SerialNumber = SN(i); % Find all calibration files (named datXXXXx.cal where XXXX has the serial number) with % the same serial number. Then find the most recent version of that file by looking at % x where x = a,b,c,d,... Letter later in the alphabet indicate a more recent version % (i.e a is earliest, b next then c and so on) if isempty(CalPath) CalFiles = sortrows(getfname('\\tsunami.shore.mbari.org\oasis\eqpac\stordat\dat0*.cal')); else CalFiles = sortrows(getfname([CalFile 'dat0*.cal'])); end [r c] = size(CalFiles); n = 1; for i = 1:r CF(i,1) = sscanf(CalFiles(i,:),'dat%4d'); end j = find(CF == SerialNumber); if length(j) > 1 V = abs(CalFiles(j,8)); i = max(find(V == max(V))); j = j(i); end if isempty(CalPath) CalFile = ['\\tsunami.shore.mbari.org\oasis\eqpac\stordat\' CalFiles(j,:)]; else CalFile = [CalPath filesep CalFiles(j,:)]; end end % Have to use 8 char dos names with autocon, so I create temp copies of the % data files with short names [OutPath OutFilename OutExt] = fileparts(OutFile); if isempty(OutPath) fsep = []; else fsep = filesep; end TempOutFile = [OutPath fsep 'sat_out.tmp']; TempInFile = [OutPath fsep 'sat_in.tmp']; TempCalFile = [OutPath fsep 'sat_cal.tmp']; % Delete the temp files if they already exist if exist(TempOutFile,'file') delete(TempOutFile) end if exist(TempInFile,'file') delete(TempInFile) end %fprintf(1,'copy %s %s:',CalFile, TempCalFile) [s w] = dos(['copy ' CalFile ' ' TempCalFile]); %fprintf(1,'%s\n',w) %fprintf(1,'copy %s %s:',InFile, TempInFile) [s w] = dos(['copy ' InFile ' ' TempInFile]); %fprintf(1,'%s\n',w) dos(['autocon ' TempCalFile ' ' TempInFile ' ' TempOutFile ]); %fprintf(1,'copy %s %s:',TempOutFile, OutFile) [s w] = dos(['copy ' TempOutFile ' ' OutFile]); %fprintf(1,'%s\n',w) delete(TempOutFile); delete(TempInFile); delete(TempCalFile); %======================================== % Add Auxillary information if requested %======================================== A.FileName = OutFile; A.BinarySrcFile = InFile; A.CalibrationFile = CalFiles(j,:); if nargout Aux = A; end