source: aedes_readprocpar.m

Last change on this file was 147, checked in by tjniskan, 7 years ago
  • Added support for Windows network paths (
    server\share) to

aedes_juigetfiles.m (Windows only)

  • Added a link for suppressing the license information from printing to

workspace

  • Fixed some uicontrol colors in aedes_headerbrowser.m
  • Changed the buffer size for reading VNMR PROCPAR to 1MB. The

previous buffer size (10kB) was apparently too low for some SWIFT data

  • aedes_killfigs.m now has an option to force close only Aedes-related

figures

  • Updated figure tags for aedes_killfigs.m
  • Added a request for restarting Aedes to the "Update successful" dialog

M aedes_readprocpar.m
M aedes_killfigs.m
M aedes_data_read.m
M aedes_gui_defaults.m
M aedes_resviewer.m
M aedes.m
M aedes_update.m
M aedes_export_gui.m
M aedes_headerbrowser.m
M aedes_revision.m
M aedes_juigetfiles.m
M aedes_errordump.m

File size: 4.8 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',1024*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
106%try
107  nonlabelchars='123456789';
108  field_chars = '_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
109  nonfield_chars = char(setdiff(0:256,double(field_chars)));
110  for ii=1:length(procpar_str)
111    if any(procpar_str{ii}(1)==nonlabelchars)
112      %% Read info
113      str=deblank(procpar_str{ii});
114      ind=find(str==' ');
115      if isempty(ind)
116        ind=0;
117      end
118      str=str(ind(1)+1:end);
119     
120      if str(1)=='"'
121        ind2=find(str=='"');
122        for kk=1:2:(length(ind2))
123          procpar.(label){end+1} = strrep(str(ind2(kk):ind2(kk+1)),'"','');
124        end
125      else
126        procpar.(label) = str2num(str);
127      end
128    elseif procpar_str{ii}(1)=='"' % Read string from line
129      str=deblank(procpar_str{ii});
130      procpar.(label){end+1} = strrep(str,'"','');
131    elseif procpar_str{ii}(1)=='0' % Empty line, end of block
132      continue
133    else
134      %% Read label
135      ind=find(procpar_str{ii}==' ');
136      label=procpar_str{ii}(1:ind-1);
137     
138      %% Make sure that the characters in the label are compatible with
139      %% Matlab structure fields. If not, replace them with underscore...
140      ind2=ismember(label,nonfield_chars);
141      if any(ind2)
142        label(ind2)='_';
143      end
144      procpar.(label)={};
145    end
146  end
147 
148  %% Parse array parameter. If more than one parameters are arrayed, they
149  %  are separated with commas. If parameters are jointly arrayed they
150  %  are enclosed in brackets.
151  if isfield(procpar,'array') && ~isempty(procpar.array{1})
152    str = procpar.array{1};
153   
154        % Add Matlab cell characters
155        str = strrep(strrep(str,'(','{'),')','}');
156        str = ['{',str,'}'];
157       
158        % Add string characters around words
159        str=regexprep(str,'(\w+)(,|\})','''$1''$2');
160       
161        % Evaluate to formulate s cell
162        procpar.array = eval(str);
163       
164  end
165%catch
166%  msg=['Error while parsing procpar lines'];
167%  procpar=[];
168%  return
169%end
170
171
Note: See TracBrowser for help on using the repository browser.

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