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