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