source: trunk/src/read_field.m @ 225

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

various bug corrections.

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