Changeset 747 for trunk


Ignore:
Timestamp:
Apr 22, 2014, 9:44:39 AM (10 years ago)
Author:
sommeria
Message:

adpatations to 3D fields

Location:
trunk/src
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/compile.m

    r746 r747  
    1111    return
    1212else
    13     hh=msgbox_uvmat('INFO',['compilation of ' FctName ' in progress...']);
     13    hh=msgbox_uvmat('WAITING...',['compilation of ' FctName ' in progress...']);
    1414end
    1515disp(['compiling ' FctName ' ...'])
  • trunk/src/disp_uvmat.m

    r667 r747  
    1010%  checkrun: =0: batch mode: text display on log file
    1111
    12 function disp_uvmat(title,display_str,checkrun)
     12function hh=disp_uvmat(title,display_str,checkrun)
     13hh=[];
    1314if checkrun
    14     msgbox_uvmat(title,display_str,'')
     15    hh=msgbox_uvmat(title,display_str,'');
    1516else
    1617    disp([title ': ' display_str])
  • trunk/src/fill_GUI.m

    r710 r747  
    3838            set(handles.(fields{ifield}),'Visible','on')
    3939            errormsg=fill_GUI(Param.(fields{ifield}),handles.(fields{ifield}));% recursively apply the function to the substructure
    40 %         elseif isfield(UserData,fields{ifield}) && isfield(handles,fields{ifield}) && isfield(Param.(fields{ifield}),'Name')
    41 %             UserData.(fields{ifield})=Param.(fields{ifield});
    42 %             set(handles.(fields{ifield}),'String',Param.(fields{ifield}).Name)
    4340        end
    4441    else
     
    8784                            if isnumeric(input_data)
    8885                                if numel(input_data)>0
    89                                     input_string=num2str(input_data(ibox));
     86                                    input_string=num2str(input_data(ibox),4);
    9087                                end
    9188                            else
     
    9592                        case{'listbox','popupmenu'}
    9693                            if isnumeric(input_data)
    97                                 input_data=num2str(input_data);
     94                                input_data=num2str(input_data,4);
    9895                            end
    9996                            menu=get(hh(ibox),'String');
  • trunk/src/find_field_bounds.m

    r667 r747  
    5151        if NbDim==3
    5252            ZName=Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(1)};
    53             CoordMax(imax(ind),1)=max(max(Field.(ZName)));
     53            CoordMax(ind,1)=max(max(Field.(ZName)));
    5454            CoordMin(ind,1)=min(min(Field.(ZName)));
    5555        end
     
    7272if NbDim==3
    7373    FieldOut.ZMax=max(CoordMax(ind,1));
    74     FieldOut.ZMin=max(CoordMin(ind,1));
     74    FieldOut.ZMin=min(CoordMin(ind,1));
    7575end
    7676% adjust the mesh to a value 1, 2 , 5 *10^n
  • trunk/src/find_field_cells.m

    r690 r747  
    257257    DimIndices=[];
    258258    for idim=1:numel(DimCell)
    259         ind_dim=find(strcmp(DimCell{idim},ListDimName));%find the dim index in the list of coordinate variables
     259        ind_dim=find(strcmp(DimCell{idim},ListDimName));%find the dim index in the list of dimensions ListDimName
    260260        if ~isempty(ind_dim)
    261             DimIndices=[DimIndices ind_dim]; %update the list of coord dimensions included in DimCell
    262             if check_var && CoordSize(ind_dim)==2 % determine the size of the coordinate in case of coordiante variable limited to lower and upper bounds
     261            DimIndices=[DimIndices ind_dim]; %update the list of dim indices included in DimCell
     262            if check_var && CoordSize(ind_dim)==2 % determine the size of the coordinate in case of coordinate definition limited to lower and upper bounds
    263263                if isvector(Data.(ListVarName{ivardim}))
    264264                    if numel(Data.(ListVarName{ivardim}))>2
     
    287287        NewNbDim(nbcell)=numel(DimIndices);
    288288        NewCellInfo{nbcell}.CoordType='grid';
    289         NewCellInfo{nbcell}.CoordSize=CoordSize;
     289        NewCellInfo{nbcell}.CoordSize=CoordSize(DimIndices);
    290290        NewCellInfo{nbcell}.CoordIndex=ListCoordIndex(DimIndices);
    291291    end
  • trunk/src/get_field.m

    r701 r747  
    3434function varargout = get_field(varargin)
    3535
    36 % Last Modified by GUIDE v2.5 23-Oct-2013 23:44:17
     36% Last Modified by GUIDE v2.5 21-Apr-2014 15:03:19
    3737
    3838% Begin initialization code - DO NOT EDIT
     
    8686Field.Display=Field;
    8787Field.Check0D=zeros(size(Field.ListVarName));% =1 for arrays with a single value
    88 NbVar=numel(Field.VarDimName);
     88NbVar=numel(Field.VarDimName);%nbre of variables in the input data
    8989for ilist=1:NbVar
    9090    if ischar(Field.VarDimName{ilist})
     
    9292    end
    9393    NbDim=numel(Field.VarDimName{ilist});
    94     check_singleton=false(1,NbDim);
     94    check_singleton=false(1,NbDim);%  check singleton, false by default
    9595    for idim=1:NbDim
    9696        dim_index=strcmp(Field.VarDimName{ilist}{idim},Field.ListDimName);%index in the list of dimensions
     
    101101    Field.Display.VarDimName{ilist}=Field.VarDimName{ilist}(~check_singleton);% eliminate singletons in the list of variable dimensions
    102102    end
    103     %Field.NbDim(ilist)=numel(Field.VarDimNameNonSingleton{ilist});%nbre of array dimensions after elimination of singletons
    104103end
    105104if ~isfield(Field,'VarAttribute')
     
    109108    Field.VarAttribute(numel(Field.VarAttribute)+1:NbVar)=cell(1,NbVar-numel(Field.VarAttribute));
    110109end
    111 % Field.Display = list of variables and corresponding properties obtained after removal of singletons
    112 Field.Display.ListVarName=Field.ListVarName(~Field.Check0D);
     110% Field.Display = list of variables and corresponding properties obtained after removal of variables with a single value and singleton dimensions
     111Field.Display.ListVarName=Field.ListVarName(~Field.Check0D); %list of variables available for plots, after eliminating variables with a single value
    113112Field.Display.VarAttribute=Field.VarAttribute(~Field.Check0D);
    114113Field.Display.VarDimName=Field.Display.VarDimName(~Field.Check0D);
    115 Field.Display.DimValue=Field.DimValue(Field.DimValue~=1);
    116 Field.Display.ListDimName=Field.ListDimName(Field.DimValue~=1);
     114Field.Display.ListDimName=Field.ListDimName(Field.DimValue~=1);% list of non singleton dimension names
     115Field.Display.DimValue=Field.DimValue(Field.DimValue~=1);% corresponding list of non singleton dimension values
     116
    117117
    118118%% analyse the input field cells
     
    159159set(handles.vector_x,'String',Field.Display.ListVarName)% fill the menu of x vector components
    160160set(handles.vector_y,'String',Field.Display.ListVarName)% fill the menu of y vector components
    161 set(handles.vector_z,'String',[{''} Field.Display.ListVarName])% fill the menu of y vector components
     161set(handles.vector_z,'String',Field.Display.ListVarName)% fill the menu of y vector components
    162162set(handles.vec_color,'String',[{''} Field.Display.ListVarName])% fill the menu of y vector components
    163163set(handles.scalar,'Value',1)% fill the menu of y vector components
    164 set(handles.scalar,'String',Field.Display.ListVarName)% fill the menu of y vector components
     164set(handles.scalar,'String',Field.Display.ListVarName)% fill the menu for scalar
    165165set(handles.ordinate,'Value',1)% fill the menu of y vector components
    166 set(handles.ordinate,'String',Field.Display.ListVarName)% fill the menu of y vector components
     166set(handles.ordinate,'String',Field.Display.ListVarName)% fill the menu of y coordinate for 1D plots
    167167if isfield(Field,'Conventions')&& strcmp(Field.Conventions,'uvmat/civdata')
    168     set(handles.FieldOption,'String',{'1D plot';'scalar';'vectors';'civdata...'})
     168    set(handles.FieldOption,'String',{'1D plot';'scalar';'vectors';'civdata...'})% provides the possibility to come back to civdata
    169169else
    170170    set(handles.FieldOption,'String',{'1D plot';'scalar';'vectors'})
     
    238238set(hObject,'Position',pos_view_field)
    239239set(handles.get_field,'WindowStyle','modal')% Make the GUI modal
     240
     241%% set z coordinate menu if relevant
     242if Field.MaxDim>=3
     243    set(handles.Check3D,'Value',1)
     244else
     245    set(handles.Check3D,'Value',0)
     246end
     247Check3D_Callback(hObject, eventdata, handles)
    240248drawnow
    241249uiwait(handles.get_field);
    242 
    243 return
    244 
    245 %% set z coordinate menu if relevant
    246 if Field.MaxDim>=3
    247     set(handles.vector_z,'Visible','on')
    248     set(handles.vector_z,'String',Field.ListVarName(~Field.Check0D))
    249     set(handles.Coord_z,'Visible','on')
    250     set(handles.SwitchVarIndexZ,'Visible','on')
    251     set(handles.Z_title,'Visible','on')
    252 else
    253     set(handles.vector_z,'Visible','off')
    254     set(handles.Coord_z,'Visible','off')
    255     set(handles.Z_title,'Visible','off')
    256 end
    257 
    258 %% make selections according to ParamIn
    259 if isfield(ParamIn,'vector_x') && isfield(ParamIn,'vector_y')
    260    
    261 end
    262250
    263251%------------------------------------------------------------------------
     
    431419            end
    432420        end
    433         scalar_index=find(~test_coord,1);%get the first variable not a coordiante
     421        scalar_index=find(~test_coord,1);%get the first variable not a coordinate
    434422        if isempty(scalar_index)
    435423            set(handles.scalar,'Value',1)
     
    589577test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
    590578dim_var=Field.Display.VarDimName{scalar_index};%list of dimensions of the selected variable
    591 CheckDimensionX=get(handles.CheckDimensionX,'Value');
    592 CheckDimensionY=get(handles.CheckDimensionY,'Value');
    593 if ~CheckDimensionX  || ~CheckDimensionY
     579if ~get(handles.CheckDimensionX,'Value')  || ~get(handles.CheckDimensionY,'Value')
    594580    %look for coordinate variables among the other variables
    595581    for ilist=1:numel(Field.Display.VarDimName)
     
    616602    SwitchVarIndexTime_Callback([], [], handles)
    617603end
    618 % if numel(var_component)<2
    619 %     if numel(test_coord)<2
    620 %         ListCoord={''};
    621 %     else
    622 %         set(handles.Coord_x,'Value',2)
    623 %         set(handles.Coord_y,'Value',1)
    624 %     end
    625 % else
     604
    626605coord_val=[0 0];
    627606% look for labelled unstructured coordinates
     
    644623    end
    645624end
    646 if  CheckDimensionX
     625if  get(handles.CheckDimensionX,'Value')
    647626    set(handles.Coord_x,'Value',2)
    648627    set(handles.Coord_x,'String',dim_var')
     
    651630    set(handles.Coord_x,'String',ListCoord)
    652631end
    653 if  CheckDimensionY
     632if  get(handles.CheckDimensionY,'Value')
    654633    set(handles.Coord_y,'Value',1)
    655634    set(handles.Coord_y,'String',dim_var')
     
    657636    set(handles.Coord_y,'Value',coord_val(2))
    658637    set(handles.Coord_y,'String',ListCoord)
     638end
     639if  get(handles.CheckDimensionZ,'Value')
     640    set(handles.Coord_z,'Value',1)
     641    set(handles.Coord_z,'String',dim_var')
     642else
     643    set(handles.Coord_z,'Value',coord_val(2))
     644    set(handles.Coord_z,'String',ListCoord)
    659645end
    660646
     
    860846% --- Executes on selection change in SwitchVarIndexTime.
    861847%------------------------------------------------------------------------
     848
    862849function SwitchVarIndexTime_Callback(hObject, eventdata, handles)
    863850
     
    891878    case 'variable'% TimeName menu represents the available variables
    892879        set(handles.TimeName, 'Visible','on')
    893         TimeVarName=Field.Display.SingleVarName;% slist of variables with a single dimension (candidate for time)
    894         List=get(handles.TimeName,'String');
    895         option=List{get(handles.TimeName,'Value')};
    896         ind=find(strcmp(option,TimeVarName));
    897         if isempty(ind)
    898             set(handles.TimeName, 'Value',1);
    899         else
    900             set(handles.TimeName, 'Value',ind);
    901         end
    902         set(handles.TimeName, 'String',TimeVarName)
    903     case 'matrix_index'% TimeName menu represents the available dimensions
     880        VarNbDim=cellfun('length',Field.Display.VarDimName); % check the nbre of dimensions of each input variable
     881        TimeVarName=Field.Display.ListVarName(VarNbDim==1);% list of variables with a single dimension (candidate for time)
     882        List=get(handles.TimeName,'String');% list of names on the menu for time
     883        if isempty(List)
     884            ind=1;
     885        else
     886            option=List{get(handles.TimeName,'Value')};% previous selected option
     887            ind=find(strcmp(option,TimeVarName)); %check whether the previous selection is available in the newlist
     888            if isempty(ind)
     889                ind=1;
     890            end
     891        end
     892        if ~isempty(TimeVarName)
     893            set(handles.TimeName, 'Value',ind);% select first value in the menu if the option is not found
     894            set(handles.TimeName, 'String',TimeVarName)% update the menu for time name
     895        end
     896    case 'matrix index'% TimeName menu represents the available dimensions
    904897        set(handles.TimeName, 'Visible','on')     
    905898        set(handles.TimeName, 'Value',1);
     
    966959    case 'vectors'
    967960end
    968 % hObject    handle to CheckDimensionY (see GCBO)
    969 % eventdata  reserved - to be defined in a future version of MATLAB
    970 % handles    structure with handles and user data (see GUIDATA)
    971 
    972 % Hint: get(hObject,'Value') returns toggle state of CheckDimensionY
     961
     962
     963% --- Executes on button press in CheckDimensionZ.
     964function CheckDimensionZ_Callback(hObject, eventdata, handles)
     965FieldList=get(handles.FieldOption,'String');
     966FieldOption=FieldList{get(handles.FieldOption,'Value')};
     967switch FieldOption
     968    case '1D plot'
     969       
     970    case 'scalar'
     971       scalar_Callback(hObject, eventdata, handles)
     972    case 'vectors'
     973end
     974
     975% --- Executes on selection change in TimeName.
     976function TimeName_Callback(hObject, eventdata, handles)
     977index=get(handles.SwitchVarIndexTime,'Value');
     978if index==3 ; % TimeName is used to chose a variable
     979    index=get(handles.TimeName,'Value');
     980    string=get(handles.TimeName,'String');
     981    VarName=string{index};
     982end
     983update_field(handles,VarName)
     984
     985
     986% --- Executes on button press in Check3D.
     987function Check3D_Callback(hObject, eventdata, handles)
     988if get(handles.Check3D,'Value')
     989    status='on';
     990else
     991    status='off';
     992end
     993set(handles.Coord_z,'Visible',status)
     994set(handles.CheckDimensionZ,'Visible',status)
     995set(handles.Z_title,'Visible',status)
     996set(handles.vector_z,'Visible',status)
     997set(handles.W_title,'Visible',status)   
     998
     999
  • trunk/src/msgbox_uvmat.m

    r746 r747  
    66% OUTPUT:
    77% answer  (text string)= 'yes', 'No', 'cancel', or the text string introduced as input
     8% for title='WAITING...', the output is the handle of the figure, to allow deletion by the calling program.
    89%
    910%INPUT:
    1011% title: string indicating the type of message box:
    11 %          title= 'INPUT_TXT','CONFIMATION' ,'ERROR', 'WARNING', 'INPUT_Y-N','INPUT_MENU' default = 'INPUT_TXT' (the title is displayed in the upper bar of the fig).
     12%          title= 'INPUT_TXT','INPUT_Y-N','INPUT_MENU','ERROR', 'WARNING','CONFIMATION','WAITING...',default = 'INPUT_TXT' (the title is displayed in the upper bar of the fig).
    1213%          if title='INPUT_TXT', input data is asked in an edit box
    13 %          if title='CONFIMATION'', 'ERROR', 'WARNING', the figure remains  opened until a button 'OK' is pressed
     14%          if title='CONFIMATION'', 'ERROR', 'WARNING','RULER' the figure remains  opened until a button 'OK' is pressed
     15%             title='RULER' is used for display of length and angle from the ruler tool.
    1416%          if title='INPUT_Y-N', an answer Yes/No is requested
    15 % display, displayed text
     17%          if title='WAITING...' the figure remains open until the program deletes it
     18% display: displayed text
    1619% default_answer: default answer in the edit box (only used with title='INPUT_TXT')
    1720
     
    8891            testCancel=1; %no cancel button
    8992            testNo=1; % button No activated
    90         case {'RULER'}
     93        case 'RULER'
    9194            icontype='';
    9295            testinputstring=1;
     
    97100            testinputstring=2;
    98101            testCancel=1; %no cancel button
    99         case 'INFO'
     102        case 'WAITING...'
    100103            icontype='';
    101104            testOK=0;
     
    213216    if strcmp(get(handles.OK,'Visible'),'on')
    214217    delete(handles.figure1);
    215     else %case of INFO display (non modal)
     218    else %case of WAITING... display (non modal)
    216219        varargout{1}=hObject;
    217220    end
  • trunk/src/nc2struct.m

    r693 r747  
    2828%         if ListVarName=[] or {}, no variable value is read (only global attributes and list of variables and dimensions)
    2929%         if ListVarName is absent, or = '*', ALL the variables of the netcdf file are read.
    30 %         if ListVarName is a cell array with n lines, the set of variables will be sought by order of priority
    31 %                  in the list, while output names will be set by the first line
    32 %        - the string 'ListGlobalAttribute' followed by a list of attribute  names: reads only these attributes (fast reading)
    33 %        - the string 'TimeVarName', a string (the variable considered as
    34 %        time), an integer (the selected time index), the cell of other
    35 %        input variables limited to the input time index (considered as the last index of arrays)
    36 %        - the string 'TimeDimName', a string (the dimension considered as time), an integer (the selected time index), the cell of other
    37 %        input variables limited to the input time index (considered as the last index of arrays)
     30%         if ListVarName is a cell array with n lines, the set of variables will be sought by order of priority in the list,
     31%            while output names will be set by the first line
     32%       - the string 'ListGlobalAttribute' followed by a list of attribute  names: reads only these attributes (fast reading)
     33%       - the string 'TimeVarName', a string (the variable considered as time), an integer or vector with integer values
     34%            representing time indices to select, the cell of other input variable names.
     35%       - the string 'TimeDimName', a string (the name of the dimension considered as time), an integer or vector with integer values
     36%            representing time indices to select, the cell of other input variable names.
    3837
    3938%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
     
    5352%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    5453   
    55 function [Data,var_detect,ichoice]=nc2struct(nc,varargin)
    56 
     54function [Data,var_detect,ichoice,errormsg]=nc2struct(nc,varargin)
     55errormsg='';%default error message
    5756if isempty(varargin)
    5857    varargin{1}='*';
     
    6766   
    6867    %% open the netcdf file for reading
    69     if ischar(nc) 
     68    if ischar(nc)
    7069        if exist(nc,'file')
    7170            try
    72             nc=netcdf.open(nc,'NC_NOWRITE');
    73             testfile=1;
     71                nc=netcdf.open(nc,'NC_NOWRITE');
     72                testfile=1;
    7473            catch ME
    75               Data.Txt=['ERROR opening ' nc ': ' ME.message];
    76               return
     74                errormsg=['ERROR opening ' nc ': ' ME.message];
     75                return
    7776            end
    7877        else
    79            Data.Txt=['ERROR:file ' nc ' does not exist'];
    80            return
     78            errormsg=['ERROR:file ' nc ' does not exist'];
     79            return
    8180        end
    8281    else
     
    8988            valuestr=[];%default
    9089            try
    91             valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),varargin{ilist});
     90                valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),varargin{ilist});
    9291            catch ME
    9392            end
     
    9594        end
    9695        netcdf.close(nc)
    97        return
     96        return
    9897    end
    9998   
    10099    %% time variable or dimension
    101100    input_index=1;
     101    CheckTimeVar=0;
     102    TimeVarName='';
    102103    if isequal(varargin{1},'TimeVarName')
    103104        TimeVarName=varargin{2};
    104         TimeVarIndex=varargin{3};
    105         input_index=4;
     105        CheckTimeVar=1;
     106        TimeIndex=varargin{3};
     107        input_index=4;% list of varibles to read is at fourth argument
    106108    elseif isequal(varargin{1},'TimeDimName')
    107109        TimeDimName=varargin{2};
    108         TimeVarIndex=varargin{3};
     110        TimeIndex=varargin{3};
    109111        input_index=4;
    110112    end
    111 
     113   
    112114    %% full reading: get the nbre of dimensions, variables, global attributes
    113     ListVarName=varargin{input_index}; 
     115    ListVarName=varargin{input_index};
    114116    [ndims,nvars,ngatts]=netcdf.inq(nc);%nbre of dimensions, variables, global attributes, in the netcdf file
    115117   
     
    130132                eval(['Data.' keystr '=valuestr;'])
    131133            else
    132                 eval(['Data.' keystr '='';']) 
     134                eval(['Data.' keystr '='';'])
    133135            end
    134136            att_key{iatt}=keystr;
     
    139141    end
    140142    Data.ListGlobalAttribute=att_key;
    141 
     143   
    142144    %%  -------- read dimension names-----------
    143145    ListDimNameNetcdf=cell(1,ndims);
     
    146148        [ListDimNameNetcdf{idim},dim_value(idim)] = netcdf.inqDim(nc,idim-1);%get name and value of each dimension
    147149    end
    148     if ~isempty(ListDimNameNetcdf) 
     150    if ~isempty(ListDimNameNetcdf)
    149151        flag_used=zeros(1,ndims);%initialize the flag indicating the selected dimensions in the list (0=unused)
    150152    end
    151153    if isequal(varargin{1},'TimeDimName')% time dimension introduced
    152         TimeDimIndex=find(strcmp(varargin{2},ListDimNameNetcdf));
     154        TimeDimIndex=find(strcmp(TimeDimName,ListDimNameNetcdf));
    153155        if isempty(TimeDimIndex)
    154             Data.Txt=['requested time dimension ' varargin{2} ' not found'];
     156            errormsg=['requested time dimension ' varargin{2} ' not found'];
    155157            return
    156158        end
    157159        if dim_value(TimeDimIndex)<varargin{3}
    158             Data.Txt=['requested time index ' num2str(varargin{3}) ' exceeds matrix dimension'];
     160           errormsg=['requested time index ' num2str(varargin{3}) ' exceeds matrix dimension'];
    159161            return
    160162        end
    161     end
    162  
     163    end 
     164    
    163165    %%  -------- read names of variables -----------
    164166    ListVarNameNetcdf=cell(1,nvars); %default
     
    166168    nbatt=zeros(1,nvars);
    167169    for ncvar=1:nvars %loop on the variables of the netcdf file
    168         %get name, type, dimensions and attribute numbers of each variable 
     170        %get name, type, dimensions and attribute numbers of each variable
    169171        [ListVarNameNetcdf{ncvar},xtype(ncvar),dimids{ncvar},nbatt(ncvar)] = netcdf.inqVar(nc,ncvar-1);
    170     end 
    171     testmulti=0;
     172    end
     173%     testmulti=0;
    172174    if isequal(ListVarName,'*')||isempty(ListVarName)
    173         var_index=1:nvars; %all the variables are selected in the netcdf file 
     175        var_index=1:nvars; %all the variables are selected in the netcdf file
    174176        Data.ListVarName=ListVarNameNetcdf;
    175177    else   %select input variables, if requested by the input ListVarName
    176         ind_remove=[];
    177178        check_keep=ones(1,size(ListVarName,2));
    178179        for ivar=1:size(ListVarName,2) % check redondancy of variable names
     
    181182            end
    182183        end
    183         ListVarName=ListVarName(:,logical(check_keep));         
     184        ListVarName=ListVarName(:,logical(check_keep));
    184185        sizvar=size(ListVarName);
    185         testmulti=(sizvar(1)>1);%test for multiple choice of variable ranked by order of priority
    186186        var_index=zeros(1,sizvar(2));%default
    187         if testmulti %multiple choice of variable ranked by order of priority
     187        if sizvar(1)>1 %multiple choice of variable ranked by order of priority
    188188            for iline=1:sizvar(1)
    189189                search_index=find(strcmp(ListVarName{iline,1},ListVarNameNetcdf),1);%look for the first variable name in the list of netcdf variables
     
    196196            iline=1;
    197197        end
    198         for ivar=1:sizvar(2)
     198        %ListVarName=ListVarName(iline,:);% select the appropriate option for input variable (lin ein the input name matrix)
     199        if CheckTimeVar
     200            TimeVarIndex=find(strcmp(TimeVarName,ListVarNameNetcdf),1); %look for the index of the time variable in the netcdf list
     201            if isempty(TimeVarIndex)
     202                errormsg='requested variable for time is missing';
     203                return
     204            end
     205            TimeDimIndex=dimids{TimeVarIndex}(1)+1;
     206            ListVarName=[ListVarName {TimeVarName}];
     207        end
     208        for ivar=1:size(ListVarName,2)
    199209            search_index=find(strcmp(ListVarName{iline,ivar},ListVarNameNetcdf),1);%look for the variable name in the list of netcdf file
    200210            if ~isempty(search_index)
     
    202212            end
    203213        end
    204         var_detect=(var_index~=0);%=1 for detected variables         
     214        var_detect=(var_index~=0);%=1 for detected variables
    205215        list_index=find(var_index);% indices in the input list corresponding to a detected variable
    206216        var_index=var_index(list_index);% netcdf variable indices corresponding to the output list of read variable
    207217        Data.ListVarName=ListVarName(1,list_index);%the first line of ListVarName sets the output names of the variables
    208218    end
    209      
    210   %% get the dimensions and attributes associated to  variables
    211   var_dim=cell(size(var_index));% initiate list of dimensions for variables
     219   
     220    %% get the dimensions and attributes associated to  variables
     221    var_dim=cell(size(var_index));% initiate list of dimensions for variables
    212222    for ivar=1:length(var_index)
    213223        var_dim{ivar}=dimids{var_index(ivar)}+1; %netcdf dimension indices used by the variable #ivar
     
    222232            end
    223233            try
    224              if isempty(valuestr)
    225                 Data.VarAttribute{ivar}.(attname)=valuestr;
    226             end
     234                if isempty(valuestr)
     235                    Data.VarAttribute{ivar}.(attname)=valuestr;
     236                end
    227237            catch ME
    228238                display(attname)
    229239                display(valuestr)
    230                 display(ME.message)         
     240                display(ME.message)
    231241                Data.VarAttribute{ivar}.(['atrr_' num2str(iatt)])='not read';
    232242            end
     
    234244    end
    235245   
    236 
    237246    %% select the dimensions used for the set of input variables
    238     if ~isempty(var_index)     
    239         dim_index=find(flag_used);%list of netcdf dimensions indices corresponding to used dimensions 
    240         Data.ListDimName=ListDimNameNetcdf(dim_index); 
     247    if ~isempty(var_index)
     248        dim_index=find(flag_used);%list of netcdf dimensions indices corresponding to used dimensions
     249        Data.ListDimName=ListDimNameNetcdf(dim_index);
    241250        Data.DimValue=dim_value(dim_index);
     251        if input_index==4% if a dimension is selected as time
     252            Data.DimValue(TimeDimIndex)=numel(TimeIndex);
     253        end
    242254    end
    243255   
     
    246258        for ivar=1:length(var_index)
    247259            VarName=Data.ListVarName{ivar};
    248             VarName=regexprep(VarName,'-',''); %suppress '-' if it exists in the netcdf variable name
    249             CheckSub=0;
     260            VarName=regexprep(VarName,'-','_'); %suppress '-' if it exists in the netcdf variable name (leads to errors in matlab)
     261%             CheckSub=0;
    250262            if input_index==4% if a dimension is selected as time
    251                 if var_dim{ivar}(end)==TimeDimIndex% if the last dim of the variable is the time
    252                     slice_length=prod(var_dim{ivar}(1:end-1));
    253                     Data.(VarName)=double(netcdf.getVar(nc,var_index(ivar)-1,TimeIndex*slice_length,slice_length)); %read the variable data
    254                     CheckSub=1;
    255                 end
    256             end
    257             if ~CheckSub
     263                ind_vec=zeros(1,numel(var_dim{ivar}));% vector with zeros corresponding to al the dimensions of the variable VarName
     264                ind_size=dim_value(var_dim{ivar});% vector giving the size of the variable VarName
     265                index_time=find(var_dim{ivar}==TimeDimIndex);
     266                if ~isempty(index_time)
     267                    ind_vec(index_time)=TimeIndex-1;% selected index(or indices) to read
     268                    ind_size(index_time)=numel(TimeIndex);%length of the selected set of time indices
     269                    if numel(TimeIndex)==1 && ~strcmp(VarName,TimeVarName)
     270                        Data.VarDimName{ivar}(index_time)=[];% for a single selected time remove the time in the list of dimensions (except for tTime itself)
     271                    end
     272                end                   
     273                Data.(VarName)=double(netcdf.getVar(nc,var_index(ivar)-1,ind_vec,ind_size)); %read the variable data
     274                Data.(VarName)=squeeze(Data.(VarName));%remove singeton dimension
     275            else
    258276                Data.(VarName)=netcdf.getVar(nc,var_index(ivar)-1); %read the whole variable data
    259                 if xtype(var_index(ivar))==5
     277            end
     278            if xtype(var_index(ivar))==5
    260279                Data.(VarName)=double(Data.(VarName)); %transform to double for single pecision
    261                 end
    262280            end
    263281        end
     
    267285    %%  -------- close fle-----------
    268286    if testfile==1
    269         netcdf.close(nc) 
    270     end
    271    
    272 %% old netcdf library
     287        netcdf.close(nc)
     288    end
     289   
     290    %% old netcdf library
    273291else
    274292    [Data,var_detect,ichoice]=nc2struct_toolbox(nc,varargin);
  • trunk/src/proj_field.m

    r738 r747  
    12961296                    Coord{1}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(1)});
    12971297                    Coord{2}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(2)});
     1298                    if NbDim==3
     1299                        Coord{3}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(3)});
     1300                    end
    12981301                    if numel(Coord{NbDim-1})==2
    12991302                        DY=(Coord{NbDim-1}(2)-Coord{NbDim-1}(1))/(DimValue(1)-1);
     
    13021305                        DX=(Coord{NbDim}(2)-Coord{NbDim}(1))/(DimValue(2)-1);
    13031306                    end
    1304                     if testYMin%test_direct(indY)
    1305                         YIndexMin=(YMin-Coord{NbDim-1}(1))/DY+1;% matrix index corresponding to the min y value for the new field
    1306                         YIndexMax=(YMax-Coord{NbDim-1}(1))/DY+1;% matrix index corresponding to the max y value for the new field
     1307                    if testYMax
     1308                         YIndexMax=(YMax-Coord{NbDim-1}(1))/DY+1;% matrix index corresponding to the max y value for the new field
     1309                        if testYMin%test_direct(indY)
     1310                            YIndexMin=(YMin-Coord{NbDim-1}(1))/DY+1;% matrix index corresponding to the min x value for the new field
     1311                        else
     1312                            YIndexMin=1;
     1313                        end         
    13071314                    else
    1308                         YIndexMin=(Coord{NbDim-1}(1)-YMax)/DY+1;
    1309                         YIndexMax=(Coord{NbDim-1}(1)-YMin)/DY+1;
    1310                         Ybound(2)=Coord{NbDim-1}(1)-DY*(YIndexMax-1);
    1311                         Ybound(1)=Coord{NbDim-1}(1)-DY*(YIndexMin-1);
    1312                     end
    1313                     if testXMin%test_direct(NbDim)==1
    1314                         XIndexMin=(XMin-Coord{NbDim}(1))/DX+1;% matrix index corresponding to the min x value for the new field
    1315                         XIndexMax=(XMax-Coord{NbDim}(1))/DX+1;% matrix index corresponding to the max x value for the new field
    1316                         Xbound(1)=Coord{NbDim}(1)+DX*(XIndexMin-1);%  x value corresponding to XIndexMin
    1317                         Xbound(2)=Coord{NbDim}(1)+DX*(XIndexMax-1);%  x value corresponding to XIndexMax
     1315                        YIndexMax=Coord{NbDim-1}(end)/DY;
     1316                        YIndexMin=1;
     1317                    end
     1318                    if testXMax
     1319                         XIndexMax=(XMax-Coord{NbDim}(1))/DY+1;% matrix index corresponding to the max y value for the new field
     1320                        if testYMin%test_direct(indY)
     1321                            XIndexMin=(XMin-Coord{NbDim}(1))/DX+1;% matrix index corresponding to the min x value for the new field
     1322                        else
     1323                            XIndexMin=1;
     1324                        end         
    13181325                    else
    1319                         XIndexMin=(Coord{NbDim}(1)-XMax)/DX+1;
    1320                         XIndexMax=(Coord{NbDim}(1)-XMin)/DX+1;
    1321                         Xbound(2)=Coord{NbDim}(1)+DX*(XIndexMax-1);
    1322                         Xbound(1)=Coord{NbDim}(1)+DX*(XIndexMin-1);
    1323                     end
     1326                        XIndexMax=Coord{NbDim}(end)/DX;
     1327                        XIndexMin=1;
     1328                    end
     1329%                         YIndexMin=(Coord{NbDim-1}(1)-YMax)/DY+1;
     1330% %                         YIndexMax=(Coord{NbDim-1}(1)-YMin)/DY+1;
     1331%                         Ybound(2)=Coord{NbDim-1}(1)-DY*(YIndexMax-1);
     1332%                         Ybound(1)=Coord{NbDim-1}(1)-DY*(YIndexMin-1);
     1333%                     end
     1334%                     if testXMin%test_direct(NbDim)==1
     1335%                         XIndexMin=(XMin-Coord{NbDim}(1))/DX+1;% matrix index corresponding to the min x value for the new field
     1336%                         XIndexMax=(XMax-Coord{NbDim}(1))/DX+1;% matrix index corresponding to the max x value for the new field
     1337%                         Xbound(1)=Coord{NbDim}(1)+DX*(XIndexMin-1);%  x value corresponding to XIndexMin
     1338%                         Xbound(2)=Coord{NbDim}(1)+DX*(XIndexMax-1);%  x value corresponding to XIndexMax
     1339%                     else
     1340%                         XIndexMin=(Coord{NbDim}(1)-XMax)/DX+1;
     1341%                         XIndexMax=(Coord{NbDim}(1)-XMin)/DX+1;
     1342%                         Xbound(2)=Coord{NbDim}(1)+DX*(XIndexMax-1);
     1343%                         Xbound(1)=Coord{NbDim}(1)+DX*(XIndexMin-1);
     1344%                     end
    13241345                    YIndexRange(1)=ceil(min(YIndexMin,YIndexMax));%first y index to select from the previous field
    13251346                    YIndexRange(1)=max(YIndexRange(1),1);% avoid bound lower than the first index
     
    13461367                    else
    13471368                        if NbDim==3
     1369                            DZ=(Coord{1}(end)-Coord{1}(1))/(numel(Coord{1})-1);
    13481370                            DimCell(1)=[]; %suppress z variable
    13491371                            DimValue(1)=[];
     1372                            test_direct=1;%TOdo; GENERALIZE, SEE CASE OF points
    13501373                            if test_direct(1)
    13511374                                iz=ceil((ObjectData.Coord(1,3)-Coord{1}(1))/DZ)+1;
  • trunk/src/read_field.m

    r693 r747  
    3636errormsg='';
    3737if ~exist(FileName,'file')
    38     erromsg=['input file ' FileName ' does not exist'];
     38    errormsg=['input file ' FileName ' does not exist'];
    3939    return
    4040end
     
    9292                end
    9393            else  % an operator 'vec' or 'norm' is used
    94                 %Operator=r.Operator;
    9594                if ~check_colorvar(ilist) && strcmp(r.Operator,'norm')
    9695                    ProjModeRequestVar='interp_lin';%scalar field (requires interpolation for plot)
     
    121120        end
    122121        if isfield(ParamIn,'TimeDimName')% case of reading of a single time index in a multidimensional array
    123             [Field,var_detect,ichoice]=nc2struct(FileName,'TimeDimName',ParamIn.TimeDimName,num,[ParamIn.Coord_x (ParamIn.Coord_y) ListVar]);
    124         else
    125             [Field,var_detect,ichoice]=nc2struct(FileName,[ParamIn.Coord_x (ParamIn.Coord_y) ListVar]);
    126         end
    127         if isfield(Field,'Txt')
    128             errormsg=Field.Txt;
     122            [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeDimName',ParamIn.TimeDimName,num,[ParamIn.Coord_x (ParamIn.Coord_y) ListVar]);
     123        elseif isfield(ParamIn,'TimeVarName')% case of reading of a single time  in a multidimensional array
     124            [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeVarName',ParamIn.TimeVarName,num,[ParamIn.Coord_x (ParamIn.Coord_y) ListVar]);
     125        else
     126            [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,[ParamIn.Coord_x (ParamIn.Coord_y) (ParamIn.Coord_z) ListVar]);
     127        end
     128        if ~isempty(errormsg)
    129129            return
    130130        end
  • trunk/src/set_object.m

    r745 r747  
    701701    norm_plane(3)=OmAxis(3)*coeff+cos_om;
    702702end
     703Coord=get(handles.Coord,'Data');
     704Coord(3)=Z_value;
     705set(handles.Coord,'Data',Coord)
    703706
    704707% update graph
  • trunk/src/uvmat.m

    r745 r747  
    195195set(handles.PlotAxes,'UserData',AxeData)
    196196% position of table Coord_y
    197 set(handles.Coord_y,'Unit','pixel')
    198 Pos=get(handles.Coord_y,'Position');
    199 set(handles.Coord_y,'Unit','normalized')
    200 set(handles.Coord_y,'ColumnWidth',{Pos(3)})
    201 set(handles.Coord_y,'ColumnFormat',{'char'})
    202 set(handles.Coord_y,'ColumnEditable',false)
    203 set(handles.Coord_y,'ColumnName',{''})
     197%set(handles.Coord_y,'Unit','pixel')
     198% Pos=get(handles.Coord_y,'Position');
     199% set(handles.Coord_y,'Unit','normalized')
     200% set(handles.Coord_y,'ColumnWidth',{Pos(3)})
     201% set(handles.Coord_y,'ColumnFormat',{'char'})
     202% set(handles.Coord_y,'ColumnEditable',false)
     203% set(handles.Coord_y,'ColumnName',{''})
    204204
    205205%% set functions for the mouse and keyboard
     
    994994% time not set by the input file: images or civ data: indicate that time is read from the xml file
    995995if isfield(XmlData,'Time')&& ~isempty(XmlData.Time) && ...
    996         (strcmp(FileType,'image')|| strcmp(FileType,'multimage')||strcmp(FileType,'civdata')||strcmp(FileType,'civx'))
     996        (strcmp(FileType,'image')|| strcmp(FileType,'multimage'))%||strcmp(FileType,'civdata')||strcmp(FileType,'civx'))
    997997    TimeName='xml';
    998998elseif strcmp(FileType,'civdata')
     
    11101110        set(handles.ColorScalar,'String',ColorList)
    11111111        set(handles.Vectors,'Visible','on')
    1112         set(handles.Coord_x,'Value',1);
     1112        %set(handles.Coord_x,'Value',1);
    11131113        set(handles.Coord_x,'String','X');
    1114 %         set(handles.Coord_y,'Value',1);
    1115         set(handles.Coord_y,'Data',{'Y'});
     1114        set(handles.Coord_y,'String','Y');
    11161115    case 'netcdf'
    11171116        set(handles_Fields,'Value',1)
     
    11251124        set(handles_Fields,'Value',1) % set menu to 'image'
    11261125        set(handles_Fields,'String',{'image'})
    1127         set(handles.Coord_x,'Value',1);
     1126        %set(handles.Coord_x,'Value',1);
    11281127        set(handles.Coord_x,'String','AX');
    1129     set(handles.Coord_y,'Data',{'AY'});
     1128    set(handles.Coord_y,'String','AY');
    11301129end
    11311130set(handles.uvmat,'UserData',UvData)
    11321131
    1133 %% set index navigation options and inputfilerefresh plots
     1132%% set index navigation options
    11341133scan_option='i';%default
    11351134state_j='off'; %default
     
    16231622FileExt=InputFile.FileExt;
    16241623NomType=InputFile.NomType;
    1625 % i1=str2num(get(handles.i1,'String'));%read the field indices (for movie, it is not given by the file name)
    1626 % i2=[];%default
    1627 % if strcmp(get(handles.i2,'Visible'),'on')
    1628 %     i2=str2num(get(handles.i2,'String'));
    1629 % end
    1630 % j1=[];
    1631 % if strcmp(get(handles.j1,'Visible'),'on')
    1632 %     j1=stra2num(get(handles.j1,'String'));
    1633 % end
    1634 % j2=j1;
    1635 % if strcmp(get(handles.j2,'Visible'),'on')
    1636 %     j2=stra2num(get(handles.j2,'String'));
    1637 % end
    16381624[tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(InputFile.FileIndex);% check back the indices used
    16391625if isempty(i1)
     
    17001686        end
    17011687    else % free increment
    1702         runaction=get(gcbo,'tag');
     1688       % runaction=get(gcbo,'tag');
    17031689        if strcmp(increment,'+')% if runplus or movie is activated
    17041690            step=1;
     
    18171803filename=fullfile_uvmat(InputFile.RootPath,InputFile.SubDir,InputFile.RootFile,FileExt,NomType,i1,i2,j1,j2);
    18181804
    1819 %% inputfilerefresh plots
     1805%% refresh plots
    18201806if sub_value
    18211807    filename_1=fullfile_uvmat(InputFile.RootPath_1,InputFile.SubDir_1,InputFile.RootFile_1,InputFile.FileExt_1,InputFile.NomType_1,i1_1,i2_1,j1_1,j2_1);
     
    21492135        end
    21502136    case {'video','mmreader'}
    2151         ParamIn=UvData.MovieObject{1};      
     2137        ParamIn=UvData.MovieObject{1}; % movie object     
    21522138        if strcmp(NomType,'*')
    21532139            frame_index=num_i1;%frame index from a single movies or multimage
     
    21742160    ParamIn.VelType=VelType;
    21752161    ParamIn.Coord_x=get(handles.Coord_x,'String');
    2176     ParamIn.Coord_y=get(handles.Coord_y,'Data');
    2177 end
    2178 check_tps = 0;         
    2179 if strcmp(UvData.FileType{1},'civdata')&&~strcmp(ParamIn.FieldName,'velocity')&&~strcmp(ParamIn.FieldName,'get_field...')
    2180        check_tps=1;%tps needed to get the requested field
    2181 end
     2162    ParamIn.Coord_y=get(handles.Coord_y,'String');
     2163    ParamIn.Coord_z=get(handles.Coord_z,'String');
     2164    TimeName=get(handles.TimeName,'String');
     2165    r=regexp(TimeName,'^(?<type>(dim:)|(var:))','names');%look for 'var:' or 'dim:' at the beginning of time name
     2166    if ~isempty(r)
     2167        frame_index=num_i1;%time index chosen by i1
     2168        if strcmp(r.type,'dim:')
     2169            ParamIn.TimeDimName=TimeName(5:end);
     2170        elseif strcmp(r.type,'var:')
     2171            ParamIn.TimeVarName=TimeName(5:end);
     2172        end
     2173    end
     2174end
     2175% check_tps = 0;         
     2176% if strcmp(UvData.FileType{1},'civdata')&&~strcmp(ParamIn.FieldName,'velocity')&&~strcmp(ParamIn.FieldName,'get_field...')
     2177%        check_tps=1;%tps needed to get the requested field
     2178% end
    21822179[Field{1},ParamOut,errormsg] = read_field(FileName,UvData.FileType{1},ParamIn,frame_index);
    21832180if ~isempty(errormsg)
     
    22242221        case {'video','mmreader'}
    22252222            ParamIn_1=UvData.MovieObject{2};
    2226                         if ~strcmp(NomType_1,'*')
     2223            if ~strcmp(NomType_1,'*')
    22272224                frame_index_1=j1_1;%frame index for movies or multimage
    22282225            else
     
    22452242    end
    22462243    if isequal(get(handles.NomType_1,'Visible'),'on')
    2247     NomType_1=get(handles.NomType_1,'String');
     2244        NomType_1=get(handles.NomType_1,'String');
    22482245    else
    22492246        NomType_1=get(handles.NomType,'String');
     
    22612258        ParamIn_1.VelType=VelType_1;
    22622259        ParamIn_1.Coord_x=get(handles.Coord_x,'String');
    2263         ParamIn_1.Coord_y=get(handles.Coord_y,'Data');
     2260        ParamIn_1.Coord_y=get(handles.Coord_y,'String');
    22642261        end 
    22652262        [Field{2},ParamOut_1,errormsg] = read_field(FileName_1,UvData.FileType{2},ParamIn_1,frame_index_1);
     
    23122309test_veltype_1=0;
    23132310if isempty(FileName_1)
    2314     %     set(handles.FieldName_1,'Value',1); %update the field menu
    2315     %     if isstruct(ParamOut)
    2316     %     set(handles.FieldName_1,'String',[{''};ParamOut.FieldList]); %update the field menu
    2317     %     end
    23182311elseif ~test_keepdata_1
    23192312    if (strcmp(UvData.FileType{2},'civx')||strcmp(UvData.FileType{2},'civdata'))&& ~strcmp(FieldName_1,'get_field...')
    2320 %     if (~strcmp(UvData.FileType{2},'netcdf')&&~strcmp(UvData.FileType{2},'civdata')&&~strcmp(UvData.FileType{2},'civx'))|| isequal(FieldName_1,'get_field...')
    23212313        test_veltype_1=1;
    23222314        set(handles.VelType_1,'Visible','on')
     
    23732365TimeUnit='';
    23742366if isfield(UvData,'TimeUnit')
    2375 TimeUnit=UvData.TimeUnit;%retrieve info from update_rootinfo
    2376 end
     2367    TimeUnit=UvData.TimeUnit;%retrieve info from update_rootinfo
     2368end
     2369TimeName=get(handles.TimeName,'String');
     2370
    23772371% time from xml file or video movie
    2378 TimeName=get(handles.TimeName,'String');% indicate that time is from xml
    23792372if strcmp(TimeName,'xml')||strcmp(TimeName,'video')
    23802373    if isempty(num_i2)||isnan(num_i2)
     
    23982391end
    23992392
    2400 % get time in the input file, not defined in a xml file or movie
     2393% time in the input file, not defined in a xml file or movie
    24012394if isempty(abstime)
    24022395    if strcmp(TimeName,'civdata')||strcmp(TimeName,'civx')
    24032396        abstime=Field{1}.Time;
    2404     elseif ~isempty(regexp(TimeName,'^att:'))||~isempty(regexp(TimeName,'^var:'))
    2405         abstime=Field{1}.(TimeName(5:end));%the time is an attribute or variale selected by get_file
     2397    elseif ~isempty(regexp(TimeName,'^att:', 'once'))
     2398        abstime=Field{1}.(TimeName(5:end));%the time is an attribute  selected by get_file
     2399        if isfield(Field{1},[TimeName(5:end) 'Unit'])
     2400            TimeUnit=Field{1}.([TimeName(5:end) 'Unit']);
     2401        else
     2402            TimeUnit='';
     2403        end
     2404    elseif  ~isempty(regexp(TimeName,'^var:'))
     2405        abstime=Field{1}.(TimeName(5:end));%the time is a variale selected by get_file
     2406        % TODO: look for time unit attribute
    24062407    elseif ~isempty(regexp(TimeName,'^dim:'))
    24072408        abstime=str2num(get(handles.i1,'String'));
     2409        TimeUnit='index';
    24082410    end
    24092411    if isfield(Field{1},'Dt')
    24102412        dt=Field{1}.Dt;%dt read from the netcdf input file
    2411         if isfield(Field{1},'TimeUnit')
    2412             TimeUnit=Field{1}.TimeUnit;
    2413         end
    24142413    elseif numel(Field)==2 && isfield(Field{2},'Dt')%dt obtained from the second field if not defined in the first
    24152414        dt=Field{2}.Dt;%dt read from the netcdf input file
    2416         if isfield(Field{2},'TimeUnit')
    2417             TimeUnit=Field{2}.TimeUnit;
    2418         end
    24192415    end
    24202416end
     
    25232519UvData.Field=find_field_bounds(UvData.Field);
    25242520
    2525 if UvData.Field.NbDim>1
    2526     % default projection plane
    2527     if isempty(UvData.ProjObject{1})
    2528         UvData.ProjObject{1}.Type='plane';%main plotting plane
    2529         UvData.ProjObject{1}.ProjMode='projection';%main plotting plane
    2530        % UvData.ProjObject{1}.Coord=[0 0 0];
    2531         UvData.ProjObject{1}.DisplayHandle.uvmat=[]; %plane not visible in uvmat
    2532         UvData.ProjObject{1}.DisplayHandle.view_field=[]; %plane not visible in uvmat
    2533     end
    2534     %% 3D case (menuvolume)
    2535     if UvData.Field.NbDim==3% && UvData.NewSeries
    2536         test_set_object=1;
    2537         hset_object=findobj(allchild(0),'tag','set_object');% look for the set_object GUI
    2538         ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
    2539         ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
    2540         if ~isempty(hset_object) %if set_object is detected
    2541             delete(hset_object);% delete the GUI set_object if it does not fit
    2542         end
    2543         if test_set_object% reinitiate the GUI set_object
    2544             delete_object(1);% delete the current projection object in the list UvData.ProjObject, delete its graphic representations and update the list displayed in handles.ListObject and 2
    2545             UvData.ProjObject{1}.NbDim=NbDim;%test for 3D objects
    2546             UvData.ProjObject{1}.RangeZ=UvData.Field.CoordMesh;%main plotting plane
    2547             UvData.ProjObject{1}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen
    2548             UvData.ProjObject{1}.Angle=[0 0 0];
    2549             UvData.ProjObject{1}.HandlesDisplay=plot(0,0,'Tag','proj_object');% A REVOIR
    2550             UvData.ProjObject{1}.Name='1-PLANE';
    2551             UvData.ProjObject{1}.enable_plot=1;
    2552             set_object(UvData.ProjObject{1},handles,ZBounds);
    2553             set(hset_object,'name','set_object');% rename if set_object already used with series
    2554             set(handles.ListObject,'Value',1);
    2555             set(handles.ListObject,'String',{'1-PLANE'});
    2556             set(handles.CheckEditObject,'Value',1)% put the plane in edit mode to enable the z cursor
    2557             CheckEditObject_Callback([],[], handles)
    2558         end
    2559         %multilevel case (single menuplane in a 3D space)
    2560     elseif isfield(UvData,'Z')
    2561         if isfield(UvData,'CoordType')&& isequal(UvData.CoordType,'phys') && isfield(UvData,'XmlData')
    2562             XmlData=UvData.XmlData{1};
    2563             if isfield(XmlData,'PlanePos')
    2564                 UvData.ProjObject{1}.Coord=XmlData.PlanePos(UvData.ZIndex,:);
    2565             end
    2566             if isfield(XmlData,'PlaneAngle')
    2567                 siz=size(XmlData.PlaneAngle);
    2568                 indangle=min(siz(1),UvData.ZIndex);%take first angle if a single angle is defined (translating scanning)
    2569                 UvData.ProjObject{1}.PlaneAngle=XmlData.PlaneAngle(indangle,:);
    2570             end
    2571         elseif isfield(UvData,'ZIndex')
    2572             UvData.ProjObject{1}.ZObject=UvData.ZIndex;
    2573         end
    2574     end
    2575 end
    2576 
    25772521testnewseries=UvData.NewSeries;
    25782522UvData.NewSeries=0;% put to 0 the test for a new field series (set by RootPath_callback)
    2579 set(handles.uvmat,'UserData',UvData)
    25802523
    25812524%% reset the min and max of scalar if only the mask is displayed(TODO: check the need)
     
    25882531if UvData.Field.NbDim<=1
    25892532    set(handles.Objects,'Visible','off')
    2590 %     set(handles.ListObject_1_title,'Visible','off')
    2591 %     set(handles.ListObject_1,'Visible','off')
    25922533    [PlotType,PlotParamOut]=plot_field(UvData.Field,handles.PlotAxes,read_GUI(handles.uvmat));
    25932534    errormsg=fill_GUI(PlotParamOut,handles.uvmat);
     
    25972538        end
    25982539    end
    2599    
     2540    set(handles.uvmat,'UserData',UvData)
    26002541%% 2D or 3D fieldname are generally projected
    26012542else
    26022543    set(handles.Objects,'Visible','on')
    2603 %     set(handles.ListObject_1_title,'Visible','on')
    2604 %     set(handles.ListObject_1,'Visible','on')
    26052544   
    26062545    %% Plot the projections on the selected  projection objects
    2607     % main projection object (uvmat display)
    2608     list_object=get(handles.ListObject_1,'String');
    2609     if isequal(list_object,{''})||isequal(list_object,' ')%refresh list of objects if the menu is empty
     2546    %if no projection object exists, create a default one
     2547    if isempty(UvData.ProjObject{1})
    26102548        set(handles.ListObject,'Value',1)
    26112549        set(handles.ListObject,'String',{'plane'})
     
    26162554        set(handles.ListObject_1,'Value',1)
    26172555        set(handles.ListObject_1,'String',{'plane'})
     2556        if UvData.Field.NbDim==3 %3D case
     2557%             ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
     2558%             ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
     2559            UvData.ProjObject{1}.NbDim=3;%test for 3D objects
     2560            UvData.ProjObject{1}.RangeZ=UvData.Field.CoordMesh;%main plotting plane
     2561            UvData.ProjObject{1}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen
     2562            UvData.ProjObject{1}.Angle=[0 0 0];
     2563        elseif isfield(UvData,'Z')
     2564            %multilevel case (single menuplane in a 3D space)
     2565            if isfield(UvData,'CoordType')&& isequal(UvData.CoordType,'phys') && isfield(UvData,'XmlData')
     2566                XmlData=UvData.XmlData{1};
     2567                if isfield(XmlData,'PlanePos')
     2568                    UvData.ProjObject{1}.Coord=XmlData.PlanePos(UvData.ZIndex,:);
     2569                end
     2570                if isfield(XmlData,'PlaneAngle')
     2571                    siz=size(XmlData.PlaneAngle);
     2572                    indangle=min(siz(1),UvData.ZIndex);%take first angle if a single angle is defined (translating scanning)
     2573                    UvData.ProjObject{1}.PlaneAngle=XmlData.PlaneAngle(indangle,:);
     2574                end
     2575            elseif isfield(UvData,'ZIndex')
     2576                UvData.ProjObject{1}.ZObject=UvData.ZIndex;
     2577            end
     2578        end
    26182579    end
    26192580    IndexObj=get(handles.ListObject_1,'Value');%selected projection object for main view
     
    26482609   
    26492610    %% second projection object (view_field display)
    2650     if length( IndexObj)>=2
     2611    if length( IndexObj)==2
    26512612        view_field_handle=findobj(allchild(0),'tag','view_field');%handles of the view_field GUI
    26522613        if ~isempty(view_field_handle)
     
    26542615            haxes(2)=plot_handles{2}.PlotAxes;
    26552616            PlotParam{2}=read_GUI(view_field_handle);
    2656            % PlotParam{2}=read_GUI(handles.uvmat);%read plotting parameters on the uvmat interface
    26572617            PosColorbar{2}='*'; %TODO: deal with colorbar position on view_field
    26582618        end
     
    26652625        if numel(UvData.ProjObject)<iobj
    26662626            break
     2627        end
     2628        if UvData.Field.NbDim==3% TO GENERALISE
     2629            UvData.ProjObject{iobj}.NbDim=3;%test for 3D objects
     2630            UvData.ProjObject{iobj}.RangeZ=UvData.Field.CoordMesh;%main plotting plane
     2631            UvData.ProjObject{iobj}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen
     2632            UvData.ProjObject{iobj}.Angle=[0 0 0];
    26672633        end
    26682634        [ObjectData,errormsg]=proj_field(UvData.Field,UvData.ProjObject{iobj});% project field on the object
     
    27272693    end
    27282694   
     2695    set(handles.uvmat,'UserData',UvData)
     2696   
    27292697    %% update the mask
    27302698    if isequal(get(handles.CheckMask,'Value'),1)%if the mask option is on
     
    27782746    end
    27792747end
     2748
     2749if UvData.Field.NbDim==3
     2750    CheckEditObject_Callback(handles.uvmat, [], handles)
     2751end   
    27802752ResizeFcn(handles.uvmat,[],handles)
    27812753set(handles.uvmat,'Pointer',pointer)
     
    27842756function histo1_menu_Callback(hObject, eventdata, handles)
    27852757%--------------------------------------------
     2758%% get the current field stored in uvmat user data
     2759UvData=get(handles.uvmat,'UserData');
     2760Field=UvData.Field;
     2761
     2762%% get from the menu 'histo1_menu' the name(s) of the fields to use
    27862763histo_menu=get(handles.histo1_menu,'String');
    27872764histo_value=get(handles.histo1_menu,'Value');
    27882765FieldName=histo_menu{histo_value};
    2789 
    2790 UvData=get(handles.uvmat,'UserData');
    2791 Field=UvData.Field;
    27922766r=regexp(FieldName,'(?<var1>.*)(?<sep>,)(?<var2>.*)','names');
    27932767FieldName_2='';
    27942768if ~isempty(r)
    2795     FieldName=r.var1;
    2796     FieldName_2=r.var2;
     2769    FieldName=r.var1;% name of first variable
     2770    FieldName_2=r.var2;% name of second variable
    27972771end
    27982772if ~isfield(UvData.Field,FieldName)
     
    28002774    return
    28012775end
    2802 FieldHisto=Field.(FieldName);
    2803 if isfield(Field,'FF') && ~isempty(Field.FF) && isequal(size(Field.FF),size(FieldHisto))
     2776
     2777%% extract the fields to use
     2778% eliminate false data if relevant (false flag FF exists)
     2779check_false=0;
     2780if isfield(Field,'FF') && ~isempty(Field.FF) && isequal(size(Field.FF),size(Field.(FieldName)))
    28042781    indsel=find(Field.FF==0);%find values marked as false
    28052782    if ~isempty(indsel)
    2806         FieldHisto=FieldHisto(indsel);
     2783        FieldHisto=Field.(FieldName)(indsel);%field of the first variable (U)
    28072784        if ~isempty(FieldName_2)
    2808             FieldHisto(:,:,2)=Field.(FieldName_2)(indsel);
    2809         end
    2810     end
    2811 elseif ~isempty(FieldName_2)
    2812     FieldHisto(:,:,2)=Field.(FieldName_2);
    2813 end
     2785            if isfield(Field,'NbDim') && Field.NbDim==3
     2786                 FieldHisto(:,:,:,2)=Field.(FieldName_2)(indsel);%field of the second variable (U)
     2787            else
     2788            FieldHisto(:,:,2)=Field.(FieldName_2)(indsel);%field of the second variable (U)
     2789            end
     2790        end
     2791        check_false=1;
     2792    end
     2793end
     2794% no false data
     2795if ~check_false
     2796    FieldHisto=Field.(FieldName);%field of the first variable (U)
     2797    if ~isempty(FieldName_2)
     2798        if isfield(Field,'NbDim') && Field.NbDim==3
     2799            FieldHisto(:,:,:,2)=Field.(FieldName_2);%field of the second variable (V)
     2800        else
     2801            FieldHisto(:,:,2)=Field.(FieldName_2);%field of the second variable (V)
     2802        end
     2803    end
     2804end
     2805
     2806%% calculate and plot histogram
    28142807if isempty(Field)
    28152808    msgbox_uvmat('ERROR',['empty field ' FieldName])
     
    28442837            Histo.VarAttribute{1}.units=units;
    28452838        end
    2846         eval(['Histo.' FieldName '=linspace(Amin,Amax,50);'])%absissa values for histo
     2839        Histo.(FieldName)=linspace(Amin,Amax,50); %absissa values for histo
    28472840        if isfield(Field,'NbDim') && isequal(Field.NbDim,3)
    28482841            C=reshape(double(FieldHisto),1,[]);% reshape in a vector
     
    31023095%------------------------------------------------------------------------
    31033096% --- Executes on menu selection FieldName
    3104 function FieldName_Callback(hObject, eventdata, handles)
     3097
     3098    function FieldName_Callback(hObject, eventdata, handles)
    31053099%------------------------------------------------------------------------
    31063100
     
    31143108[tild,tild,tild,i1,i2,j1,j2,tild,NomType]=fileparts_uvmat(['xxx' get(handles.FileIndex,'String') FileExt]);
    31153109
    3116 switch field
    3117    
     3110switch field 
    31183111    case 'get_field...'
    31193112        %% fill the coordinates and variables from selections in get_field
     
    31563149        FieldList={};
    31573150        VecColorList={''};
     3151        ZName='';
    31583152        switch GetFieldData.FieldOption
    31593153            case 'vectors'
    31603154                UName=GetFieldData.PanelVectors.vector_x;
    31613155                VName=GetFieldData.PanelVectors.vector_y;
    3162                 YName={GetFieldData.Coordinates.Coord_y};
     3156                YName=GetFieldData.Coordinates.Coord_y;
     3157                if isfield(GetFieldData.Coordinates,'Coord_z')
     3158                ZName=GetFieldData.Coordinates.Coord_z;
     3159                end
    31633160                CName=GetFieldData.PanelVectors.vec_color;
    31643161                FieldList={['vec(' UName ',' VName ')'];...
     
    31723169            case 'scalar'
    31733170                AName=GetFieldData.PanelScalar.scalar;
    3174                 YName={GetFieldData.Coordinates.Coord_y};
     3171                YName=GetFieldData.Coordinates.Coord_y;
     3172                if isfield(GetFieldData.Coordinates,'Coord_z')
     3173                ZName=GetFieldData.Coordinates.Coord_z;
     3174                end
    31753175                FieldList={AName};
    31763176            case '1D plot'
     
    31793179                display_file_name(handles,FileName,1)
    31803180        end
     3181        % get time as file index, attribute, variable or matrix index
    31813182        if ~strcmp(GetFieldData.FieldOption,'civdata...')
    31823183            XName=GetFieldData.Coordinates.Coord_x;
     
    31913192                    set(handles.NomType,'String','*')
    31923193                    set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
     3194                    set(handles.i1,'String','1')% set counter to 1 (now the time index in the input matrix)
    31933195                    set(handles.FileIndex,'String','')
    31943196                    ParamIn.TimeVarName=GetFieldData.Time.TimeName;
    3195                 case 'matrix_index'
     3197                case 'matrix index'
    31963198                    set(handles.TimeName,'String',['dim:' GetFieldData.Time.TimeName]);
    31973199                    set(handles.NomType,'String','*')
    31983200                    set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
     3201                    set(handles.i1,'String','1')% set counter to 1 (now the time index in the input matrix)
    31993202                    set(handles.FileIndex,'String','')
    32003203                    ParamIn.TimeDimName=GetFieldData.Time.TimeName;
    32013204            end
    32023205            set(handles.Coord_x,'String',XName)
    3203             if ischar(YName)
    3204                 YName={YName};
    3205             end
    3206             set(handles.Coord_y,'Data',YName)
     3206%             if ischar(YName)
     3207%                 YName={YName};
     3208%             end
     3209            set(handles.Coord_y,'String',YName)
     3210            set(handles.Coord_z,'String',ZName)
    32073211            set(handles.FieldName,'Value',1)
    32083212            set(handles.FieldName,'String',[FieldList; {'get_field...'}]);
     
    33133317                UName=GetFieldData.PanelVectors.vector_x;
    33143318                VName=GetFieldData.PanelVectors.vector_y;
    3315                 YName={GetFieldData.Coordinates.Coord_y};
     3319                YName=GetFieldData.Coordinates.Coord_y;
    33163320                CName=GetFieldData.PanelVectors.vec_color;
    33173321                FieldList={['vec(' UName ',' VName ')'];...
     
    33253329            case 'scalar'
    33263330                AName=GetFieldData.PanelScalar.scalar;
    3327                 YName={GetFieldData.Coordinates.Coord_y};
     3331                YName=GetFieldData.Coordinates.Coord_y;
    33283332                FieldList={AName};
    33293333            case '1D plot'
     
    33543358            end
    33553359            set(handles.Coord_x,'String',XName)
    3356             if ischar(YName)
    3357                 YName={YName};
    3358             end
    3359             set(handles.Coord_y,'Data',YName)
     3360%             if ischar(YName)
     3361%                 YName={YName};
     3362%             end
     3363            set(handles.Coord_y,'String',YName)
    33603364            set(handles.FieldName_1,'Value',1)
    33613365            set(handles.FieldName_1,'String',[FieldList; {'get_field...'}]);
     
    37963800
    37973801%% adapt the GUI to the input/output conditions of the selected transform fct
    3798 DataOut=[];
    37993802CoordUnit='';
    38003803CoordUnitPrev='';
     
    38043807if ~isempty(list_path{ichoice})
    38053808    if nargin(transform_handle)>1 && isfield(UvData,'XmlData')&&~isempty(UvData.XmlData)
    3806         %XmlData=UvData.XmlData{1};
    3807         DataOut=feval(transform_handle,'*',UvData.XmlData{1});
     3809        DataOut=feval(transform_handle,'*',UvData.XmlData{1});% execute the transform fct to get the required conditions
    38083810        if isfield(DataOut,'CoordUnit')% set the requested coord unit (info used to possibly delete the current projection objects)
    38093811            CoordUnit=DataOut.CoordUnit;
     
    38143816        if isfield(DataOut,'TransformInput')%  used to add transform parameters at selection of the transform fct
    38153817            UvData.XmlData{1}.TransformInput=DataOut.TransformInput;
    3816 %             ListFields=fieldnames(DataOut.XmlData);
    3817 %             for ilist=1:numel(ListFields)
    3818 %             UvData.XmlData{1}.(ListFields{ilist})=DataOut.XmlData.(ListFields{ilist});
    3819 %             end
    3820         end
    3821 %     else
    3822 %         DataOut=feval(transform_handle,'*');
    3823     end
    3824 end
    3825 
     3818        end
     3819    end
     3820end
    38263821
    38273822%% delete drawn objects if the output CooordUnit is different from the previous one
     
    43064301    ProjData= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData
    43074302    [PlotType,PlotParam]=plot_field(ProjData,hhview_field.PlotAxes,read_GUI(hview_field));%read plotting parameters on the uvmat interface
    4308    
    4309     %write_plot_param(hhview_field,PlotParam); %update the display of plotting parameters for the current object
    43104303    haxes=findobj(hview_field,'tag','axes3');
    43114304    pos=get(hview_field,'Position'); 
     
    44854478        end
    44864479    end
    4487     %write_plot_param(hhview_field,PlotParam); %update the display of plotting parameters for the current object
    44884480    haxes=findobj(hview_field,'tag','axes3');
    44894481    pos=get(hview_field,'Position');
     
    44944486    else
    44954487        Data=get(hview_field,'UserData');
    4496 %         set(hview_field,'Position',Data.GUISize)% restore the size of view_field for plots
    44974488    end
    44984489else
     
    55455536Param.TransformName=TransformList{get(handles.TransformName,'Value')};
    55465537Param.Coord_x_str=get(handles.Coord_x,'String');
    5547 Param.Coord_x_val=get(handles.Coord_x,'Value');
    5548 Param.Coord_y_str=get(handles.Coord_y,'Data');
     5538%Param.Coord_x_val=get(handles.Coord_x,'Value');
     5539Param.Coord_y_str=get(handles.Coord_y,'String');
    55495540
    55505541% --------------------------------------------------------------------
     
    55625553% end
    55635554
    5564 % --- Executes on selection change in Coord_y.
    5565 function Coord_y_Callback(hObject, eventdata, handles)
    5566 
    5567 % --- Executes on selection change in Coord_x.
    5568 function Coord_x_Callback(hObject, eventdata, handles)
    5569 
    5570 
    5571 % --- Executes on button press in CheckColorBar.
    5572 function CheckColorBar_Callback(hObject, eventdata, handles)
    5573 
    5574 
    5575 
    5576 function TransformPath_Callback(hObject, eventdata, handles)
    5577 % hObject    handle to TransformPath (see GCBO)
    5578 % eventdata  reserved - to be defined in a future version of MATLAB
    5579 % handles    structure with handles and user data (see GUIDATA)
    5580 
    5581 % Hints: get(hObject,'String') returns contents of TransformPath as text
    5582 %        str2double(get(hObject,'String')) returns contents of TransformPath as a double
    55835555
    55845556
     
    56925664    set(handles.TableDisplay,'Visible','off')
    56935665end
     5666
     5667
     5668
     5669function Coord_z_Callback(hObject, eventdata, handles)
     5670% hObject    handle to Coord_z (see GCBO)
     5671% eventdata  reserved - to be defined in a future version of MATLAB
     5672% handles    structure with handles and user data (see GUIDATA)
     5673
     5674% Hints: get(hObject,'String') returns contents of Coord_z as text
     5675%        str2double(get(hObject,'String')) returns contents of Coord_z as a double
     5676
     5677
     5678% --- Executes during object creation, after setting all properties.
     5679function Coord_z_CreateFcn(hObject, eventdata, handles)
     5680% hObject    handle to Coord_z (see GCBO)
     5681% eventdata  reserved - to be defined in a future version of MATLAB
     5682% handles    empty - handles not created until after all CreateFcns called
     5683
     5684% Hint: edit controls usually have a white background on Windows.
     5685%       See ISPC and COMPUTER.
     5686if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
     5687    set(hObject,'BackgroundColor','white');
     5688end
Note: See TracChangeset for help on using the changeset viewer.