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