Changeset 334 for trunk/src/read_field.m


Ignore:
Timestamp:
Dec 14, 2011, 1:33:18 PM (12 years ago)
Author:
sommeria
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/read_field.m

    r273 r334  
    3434VelType=ParamIn.VelType;
    3535end
    36 
    37 %% case of netcdf input file
    38 if strcmp(FileType,'netcdf')  %read the first nc field
    39     ParamOut.FieldName=ParamIn.FieldName;
    40     GUIName='get_field'; %default name of the GUI get_field
    41     if isfield(ParamIn,'GUIName')
    42         GUIName=ParamIn.GUIName;
    43     end
    44     test_civx=0;
    45     if ~strcmp(ParamIn.FieldName,'get_field...')% if get_field is not requested, look for Civx data
    46         FieldList=calc_field;%list of possible fields for Civx data
    47         ParamOut.ColorVar='';%default
    48         field_index=strcmp(ParamIn.FieldName,FieldList);%look for ParamIn.FieldName in the list of possible fields for Civx data
    49         if isempty(find(field_index,1))% ParamIn.FieldName is not in the list, check whether Civx data exist
    50             Data=nc2struct(ObjectName,'ListGlobalAttribute','Conventions','absolut_time_T0','civ');
    51             % case of new civdata conventions
    52             if isequal(Data.Conventions,'uvmat/civdata')
    53                 ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default
    54                 ParamOut.ColorVar='ima_cor';
    55                 InputField=[{ParamOut.FieldName} {ParamOut.ColorVar}];
    56                 [Field,ParamOut.VelType]=read_civdata(ObjectName,InputField,ParamIn.VelType);
    57                 test_civx=Field.CivStage;
    58             %case of old civx conventions
    59             elseif ~isempty(Data.absolut_time_T0)&& ~isequal(Data.civ,0)
    60                 ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default
    61                 ParamOut.ColorVar='ima_cor';
    62                 InputField=[{ParamOut.FieldName} {ParamOut.ColorVar}];
    63                 [Field,ParamOut.VelType]=read_civxdata(ObjectName,InputField,ParamIn.VelType);
     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
    6485                test_civx=Field.CivStage;
    6586                ParamOut.CivStage=Field.CivStage;
    66             % not cvix file, fields will be chosen through the GUI get_field   
    67             else
    68                 ParamOut.FieldName='get_field...';
    69                 hget_field=findobj(allchild(0),'Name',GUIName);%find the get_field... GUI
    70                 if ~isempty(hget_field)
    71                     delete(hget_field)%delete  get_field for reinitialisation
    72                 end
    73             end
     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...'}];
    74138        else
    75             InputField={ParamOut.FieldName};
    76             if isfield(ParamIn,'ColorVar')
    77                 ParamOut.ColorVar=ParamIn.ColorVar;
    78                 InputField=[InputField {ParamOut.ColorVar}];
    79             end
    80             [Field,ParamOut.VelType,errormsg]=read_civxdata(ObjectName,InputField,ParamIn.VelType);
    81             if ~isempty(errormsg)
    82                 return
    83             end
    84             test_civx=Field.CivStage;
    85             ParamOut.CivStage=Field.CivStage;
    86         end
    87     end
    88     if ~test_civx% read the field names on the interface get_field.
    89         hget_field=findobj(allchild(0),'Name',GUIName);%find the get_field... GUI
    90         if isempty(hget_field)% open the GUI get_field if it is not found
    91             hget_field= get_field(ObjectName);%open the get_field GUI
    92             set(hget_field,'Name',GUIName)%update the name of get_field (e.g. get_field_1)
    93         end
    94         hhget_field=guidata(hget_field);
    95         %% update  the get_field GUI
    96         set(hhget_field.inputfile,'String',ObjectName)
    97         set(hhget_field.list_fig,'Value',1)
    98         if exist('num','var')&&~isnan(num)
    99             set(hhget_field.TimeIndexValue,'String',num2str(num))
    100         end
    101         funct_list=get(hhget_field.ACTION,'UserData');
    102         funct_index=get(hhget_field.ACTION,'Value');
    103         funct=funct_list{funct_index};%select  the current action in get_field, e;g. PLOT
    104         Field=funct(hget_field); %%activate the current action selected in get_field, e;g.read the names of the variables to plot
    105         Tabchar={''};%default
    106         Tabcell=[];
    107         set(hhget_field.inputfile,'String',ObjectName)
    108         if isfield(Field,'ListGlobalAttribute')&& ~isempty(Field.ListGlobalAttribute)
    109             for iline=1:length(Field.ListGlobalAttribute)
    110                 Tabcell{iline,1}=Field.ListGlobalAttribute{iline};
    111                 if isfield(Field, Field.ListGlobalAttribute{iline})
    112                     eval(['val=Field.' Field.ListGlobalAttribute{iline} ';'])
    113                     if ischar(val);
    114                         Tabcell{iline,2}=val;
    115                     else
    116                         Tabcell{iline,2}=num2str(val);
    117                     end
    118                 end
    119             end
    120             if ~isempty(Tabcell)
    121                 Tabchar=cell2tab(Tabcell,'=');
    122                 Tabchar=[{''};Tabchar];
    123             end
    124         end
    125         %set(hhget_field.attributes,'String',Tabchar);%update list of global attributes in get_field
    126         ParamOut.CivStage=0;
    127         ParamOut.VelType=[];
    128         if isfield(Field,'TimeIndex')
    129             ParamOut.TimeIndex=Field.TimeIndex;
    130         end
    131         if isfield(Field,'TimeValue')
    132             ParamOut.TimeValue=Field.TimeValue;
    133         end
    134     end
    135     if test_civx
    136         ParamOut.FieldList=[{'image'};FieldList;{'get_field...'}];
    137     else
    138         ParamOut.FieldList={'get_field...'};
    139     end
    140 else
    141    
    142     %% case of image
     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)
    143174    ParamOut.FieldName='image';
    144175    ParamOut.FieldList={'image'};
    145176    Npz=1;%default
    146     switch FileType
    147         case 'movie'
    148             try
    149                 A=read(ObjectName,num);
    150                 FieldName='image';
    151             catch ME
    152                 errormsg=ME.message;
    153                 return
    154             end
    155         case 'avi'
    156             try
    157                 mov=aviread(ObjectName,num);
    158             catch ME
    159                 errormsg=ME.message;
    160                 return
    161             end
    162             A=frame2im(mov(1));
    163             FieldName='image';
    164         case 'vol'
    165             A=imread(ObjectName);
    166             Npz=size(A,1)/ParamIn.Npy;
    167             A=reshape(A',ParamIn.Npx,ParamIn.Npy,Npz);
    168             A=permute(A,[3 2 1]);
    169             FieldName='image';
    170         case 'multimage'
    171             A=imread(ObjectName,num);
    172             FieldName='image';
    173         case 'image'
    174             A=imread(ObjectName);
    175             FieldName='image';
    176     end
    177177    npxy=size(A);
    178178    Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
     
    213213
    214214
     215
Note: See TracChangeset for help on using the changeset viewer.