0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1 % FROMCOMPLEXDATAFILE Construct an AO from filename AND parameter list
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 3 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 4 % FUNCTION: fromDatafile
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 5 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 6 % DESCRIPTION: Construct an AO from filename AND parameter list
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 7 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 8 % CALL: a = fromComplexDatafile(a, pli)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 9 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 10 % PARAMETER: a: empty ao-object
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 11 % pli: plist-object (must contain the filename)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 12 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 13 % VERSION: $Id: fromComplexDatafile.m,v 1.12 2011/08/12 09:55:39 hewitson Exp $
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 14 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 16
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 17 function objs = fromComplexDatafile(ain, pli)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 18
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 19 utils.helper.msg(utils.const.msg.PROC1, 'loading complex data from filename and/or plist');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 20
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 21 VERSION = '$Id: fromComplexDatafile.m,v 1.12 2011/08/12 09:55:39 hewitson Exp $';
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 22
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 23 % get AO info
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 24 mi = ao.getInfo('ao', 'From Complex ASCII File');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 25
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 26 % Set the method version string in the minfo object
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 27 mi.setMversion([VERSION '-->' mi.mversion]);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 28
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 29 % Get filename
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 30 file_name = find(pli, 'filename');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 31 file_path = find(pli, 'filepath');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 32
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 33 [filePath, fileName, ext] = fileparts(file_name);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 34
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 35 % Add the file extenstion to the fileName
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 36 fileName = strcat(fileName, ext);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 37
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 38 % Define the path of the
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 39 if ~isempty(file_path) && ~isempty(filePath)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 40 % Do nothing because we will use filePath
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 41 elseif ~isempty(file_path)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 42 filePath = file_path;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 43 elseif ~isempty(filePath)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 44 % Do nothing because we will use filePath
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 45 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 46 filePath = pwd();
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 47 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 48
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 49 absolutePathname = fullfile(filePath, fileName);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 50
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 51 % Check if the abolute Pathname exist
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 52 if ~exist(absolutePathname, 'file')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 53 absolutePathname = fileName;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 54 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 55
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 56 %%%%%%%%%% Get default parameter list %%%%%%%%%%
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 57 pl = applyDefaults(mi.plists, pli);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 58
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 59 pl = pset(pl, 'filename', fileName);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 60 pl = pset(pl, 'filepath', filePath);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 61
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 62 data_type = find (pl, 'type');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 63 columns = find (pl, 'columns');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 64 comment_char = find (pl, 'comment_char');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 65 orig_col = columns; % necessary for the histroy
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 66 objs = [];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 67
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 68 %%%%%%%%%% read file %%%%%%%%%%
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 69 [fid,msg] = fopen (absolutePathname, 'r');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 70 if (fid < 0)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 71 error ('### can not open file: %s \n### error msg: %s', fileName, msg);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 72 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 73
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 74 %%%%%%%%%% create scan format: '%f %f %f %f %f %*[^\n]' %%%%%%%%%%
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 75 scan_format = '';
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 76 read_col = 0;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 77 sort_col = sort(columns);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 78
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 79 %%%%%%%%%% Get/Count max number of lines %%%%%%%%%%
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 80 maxLines = numlines(fid);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 81 utils.helper.msg(utils.const.msg.PROC2, 'Counting lines: %d', maxLines);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 82 fseek(fid, 0, 'bof');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 83
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 84 %%%%%%%%%% Read data %%%%%%%%%%
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 85 readlines = min(50000, maxLines);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 86 nlines = 0;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 87
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 88 %%% Based on skipping the not used columns we have to transform the columns.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 89 %%% We must transform the columns [ 2 5 2 6 5 7] to [ 1 2 1 3 2 4]
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 90 %%% In each loop we have to replace the corresponding value. In the first loop
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 91 %%% the first minimum, in the second loop the second minimum, ... with the
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 92 %%% current loop number.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 93 for j=1:max(columns)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 94 if ismember(j, columns)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 95 scan_format = [scan_format '%n '];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 96 read_col = read_col + 1;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 97 replace = min(sort_col);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 98
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 99 columns (columns==replace) = read_col;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 100 sort_col(sort_col==replace) = [];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 101 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 102 scan_format = [scan_format '%*n '];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 103 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 104 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 105 scan_format = [deblank(scan_format) '%*[^\n]'];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 106
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 107 %%% preallocate data array
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 108 f_data = zeros(maxLines, read_col);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 109
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 110 %%% check if using robust read: 'yes'/'no' or true/false or 'true'/'false'
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 111 robust = find(pl, 'Robust');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 112 if isempty(robust)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 113 robust = false;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 114 elseif ischar(robust)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 115 if strcmpi(robust, 'yes') || strcmpi(robust, 'true')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 116 robust = true;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 117 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 118 robust = false;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 119 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 120 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 121
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 122 if robust
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 123
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 124 f_data = robustRead(fid, f_data, columns, orig_col);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 125
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 126 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 127
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 128 %%% Look for the first line of data
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 129 if ~isempty(comment_char)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 130 while ~feof(fid)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 131 f = deblank(fgetl(fid));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 132 if ~isempty(f)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 133 if f(1) ~= comment_char
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 134 break;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 135 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 136 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 137 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 138 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 139 f = deblank(fgetl(fid));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 140 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 141
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 142 %%% Scan it to find how many columns we have in the file
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 143 C = textscan(f, scan_format, 1, 'CollectOutput', 1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 144 if any(isnan(C{:}))
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 145 error('### Error in file format. Perhaps you specified more columns than the file contains?');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 146 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 147
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 148 fseek(fid, 0, 'bof');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 149 %%% read file to end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 150 while ~feof(fid) && nlines < maxLines
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 151
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 152 if isempty(comment_char)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 153 C = textscan(fid, scan_format, readlines, ...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 154 'CollectOutput', 1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 155 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 156 C = textscan(fid, scan_format, readlines, ...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 157 'CommentStyle', comment_char, ...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 158 'CollectOutput', 1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 159 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 160 f_data(nlines+1:nlines+size(C{1},1),:) = C{1};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 161 nlines = nlines + length(C{1});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 162
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 163 if isempty(C{1})
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 164 error('\n### There are no data.\n### Did you use the right comment character?\n### The current comment character is: [%s]\n### Use a parameter list with the parameter:\n### plist(''comment_char'', ''%%'')', comment_char);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 165 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 166 utils.helper.msg(utils.const.msg.PROC2, 'read %09d lines of %09d', nlines, maxLines);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 167
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 168 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 169 fclose(fid);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 170
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 171 %%% get only the data we want
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 172 if size(f_data,1) > nlines
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 173 f_data = f_data(1:nlines, :);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 174 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 175 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 176
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 177
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 178 %%%%%%%%%% Create for each three columns the data object %%%%%%%%%%
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 179
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 180 %%%%%%%%%% The numbers in columns must be straight %%%%%%%%%%
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 181 if mod(length(columns),3) ~= 0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 182 error('### The numbers in columns must be multiple of three.');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 183 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 184
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 185 complex_type = pl.find('complex_type');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 186
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 187 for lauf = 1:length(columns)/3
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 188
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 189 data_x = f_data(:, columns(lauf*3-2));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 190 data_y_1 = f_data(:, columns(lauf*3-1));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 191 data_y_2 = f_data(:, columns(lauf*3));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 192
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 193 if strcmpi(complex_type, 'abs/deg')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 194 data_y = data_y_1 .* exp(1i*data_y_2*pi/180);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 195
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 196 elseif strcmpi(complex_type, 'dB/deg')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 197 data_y = 10.^(data_y_1./20) .* exp(1i*data_y_2*pi/180);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 198
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 199 elseif strcmpi(complex_type, 'abs/rad')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 200 data_y = data_y_1 .* exp(1i*data_y_2);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 201
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 202 elseif strcmpi(complex_type, 'dB/rad')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 203 data_y = 10.^(data_y_1./20) .* exp(1i*data_y_2);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 204
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 205 elseif strcmpi(complex_type, 'real/imag')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 206 data_y = complex(data_y_1, data_y_2);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 207
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 208 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 209 error('### I can not handle real [%s] and imaginary [%s].', real_type, imag_type);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 210 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 211
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 212 % create data object corresponding to the parameter list
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 213 ao_data = [];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 214 switch lower(data_type)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 215 case 'tsdata'
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 216 ao_data = tsdata(data_x, data_y);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 217 case 'fsdata'
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 218 ao_data = fsdata(data_x, data_y);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 219 case 'cdata'
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 220 error('### Please code me up');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 221 case 'xydata'
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 222 ao_data = xydata(data_x, data_y);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 223 otherwise
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 224 error('### unknown data type ''%s''', data_type);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 225 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 226 aa = ao(ao_data);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 227 % overide the default name
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 228 if isempty(pl.find('name'))
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 229 pl.pset('name', sprintf('%s_%02d_%02d_%02d', fileName, orig_col(lauf*3-2), orig_col(lauf*3-1), orig_col(lauf*3)));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 230 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 231
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 232 % set units
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 233 aa.setXunits(pl.find('xunits'));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 234 aa.setYunits(pl.find('yunits'));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 235
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 236 % Add history
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 237 pl = pl.pset('columns', [orig_col(lauf*3-2) orig_col(lauf*3-1) orig_col(lauf*3)]);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 238 aa.addHistory(mi, pl, [], []);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 239
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 240 objs = [objs aa];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 241
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 242 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 243
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 244 % set any object properties now
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 245 objs.setObjectProperties(pl);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 246
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 247 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 248
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 250 % Local Functions %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 252
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 253 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 254 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 255 % FUNCTION: numlines
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 256 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 257 % SYNTAX: count = numlines(fid);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 258 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 259 % DESCRIPTION: Number of lines in an ASCII file
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 260 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 261 % HISTORY: 02-08-2002 Peter Acklam, CSSM post
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 262 % Creation.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 263 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 264 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 265
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 266 function lines = numlines(fid)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 267
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 268 lines = 0; % number of lines in file
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 269 nlchr = uint8(sprintf('\n')); % newline chr as uint8
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 270 bsize = 4 * 256 * 8192; % block size to read
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 271
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 272 while ~feof(fid)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 273 block = fread(fid, bsize, '*uint8');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 274 lines = lines + sum(block == nlchr);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 275 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 276 if ~isempty(block) % in case file is empty
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 277 lines = lines + double(block(end) ~= nlchr);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 278 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 279 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 280
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 281 % A robust and slow data reader
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 282 function f_data = robustRead(fid, f_data, columns, orig_cols)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 283
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 284 cols = unique(columns);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 285 ocols = unique(orig_cols);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 286 Nline = 1;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 287 while ~feof(fid)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 288 % read and parse line
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 289 tokens = sscanf(fgets(fid), '%f');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 290 % parse tokens
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 291 if ~isempty(tokens)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 292 f_data(Nline, cols) = tokens(ocols);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 293 if mod(Nline, 1000) == 0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 294 utils.helper.msg(utils.const.msg.PROC2, 'lines read: %d', Nline);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 295 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 296 Nline = Nline + 1;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 297 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 298 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 299
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 300 % drop empty lines
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 301 f_data = f_data(1:Nline-1, :);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 302
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 303 end