source: aedes_readprocpar.m @ 132

Last change on this file since 132 was 80, checked in by tjniskan, 10 years ago
  • Changed the historical "an2_" prefix to "aedes_" in all files. NOTE:

Any script or function relying to Aedes functions will be broken
because of this. Just do a search/replace from "an2_" to "aedes_" in
your files and all should be well...

  • Changed the name of an2_readtab.m to a more informative

aedes_readphasetable.m

File size: 4.4 KB
Line 
1function [procpar,msg] = aedes_readprocpar(filename)
2% AEDES_READPROCPAR - Read VNMR (Varian) PROCPAR-file
3%   
4%
5% Synopsis:
6%       [procpar,msg]=aedes_readprocpar(filename)
7%
8% Description:
9%       The function reads the VNMR parameter file and returns a
10%       procpar-structure with parameters as structure fields. The input
11%       argument is a string containing either the full path to the
12%       procpar file or the .fid-directory containing the procpar file.
13%
14%       If an error occurs, the first output argument will be empty
15%       (i.e. procpar=[];) and the second output argument msg will
16%       contain the error message. Msg is an empty string if no error has
17%       occurred.
18%
19%       NOTE: AEDES_READPROCPAR adds an additional array field in the
20%       procpar-structure. The parameter procpar.arrayjoint does NOT
21%       exist in the original procpar-file. The arrayjoint field contains
22%       only a flag that can be used to determine if multiparameter
23%       arrayed acquisition is arrayed jointly (1=parameters arrayed
24%       jointly, 0=parameters not arrayed jointly).
25%
26% Examples:
27%       procpar=aedes_readprocpar('C:\MyData\MyAcquisition.fid\procpar')
28%
29%       or
30%
31%       procpar=aedes_readprocpar('C:\MyData\MyAcquisition.fid')
32%
33% See also:
34%       AEDES_READFID, AEDES_DATA_READ, AEDES, AEDES_READTAB
35
36% This function is a part of Aedes - A graphical tool for analyzing
37% medical images
38%
39% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi>
40%
41% Department of Physics, Department of Neurobiology
42% University of Kuopio, FINLAND
43%
44% This program may be used under the terms of the GNU General Public
45% License version 2.0 as published by the Free Software Foundation
46% and appearing in the file LICENSE.TXT included in the packaging of
47% this program.
48%
49% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
50% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
51
52
53% Default values for output arguments
54procpar=[];
55msg='';
56
57
58%% Ask for a file if not given as an input argument
59if nargin==0
60  [fn,fp,fi]=uigetfile({'PROCPAR;procpar','Varian PROCPAR files';...
61                   '*.*','All Files (*.*)'},...
62                       'Select PROCPAR file');
63  if all(fn==0) | all(fp==0)
64    % Cancel pressed
65    return
66  end
67  filename = [fp,fn];
68end
69
70% Parse filename
71[fpath,fname,fext]=fileparts(filename);
72if ~strcmpi(fname,'procpar')
73  if isempty(fname)
74    fpath = [fpath,filesep];
75  else
76    fpath = [fpath,filesep,fname,fext,filesep];
77  end
78  fname = 'procpar';
79else
80  fpath = [fpath,filesep];
81end
82
83%% Open file
84fid=fopen([fpath,fname],'r','ieee-be');
85if fid<0
86  msg=['Could not open procpar file "',fpath,fname,'" for reading'];
87  return
88end
89
90
91%% Read whole file into cell array
92try
93  C = textscan(fid,'%s','delimiter','\n','BufSize',10*1024);
94  procpar_str=C{1};
95catch
96  msg={'Error while reading procpar file.','',...
97       lasterr};
98  fclose(fid);
99  return
100end
101
102%% Close file
103fclose(fid);
104
105%% Parse procpar file lines
106try
107  nonlabelchars='123456789';
108  for ii=1:length(procpar_str)
109    if any(procpar_str{ii}(1)==nonlabelchars)
110      %% Read info
111      str=deblank(procpar_str{ii});
112      ind=find(str==' ');
113      if isempty(ind)
114        ind=0;
115      end
116      str=str(ind(1)+1:end);
117     
118      if str(1)=='"'
119        ind2=find(str=='"');
120        for kk=1:2:(length(ind2))
121          procpar.(label){end+1} = strrep(str(ind2(kk):ind2(kk+1)),'"','');
122        end
123      else
124        procpar.(label) = str2num(str);
125      end
126    elseif procpar_str{ii}(1)=='"' % Read string from line
127      str=deblank(procpar_str{ii});
128      procpar.(label){end+1} = strrep(str,'"','');
129    elseif procpar_str{ii}(1)=='0' % Empty line, end of block
130    continue
131    else
132      %% Read label
133      ind=find(procpar_str{ii}==' ');
134      label=procpar_str{ii}(1:ind-1);
135      procpar.(label)={};
136    end
137  end
138 
139  %% Parse array parameter. If more than one parameters are arrayed, they
140  %  are separated with commas. If parameters are jointly arrayed they
141  %  are enclosed in brackets.
142  if isfield(procpar,'array') && ~isempty(procpar.array{1})
143    str = procpar.array{1};
144   
145        % Add Matlab cell characters
146        str = strrep(strrep(str,'(','{'),')','}');
147        str = ['{',str,'}'];
148       
149        % Add string characters around words
150        str=regexprep(str,'(\w+)(,|\})','''$1''$2');
151       
152        % Evaluate to formulate s cell
153        procpar.array = eval(str);
154       
155  end
156catch
157  msg=['Error while parsing procpar lines'];
158  procpar=[];
159  return
160end
161
162
Note: See TracBrowser for help on using the repository browser.

Powered by Trac 1.0.9.Copyright © Juha-Pekka Niskanen 2008