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