1 ## Copyright (C) 2010 Peter Cloetens
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with Octave; see the file COPYING. If not, see
15 ## <http://www.gnu.org/licenses/>.
18 ## function [res, pos] = findheader(hd, what, kind)
19 ## read a given info from header of edf-files (.edf), info-file (.info) or parameter file (.par)
22 ## argument 1 : header or info string
23 ## argument 2 : parameter to be read (can be 'date')
24 ## argument 3 : kind|type of parameter
25 ## possible values are: 'motor', 'counter', 'integer', 'float', 'list' or 'string'
27 ## Author: Peter Cloetens cloetens@esrf.eu
28 ## Created: 2010-12-10
29 ## * main change from historical version: avoid any assumption on offset, change help
31 function [res, pos] = findheader(hd, what, kind)
34 disp('3 input arguments required:')
39 if strcmp(what,'date')
40 pos = findstr(hd,what);
42 pos_equal = findstr(hd(pos:end),'=');
43 pos_equal = pos(1)+pos_equal(1)-1;
44 pos_semicolon = findstr(hd(pos_equal:end),';');
45 pos_semicolon = pos_equal+pos_semicolon(1)-1;
46 res = hd(pos_equal+2:pos_semicolon-2);
47 else % what is not in header
50 elseif strcmp(kind,'motor')
51 pos = findstr(hd,'motor_mne');
53 pos_equal = findstr(hd(pos:end),'=');
54 pos_equal = pos(1)+pos_equal(1)-1;
55 pos_semicolon = findstr(hd(pos_equal:end),';');
56 pos_semicolon = pos_equal+pos_semicolon(1)-1;
58 posend = pos_semicolon-1;
60 res = []; % in case motor does not exist
61 while pos<posend; % looking number of motor
62 motor = sscanf(hd(pos:posend),'%s',1);
63 if strcmp(motor, what) % motor was found -> taking corresponding position
64 pos = findstr(hd,'motor_pos');
65 pos_equal = findstr(hd(pos:end),'=');
66 pos_equal = pos(1)+pos_equal(1)-1;
67 res = sscanf(hd(pos_equal+1:end),'%g',motnum);
72 pos += findstr(hd(pos:posend), motor)(1) + length(motor);
77 elseif strcmp(kind,'counter')
78 pos=findstr(hd,'counter_mne');
80 pos_equal = findstr(hd(pos:end),'=');
81 pos_equal = pos(1)+pos_equal(1)-1;
82 pos_semicolon = findstr(hd(pos_equal:end),';');
83 pos_semicolon = pos_equal+pos_semicolon(1)-1;
85 posend = pos_semicolon-1;
87 res = []; % in case counter does not exist
88 while pos<posend; % looking number of motor
89 motor = sscanf(hd(pos:posend),'%s',1);
90 if strcmp(motor,what) % motor was found -> taking corresponding position
91 pos = findstr(hd,'counter_pos');
92 pos_equal = findstr(hd(pos:end),'=');
93 pos_equal = pos(1)+pos_equal(1)-1;
94 res = sscanf(hd(pos_equal+1:end),'%g',motnum);
99 pos += findstr(hd(pos:posend), motor)(1) + length(motor);
104 else # kind is not 'motor' 'counter' 'date'
105 pos=findstr(hd,what);
108 pos_equal = findstr(hd(pos:end),'=');
109 pos_equal = pos+pos_equal(1);
112 res = sscanf(hd(pos_equal:end),'%i');
114 res = sscanf(hd(pos_equal:end),'%f');
116 res = sscanf(hd(pos_equal:end),'%s',1);
118 pos_end = findstr(hd(pos_equal:end),'}');
119 res = hd(pos_equal:pos_equal+pos_end-1);