[379] | 1 | |
---|
[181] | 2 | %'read_field': read input fields in different formats |
---|
| 3 | %-------------------------------------------------------------------------- |
---|
[450] | 4 | % function [Field,ParamOut,errormsg] = read_field(FileName,FileType,ParamIn,num) |
---|
[181] | 5 | % |
---|
| 6 | % OUTPUT: |
---|
| 7 | % Field: matlab structure representing the field |
---|
| 8 | % ParamOut: structure representing parameters: |
---|
| 9 | % .FieldName; field name |
---|
| 10 | % .FieldList: menu of possible fields |
---|
| 11 | % .VelType |
---|
| 12 | % .CivStage: stage of civx processing (=0, not Civx, =1 (civ1), =2 (fix1).... |
---|
| 13 | % .Npx,.Npy: for images, nbre of pixels in x and y |
---|
| 14 | % errormsg: error message, ='' by default |
---|
| 15 | % |
---|
| 16 | %INPUT |
---|
[466] | 17 | % FileName: name of the input file |
---|
[181] | 18 | % FileType: type of file |
---|
| 19 | % = netcdf : netcdf file |
---|
| 20 | % = image : usual image as recognised by Matlab |
---|
| 21 | % = multimage: image series stored in a single file |
---|
[441] | 22 | % = mmreader: movie read with mmreader |
---|
| 23 | % = video: movie read with VideoReader (recent versions of Matlab) |
---|
[181] | 24 | % = vol: images representing scanned volume (images concatened in the y direction) |
---|
[450] | 25 | % ParamIn: movie object or Matlab structure of input parameters |
---|
[445] | 26 | % .FieldName: name (char string) of the input field (for Civx data) |
---|
| 27 | % .VelType: char string giving the type of velocity data ('civ1', 'filter1', 'civ2'...) |
---|
[181] | 28 | % .ColorVar: variable used for vector color |
---|
| 29 | % .Npx, .Npy: nbre of pixels along x and y (used for .vol input files) |
---|
[466] | 30 | % num: frame number for movies |
---|
| 31 | |
---|
[450] | 32 | function [Field,ParamOut,errormsg] = read_field(FileName,FileType,ParamIn,num) |
---|
[181] | 33 | Field=[]; |
---|
[354] | 34 | if ~exist('num','var') |
---|
| 35 | num=1; |
---|
| 36 | end |
---|
| 37 | if ~exist('ParamIn','var') |
---|
| 38 | ParamIn=[]; |
---|
| 39 | end |
---|
| 40 | ParamOut=ParamIn;%default |
---|
[181] | 41 | errormsg=''; |
---|
[466] | 42 | % if isfield(ParamIn,'VelType') |
---|
| 43 | % VelType=ParamIn.VelType; |
---|
| 44 | % end |
---|
[334] | 45 | A=[]; |
---|
| 46 | %% distingush different input file types |
---|
[445] | 47 | try |
---|
| 48 | switch FileType |
---|
| 49 | case {'civx','civdata','netcdf'} %read the first nc field |
---|
| 50 | % ParamOut.FieldName=ParamIn.FieldName; |
---|
| 51 | GUIName='get_field'; %default name of the GUI get_field |
---|
| 52 | if isfield(ParamIn,'GUIName') |
---|
| 53 | GUIName=ParamIn.GUIName; |
---|
| 54 | end |
---|
| 55 | CivStage=0; |
---|
| 56 | if ~strcmp(ParamIn.FieldName,'get_field...')% if get_field is not requested, look for Civx data |
---|
| 57 | FieldList=calc_field;%list of possible fields for Civx data |
---|
| 58 | ParamOut.ColorVar='';%default |
---|
| 59 | field_index=strcmp(ParamIn.FieldName,FieldList);%look for ParamIn.FieldName in the list of possible fields for Civx data |
---|
| 60 | if isempty(find(field_index,1))% ParamIn.FieldName is not in the list, check whether Civx data exist |
---|
[450] | 61 | Data=nc2struct(FileName,'ListGlobalAttribute','Conventions','absolut_time_T0','civ','CivStage'); |
---|
[445] | 62 | % case of new civdata conventions |
---|
| 63 | if isequal(Data.Conventions,'uvmat/civdata') |
---|
| 64 | ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default |
---|
| 65 | ParamOut.ColorVar='ima_cor'; |
---|
| 66 | InputField=[{ParamOut.FieldName} {ParamOut.ColorVar}]; |
---|
[450] | 67 | [Field,ParamOut.VelType,errormsg]=read_civdata(FileName,InputField,ParamIn.VelType,Data.CivStage); |
---|
[445] | 68 | CivStage=Field.CivStage; |
---|
| 69 | ParamOut.CivStage=Field.CivStage; |
---|
| 70 | %case of old civx conventions |
---|
| 71 | elseif ~isempty(Data.absolut_time_T0)&& ~isequal(Data.civ,0) |
---|
| 72 | ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default |
---|
| 73 | ParamOut.ColorVar='ima_cor'; |
---|
| 74 | InputField=[{ParamOut.FieldName} {ParamOut.ColorVar}]; |
---|
[450] | 75 | [Field,ParamOut.VelType]=read_civxdata(FileName,InputField,ParamIn.VelType); |
---|
[445] | 76 | CivStage=Field.CivStage; |
---|
| 77 | ParamOut.CivStage=Field.CivStage; |
---|
| 78 | % not cvix file, fields will be chosen through the GUI get_field |
---|
| 79 | else |
---|
| 80 | ParamOut.FieldName='get_field...'; |
---|
| 81 | hget_field=findobj(allchild(0),'Name',GUIName);%find the get_field... GUI |
---|
| 82 | if ~isempty(hget_field) |
---|
| 83 | delete(hget_field)%delete get_field for reinitialisation |
---|
| 84 | end |
---|
| 85 | end |
---|
| 86 | else |
---|
| 87 | InputField={ParamOut.FieldName}; |
---|
| 88 | if isfield(ParamIn,'ColorVar') |
---|
| 89 | ParamOut.ColorVar=ParamIn.ColorVar; |
---|
| 90 | InputField=[InputField {ParamOut.ColorVar}]; |
---|
| 91 | end |
---|
[450] | 92 | [Field,ParamOut.VelType,errormsg]=read_civxdata(FileName,InputField,ParamIn.VelType); |
---|
[445] | 93 | if ~isempty(errormsg) |
---|
| 94 | return |
---|
| 95 | end |
---|
[404] | 96 | CivStage=Field.CivStage; |
---|
[405] | 97 | ParamOut.CivStage=Field.CivStage; |
---|
[334] | 98 | end |
---|
[445] | 99 | ParamOut.FieldList=[{'image'};FieldList;{'get_field...'}]; |
---|
| 100 | end |
---|
| 101 | if CivStage==0% read the field names on the interface get_field. |
---|
| 102 | hget_field=findobj(allchild(0),'Name',GUIName);%find the get_field... GUI |
---|
| 103 | if isempty(hget_field)% open the GUI get_field if it is not found |
---|
[450] | 104 | hget_field= get_field(FileName);%open the get_field GUI |
---|
[445] | 105 | set(hget_field,'Name',GUIName)%update the name of get_field (e.g. get_field_1) |
---|
[334] | 106 | end |
---|
[445] | 107 | hhget_field=guidata(hget_field); |
---|
| 108 | %% update the get_field GUI |
---|
[450] | 109 | set(hhget_field.inputfile,'String',FileName) |
---|
[445] | 110 | set(hhget_field.list_fig,'Value',1) |
---|
| 111 | if exist('num','var')&&~isnan(num) |
---|
| 112 | set(hhget_field.TimeIndexValue,'String',num2str(num)) |
---|
[334] | 113 | end |
---|
[445] | 114 | funct_list=get(hhget_field.ACTION,'UserData'); |
---|
| 115 | funct_index=get(hhget_field.ACTION,'Value'); |
---|
| 116 | funct=funct_list{funct_index};%select the current action in get_field, e;g. PLOT |
---|
| 117 | Field=funct(hget_field); %%activate the current action selected in get_field, e;g.read the names of the variables to plot |
---|
| 118 | Tabchar={''};%default |
---|
| 119 | Tabcell=[]; |
---|
[450] | 120 | set(hhget_field.inputfile,'String',FileName) |
---|
[445] | 121 | if isfield(Field,'ListGlobalAttribute')&& ~isempty(Field.ListGlobalAttribute) |
---|
| 122 | for iline=1:length(Field.ListGlobalAttribute) |
---|
| 123 | Tabcell{iline,1}=Field.ListGlobalAttribute{iline}; |
---|
| 124 | if isfield(Field, Field.ListGlobalAttribute{iline}) |
---|
| 125 | eval(['val=Field.' Field.ListGlobalAttribute{iline} ';']) |
---|
| 126 | if ischar(val); |
---|
| 127 | Tabcell{iline,2}=val; |
---|
| 128 | else |
---|
| 129 | Tabcell{iline,2}=num2str(val); |
---|
| 130 | end |
---|
[334] | 131 | end |
---|
[181] | 132 | end |
---|
[445] | 133 | if ~isempty(Tabcell) |
---|
| 134 | Tabchar=cell2tab(Tabcell,'='); |
---|
| 135 | Tabchar=[{''};Tabchar]; |
---|
| 136 | end |
---|
[181] | 137 | end |
---|
[445] | 138 | ParamOut.CivStage=0; |
---|
| 139 | ParamOut.VelType=[]; |
---|
| 140 | if isfield(Field,'TimeIndex') |
---|
| 141 | ParamOut.TimeIndex=Field.TimeIndex; |
---|
[334] | 142 | end |
---|
[445] | 143 | if isfield(Field,'TimeValue') |
---|
| 144 | ParamOut.TimeValue=Field.TimeValue; |
---|
| 145 | end |
---|
| 146 | ParamOut.FieldList={'get_field...'}; |
---|
[181] | 147 | end |
---|
[445] | 148 | case {'video','mmreader'} |
---|
[450] | 149 | A=read(ParamIn,num); |
---|
[445] | 150 | case 'vol' |
---|
[450] | 151 | A=imread(FileName); |
---|
[445] | 152 | Npz=size(A,1)/ParamIn.Npy; |
---|
| 153 | A=reshape(A',ParamIn.Npx,ParamIn.Npy,Npz); |
---|
| 154 | A=permute(A,[3 2 1]); |
---|
| 155 | case 'multimage' |
---|
| 156 | warning 'off' |
---|
[450] | 157 | A=imread(FileName,num); |
---|
[445] | 158 | case 'image' |
---|
[450] | 159 | A=imread(FileName); |
---|
[445] | 160 | end |
---|
| 161 | catch ME |
---|
| 162 | errormsg=ME.message; |
---|
| 163 | return |
---|
[334] | 164 | end |
---|
[445] | 165 | |
---|
[334] | 166 | %% case of image |
---|
| 167 | if ~isempty(A) |
---|
[452] | 168 | if isstruct(ParamOut) |
---|
[181] | 169 | ParamOut.FieldName='image'; |
---|
| 170 | ParamOut.FieldList={'image'}; |
---|
[452] | 171 | end |
---|
[182] | 172 | Npz=1;%default |
---|
[181] | 173 | npxy=size(A); |
---|
[397] | 174 | % Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers |
---|
| 175 | % Rangy=[npxy(1)-0.5 0.5]; % |
---|
[181] | 176 | Field.NbDim=2;%default |
---|
| 177 | Field.AName='image'; |
---|
| 178 | Field.ListVarName={'AY','AX','A'}; % |
---|
| 179 | if ndims(A)==3 |
---|
| 180 | if Npz==1;%color |
---|
| 181 | Field.VarDimName={'AY','AX',{'AY','AX','rgb'}}; % |
---|
| 182 | Field.AY=[npxy(1)-0.5 0.5]; |
---|
| 183 | Field.AX=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers |
---|
[452] | 184 | if isstruct(ParamOut) |
---|
[182] | 185 | ParamOut.Npx=npxy(2);% display image size on the interface |
---|
| 186 | ParamOut.Npy=npxy(1); |
---|
[452] | 187 | end |
---|
[186] | 188 | Field.VarAttribute{3}.Mesh=1; |
---|
[181] | 189 | else |
---|
| 190 | Field.NbDim=3; |
---|
| 191 | Field.ListVarName=['AZ' Field.ListVarName]; |
---|
| 192 | Field.VarDimName={'AZ','AY','AX',{'AZ','AY','AX'}}; |
---|
| 193 | Field.AZ=[npxy(1)-0.5 0.5]; |
---|
| 194 | Field.AY=[npxy(2)-0.5 0.5]; |
---|
| 195 | Field.AX=[0.5 npxy(3)-0.5]; % coordinates of the first and last pixel centers |
---|
[452] | 196 | if isstruct(ParamOut) |
---|
[182] | 197 | ParamOut.Npx=npxy(3);% display image size on the interface |
---|
| 198 | ParamOut.Npy=npxy(2); |
---|
[452] | 199 | end |
---|
[186] | 200 | Field.VarAttribute{4}.Mesh=1; |
---|
[181] | 201 | end |
---|
| 202 | else |
---|
| 203 | Field.VarDimName={'AY','AX',{'AY','AX'}}; % |
---|
| 204 | Field.AY=[npxy(1)-0.5 0.5]; |
---|
| 205 | Field.AX=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers |
---|
[182] | 206 | ParamOut.Npx=npxy(2);% display image size on the interface |
---|
| 207 | ParamOut.Npy=npxy(1); |
---|
[186] | 208 | Field.VarAttribute{3}.Mesh=1; |
---|
[181] | 209 | end |
---|
| 210 | Field.A=A; |
---|
| 211 | Field.CoordUnit='pixel'; %used for mouse_motion |
---|
| 212 | end |
---|
| 213 | |
---|
| 214 | |
---|
[334] | 215 | |
---|