source: trunk/src/read_field.m @ 246

Last change on this file since 246 was 236, checked in by sommeria, 13 years ago

correct Matlab PIV, remove call to image tool box. Improve menu of uvmat VelType? (replacement of buttons)

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