Changeset 445 for trunk/src/read_field.m
- Timestamp:
- Jun 8, 2012, 4:30:52 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/read_field.m
r441 r445 24 24 % = vol: images representing scanned volume (images concatened in the y direction) 25 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'...)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'...) 28 28 % .ColorVar: variable used for vector color 29 29 % .Npx, .Npy: nbre of pixels along x and y (used for .vol input files) … … 43 43 A=[]; 44 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); 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 59 Data=nc2struct(ObjectName,'ListGlobalAttribute','Conventions','absolut_time_T0','civ','CivStage'); 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}]; 65 [Field,ParamOut.VelType,errormsg]=read_civdata(ObjectName,InputField,ParamIn.VelType,Data.CivStage); 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}]; 73 [Field,ParamOut.VelType]=read_civxdata(ObjectName,InputField,ParamIn.VelType); 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 90 [Field,ParamOut.VelType,errormsg]=read_civxdata(ObjectName,InputField,ParamIn.VelType); 91 if ~isempty(errormsg) 92 return 93 end 65 94 CivStage=Field.CivStage; 66 95 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; 96 end 97 ParamOut.FieldList=[{'image'};FieldList;{'get_field...'}]; 95 98 end 96 ParamOut.FieldList=[{'image'};FieldList;{'get_field...'}]; 97 end 98 % ParamOut.FieldList=[{'image'};FieldList;{'get_field...'}]; 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 102 hget_field= get_field(ObjectName);%open the get_field GUI 103 set(hget_field,'Name',GUIName)%update the name of get_field (e.g. get_field_1) 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 102 hget_field= get_field(ObjectName);%open the get_field GUI 103 set(hget_field,'Name',GUIName)%update the name of get_field (e.g. get_field_1) 104 end 105 hhget_field=guidata(hget_field); 106 %% update the get_field GUI 107 set(hhget_field.inputfile,'String',ObjectName) 108 set(hhget_field.list_fig,'Value',1) 109 if exist('num','var')&&~isnan(num) 110 set(hhget_field.TimeIndexValue,'String',num2str(num)) 111 end 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=[]; 118 set(hhget_field.inputfile,'String',ObjectName) 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 129 end 130 end 131 if ~isempty(Tabcell) 132 Tabchar=cell2tab(Tabcell,'='); 133 Tabchar=[{''};Tabchar]; 134 end 135 end 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...'}; 104 145 end 105 hhget_field=guidata(hget_field); 106 %% update the get_field GUI 107 set(hhget_field.inputfile,'String',ObjectName) 108 set(hhget_field.list_fig,'Value',1) 109 if exist('num','var')&&~isnan(num) 110 set(hhget_field.TimeIndexValue,'String',num2str(num)) 111 end 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=[]; 118 set(hhget_field.inputfile,'String',ObjectName) 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 129 end 130 end 131 if ~isempty(Tabcell) 132 Tabchar=cell2tab(Tabcell,'='); 133 Tabchar=[{''};Tabchar]; 134 end 135 end 136 %set(hhget_field.attributes,'String',Tabchar);%update list of global attributes in get_field 137 ParamOut.CivStage=0; 138 ParamOut.VelType=[]; 139 if isfield(Field,'TimeIndex') 140 ParamOut.TimeIndex=Field.TimeIndex; 141 end 142 if isfield(Field,'TimeValue') 143 ParamOut.TimeValue=Field.TimeValue; 144 end 145 ParamOut.FieldList={'get_field...'}; 146 end 147 % if CivStage~=0 148 % ParamOut.FieldList=[{'image'};FieldList;{'get_field...'}]; 149 % else 150 % % ParamOut.FieldList={'get_field...'}; 151 % end 152 case {'video','mmreader'} 153 try 146 case {'video','mmreader'} 154 147 A=read(ObjectName,num); 155 catch ME 156 errormsg=ME.message; 157 return 158 end 159 FieldName='image'; 160 case 'vol' 161 A=imread(ObjectName); 162 Npz=size(A,1)/ParamIn.Npy; 163 A=reshape(A',ParamIn.Npx,ParamIn.Npy,Npz); 164 A=permute(A,[3 2 1]); 165 FieldName='image'; 166 case 'multimage' 167 A=imread(ObjectName,num); 168 FieldName='image'; 169 case 'image' 170 A=imread(ObjectName); 171 FieldName='image'; 172 end 148 case 'vol' 149 A=imread(ObjectName); 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' 155 A=imread(ObjectName,num); 156 case 'image' 157 A=imread(ObjectName); 158 end 159 catch ME 160 errormsg=ME.message; 161 return 162 end 163 173 164 %% case of image 174 165 if ~isempty(A)
Note: See TracChangeset
for help on using the changeset viewer.