source: an2_readprocpar.m @ 44

Last change on this file since 44 was 39, checked in by tjniskan, 11 years ago
  • Added "Recent Files" quick access menu in File-menu
  • Fixed a bug in plugins/copy_data_to_workspace.m that made writing a

new name for a variable difficult

  • Fixed a bug in the file prefix editbox in an2_export_gui.m
  • Changed references to Analyze 2.0 in all license notices to Aedes.

The name change should now be complete...

M an2_export_gui.m
M an2_cellsprintf.m
M an2_calc_wait.m
M an2_check_file_exist.m
M an2_iseven.m
M an2_cellwrite.m
M an2_wbar.m
M an2_rot3d.m
M an2_readfdf.m
M an2_revision.m
M an2_viewprocpar.m
M an2_checkcthdr.m
M an2_readprocpar.m
M an2_fitmaps.m
M an2_read_nifti.m
M an2_data_read.m
M an2_resviewer.m
M an2_maptool.m
M aedes.m
M an2_res2table.m
M an2_copy_roi.m
M plugins/save_roi_as_mask.m
M plugins/write_difference_images.m
M plugins/plot_profile.m
M plugins/calculate_t2_map.m
M plugins/calculate_t1r_map.m
M plugins/view_kspace.m
M plugins/copy_data_to_workspace.m
M plugins/take_snapshot.m
M an2_inputdlg.m
M an2_roi_copy_gui.m
M an2_readctdata.m
M an2_readfid.m
M an2_readfidprefs.m
M an2_readtab.m
M an2_check_updates.m
M an2_killfigs.m
M an2_roi_stats.m
M an2_saveres.m
M an2_rotateflip.m
M an2_juigetfiles.m
M an2_gui_defaults.m
M an2_editstack.m
M an2_update.m
M an2_write_nifti.m

File size: 5.0 KB
Line 
1function [procpar,msg] = an2_readprocpar(filename)
2% AN2_READPROCPAR - Read VNMR (Varian) PROCPAR-file
3%   
4%
5% Synopsis:
6%       [procpar,msg]=an2_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: AN2_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=an2_readprocpar('C:\MyData\MyAcquisition.fid\procpar')
28%
29%       or
30%
31%       procpar=an2_readprocpar('C:\MyData\MyAcquisition.fid')
32%
33% See also:
34%       AN2_READFID, AN2_DATA_READ, AEDES, AN2_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, (or 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    ind_comma = find(str==',');
145    ind_bracket1 = find(str=='(');
146    ind_bracket2 = find(str==')');
147    if ~isempty(ind_comma)
148      % More than one parameters are arrayed
149      if isempty(ind_bracket1) & isempty(ind_bracket2)
150        procpar.array = eval(['{''' strrep(str,',',''',''')  '''}']);
151        procpar.arrayjoint = 0;
152      else % Parameters are jointly arrayed
153        str = strrep(str,'(','');
154        str = strrep(str,')','');
155        procpar.array = eval(['{''' strrep(str,',',''',''')  '''}']);
156        procpar.arrayjoint = 1;
157      end
158    else
159      % NOTE: This is an additional field that is NOT found in the
160      % procpar file. This field is added by an2_readprocpar to serve as a
161      % simple flag to determine if the parameters in the array parameter
162      % are jointly arrayed.
163      procpar.arrayjoint = 0;
164    end
165  end
166catch
167  msg=['Error while parsing procpar lines'];
168  procpar=[];
169  return
170end
171
172
Note: See TracBrowser for help on using the repository browser.

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