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