% Satlantic.m % Jeff Scrutton % annotated by Erich Riencker 10-29-97 % % Reads in argos data file and parses into good data (messages.txt) Reject data(regects.txt) % a log file of all of the processed data (log.txt) and a location file (location.txt) fclose('all'); clear all ; [filename,pathname] = uigetfile('*.txt','ARGOS file...'); if filename == 0 disp('Program cancelled.'); break; end fname = [ pathname filename ]; f = fopen(fname,'r'); %read the input file log = fopen('log.txt','w'); %open log file rej = fopen('rejects.txt','w'); %open rejects file keep = fopen('messages.txt','w');%open message file locn = fopen('location.txt','w');%open location file separator = '-----'; message = ''; messages = 0; rejects = 0; valid = 0; false = 0; true = 1; while ~feof(f) % % Find start of block... % line = fgetl(f); % I dont think this is running because feof prevents line from getting to -1 if (line == -1) %report at end disp('End of input file.'); fprintf(1,'%d messages processed (%d valid / %d rejects)\r\n',messages,valid,rejects); fclose('all'); return; end %what the heck is this doing anyway if ( length(findstr(line(1),'0123456789')) == 0 ) %first char must be 0 to 9 disp('Warning: strange input file!'); end while line(1) == ' ' %while line begins with a space line = fgetl(f); %Just get another line if (line == -1) disp('End of input file.'); fclose('all'); return; end end %while line(1)== ' ' fprintf(locn,'%s\r\n',line); %print the line to location fprintf(log,'%s\r\n',line); %print the line to log %disp(line); %debug tool % The first line of each block starts at the far left side of the page % the third value on the line tells how many lines in the block n = sscanf(line,'%d',4);%scan the line for doubles no bigger than 4 chars long nlines = n(3); %Third value in is the Number of lines in this block for i = 1:nlines-1; % Read so many lines of data for this block line = fgetl(f); if (line == -1) fclose('all'); error('Premature end of input file.'); end if ( line(6) == '-' ); %then it is a ' 1997-10-11 ....' type of line if ( length(message) > 0 ); text = message(2:22); %year-month-day time [int] words = sscanf(message(23:length(message)),'%X'); %the rest of the line is hex data %the next line creates the output text = [ text sprintf(' %04X',words) ]; %then we put it back together WITH leading zeros reject = false; if ( length(words) ~= 16 ) % Not a good data message reject = true; else bytes = [ fix(words/256) fix(rem(words,256)) ]; sum = 0; for j = 1 : 31 sum = sum + bytes(j); end if ( rem(sum,256) ~= bytes(32) ) reject = true; end end if ( reject ) rejects = rejects + 1; fprintf(rej,'%s\r\n',text); %write to the rejects file text = [ 'X ' text]; else valid = valid + 1; fprintf(keep,'%s\r\n',text); %write the output to the keep file text = [' ' text]; end fprintf(log,'%s\r\n',text); %Good or bad, write to file %disp(text); end message = ''; messages = messages + 1; end message = [ message line ]; end fprintf(log,'%s',separator); %disp(separator); end