Changeset 527 for trunk/src/read_field.m
- Timestamp:
- Aug 20, 2012, 11:12:46 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/read_field.m
r526 r527 35 35 ParamOut=ParamIn;%default 36 36 errormsg=''; 37 % if isfield(ParamIn,'VelType')38 % VelType=ParamIn.VelType;39 % end40 37 A=[]; 41 38 if isstruct(ParamIn) … … 52 49 end 53 50 %% distingush different input file types 54 try 55 switch FileType 56 case 'civdata' 57 [Field,ParamOut.VelType,errormsg]=read_civdata(FileName,InputField,ParamIn.VelType); 58 if ~isempty(errormsg),errormsg=['read_civdata:' errormsg];return,end 59 ParamOut.CivStage=Field.CivStage; 60 case 'civx' 61 ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default 62 [Field,ParamOut.VelType]=read_civxdata(FileName,InputField,ParamIn.VelType); 63 if ~isempty(errormsg),errormsg=['read_civxdata:' errormsg];return,end 64 ParamOut.CivStage=Field.CivStage; 65 case 'netcdf' 66 ListVar={}; 67 for ilist=1:numel(InputField) 68 r=regexp(InputField{ilist},'(?<Operator>(^vec|^norm))\((?<UName>.+),(?<VName>.+)\)$','names'); 69 if isempty(r) 70 ListVar=[ListVar InputField(ilist)]; 71 Role{numel(ListVar)}='scalar'; 72 % FieldRequest{numel(ListVar)}='interp_lin';%scalar field (requires interpolation for plot) 73 else 74 ListVar=[ListVar {r.UName,r.VName}]; 75 Role{numel(ListVar)}='vector_y'; 76 Role{numel(ListVar)-1}='vector_x'; 77 % TODO; introduce that for unstructured coordinates 78 % switch r.Operator TODO; introduce that for unstructured coordinates 79 % case 'norm' 80 % FieldRequest{numel(ListVar)-1}='interp_lin';%scalar field (requires interpolation for plot) 81 % FieldRequest{numel(ListVar)}='interp_lin'; 82 % otherwise 83 % FieldRequest{numel(ListVar)-1}=''; 84 % end 85 end 51 switch FileType 52 case 'civdata' 53 [Field,ParamOut.VelType,errormsg]=read_civdata(FileName,InputField,ParamIn.VelType); 54 if ~isempty(errormsg),errormsg=['read_civdata / ' errormsg];return,end 55 ParamOut.CivStage=Field.CivStage; 56 case 'civx' 57 ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default 58 [Field,ParamOut.VelType,errormsg]=read_civxdata(FileName,InputField,ParamIn.VelType); 59 if ~isempty(errormsg),errormsg=['read_civxdata / ' errormsg];return,end 60 ParamOut.CivStage=Field.CivStage; 61 case 'netcdf' 62 ListVar={}; 63 for ilist=1:numel(InputField) 64 r=regexp(InputField{ilist},'(?<Operator>(^vec|^norm))\((?<UName>.+),(?<VName>.+)\)$','names'); 65 if isempty(r) 66 ListVar=[ListVar InputField(ilist)]; 67 Role{numel(ListVar)}='scalar'; 68 % FieldRequest{numel(ListVar)}='interp_lin';%scalar field (requires interpolation for plot) 69 else 70 ListVar=[ListVar {r.UName,r.VName}]; 71 Role{numel(ListVar)}='vector_y'; 72 Role{numel(ListVar)-1}='vector_x'; 73 % TODO; introduce that for unstructured coordinates 74 % switch r.Operator TODO; introduce that for unstructured coordinates 75 % case 'norm' 76 % FieldRequest{numel(ListVar)-1}='interp_lin';%scalar field (requires interpolation for plot) 77 % FieldRequest{numel(ListVar)}='interp_lin'; 78 % otherwise 79 % FieldRequest{numel(ListVar)-1}=''; 80 % end 86 81 end 87 if check_colorvar 88 Role{numel(ListVar)}='ancillary';% scalar used for color vector (not projected) 89 end 90 [Field,var_detect,ichoice]=nc2struct(FileName,[ParamIn.Coord_x ParamIn.Coord_y ListVar]); 91 for ivar=1:numel(ListVar) 92 Field.VarAttribute{ivar+2}.Role=Role{ivar}; 93 % Field.VarAttribute{ivar+2}.FieldRequest=FieldRequest{ivar}; 94 end 95 96 case 'video' 97 if strcmp(class(ParamIn),'VideoReader') 98 A=read(ParamIn,num); 99 else 100 ParamOut=VideoReader(FileName); 101 A=read(ParamOut,num); 102 end 103 case 'mmreader' 104 if strcmp(class(ParamIn),'mmreader') 105 A=read(ParamIn,num); 106 else 107 ParamOut=mmreader(FileName); 108 A=read(ParamOut,num); 109 end 110 case 'vol' 111 A=imread(FileName); 112 Npz=size(A,1)/ParamIn.Npy; 113 A=reshape(A',ParamIn.Npx,ParamIn.Npy,Npz); 114 A=permute(A,[3 2 1]); 115 case 'multimage' 116 warning 'off' 117 A=imread(FileName,num); 118 case 'image' 119 A=imread(FileName); 120 end 121 catch ME 122 errormsg=[FileType ' input: ' ME.message]; 82 end 83 if check_colorvar 84 Role{numel(ListVar)}='ancillary';% scalar used for color vector (not projected) 85 end 86 [Field,var_detect,ichoice]=nc2struct(FileName,[ParamIn.Coord_x ParamIn.Coord_y ListVar]); 87 for ivar=1:numel(ListVar) 88 Field.VarAttribute{ivar+2}.Role=Role{ivar}; 89 % Field.VarAttribute{ivar+2}.FieldRequest=FieldRequest{ivar}; 90 end 91 92 case 'video' 93 if strcmp(class(ParamIn),'VideoReader') 94 A=read(ParamIn,num); 95 else 96 ParamOut=VideoReader(FileName); 97 A=read(ParamOut,num); 98 end 99 case 'mmreader' 100 if strcmp(class(ParamIn),'mmreader') 101 A=read(ParamIn,num); 102 else 103 ParamOut=mmreader(FileName); 104 A=read(ParamOut,num); 105 end 106 case 'vol' 107 A=imread(FileName); 108 Npz=size(A,1)/ParamIn.Npy; 109 A=reshape(A',ParamIn.Npx,ParamIn.Npy,Npz); 110 A=permute(A,[3 2 1]); 111 case 'multimage' 112 warning 'off' 113 A=imread(FileName,num); 114 case 'image' 115 A=imread(FileName); 116 end 117 if ~isempty(errormsg) 118 errormsg=[FileType ' input: ' errormsg]; 123 119 return 124 120 end
Note: See TracChangeset
for help on using the changeset viewer.