source: trunk/src/read_field.m @ 332

Last change on this file since 332 was 273, checked in by sommeria, 13 years ago

GUI civ renovated with panels

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