function crd = readcrd(filename) % Brian Schlining % 26 Jan 2000 %=========== % Open File %=========== if ~nargin [infile inpath] = uigetfile('*.crd','Select prr card file (contains metadata)',0,0); if infile == 0 crd = []; return % Return if CANCEL is selected end filename = [inpath infile]; end fid = fopen(filename,'rt'); if fid <= 0 warning(['Unable to open ' filename]); crd = []; return end crd.src = filename; %================ % Parse the file %================ % Get the date dateS = stringtokenizer(fgetl(fid), 2, '.'); timeS = stringtokenizer(fgetl(fid), 2, '.'); crd.date = datenum([dateS ' ' timeS]); % Get the position info crd.location = stringtokenizer(fgetl(fid), 2, '.'); % Get other metadata crd.skyState = stringtokenizer(fgetl(fid), 2, '.'); crd.operatorName = stringtokenizer(fgetl(fid), 2, '.'); crd.sunPosition = sscanf(stringtokenizer(fgetl(fid), 2, '.'), '%f'); crd.filename = stringtokenizer(fgetl(fid), 2, '.'); % Get instrument info S = fgetl(fid); crd.numCpu = sscanf(stringtokenizer(fgetl(fid), 2, ','), '%f'); S = fgetl(fid); for n = 1:crd.numCpu S = fgetl(fid); crd.channelSequence{n} = abs(deblank(S)) - 48; end S = fgetl(fid); % blank line S = fgetl(fid); % Cal file line crd.calibrationFile = stringtokenizer(S, 1, ';'); crd.cruiseId = stringtokenizer(fgetl(fid), 2, '.'); S = stringtokenizer(fgetl(fid), 2, '.'); startTime = stringtokenizer(S, 1, ','); S = stringtokenizer(S, 2, ','); crd.softwareVersion = stringtokenizer(S, 2, ':'); S = fgetl(fid); % Ignore this line S = fgetl(fid); while ~strcmp(lower(stringtokenizer(S, 1)), 'end') t = lower(stringtokenizer(S, 3, ',')); if isempty(t) crd.firstRecord = sscanf(stringtokenizer(S, 1, ','), '%f'); crd.firstTime = datenum([dateS ' ' stringtokenizer(S, 2, ',')]); else switch t case 'downcast ended' crd.endDowncastRecord = sscanf(stringtokenizer(S, 1, ','), '%f'); crd.endDowncastTime = datenum([dateS ' ' stringtokenizer(S, 2, ',')]); case 'upcast ended' crd.endUpcastRecord = sscanf(stringtokenizer(S, 1, ','), '%f'); crd.endUpcastTime = datenum([dateS ' ' stringtokenizer(S, 2, ',')]); end end S = fgetl(fid); end crd.endTime = datenum([dateS ' ' stringtokenizer(S, 2, '.')]); fclose(fid);