source: trunk/src/read_field.m @ 404

Last change on this file since 404 was 404, checked in by sommeria, 12 years ago

various bugs corrected. nc2struct_toolbox suppressed (correspond to obsolete versions of Matlab)

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