source: trunk/src/read_field.m @ 233

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

small bug corrections, and improved display of image correlations (Testcvi1)

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