function X = ptt2out(FileName) % PTT2OUT - Convert *.ptt files to *.out files % Brian Schlining % 21 Jan 1999 %=================================== % Get FileName if it's not supplied %=================================== if ~nargin [infile inpath] = uigetfile('*.ptt','Select an Eqpac Data File',0,0); if infile == 0 X = []; return end FileName = [inpath infile]; end % Get the filename from the path and store it in the data structure [trash, File, Ext] = fileparts(FileName); X.Filename = [File Ext]; fid = fopen(FileName,'rt'); % Open the File Header = fgetl(fid); % Get the first line which contains the column descriptions BytesInHeader = length(Header); % Need to reposition the file pointer %========================================================== % Figure out roughly how many rows of data are in the file %========================================================== sByte = ftell(fid); % Get current position (in bytes) fseek(fid,0,'eof'); % go to the end of the file fByte = ftell(fid); % Get the position in Bytes BytesOfData = fByte - sByte; fseek(fid,BytesInHeader + 2,'bof'); % Rewind back to the original position + 1 line numRows = ceil(BytesOfData/279); % 279 is a ROUGH approx. of the number of characters per line x = ones(numRows,31)*NaN; % Preallocate memory n = 0; % Line counter %m = 1; % for debugging, otherwise ignore this while ~feof(fid) s = fgetl(fid); %m = m + 1; % For debugging % Not every line is the same length, so find out where each data value % starts and stops by finding the spaces if ~isempty(s) y = sscanf(s,'%f %f %f/%f/%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f'); %fprintf(1,'%5i %3i %s\n',m,length(y),s) if length(y) > 30 n = n + 1; x(n,:) = y(1:31,1)'; end end end fclose(fid); % Chop off any trailing NaN's left over from memory allocation j = find(~isnan(x(:,1))); x = x(j,:); SN = median(x(:,7)); % Easy way to get rid of bad SN values X = setfield(X,['SN_' num2str(SN)],ones(size(x(:,7)))*SN); X.LU_412 = x(:,8); X.LU_443 = x(:,9); X.LU_490 = x(:,10); X.LU_510 = x(:,11); X.LU_555 = x(:,12); X.LU_670 = x(:,13); X.LU_683 = x(:,14); X.ED_490 = x(:,17); X.FLOUR_none = x(:,29); T_w = x(:,30); V_BAT = x(:,31); Hour = floor(x(:,2)/10000); Minute = floor(x(:,2)/100) - Hour; Second = x(:,2) - Hour - Minute; X.TIME_TAG = datenum(x(:,5),x(:,3),x(:,4),Hour, Minute, Second); X.MS_TAG = ones(size(x(:,1)))*NaN; % Set bad values to NaN. % Data is bad if Lux+1/Lux < -0.1 (ex. Lu443/Lu412). Why do we consider this bad you ask? % Peter Strutton came up with this ratio method through empirical analysis. If you have % questions about it he's DA MAN to ask. In addition, Any LU's less than -1 are flagged too i = (X.LU_443./X.LU_412 < -0.1 ); j = (X.LU_490./X.LU_443 < -0.1 ); k = (X.LU_510./X.LU_490 < -0.1 ); l = (X.LU_555./X.LU_510 < -0.1 ); m = (X.LU_670./X.LU_555 < -0.1 ); n = (X.LU_683./X.LU_670 < -0.1 ); i = (i|j|k|l|m|n); % If any of the ratios are BAD all points in that sample are flagged X.LU_412(i) = NaN; X.LU_443(i) = NaN; X.LU_490(i) = NaN; X.LU_510(i) = NaN; X.LU_555(i) = NaN; X.LU_670(i) = NaN; X.LU_683(i) = NaN; X.LU_412(i) = NaN; i = find(X.LU_412 < -1);X.LU_412(i) = NaN; i = find(X.LU_443 < -1);X.LU_443(i) = NaN; i = find(X.LU_490 < -1);X.LU_490(i) = NaN; i = find(X.LU_510 < -1);X.LU_510(i) = NaN; i = find(X.LU_555 < -1);X.LU_555(i) = NaN; i = find(X.LU_670 < -1);X.LU_670(i) = NaN; i = find(X.LU_683 < -1);X.LU_683(i) = NaN; i = find(X.ED_490 < -1);X.ED_490(i) = NaN;