% Satlan2.m % % Converts ARGOS telemetry from a STOR-DAT into an ASCIICON compatible file. % % Version: 1.0, 1997-10-24, Jeff Scrutton, Satlantic % % Input: % reads the file messages.txt % % Output: % write the file data.raw % % Notes: % * This script does not put out decent time stamps % * Channel selection is currently set for MBARI units as deployed by Pete Strutton. channels = [ 1 2 3 4 5 6 7 8 9 10 11 ]; % Select desired channels (should match cal file...) fin = fopen('messages.txt','r'); fout = fopen('data.raw','w'); rows = 1; while ( 1 ) line = fgetl(fin); % get a line if (line == -1) % close files and quit on end of file fclose('all'); return; end % Parse the fields % time = line(1:19); data = line(22:length(line)); itime = line(length(line)-3:length(line)-2); %instrument time stamp word = sscanf(data,'%X'); %sscanf with X(hex with uppercase letters) % Grab the serial number serialnumber = word(1); % Grab the 16-bit channels chan(1:8) = word(2:9); % Grab the 12-bit channels line = sprintf('%04X',word(10:15)); % I wana see what this is doing chan(9:16) = sscanf(line,'%3X',8); % write record header fprintf(fout,'SATDAT%04d',serialnumber); rec = sprintf('SATDAT%04d',serialnumber); %write the S/N as a string to rec % write data for c = channels rec = [rec sprintf('%6d',chan(c)) ]; % I wana see what this looks like too chan(c) = fix(chan(c)/256) + rem(chan(c),256)*256; % swap bytes intel->motorola fwrite(fout,chan(c),'int16'); % ASCIICON expects the motorola format end % write time stamp, this should be in time_t format, writing 0 for now. % % Matlab 4 has no support to deal with time_t formats. The ARGOS time tag % is probably a good candidate to write but there is no way to convert it. % % The most significant byte of word(16) is the actual instrument's % time stamp but due to the limited size of the telemetry frame it was % truncated to one byte. That stamp is the time of day, referenced to % midnight (=0) and a day being 240 "ticks" long. % % Remember the data is in motorola format if adding this field for real. % fwrite(fout,0,'long'); % write milli second stamp fwrite(fout,0,'int16'); % display record in a readable form rec = [rec ' ' time]; time1(rows,:)= [time,' ', itime]; rows = rows+1; %fprintf(1,'%s\r\n',rec); end