From: Geico Caveman on
Sorry about the somewhat ambiguous title, but nothing else would appear to fit.

I have the following header in a data file:

Sample: 'GFP(EM)
File name: datafile1.FDS
Run Date: 11:57:30, 08/09/2010
Operator: GC
Comment: '
User comment: <this can run into multiple lines>

<some random text>

Instrument Parameters
Measurement type: W scan
Scan mode: Em
Data mode: Fl
EX WL: 300.0 nm
EM Start WL: 325.0 nm
EM End WL: 575.0 nm
Scan speed: 1200 nm/min
Delay: 1.0 s
EX Slit: 2.5 nm
EM Slit: 2.5 nm

<some more irrelevant text>

----------------------

Now, I need to extract "EX Slit" from this. Following a google link, I
tried the following code fragment:

fid1=fopen(filename1,'r');


[out1,pos1]=textscan(fid1,'%s: %f nm');

fclose(fid1);

ind1=strmatch('EM Start WL',out1{1});
wavelengthrange1=out1{2}(ind1);

ind1=strmatch('EM End WL',out1{1});
wavelengthrange1=[wavelengthrange1,out1{2}(ind1)];

ind1=strmatch('EX Slit',out1{1});
entryslitwidth1=out1{2}(ind1);
ind1=strmatch('EM Slit',out1{1});
exitslitwidth1=out1{2}(ind1);

This chokes on the very first line of input (expectedly). How do I make
it to read only the relevant part of the file, and somehow ignore the
rest ?

textread may do it, according to some google links I saw, but that is
deprecated (read: may be removed from future versions of Matlab).

I am currently using readline from the file excange to read specific
lines from the header and extracting the numbers from that. This is an
undesirable way because the user comments (see above) can run into
multiple lines and screw up the line numbers.

From: dpb on
Geico Caveman wrote:
....

> I have the following header in a data file:
>
> Sample: 'GFP(EM)
> File name: datafile1.FDS
> Run Date: 11:57:30, 08/09/2010
> Operator: GC
> Comment: '
> User comment: <this can run into multiple lines>
>
....

> Delay: 1.0 s
> EX Slit: 2.5 nm
> EM Slit: 2.5 nm
>
> <some more irrelevant text>
>
> ----------------------
>
> Now, I need to extract "EX Slit" from this. ...

v = []; % create an empty var for concatenating into
fid=fopen(filename1,'rt'); % Nota Bene the "t" for text file
while ~feof(fid)
l = fgetl(fid);
idx = findstr(l,'EX Slit');
if idx>0
v = [v sscanf(l(idx+length('EX Slit')+1:), '%f')];
end
end
fclose(fid);

....

textscan() and friends are probably not best choice in this case owing
to the variable number of comment lines.

regexp() might also be useful, particularly if the file(s) are
relatively small so could snarf them entire into memory.

--