source: trunk/src/read_field.m @ 339

Last change on this file since 339 was 334, checked in by sommeria, 13 years ago

bugs corrected in fileparts_uvmat and find_file_series
name2dispaly replaced by fileparts_uvmat in uvmat, but not in other functions
bug corrected in plot_field, introduction of FileType? in read_field

File size: 9.2 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
36A=[];
37%% distingush different input file types
38switch FileType
39    case {'civx','civdata','netcdf'}  %read the first nc field
40        ParamOut.FieldName=ParamIn.FieldName;
41        GUIName='get_field'; %default name of the GUI get_field
42        if isfield(ParamIn,'GUIName')
43            GUIName=ParamIn.GUIName;
44        end
45        test_civx=0;
46        if ~strcmp(ParamIn.FieldName,'get_field...')% if get_field is not requested, look for Civx data
47            FieldList=calc_field;%list of possible fields for Civx data
48            ParamOut.ColorVar='';%default
49            field_index=strcmp(ParamIn.FieldName,FieldList);%look for ParamIn.FieldName in the list of possible fields for Civx data
50            if isempty(find(field_index,1))% ParamIn.FieldName is not in the list, check whether Civx data exist
51                Data=nc2struct(ObjectName,'ListGlobalAttribute','Conventions','absolut_time_T0','civ');
52                % case of new civdata conventions
53                if isequal(Data.Conventions,'uvmat/civdata')
54                    ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default
55                    ParamOut.ColorVar='ima_cor';
56                    InputField=[{ParamOut.FieldName} {ParamOut.ColorVar}];
57                    [Field,ParamOut.VelType]=read_civdata(ObjectName,InputField,ParamIn.VelType);
58                    test_civx=Field.CivStage;
59                    %case of old civx conventions
60                elseif ~isempty(Data.absolut_time_T0)&& ~isequal(Data.civ,0)
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]=read_civxdata(ObjectName,InputField,ParamIn.VelType);
65                    test_civx=Field.CivStage;
66                    ParamOut.CivStage=Field.CivStage;
67                    % not cvix file, fields will be chosen through the GUI get_field
68                else
69                    ParamOut.FieldName='get_field...';
70                    hget_field=findobj(allchild(0),'Name',GUIName);%find the get_field... GUI
71                    if ~isempty(hget_field)
72                        delete(hget_field)%delete  get_field for reinitialisation
73                    end
74                end
75            else
76                InputField={ParamOut.FieldName};
77                if isfield(ParamIn,'ColorVar')
78                    ParamOut.ColorVar=ParamIn.ColorVar;
79                    InputField=[InputField {ParamOut.ColorVar}];
80                end
81                [Field,ParamOut.VelType,errormsg]=read_civxdata(ObjectName,InputField,ParamIn.VelType);
82                if ~isempty(errormsg)
83                    return
84                end
85                test_civx=Field.CivStage;
86                ParamOut.CivStage=Field.CivStage;
87            end
88        end
89        if ~test_civx% read the field names on the interface get_field.
90            hget_field=findobj(allchild(0),'Name',GUIName);%find the get_field... GUI
91            if isempty(hget_field)% open the GUI get_field if it is not found
92                hget_field= get_field(ObjectName);%open the get_field GUI
93                set(hget_field,'Name',GUIName)%update the name of get_field (e.g. get_field_1)
94            end
95            hhget_field=guidata(hget_field);
96            %% update  the get_field GUI
97            set(hhget_field.inputfile,'String',ObjectName)
98            set(hhget_field.list_fig,'Value',1)
99            if exist('num','var')&&~isnan(num)
100                set(hhget_field.TimeIndexValue,'String',num2str(num))
101            end
102            funct_list=get(hhget_field.ACTION,'UserData');
103            funct_index=get(hhget_field.ACTION,'Value');
104            funct=funct_list{funct_index};%select  the current action in get_field, e;g. PLOT
105            Field=funct(hget_field); %%activate the current action selected in get_field, e;g.read the names of the variables to plot
106            Tabchar={''};%default
107            Tabcell=[];
108            set(hhget_field.inputfile,'String',ObjectName)
109            if isfield(Field,'ListGlobalAttribute')&& ~isempty(Field.ListGlobalAttribute)
110                for iline=1:length(Field.ListGlobalAttribute)
111                    Tabcell{iline,1}=Field.ListGlobalAttribute{iline};
112                    if isfield(Field, Field.ListGlobalAttribute{iline})
113                        eval(['val=Field.' Field.ListGlobalAttribute{iline} ';'])
114                        if ischar(val);
115                            Tabcell{iline,2}=val;
116                        else
117                            Tabcell{iline,2}=num2str(val);
118                        end
119                    end
120                end
121                if ~isempty(Tabcell)
122                    Tabchar=cell2tab(Tabcell,'=');
123                    Tabchar=[{''};Tabchar];
124                end
125            end
126            %set(hhget_field.attributes,'String',Tabchar);%update list of global attributes in get_field
127            ParamOut.CivStage=0;
128            ParamOut.VelType=[];
129            if isfield(Field,'TimeIndex')
130                ParamOut.TimeIndex=Field.TimeIndex;
131            end
132            if isfield(Field,'TimeValue')
133                ParamOut.TimeValue=Field.TimeValue;
134            end
135        end
136        if test_civx
137            ParamOut.FieldList=[{'image'};FieldList;{'get_field...'}];
138        else
139            ParamOut.FieldList={'get_field...'};
140        end
141       
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';
171end
172%% case of image
173if ~isempty(A)
174    ParamOut.FieldName='image';
175    ParamOut.FieldList={'image'};
176    Npz=1;%default
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
215
Note: See TracBrowser for help on using the repository browser.