source: trunk/src/read_field.m @ 182

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

introduction of a button OK to close the status GUI in civ, bug repair for volume images .vol (uvmat and set_object)

File size: 7.7 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)
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)
78            hget_field= get_field(ObjectName);%open the get_field GUI
79            set(hget_field,'Name',GUIName)
80        end
81        hhget_field=guidata(hget_field);
82        %% update  the get_field GUI
83        set(hhget_field.list_fig,'Value',1)
84        funct_list=get(hhget_field.ACTION,'UserData');
85        funct_index=get(hhget_field.ACTION,'Value');
86        funct=funct_list{funct_index};%select  the current action in get_field, e;g. PLOT
87        Field=funct(hget_field); %%activate the current action selected in get_field, e;g.read the names of the variables to plot
88        Tabchar={''};%default
89        Tabcell=[];
90        set(hhget_field.inputfile,'String',ObjectName)
91        if isfield(Field,'ListGlobalAttribute')&& ~isempty(Field.ListGlobalAttribute)
92            for iline=1:length(Field.ListGlobalAttribute)
93                Tabcell{iline,1}=Field.ListGlobalAttribute{iline};
94                if isfield(Field, Field.ListGlobalAttribute{iline})
95                    eval(['val=Field.' Field.ListGlobalAttribute{iline} ';'])
96                    if ischar(val);
97                        Tabcell{iline,2}=val;
98                    else
99                        Tabcell{iline,2}=num2str(val);
100                    end
101                end
102            end
103            if ~isempty(Tabcell)
104                Tabchar=cell2tab(Tabcell,'=');
105                Tabchar=[{''};Tabchar];
106            end
107        end
108        set(hhget_field.attributes,'String',Tabchar);%update list of global attributes in get_field
109        ParamOut.CivStage=0;
110        ParamOut.VelType=[];
111    end
112    if test_civx
113        ParamOut.FieldList=[{'image'};FieldList;{'get_field...'}];
114    else
115        ParamOut.FieldList={'get_field...'};
116    end
117else
118   
119    %% case of image
120    ParamOut.FieldName='image';
121    ParamOut.FieldList={'image'};
122    Npz=1;%default
123    switch FileType
124        case 'movie'
125            try
126                A=read(ObjectName,num_i1);
127                FieldName='image';
128            catch
129                errormsg=lasterr;
130                return
131            end
132        case 'avi'
133            try
134                mov=aviread(ObjectName,num_i1);
135            catch
136                errormsg=lasterr;
137                return
138            end
139            A=frame2im(mov(1));
140            FieldName='image';
141        case 'vol'
142            A=imread(ObjectName);
143            Npz=size(A,1)/ParamIn.Npy;
144            A=reshape(A',ParamIn.Npx,ParamIn.Npy,Npz);
145            A=permute(A,[3 2 1]);
146            FieldName='image';
147        case 'multimage'
148            A=imread(ObjectName,num_i1);
149            FieldName='image';
150        case 'image'
151            A=imread(ObjectName);
152            FieldName='image';
153    end
154    npxy=size(A);
155    Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
156    Rangy=[npxy(1)-0.5 0.5]; %
157    Field.NbDim=2;%default
158    Field.AName='image';
159    Field.ListVarName={'AY','AX','A'}; %
160    if ndims(A)==3
161        if Npz==1;%color
162            Field.VarDimName={'AY','AX',{'AY','AX','rgb'}}; %
163            Field.AY=[npxy(1)-0.5 0.5];
164            Field.AX=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
165            ParamOut.Npx=npxy(2);% display image size on the interface
166            ParamOut.Npy=npxy(1);
167        else
168            Field.NbDim=3;
169            Field.ListVarName=['AZ' Field.ListVarName];
170            Field.VarDimName={'AZ','AY','AX',{'AZ','AY','AX'}};
171            Field.AZ=[npxy(1)-0.5 0.5];
172            Field.AY=[npxy(2)-0.5 0.5];
173            Field.AX=[0.5 npxy(3)-0.5]; % coordinates of the first and last pixel centers
174            ParamOut.Npx=npxy(3);% display image size on the interface
175            ParamOut.Npy=npxy(2);
176        end
177    else
178        Field.VarDimName={'AY','AX',{'AY','AX'}}; %
179        Field.AY=[npxy(1)-0.5 0.5];
180        Field.AX=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
181        ParamOut.Npx=npxy(2);% display image size on the interface
182        ParamOut.Npy=npxy(1);
183    end
184    Field.A=A;
185    Field.CoordUnit='pixel'; %used for mouse_motion
186end
187
188
189
Note: See TracBrowser for help on using the repository browser.