Changeset 1095


Ignore:
Timestamp:
Mar 31, 2021, 3:32:03 PM (4 years ago)
Author:
sommeria
Message:

reading mat files added, +-fixed,OpenDAP improved

Location:
trunk/src
Files:
1 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/@xmltree/xmltree.m

    r925 r1095  
    3838            % Input argument is an XML string
    3939            if (~exist(varargin{1},'file') && ...
    40                 ~isempty(xml_findstr(varargin{1},'<',1,1)))
     40                    ~isempty(xml_findstr(varargin{1},'<',1,1)))
    4141                tree.tree = xml_parser(varargin{1});
    4242                tree.filename = '';
    43             % Input argument is an XML filename
     43                % Input argument is an XML filename
    4444            else
    45                 fid = fopen(varargin{1},'rt');
    46                 if (fid == -1)
    47                     error(['[XMLTree] Cannot open ' varargin{1}]);
     45                if isempty(regexp(varargin{1},'^http://'))%ordinary file (not OpenDAP)
     46                    fid = fopen(varargin{1},'rt');
     47                    if (fid == -1)
     48                        error(['[XMLTree] Cannot open ' varargin{1}]);
     49                    end
     50                    xmlstr = fread(fid,'*char')';
     51                    %xmlstr = fscanf(fid,'%c');
     52                    fclose(fid);
     53                else
     54                    xmlstr=webread(varargin{1});%OpenDAP case
    4855                end
    49                 xmlstr = fread(fid,'*char')';
    50                 %xmlstr = fscanf(fid,'%c');
    51                 fclose(fid);
    5256                tree.tree = xml_parser(xmlstr);
    53                 tree.filename = varargin{1};
     57                tree.filename = varargin{1};             
    5458            end
    5559            tree = class(tree,'xmltree');
    56         else 
     60        else
    5761            error('[XMLTree] Bad input argument');
    5862        end
  • trunk/src/find_field_bounds.m

    r1093 r1095  
    119119            FieldOut.ProjModeRequest='interp_tps';
    120120        end
    121         if strcmp(CellInfo{imax(ind)}.ProjModeRequest,'interp_lin')&& ~strcmp(FieldOut.ProjModeRequest,'interp_tps')
    122             FieldOut.ProjModeRequest='interp_lin';
    123         end
     121%         if strcmp(CellInfo{imax(ind)}.ProjModeRequest,'interp_lin')&& ~strcmp(FieldOut.ProjModeRequest,'interp_tps')
     122%             FieldOut.ProjModeRequest='interp_lin';
     123%         end
    124124    end
    125125end
  • trunk/src/find_field_cells.m

    r1093 r1095  
    149149
    150150%% initate cells around each scalar field with different coordinates
    151 % index_remove=[];
    152 % index_coord_x=zeros(size(ind_coord_x));
    153151cell_counter=0;
    154152DimCell={};
  • trunk/src/get_field.m

    r1093 r1095  
    7979if ischar(filename) % input file name
    8080    set(handles.inputfile,'String',filename)% fill the input file name
     81    if ~isempty(regexp(filename,'.mat$'))%case of .mat file
     82        Field=mat2struct(filename);
     83        errormsg='';
     84    else
    8185    [Field,tild,tild,errormsg]=nc2struct(filename,[]);% reads the  field structure, without the variables
     86    end
    8287else
    8388    msgbox_uvmat('ERROR','get_field requires a file name as input')% display error message for input file reading
     
    405410    case '1D plot'
    406411        set(handles.Coordinates,'Visible','on')
    407         %set(handles.PanelOrdinate,'Visible','on')
    408         %pos=get(handles.PanelOrdinate,'Position');
    409 %         pos(1)=2;
    410 %         pos_coord=get(handles.Coordinates,'Position');
    411 %         pos(2)=pos_coord(2)-pos(4)-2;
    412         %set(handles.PanelOrdinate,'Position',pos)
    413412        set(handles.PanelScalar,'Visible','off')
    414413        set(handles.PanelVectors,'Visible','off')
     
    419418        set(handles.Z_title,'Visible','off')
    420419        set(handles.Coord_x,'String',Field.Display.ListVarName')
    421         Coord_x_Callback(hObject, VarName, handles)
    422         %set(handles.Coord_y,'String',Field.Display.ListVarName')
    423         %Coord_x_Callback(hObject, VarName, handles)       
     420        Coord_x_Callback(hObject, VarName, handles)     
    424421    case {'scalar'}
    425422        set(handles.Coordinates,'Visible','on')
    426         %set(handles.PanelOrdinate,'Visible','off')
    427423        set(handles.PanelScalar,'Visible','on')
    428424        set(handles.PanelVectors,'Visible','off')
     
    469465        set(handles.Coord_y,'Visible','on')
    470466        set(handles.Y_title,'Visible','on')
     467        set(handles.Coord_x,'Visible','on')
    471468        %default vector selection
    472469        vector_x_value=get(handles.vector_x,'UserData');
     
    770767update_field(handles,VarName)
    771768end
     769
    772770%------------------------------------------------------------------------
    773771% --- Executes on selection change in vector_x or vector_y
     
    803801    var_coord=find(test_coord);% % list of variable indices elligible as structured coordinates
    804802    var_component(var_component==vector_x_index|var_component==vector_y_index)=[];
    805     var_coord(var_coord==vector_x_index|var_coord==vector_y_index)=[];% remove vector components form te possible list of coordinates
     803    var_coord(var_coord==vector_x_index|var_coord==vector_y_index)=[];% remove vector components from the possible list of coordinates
    806804    ListCoord=Field.Display.ListVarName([var_coord var_component]);
    807805   
     
    844842            coord_val=[1 2 3];
    845843        end
    846         set(handles.Coord_x,'Value',coord_val(end))
    847         set(handles.Coord_y,'Value',coord_val(end-1))
     844        set(handles.Coord_x,'Value',min(coord_val(end),numel(ListCoord)))
     845        set(handles.Coord_y,'Value',min(coord_val(end-1),numel(ListCoord)))
    848846        if numel(coord_val)>=3
    849847            set(handles.Coord_z,'Value',coord_val(end-2))
     
    887885%------------------------------------------------------------------------
    888886function Coord_x_Callback(hObject, DimCell, handles)
    889 DimCell
     887
    890888index=get(handles.Coord_x,'Value');
    891889string=get(handles.Coord_x,'String');
  • trunk/src/nc2struct.m

    r1093 r1095  
    11
    22%'nc2struct': transform a NetCDF file in a corresponding matlab structure
     3% or directly read the a matlab data file .mat (calling the fct mat2struct.m)
    34% it reads all the global attributes and all variables, or a selected list.
    45% The corresponding dimensions and variable attributes are then extracted
     
    6061    varargin{1}='*';
    6162end
    62 hhh=which('netcdf.open');% look for built-in matlab NetCDF library
    63 
    64 if ~isempty(hhh)
    65     %% default output
    66     Data=[];%default
    67     var_detect=[];%default
    68     ichoice=[];%default
    69 
    70     %% open the NetCDF file for reading
    71     if ischar(nc)
    72         if exist(nc,'file')
     63
     64%% default output
     65Data=[];%default
     66var_detect=[];%default
     67ichoice=[];%default
     68
     69%% open the NetCDF (or .mat) file for reading
     70if ischar(nc)
     71    testfile=1;
     72    if exist(nc,'file')
     73        if ~isempty(regexp(nc,'.mat$'))
     74            Data=mat2struct(nc,varargin{1});
     75            return
     76        else
    7377            try
    7478                nc=netcdf.open(nc,'NC_NOWRITE');
    75                 testfile=1;
    7679            catch ME
    7780                errormsg=['ERROR opening ' nc ': ' ME.message];
    7881                return
    7982            end
     83        end
     84    else %case of OpenDAP files
     85        if regexp(nc,'^http://')
     86            try
     87                nc=netcdf.open(nc,'NC_NOWRITE');
     88            catch ME
     89                errormsg=['ERROR opening ' nc ': ' ME.message];
     90                return
     91            end
    8092        else
    81             if regexp(nc,'^http://')
    82                 nc=netcdf.open(nc,'NC_NOWRITE');
    83                 testfile=1;
    84             else
    8593            errormsg=['ERROR:file ' nc ' does not exist'];
    8694            return
    87             end
    88         end
     95        end
     96    end
     97else
     98    testfile=0;
     99end
     100
     101%% short reading option for global attributes only, if the first argument is 'ListGlobalAttribute'
     102if isequal(varargin{1},'ListGlobalAttribute')
     103    for ilist=2:numel(varargin)
     104        valuestr=[];%default
     105        try
     106            valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),varargin{ilist});
     107        catch ME
     108        end
     109        eval(['Data.' varargin{ilist} '=valuestr;'])
     110    end
     111    netcdf.close(nc)
     112    return
     113end
     114
     115%% time variable or dimension
     116input_index=1;
     117CheckTimeVar=0;
     118TimeVarName='';
     119if isequal(varargin{1},'TimeVarName')
     120    TimeVarName=varargin{2};
     121    CheckTimeVar=1;
     122    TimeIndex=varargin{3};
     123    input_index=4;% list of variables to read is at fourth argument
     124elseif isequal(varargin{1},'TimeDimName')
     125    TimeDimName=varargin{2};
     126    TimeIndex=varargin{3};
     127    input_index=4;
     128end
     129
     130%% full reading: get the nbre of dimensions, variables, global attributes
     131ListVarName=varargin{input_index};
     132[ndims,nvars,ngatts]=netcdf.inq(nc);%nbre of dimensions, variables, global attributes, in the NetCDF file
     133
     134%%  -------- read all global attributes (constants)-----------
     135Data.ListGlobalAttribute={};%default
     136att_key=cell(1,ngatts);%default
     137for iatt=1:ngatts
     138    keystr= netcdf.inqAttName(nc,netcdf.getConstant('NC_GLOBAL'),iatt-1);
     139    valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),keystr);
     140    keystr=regexprep(keystr,{'\','/','\.','-',' '},{'','','','',''});%remove  '\','.' or '-' if exists
     141    if strcmp(keystr(1),'_')
     142        keystr(1)=[];
     143    end
     144    try
     145        if ischar(valuestr) %& length(valuestr)<200 & double(valuestr)<=122 & double(valuestr)>=48 %usual characters
     146            eval(['Data.' keystr '=''' valuestr ''';'])
     147        elseif isnumeric(valuestr)
     148            eval(['Data.' keystr '=valuestr;'])
     149        else
     150            eval(['Data.' keystr '='';'])
     151        end
     152        att_key{iatt}=keystr;
     153    catch ME
     154        att_key{iatt}=['attr_' num2str(iatt)];
     155        Data.(att_key{iatt})=[];
     156    end
     157end
     158Data.ListGlobalAttribute=att_key;
     159
     160%%  -------- read dimension names-----------
     161ListDimNameNetcdf=cell(1,ndims);
     162dim_value=zeros(1,ndims);
     163for idim=1:ndims %loop on the dimensions of the NetCDF file
     164    [ListDimNameNetcdf{idim},dim_value(idim)] = netcdf.inqDim(nc,idim-1);%get name and value of each dimension
     165end
     166if ~isempty(ListDimNameNetcdf)
     167    flag_used=zeros(1,ndims);%initialize the flag indicating the selected dimensions in the list (0=unused)
     168end
     169if isequal(varargin{1},'TimeDimName')% time dimension introduced
     170    TimeDimIndex=find(strcmp(TimeDimName,ListDimNameNetcdf));
     171    if isempty(TimeDimIndex)
     172        errormsg=['requested time dimension ' varargin{2} ' not found'];
     173        return
     174    end
     175    if dim_value(TimeDimIndex)<varargin{3}
     176        errormsg=['requested time index ' num2str(varargin{3}) ' exceeds matrix dimension'];
     177        return
     178    end
     179end
     180
     181%%  -------- read names of variables -----------
     182ListVarNameNetcdf=cell(1,nvars); %default
     183dimids=cell(1,nvars);
     184nbatt=zeros(1,nvars);
     185for ncvar=1:nvars %loop on the variables of the NetCDF file
     186    %get name, type, dimensions and attribute numbers of each variable
     187    [ListVarNameNetcdf{ncvar},xtype(ncvar),dimids{ncvar},nbatt(ncvar)] = netcdf.inqVar(nc,ncvar-1);
     188end
     189%     testmulti=0;
     190if isequal(ListVarName,'*')||isempty(ListVarName)
     191    var_index=1:nvars; %all the variables are selected in the NetCDF file
     192    Data.ListVarName=ListVarNameNetcdf;
     193else   %select input variables, if requested by the input ListVarName
     194    check_keep=ones(1,size(ListVarName,2));
     195    for ivar=1:size(ListVarName,2) % check redondancy of variable names
     196        if ~isempty(find(strcmp(ListVarName{1,ivar},ListVarName(1:ivar-1)), 1))
     197            check_keep(ivar)=0;% the variable #ivar is already in the list
     198        end
     199    end
     200    ListVarName=ListVarName(:,logical(check_keep));
     201    if size(ListVarName,1)>1 %multiple choice of variable ranked by order of priority
     202        for iline=1:size(ListVarName,1)
     203            search_index=find(strcmp(ListVarName{iline,1},ListVarNameNetcdf),1);%look for the first variable name in the list of NetCDF variables
     204            if ~isempty(search_index)
     205                break % go to the next line
     206            end
     207        end
     208        ichoice=iline-1;%selected line number in the list of input names of variables
    89209    else
    90         testfile=0;
    91     end
    92 
    93     %% short reading option for global attributes only, if the first argument is 'ListGlobalAttribute'
    94     if isequal(varargin{1},'ListGlobalAttribute')
    95         for ilist=2:numel(varargin)
    96             valuestr=[];%default
    97             try
    98                 valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),varargin{ilist});
    99             catch ME
    100             end
    101             eval(['Data.' varargin{ilist} '=valuestr;'])
    102         end
    103         netcdf.close(nc)
    104         return
    105     end
    106 
    107     %% time variable or dimension
    108     input_index=1;
    109     CheckTimeVar=0;
    110     TimeVarName='';
    111     if isequal(varargin{1},'TimeVarName')
    112         TimeVarName=varargin{2};
    113         CheckTimeVar=1;
    114         TimeIndex=varargin{3};
    115         input_index=4;% list of variables to read is at fourth argument
    116     elseif isequal(varargin{1},'TimeDimName')
    117         TimeDimName=varargin{2};
    118         TimeIndex=varargin{3};
    119         input_index=4;
    120     end
    121 
    122     %% full reading: get the nbre of dimensions, variables, global attributes
    123     ListVarName=varargin{input_index};
    124     [ndims,nvars,ngatts]=netcdf.inq(nc);%nbre of dimensions, variables, global attributes, in the NetCDF file
    125 
    126     %%  -------- read all global attributes (constants)-----------
    127     Data.ListGlobalAttribute={};%default
    128     att_key=cell(1,ngatts);%default
    129     for iatt=1:ngatts
    130         keystr= netcdf.inqAttName(nc,netcdf.getConstant('NC_GLOBAL'),iatt-1);
    131         valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),keystr);
    132         keystr=regexprep(keystr,{'\','/','\.','-',' '},{'','','','',''});%remove  '\','.' or '-' if exists
    133         if strcmp(keystr(1),'_')
    134             keystr(1)=[];
     210        iline=1;
     211    end
     212    %ListVarName=ListVarName(iline,:);% select the appropriate option for input variable (lin ein the input name matrix)
     213    if CheckTimeVar
     214        TimeVarIndex=find(strcmp(TimeVarName,ListVarNameNetcdf),1); %look for the index of the time variable in the netcdf list
     215        if isempty(TimeVarIndex)
     216            errormsg='requested variable for time is missing';
     217            return
     218        end
     219        TimeDimIndex=dimids{TimeVarIndex}(1)+1;
     220        ListVarName=[ListVarName {TimeVarName}];
     221    end
     222    var_index=zeros(1,size(ListVarName,2));%default list of variable indices
     223    for ivar=1:size(ListVarName,2)
     224        search_index=find(strcmp(ListVarName{iline,ivar},ListVarNameNetcdf),1);%look for the variable name in the list of NetCDF file
     225        if ~isempty(search_index)
     226            var_index(ivar)=search_index;%index of the netcdf list corresponding to the input list index ivar
     227        end
     228    end
     229    var_detect=(var_index~=0);%=1 for detected variables
     230    list_index=find(var_index);% indices in the input list corresponding to a detected variable
     231    var_index=var_index(list_index);% NetCDF variable indices corresponding to the output list of read variable
     232    Data.ListVarName=ListVarName(1,list_index);%the first line of ListVarName sets the output names of the variables
     233end
     234
     235%% get the dimensions and attributes associated to  variables
     236var_dim=cell(size(var_index));% initiate list of dimensions for variables
     237for ivar=1:length(var_index)
     238    var_dim{ivar}=dimids{var_index(ivar)}+1; %netcdf dimension indices used by the variable #ivar
     239    Data.VarDimName{ivar}=ListDimNameNetcdf(var_dim{ivar});
     240    flag_used(var_dim{ivar})=ones(size(var_dim{ivar}));%flag_used =1 for the indices of used dimensions
     241    for iatt=1:nbatt(var_index(ivar))
     242        attname = netcdf.inqAttName(nc,var_index(ivar)-1,iatt-1);
     243        valuestr= netcdf.getAtt(nc,var_index(ivar)-1,attname);
     244        attname=regexprep(attname,{'\','/','\.','-',' '},{'','','','',''});%remove  '\','.' or '-' if exists
     245        if strcmp(attname(1),'_')
     246            attname(1)=[];
    135247        end
    136248        try
    137             if ischar(valuestr) %& length(valuestr)<200 & double(valuestr)<=122 & double(valuestr)>=48 %usual characters
    138                 eval(['Data.' keystr '=''' valuestr ''';'])
    139             elseif isnumeric(valuestr)
    140                 eval(['Data.' keystr '=valuestr;'])
    141             else
    142                 eval(['Data.' keystr '='';'])
    143             end
    144             att_key{iatt}=keystr;
     249            if ~isempty(valuestr)
     250                Data.VarAttribute{ivar}.(attname)=valuestr;
     251            end
    145252        catch ME
    146             att_key{iatt}=['attr_' num2str(iatt)];
    147             Data.(att_key{iatt})=[];
    148         end
    149     end
    150     Data.ListGlobalAttribute=att_key;
    151 
    152     %%  -------- read dimension names-----------
    153     ListDimNameNetcdf=cell(1,ndims);
    154     dim_value=zeros(1,ndims);
    155     for idim=1:ndims %loop on the dimensions of the NetCDF file
    156         [ListDimNameNetcdf{idim},dim_value(idim)] = netcdf.inqDim(nc,idim-1);%get name and value of each dimension
    157     end
    158     if ~isempty(ListDimNameNetcdf)
    159         flag_used=zeros(1,ndims);%initialize the flag indicating the selected dimensions in the list (0=unused)
    160     end
    161     if isequal(varargin{1},'TimeDimName')% time dimension introduced
    162         TimeDimIndex=find(strcmp(TimeDimName,ListDimNameNetcdf));
    163         if isempty(TimeDimIndex)
    164             errormsg=['requested time dimension ' varargin{2} ' not found'];
    165             return
    166         end
    167         if dim_value(TimeDimIndex)<varargin{3}
    168            errormsg=['requested time index ' num2str(varargin{3}) ' exceeds matrix dimension'];
    169             return
    170         end
    171     end
    172 
    173     %%  -------- read names of variables -----------
    174     ListVarNameNetcdf=cell(1,nvars); %default
    175     dimids=cell(1,nvars);
    176     nbatt=zeros(1,nvars);
    177     for ncvar=1:nvars %loop on the variables of the NetCDF file
    178         %get name, type, dimensions and attribute numbers of each variable
    179         [ListVarNameNetcdf{ncvar},xtype(ncvar),dimids{ncvar},nbatt(ncvar)] = netcdf.inqVar(nc,ncvar-1);
    180     end
    181 %     testmulti=0;
    182     if isequal(ListVarName,'*')||isempty(ListVarName)
    183         var_index=1:nvars; %all the variables are selected in the NetCDF file
    184         Data.ListVarName=ListVarNameNetcdf;
    185     else   %select input variables, if requested by the input ListVarName
    186         check_keep=ones(1,size(ListVarName,2));
    187         for ivar=1:size(ListVarName,2) % check redondancy of variable names
    188             if ~isempty(find(strcmp(ListVarName{1,ivar},ListVarName(1:ivar-1)), 1))
    189                 check_keep(ivar)=0;% the variable #ivar is already in the list
    190             end
    191         end
    192         ListVarName=ListVarName(:,logical(check_keep));
    193         if size(ListVarName,1)>1 %multiple choice of variable ranked by order of priority
    194             for iline=1:size(ListVarName,1)
    195                 search_index=find(strcmp(ListVarName{iline,1},ListVarNameNetcdf),1);%look for the first variable name in the list of NetCDF variables
    196                 if ~isempty(search_index)
    197                     break % go to the next line
     253            display(attname)
     254            display(valuestr)
     255            display(ME.message)
     256            Data.VarAttribute{ivar}.(['atrr_' num2str(iatt)])='not read';
     257        end
     258    end
     259end
     260
     261%% select the dimensions used for the set of input variables
     262if ~isempty(var_index)
     263    dim_index=find(flag_used);%list of netcdf dimensions indices corresponding to used dimensions
     264    Data.ListDimName=ListDimNameNetcdf(dim_index);
     265    Data.DimValue=dim_value(dim_index);
     266    if input_index==4% if a dimension is selected as time
     267        Data.DimValue(TimeDimIndex)=numel(TimeIndex);
     268    end
     269end
     270
     271%% get the values of the input variables
     272if  ~isempty(ListVarName)
     273    for ivar=1:length(var_index)
     274        VarName=Data.ListVarName{ivar};
     275        VarName=regexprep(VarName,'-','_'); %suppress '-' if it exists in the NetCDF variable name (leads to errors in matlab)
     276        %             CheckSub=0;
     277        if input_index==4% if a dimension is selected as time
     278            ind_vec=zeros(1,numel(var_dim{ivar}));% vector with zeros corresponding to al the dimensions of the variable VarName
     279            ind_size=dim_value(var_dim{ivar});% vector giving the size (for each dimension) of the variable VarName
     280            index_time=find(var_dim{ivar}==TimeDimIndex);
     281            if ~isempty(index_time)
     282                if ind_size(index_time)<max(TimeIndex)
     283                    errormsg=['requested index ' num2str(TimeIndex) ' exceeds matrix dimension'];
     284                    return
    198285                end
    199             end
    200             ichoice=iline-1;%selected line number in the list of input names of variables
     286                ind_vec(index_time)=TimeIndex-1;% selected index(or indices) to read
     287                ind_size(index_time)=numel(TimeIndex);%length of the selected set of time indices
     288                if numel(TimeIndex)==1 && ~strcmp(VarName,TimeVarName)
     289                    Data.VarDimName{ivar}(index_time)=[];% for a single selected time remove the time in the list of dimensions (except for tTime itself)
     290                end
     291            end
     292            Data.(VarName)=netcdf.getVar(nc,var_index(ivar)-1,ind_vec,ind_size); %read the variable data
     293            Data.(VarName)=squeeze(Data.(VarName));%remove singeton dimension
    201294        else
    202             iline=1;
    203         end
    204         %ListVarName=ListVarName(iline,:);% select the appropriate option for input variable (lin ein the input name matrix)
    205         if CheckTimeVar
    206             TimeVarIndex=find(strcmp(TimeVarName,ListVarNameNetcdf),1); %look for the index of the time variable in the netcdf list
    207             if isempty(TimeVarIndex)
    208                 errormsg='requested variable for time is missing';
    209                 return
    210             end
    211             TimeDimIndex=dimids{TimeVarIndex}(1)+1;
    212             ListVarName=[ListVarName {TimeVarName}];
    213         end
    214         var_index=zeros(1,size(ListVarName,2));%default list of variable indices
    215         for ivar=1:size(ListVarName,2)
    216             search_index=find(strcmp(ListVarName{iline,ivar},ListVarNameNetcdf),1);%look for the variable name in the list of NetCDF file
    217             if ~isempty(search_index)
    218                 var_index(ivar)=search_index;%index of the netcdf list corresponding to the input list index ivar
    219             end
    220         end
    221         var_detect=(var_index~=0);%=1 for detected variables
    222         list_index=find(var_index);% indices in the input list corresponding to a detected variable
    223         var_index=var_index(list_index);% NetCDF variable indices corresponding to the output list of read variable
    224         Data.ListVarName=ListVarName(1,list_index);%the first line of ListVarName sets the output names of the variables
    225     end
    226 
    227     %% get the dimensions and attributes associated to  variables
    228     var_dim=cell(size(var_index));% initiate list of dimensions for variables
    229     for ivar=1:length(var_index)
    230         var_dim{ivar}=dimids{var_index(ivar)}+1; %netcdf dimension indices used by the variable #ivar
    231         Data.VarDimName{ivar}=ListDimNameNetcdf(var_dim{ivar});
    232         flag_used(var_dim{ivar})=ones(size(var_dim{ivar}));%flag_used =1 for the indices of used dimensions
    233         for iatt=1:nbatt(var_index(ivar))
    234             attname = netcdf.inqAttName(nc,var_index(ivar)-1,iatt-1);
    235             valuestr= netcdf.getAtt(nc,var_index(ivar)-1,attname);
    236             attname=regexprep(attname,{'\','/','\.','-',' '},{'','','','',''});%remove  '\','.' or '-' if exists
    237             if strcmp(attname(1),'_')
    238                 attname(1)=[];
    239             end
    240             try
    241                 if ~isempty(valuestr)
    242                     Data.VarAttribute{ivar}.(attname)=valuestr;
    243                 end
    244             catch ME
    245                 display(attname)
    246                 display(valuestr)
    247                 display(ME.message)
    248                 Data.VarAttribute{ivar}.(['atrr_' num2str(iatt)])='not read';
    249             end
    250         end
    251     end
    252 
    253     %% select the dimensions used for the set of input variables
    254     if ~isempty(var_index)
    255         dim_index=find(flag_used);%list of netcdf dimensions indices corresponding to used dimensions
    256         Data.ListDimName=ListDimNameNetcdf(dim_index);
    257         Data.DimValue=dim_value(dim_index);
    258         if input_index==4% if a dimension is selected as time
    259             Data.DimValue(TimeDimIndex)=numel(TimeIndex);
    260         end
    261     end
    262 
    263     %% get the values of the input variables
    264     if  ~isempty(ListVarName)
    265         for ivar=1:length(var_index)
    266             VarName=Data.ListVarName{ivar};
    267             VarName=regexprep(VarName,'-','_'); %suppress '-' if it exists in the NetCDF variable name (leads to errors in matlab)
    268 %             CheckSub=0;
    269             if input_index==4% if a dimension is selected as time
    270                 ind_vec=zeros(1,numel(var_dim{ivar}));% vector with zeros corresponding to al the dimensions of the variable VarName
    271                 ind_size=dim_value(var_dim{ivar});% vector giving the size (for each dimension) of the variable VarName
    272                 index_time=find(var_dim{ivar}==TimeDimIndex);
    273                 if ~isempty(index_time)
    274                     if ind_size(index_time)<max(TimeIndex)
    275                         errormsg=['requested index ' num2str(TimeIndex) ' exceeds matrix dimension'];
    276                         return
    277                     end
    278                     ind_vec(index_time)=TimeIndex-1;% selected index(or indices) to read
    279                     ind_size(index_time)=numel(TimeIndex);%length of the selected set of time indices
    280                     if numel(TimeIndex)==1 && ~strcmp(VarName,TimeVarName)
    281                         Data.VarDimName{ivar}(index_time)=[];% for a single selected time remove the time in the list of dimensions (except for tTime itself)
    282                     end
    283                 end
    284                 Data.(VarName)=netcdf.getVar(nc,var_index(ivar)-1,ind_vec,ind_size); %read the variable data
    285                 Data.(VarName)=squeeze(Data.(VarName));%remove singeton dimension
    286             else
    287                 Data.(VarName)=netcdf.getVar(nc,var_index(ivar)-1); %read the whole variable data
    288             end
    289             if xtype(var_index(ivar))==5
    290                 Data.(VarName)=double(Data.(VarName)); %transform to double for single pecision
    291             end
    292         end
    293     end
    294     Data.VarType=xtype(var_index);
    295 
    296     %%  -------- close fle-----------
    297     if testfile==1
    298         netcdf.close(nc)
    299     end
    300 
    301     %% old NetCDF library
    302 else
    303     [Data,var_detect,ichoice]=nc2struct_toolbox(nc,varargin);
    304 end
     295            Data.(VarName)=netcdf.getVar(nc,var_index(ivar)-1); %read the whole variable data
     296        end
     297        if xtype(var_index(ivar))==5
     298            Data.(VarName)=double(Data.(VarName)); %transform to double for single pecision
     299        end
     300    end
     301end
     302Data.VarType=xtype(var_index);
     303
     304%%  -------- close fle-----------
     305if testfile==1
     306    netcdf.close(nc)
     307end
     308
  • trunk/src/plot_field.m

    r1094 r1095  
    14261426    yi=rangy(1):dxy(1):rangy(2);
    14271427    A=griddata(vec_X,vec_Y,vec_A,xi,yi');
    1428     A=reshape(A,length(yi),length(xi));total
     1428    A=reshape(A,length(yi),length(xi));
    14291429else
    14301430    x=vec_X(1:index(1));% the set of abscissa (obtained on the first line)
  • trunk/src/proj_field.m

    r1094 r1095  
    11261126ProjMode=regexprep(ProjMode,' ',ObjectData.ProjMode);
    11271127icell_grid=[];% field cell index which defines the grid
     1128icell_scattered=[];% field cell index which defines fields with scattered coordinates
    11281129if strcmp(ObjectData.ProjMode,'projection')
    11291130    %% case of a grid requested by the input field
     
    11311132        if isfield(CellInfo{icell},'ProjModeRequest')
    11321133            switch CellInfo{icell}.ProjModeRequest
    1133                 case 'interp_lin'
    1134                     ProjMode{icell}='interp_lin';
     1134%                 case 'interp_lin'
     1135%                     ProjMode{icell}='interp_lin';
    11351136                case 'interp_tps'
    11361137                    ProjMode{icell}='interp_tps';
     
    11461147            end
    11471148            check_grid(icell)=1;
     1149        elseif strcmp(CellInfo{icell}.CoordType,'scattered')
     1150            icell_scattered=icell;
    11481151        end
    11491152    end
     
    12011204    ProjData.VarAttribute{1}.Role='coord_y';
    12021205    ProjData.VarAttribute{2}.Role='coord_x';
     1206    if ~isempty(icell_grid)
    12031207            YAttribute=FieldData.VarAttribute{CellInfo{icell_grid}.CoordIndex(NbDim-1)};
    12041208        XAttribute=FieldData.VarAttribute{CellInfo{icell_grid}.CoordIndex(NbDim)};
     1209    elseif ~isempty(icell_scattered)
     1210        NbDim=NbDimArray(icell_scattered);
     1211        YAttribute=FieldData.VarAttribute{CellInfo{icell_scattered}.CoordIndex(NbDim-1)};
     1212        XAttribute=FieldData.VarAttribute{CellInfo{icell_scattered}.CoordIndex(NbDim)};
     1213    end
    12051214    if ~testangle
    12061215        if isfield(YAttribute,'units')
  • trunk/src/read_field.m

    r1093 r1095  
    9393        if ~isempty(errormsg),errormsg=['read_civxdata / ' errormsg];return,end
    9494        ParamOut.CivStage=Field.CivStage;
    95     case 'netcdf'% general netcdf file (not recognized as civ)
     95    case {'netcdf','mat'}% general netcdf file (not recognized as civ)
    9696        ListVarName={};
    9797        Role={};
    9898        ProjModeRequest={};
    99         %ListInputField={};
    100         %checkU=0;
    101         %checkV=0;
    10299        % scan the list InputField
    103100        Operator=cell(1,numel(InputField));
     
    108105            if isempty(r)%  no operator used
    109106                ListVarName=[ListVarName InputField(ilist)];%append the variable name
    110                 %InputVar{ilist}=InputField(ilist);
    111                 %ListInputField=[ListInputField InputField(ilist)];
    112107                if check_colorvar(ilist)% case of field used for vector color
    113108                    Role{numel(ListVarName)}='ancillary';% not projected with interpolation
     
    129124                     Role=[Role {'vector_x'}];
    130125                end
    131                 %ListInputField=[ListInputField InputField(ilist)];
    132126                ListVarName=[ListVarName {r.VName}];% append the variable in the list if not previously listed
    133127                Role=[Role {'vector_y'}];
    134                 %ListInputField=[ListInputField InputField(ilist)];
    135128                Operator{numel(ListVarName)-1}=r.Operator;
    136129                Operator{numel(ListVarName)}='';           
     
    238231            Field.VarDimName=[Field.VarDimName(1:NbCoord) VarDimName];
    239232            Field.VarAttribute=[Field.VarAttribute(1:NbCoord) VarAttribute];
    240         end
    241     case 'mat'
    242          Field=load(FileName); 
     233        end 
    243234    case 'video'
    244235        if strcmp(class(ParamIn),'VideoReader')
  • trunk/src/read_xls.m

    r1093 r1095  
    1313% Copyright 2008-2021, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
    1414%   http://www.legi.grenoble-inp.fr
    15 %   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
     15%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.frread_xls.m
    1616%
    1717%     This file is part of the toolbox UVMAT.
  • trunk/src/series.m

    r1093 r1095  
    34233423
    34243424%% fill the GUI series with the content of the xml file
    3425 Param=xml2struct(filexml); % read the input xml file as a Matlab structure
    3426 
     3425[Param,RootTag,errormsg]=xml2struct(filexml); % read the input xml file as a Matlab structure
     3426if ~isempty(errormsg)
     3427    msgbox_uvmat('ERROR',errormsg);
     3428    return
     3429end
    34273430% ask to stop current Action if button RUN is in action (another process is already running)
    34283431if isequal(get(handles.RUN,'Value'),1)
  • trunk/src/series/civ_series.m

    r1093 r1095  
    366366            end
    367367            if strcmp(Param.ActionInput.ListCompareMode,'PIV')
    368                 ncfile_out=fullfile_uvmat(RootPath_A,OutputDir,RootFile_A,'.nc',NomTypeNc,i1_civ2,i2_civ2,j1_civ2,j2_civ2);
     368                ncfile_out=fullfile_uvmat(OutputPath,OutputDir,RootFile_A,'.nc',NomTypeNc,i1_civ2,i2_civ2,j1_civ2,j2_civ2);
     369%                 ncfile_out=fullfile_uvmat(RootPath_A,OutputDir,RootFile_A,'.nc',NomTypeNc,i1_civ2,i2_civ2,j1_civ2,j2_civ2);
    369370            else % displacement
    370                 ncfile_out=fullfile_uvmat(RootPath_A,OutputDir,RootFile_A,'.nc',NomTypeNc,i2_civ2,[],j2_civ2);
     371                ncfile_out=fullfile_uvmat(OutputPath,OutputDir,RootFile_A,'.nc',NomTypeNc,i2_civ2,[],j2_civ2);
    371372            end
    372373        end
  • trunk/src/series/sliding_average.m

    r1094 r1095  
    121121        return
    122122    end
    123     [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});900
     123    [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});
    124124    FileType{iview}=FileInfo{iview}.FileType;
    125125    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
     
    137137if size(time,1)>1
    138138    diff_time=max(max(diff(time)));
    139     if diff_time>0series
     139    if diff_time>0
    140140        msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)])
    141141    end   
     
    185185
    186186%% initialisation
    187 T=24.2; %main wave period
     187T=24.4; %main wave period
    188188t0=3; % time for motion start (torus at its maximum x)
    189189NbPeriod=2; %number of periods for the sliding average
     
    195195DataOut.ListGlobalAttribute= {'Conventions','Time'};
    196196DataOut.Conventions='uvmat';
    197 DataOut.ListVarName={'coord_y','coord_x','Umean','Vmean','Ucos','Vcos','DUDXsin','DUDXcos','DUDYsin','DVDXsin','DVDXcos'...
     197DataOut.ListVarName={'coord_y','coord_x','Umean','Vmean','Ucos','Vcos','Usin','Vsin','DUDXsin','DUDXcos','DUDYsin','DVDXsin','DVDXcos'...
    198198    ,'DVDYsin','Ustokes','Vstokes'};
    199199DataOut.VarDimName={'coord_y','coord_x',{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},...
    200200    {'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},...
    201     {'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'}};
     201    {'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'}};
    202202
    203203%%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
     
    237237        Ucos=zeros(NpTime,npy,npx);
    238238        Vcos=zeros(NpTime,npy,npx);
     239        Usin=zeros(NpTime,npy,npx);
     240        Vsin=zeros(NpTime,npy,npx);
    239241        DUDXcos=zeros(NpTime,npy,npx);
    240242        DUDXsin=zeros(NpTime,npy,npx);
     
    249251    Ucos=circshift(Ucos,[-1 0 0]); %shift U by ishift along the first index
    250252    Vcos=circshift(Vcos,[-1 0 0]); %shift U by ishift along the first index
     253    Usin=circshift(Usin,[-1 0 0]); %shift U by ishift along the first index
     254    Vsin=circshift(Vsin,[-1 0 0]); %shift U by ishift along the first index
    251255    DUDXcos=circshift(DUDXcos,[-1 0 0]);
    252256    DUDXsin=circshift(DUDXsin,[-1 0 0]);
     
    259263    Ucos(end,:,:)=Field.U*cos(omega*Time(index));
    260264    Vcos(end,:,:)=Field.V*cos(omega*Time(index));
     265    Usin(end,:,:)=Field.U*sin(omega*Time(index));
     266    Vsin(end,:,:)=Field.V*sin(omega*Time(index));
    261267    DUDXcos(end,:,:)=Field.DUDX*cos(omega*Time(index));
    262268    DUDXsin(end,:,:)=Field.DUDX*sin(omega*Time(index));
     
    269275    DataOut.Umean=(1/Uscale)*squeeze(nanmean(Umean,1));
    270276    DataOut.Vmean=(1/Uscale)*squeeze(nanmean(Vmean,1));
    271     DataOut.Ucos=2*squeeze(nanmean(Ucos,1));
    272     DataOut.Vcos=2*squeeze(nanmean(Vcos,1));
     277    DataOut.Ucos=2*(1/Uscale)*squeeze(nanmean(Ucos,1));
     278    DataOut.Vcos=2*(1/Uscale)*squeeze(nanmean(Vcos,1));
     279    DataOut.Usin=2*(1/Uscale)*squeeze(nanmean(Usin,1));
     280    DataOut.Vsin=2*(1/Uscale)*squeeze(nanmean(Vsin,1));
    273281    DataOut.DUDXcos=2*squeeze(nanmean(DUDXcos,1));
    274282    DataOut.DUDXsin=2*squeeze(nanmean(DUDXsin,1));
  • trunk/src/series/turb_stat.m

    r1093 r1095  
    303303
    304304%% open the result file with uvmat (in RUN mode)
    305 if checkrun
     305if checkrun && isequal(Param.IndexRange.NbSlice,1)
    306306    uvmat(OutputFile)% open the last result file with uvmat
    307307end
  • trunk/src/uigetfile_uvmat.m

    r1093 r1095  
    5454        elseif exist(InputName,'file')
    5555            [InputDir,InputFileName,Ext]=fileparts(InputName);
    56             if isempty(InputFileName)% if InputName is already the root
     56            if isempty(InputFileName)% if InputName is alr2eady the root
    5757                InputFileName=InputDir;
    5858                if  ~isempty(strcmp (computer, {'PCWIN','PCWIN64'}))%case of Windows systems
     
    308308        FullSelectName=[DirName '/' SelectName];
    309309    end
    310 end
     310end%     end
     311% end
    311312if CheckSubDir%exist(FullSelectName,'dir')% a directory has been selected
    312313    set(hObject,'BackgroundColor',[1 1 0])% paint list in yellow to indicate action
     
    344345index_dir=find(strcmp('isdir',fieldnames(ListStruct)));
    345346check_dir=cell2mat(ListCells(index_dir,:));% =1 for directories, =0 for files
    346 % for ilist=1:numel(check_dir)
    347 %     if check_dir(ilist)
    348347ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
    349 %     end
    350 % end
    351348if exist('filter_ext','var') && ~strcmp(filter_ext,'*') &&~strcmp(filter_ext,'uigetdir')
    352349    if strcmp(filter_ext,'image')
  • trunk/src/update_imadoc.m

    r1093 r1095  
    9090
    9191%% save the output file
    92 t=struct2xml(Struct,t,uid_calib); 
     92t=struct2xml(Struct,t,uid_calib);
    9393try
    94 save(t,outputfile);
     94    save(t,outputfile);
    9595catch ME
    96     errormsg=['error in update_imadoc' ME.message];
     96    errormsg=['error in saving ' outputfile ': ' ME.message];
    9797end
  • trunk/src/uvmat.m

    r1094 r1095  
    21982198        editxml(fileinput);
    21992199        return
    2200     case 'mat'% matlab data file
    2201         global Data_uvmat
    2202 Data_uvmat.Field=load(fileinput);
    2203 evalin('base','global Data_uvmat')%make CurData global in the workspace
    2204 disp('Data_uvmat.Field=')
    2205 evalin('base','Data_uvmat.Field') %display CurData in the workspace
    2206 commandwindow; %brings the Matlab command window to the front
    2207 return
     2200%     case 'mat'% matlab data file
     2201% %         global Data_uvmat
     2202% Data_uvmat.Field=load(fileinput);
     2203% evalin('base','global Data_uvmat')%make CurData global in the workspace
     2204% disp('Data_uvmat.Field=')
     2205% evalin('base','Data_uvmat.Field') %display CurData in the workspace
     2206% commandwindow; %brings the Matlab command window to the front
     2207% return
    22082208    otherwise
    22092209        set(handles_RootPath,'String',RootPath);
     
    22782278       
    22792279        %enable other menus
    2280 %         set(handles.MenuOpenCampaign,'Enable','on')
    22812280        set(handles.MenuExport,'Enable','on')
    22822281        set(handles.MenuExportFigure,'Enable','on')
     
    23552354if isfield(FileInfo,'FrameRate')% frame rate given in the file (case of video data)
    23562355    TimeUnit='s';
    2357     if isempty(j1_series); %frame index along i
     2356    if isempty(j1_series) %frame index along i
    23582357        XmlData.Time=zeros(FileInfo.NumberOfFrames+1,2);
    23592358        XmlData.Time(:,2)=(0:1/FileInfo.FrameRate:(FileInfo.NumberOfFrames)/FileInfo.FrameRate)';
     
    25522551        set(handles.Coord_x,'String','X');
    25532552        set(handles.Coord_y,'String','Y');
    2554     case 'netcdf'
     2553    case {'netcdf','mat'}
    25552554        set(handles_Fields,'Value',1)
    25562555        set(handles_Fields,'String',{'get_field...'})
     
    30193018        pause(1.02-get(handles.speed,'Value'))% wait for next image
    30203019end
    3021 if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
     3020if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj)
    30223021    UvData.aviobj=close(UvData.aviobj);
    30233022   set(handles.uvmat,'UserData',UvData);
     
    30633062set(handles.MovieBackward,'BusyAction','Cancel')
    30643063set(handles.MenuExportMovie,'BusyAction','Cancel')
    3065 %set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command buttonback to red
    30663064set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
    30673065set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
     
    30733071errormsg='';%default
    30743072%% check for movie pair status
    3075 movie_status=get(handles.movie_pair,'Value');
    3076 if movie_status
    3077     STOP_Callback(hObject, eventdata, handles)%interrupt movie pair if active
    3078 end
     3073% movie_status=get(handles.movie_pair,'Value');
     3074% if movie_status
     3075%     STOP_Callback(hObject, eventdata, handles)%interrupt movie pair if active
     3076% end
    30793077
    30803078%% read the current input file name(s) and field indices
     
    30903088    j1=str2num(get(handles.j1,'String'));%case of indexed movie
    30913089end
    3092 if movie_status% we read the second index from the edit box
    3093     i2=str2num(get(handles.i2,'String'));%read the field indices (for movie, it is not given by the file name)
    3094     if strcmp(get(handles.j2,'Visible'),'on')
    3095     j2=str2num(get(handles.j2,'String'));%
    3096     end
    3097 end
     3090% if movie_status% we read the second index from the edit box
     3091%     i2=str2num(get(handles.i2,'String'));%read the field indices (for movie, it is not given by the file name)
     3092%     if strcmp(get(handles.j2,'Visible'),'on')
     3093%     j2=str2num(get(handles.j2,'String'));%
     3094%     end
     3095% end
    30983096sub_value= get(handles.SubField,'Value');
    30993097if sub_value % a second input file has been entered
     
    31133111    set(handles.CheckFixPair,'Value',0)
    31143112end
    3115 CheckFixPair=get(handles.CheckFixPair,'Value')||(isempty(i2)&&isempty(j2));
     3113CheckFixPair=get(handles.CheckFixPair,'Value')||(isempty(i2)&& isempty(j2));
    31163114
    31173115% the pair i1-i2 or j1-j2 is imposed (check box CheckFixPair selected)
     
    31323130        end
    31333131    end
    3134 
    3135 % the pair i1-i2 or j1-j2 is free (check box CheckFixPair not selected): the list of existing indices recorded in UvData is used
     3132   
     3133    % the pair i1-i2 or j1-j2 is free (check box CheckFixPair not selected): the list of existing indices recorded in UvData is used
    31363134else
    31373135    UvData=get(handles.uvmat,'UserData');
     
    31543152        end
    31553153    else % free increment
    3156        % runaction=get(gcbo,'tag');
    31573154        if strcmp(increment,'+')% if runplus or movie is activated
    31583155            step=1;
     
    32033200        j2=UvData.j2_series{1}(ref_indices(end));
    32043201    end
    3205 
     3202   
    32063203    % case of a second file series
    32073204    if sub_value
     
    33003297    end
    33013298    if strcmp(NomType,'level')
    3302        indices=num2str(i1);
     3299        indices=num2str(i1);
    33033300    else
    3304     indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,j2);
     3301        indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,j2);
    33053302    end
    33063303    set(handles.FileIndex,'String',indices);
     
    33093306        set(handles.FileIndex_1,'String',indices_1);
    33103307    end
    3311     if isequal(movie_status,1)
    3312         set(handles.movie_pair,'Value',1)
    3313         movie_pair_Callback(hObject, eventdata, handles); %reactivate moviepair if it was activated
    3314     else
    3315         if isempty(i2), set(handles.i2,'String',''); end % suppress the second index display if not used
    3316         if isempty(j2), set(handles.j2,'String',''); end
    3317     end
     3308    if isempty(i2), set(handles.i2,'String',''); end % suppress the second index display if not used
     3309    if isempty(j2), set(handles.j2,'String',''); end
    33183310end
    33193311
     
    33523344        msgbox_uvmat('ERROR',errormsg);
    33533345    end
    3354    
    3355     %     set(hima,'CData',Field_b.A); %TODO: generalise to other kinds of fields
    33563346    pause(1.02-get(handles.speed,'Value'));% wait for next image
    33573347    errormsg=runpm(hObject,eventdata,handles,-increment);
    3358    
    3359     %     set(hima,'CData',Field_a.A);
     3348    if ~isempty(errormsg)
     3349        msgbox_uvmat('ERROR',errormsg);
     3350    end
    33603351    pause(1.02-get(handles.speed,'Value'));% wait for next image
     3352    get(handles.speed,'Value')~=0 && isequal(get(handles.movie_pair,'BusyAction'),'queue')
    33613353end
    33623354set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
     
    33643356set(handles.Dt_txt,'String','')
    33653357
    3366 
    3367 
    3368 
    33693358set(handles.runplus,'BackgroundColor',[1 0 0])%paint the command button back in red
    33703359
    3371 %
    3372 % set(handles.runmin,'BackgroundColor',[1 1 0])%paint the command button in yellow
    3373 % drawnow
    3374 % increment=-str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d
    3375 % if isnan(increment)% case of free increment: move to previous available field index
    3376 %     increment='-';
    3377 % end
    3378 % errormsg=runpm(hObject,eventdata,handles,increment);
    3379 % if ~isempty(errormsg)
    3380 %     msgbox_uvmat('ERROR',errormsg);
    3381 % end
    3382 % set(handles.runmin,'BackgroundColor',[1 0 0])%paint the command button back in red
    3383 %
    3384 % %% check the input file indexing:
    3385 % [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
    3386 % NomType=get(handles.NomType,'String');
    3387 % if ~isempty(find(regexp(NomType,'-')))
    3388 %     msgbox_uvmat('ERROR','The movie pair requires file series with a single index on the first input line')
    3389 %     return
    3390 % end
    3391 % filename=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% build the input file name (first line)
    3392 %
    3393 % set(handles.movie_pair,'BusyAction','queue')%
    3394 % set(handles.CheckFixPair,'Value',1)% impose fixed pair (needed for function runpm)
    3395 % set(handles.REFRESH,'BackgroundColor',[1 1 0])%paint the command button in yellow to indicate its activity
    3396 % set(handles.movie_pair,'BackgroundColor',[1 1 0])%paint the command button in yellow to indicate its activity
    3397 % drawnow
    3398 %
    3399 % num_i1=str2num(get(handles.i1,'String'));
    3400 % num_j1=stra2num(get(handles.j1,'String'));
    3401 % num_i2=str2num(get(handles.i2,'String'));
    3402 % num_j2=stra2num(get(handles.j2,'String'));
    3403 %
    3404 % %% determine the name 'imaname_1' of the second file in the pair
    3405 % imaname_1='';
    3406 % if isempty(num_j2)% no second j index indicated
    3407 %     if isempty(num_i2)
    3408 %         if strcmp(get(handles.j2,'Visible'),'on') %if the j box is visible
    3409 %             imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,num_i1,[],num_j1+1);
    3410 %         end
    3411 %         if exist(imaname_1,'file')
    3412 %             num_j2=num_j1+1;% look by default for the next j index as the second file
    3413 %             set(handles.j2,'String',num2stra(num_j2,NomType));
    3414 %         else
    3415 %             imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,num_i1+1,[],num_j1);
    3416 %             if exist(imaname_1,'file')
    3417 %                 num_i2=num_i1+1;
    3418 %                 set(handles.i2,'String',num2str(num_i2));
    3419 %             else
    3420 %                 msgbox_uvmat('ERROR', 'a second image index i2 or j2 is needed to show the pair as a movie')
    3421 %                 set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
    3422 %                 set(handles.movie_pair,'Value',0)
    3423 %                 return
    3424 %             end
    3425 %         end
    3426 %     else
    3427 %         num_j2=num_j1;%repeat the index i1 by default
    3428 %     end
    3429 % end
    3430 % if isempty(num_i2)
    3431 %     num_i2=num_i1;%repeat the index i1 by default
    3432 % end
    3433 % if isempty(num_j1)
    3434 %     num_j1=1;
    3435 % end
    3436 % if isempty(num_j2)
    3437 %     num_j2=num_j1;%repeat the index i1 by default
    3438 % end
    3439 % imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,num_i2,[],num_j2);
    3440 % if strcmp(NomType,'*')
    3441 %     num_frame=num_i2;
    3442 % else
    3443 %     num_frame=num_j2;
    3444 % end
    3445 % if ~exist(imaname_1,'file')
    3446 %       msgbox_uvmat('ERROR',['second input open (-)  ' imaname_1 ' not found']);
    3447 %       set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
    3448 %        set(handles.movie_pair,'Value',0)
    3449 %       return
    3450 % end
    3451 %
    3452 % %% display the first field in the pair (including possibly a background field from second line input filename_1)
    3453 % filename_1='';%default
    3454 % FileIndex_1='';
    3455 % if get(handles.SubField,'Value')
    3456 %     [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);
    3457 %     filename_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];
    3458 % end
    3459 % [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(FileIndex_1);% get the indices of the second series from the string FileIndex_1
    3460 % if isempty(j1_1)% case of movies, the index is not given by file index
    3461 %     j1_1=num_j1;
    3462 % end
    3463 %
    3464 % errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1);
    3465 %
    3466 % if isempty(errormsg)
    3467 %     set(handles.REFRESH,'BackgroundColor',[1 0 0])% set button color to red, update successfull
    3468 % else
    3469 %      msgbox_uvmat('ERROR',errormsg);
    3470 %      set(handles.REFRESH,'BackgroundColor',[1 0 1])% keep button color magenta, input not succesfull
    3471 % end
    3472 % UvData=get(handles.uvmat,'UserData');
    3473 % Field_a=UvData.Field;% movie on the field defined by the second input line
    3474 %
    3475 % %% display time interval for the image pair
    3476 % if isfield(UvData,'XmlData')&&isfield(UvData.XmlData{1},'Time')...
    3477 %         && size(UvData.XmlData{1}.Time,1)>=num_i2+1 && size(UvData.XmlData{1}.Time,2)>=num_j2+1
    3478 %     dt=(UvData.XmlData{1}.Time(num_i2+1,num_j2+1)-UvData.XmlData{1}.Time(num_i1+1,num_j1+1));
    3479 %     if  isfield(UvData,'TimeUnit')
    3480 %         set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' UvData.TimeUnit] )
    3481 %     else
    3482 %         set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
    3483 %     end
    3484 % else
    3485 %     set(handles.Dt_txt,'String','')
    3486 % end
    3487 %
    3488 % %% read the second field
    3489 % if isempty(UvData.MovieObject)
    3490 %     [Field_b,ParamOut,errormsg] = read_field(imaname_1,UvData.FileInfo{index}.FileType,[],num_frame);
    3491 % else
    3492 %     [Field_b,ParamOut,errormsg] = read_field(imaname_1,UvData.FileInfo{1}.FileType,UvData.MovieObject{1},num_frame);
    3493 % end
    3494 % if ~isempty(errormsg)
    3495 %     msgbox_uvmat('ERROR',['Error in reading second image: ' errormsg])
    3496 %     return
    3497 % end
    3498 %
    3499 % %% apply phys or other transform on the two input fields
    3500 % transform=get(handles.TransformPath,'UserData');
    3501 % if  ~isempty(transform)
    3502 %     if isfield(UvData,'XmlData') && ~isempty(UvData.XmlData) %use geometry calib recorded from the ImaDoc xml file as first priority
    3503 %         if nargin(transform)>=2
    3504 %             Field_b=transform(Field_b,UvData.XmlData{1});
    3505 %         else
    3506 %             Field_b=transform(Field_b);
    3507 %         end
    3508 %     end
    3509 % end
    3510 %
    3511 % %% make movie until movie speed is set to 0 or STOP is activated
    3512 % hima=findobj(handles.PlotAxes,'Tag','ima');% %handles.PlotAxes =main plotting window (A GENERALISER)
    3513 % set(handles.STOP,'Visible','on')
    3514 % set(handles.speed,'Visible','on')
    3515 % set(handles.speed_txt,'Visible','on')
    3516 % while get(handles.speed,'Value')~=0 && isequal(get(handles.movie_pair,'BusyAction'),'queue') % enable STOP command
    3517 %     % read and plot the series of images in non erase mode
    3518 %     set(hima,'CData',Field_b.A); %TODO: generalise to other kinds of fields
    3519 %     pause(1.02-get(handles.speed,'Value'));% wait for next image
    3520 %     set(hima,'CData',Field_a.A);
    3521 %     pause(1.02-get(handles.speed,'Value'));% wait for next image
    3522 % end
    3523 % set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
    3524 % set(handles.movie_pair,'Value',0)
    3525 % set(handles.Dt_txt,'String','')
    35263360
    35273361%------------------------------------------------------------------------
     
    36603494end
    36613495switch UvData.FileInfo{1}.FieldType
    3662     case {'civdata','netcdf'}
     3496    case {'civdata','netcdf','mat'}
    36633497        list_fields=get(handles.FieldName,'String');% list menu fields
    36643498        FieldName= list_fields{get(handles.FieldName,'Value')}; % selected field
    3665         if ~strcmp(FieldName,'get_field...')
     3499        if strcmp(FieldName,'get_field...')
     3500            FieldName_Callback(hObject, eventdata, handles)
     3501            return
     3502        else
    36663503            if get(handles.FixVelType,'Value')
    36673504                VelTypeList=get(handles.VelType,'String');
     
    36973534    end
    36983535    ParamIn.Coord_z=get(handles.Coord_z,'String');
    3699     %ParamIn.CheckCoordIndex=strcmp(get(handles.SwitchCoordIndex,'String'),'dim');
    37003536    TimeName=get(handles.TimeName,'String');
    37013537    r=regexp(TimeName,'^(?<type>(dim:)|(var:))','names');%look for 'var:' or 'dim:' at the beginning of time name
     
    37683604    end
    37693605    switch UvData.FileInfo{2}.FileType
    3770         case {'civx','civdata','netcdf','pivdata_fluidimage'}
     3606        case {'civx','civdata','netcdf','pivdata_fluidimage','mat'}
    37713607            list_fields=get(handles.FieldName_1,'String');% list menu fields
    37723608            FieldName_1= list_fields{get(handles.FieldName_1,'Value')}; % selected field
     
    41704006            break
    41714007        end
    4172         if UvData.Field.NbDim==3
     4008        if isfield(UvData.Field,'NbDim') && UvData.Field.NbDim==3
    41734009            UvData.ProjObject{iobj}.NbDim=3;%test for 3D objects
    41744010            if ~isfield(UvData.ProjObject{iobj},'RangeZ')
     
    53565192    prev_path=fullfile(fileparts(which('uvmat')),'transform_field');
    53575193end
    5358 if strcmp(transform_name,'more...');
     5194if strcmp(transform_name,'more...')
    53595195    transform_fct_chosen=uigetfile_uvmat('Pick the transform function',prev_path,'.m');
    53605196    if ~isempty(transform_fct_chosen)
     
    54445280%% delete drawn objects if the output CooordUnit is different from the previous one
    54455281if  ~strcmp(CoordUnit,CoordUnitPrev)
    5446 %     for iobj=1:numel(UvData.ProjObject)
    5447 %         delete_object(iobj)
    5448 %     end
    54495282    set(handles.CheckFixLimits,'Value',0)
    54505283    hother=findobj('Tag','proj_object');%find all the proj objects
     
    58345667AxeData=[];
    58355668if isfield(UvData,'PlotAxes')
    5836 AxeData=UvData.PlotAxes;% retrieve the current plotted data
     5669    AxeData=UvData.PlotAxes;% retrieve the current plotted data
    58375670end
    58385671PlotParam=read_GUI(handles.uvmat);
  • trunk/src/xml2struct.m

    r1093 r1095  
    2929%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3030%     GNU General Public License (see LICENSE.txt) for more details.
    31 %=======================================================================
     31%=======================================================================UVMAT-https     
    3232
    3333function [s,RootTag,errormsg]=xml2struct(filename,varargin)
Note: See TracChangeset for help on using the changeset viewer.