Home > . > read_get_field.m

# read_get_field

## PURPOSE

'read_get_field': read the list of selected variables from the GUI get_field (SAME AS THE FIRST

## SYNOPSIS

function [SubField,errormsg]=read_get_field(hget_field)

## DESCRIPTION

    'read_get_field': read the list of selected variables from the GUI get_field (SAME AS THE FIRST
     INPUT:
     hget_field: handles of the GUI get_field

## CROSS-REFERENCE INFORMATION

This function calls:

- nc2struct 'nc2struct': transform a netcdf file in a corresponding matlab structure

This function is called by:

- get_field 'get_field': display variables and attributes from a Netcdf file, and plot selected fields
- uvmat 'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization

## SUBFUNCTIONS

- function VarIndex_y=name2index(cell_str,ListVarName)

## SOURCE CODE

    0001 %'read_get_field': read the list of selected variables from the GUI get_field (SAME AS THE FIRST
    0002 % INPUT:
    0003 % hget_field: handles of the GUI get_field
    0004
    0005 function [SubField,errormsg]=read_get_field(hget_field)
    0006 %---------------------------------------------------------
    0007 SubField=[];%default
    0008 errormsg=[]; %default
    0009 handles=guidata(hget_field);%handles of GUI elements in get_field
    0010 Field=get(hget_field,'UserData');% read the current field Structure in the get_field interface
    0011 if isfield(Field,'VarAttribute')
    0012     VarAttribute=Field.VarAttribute;
    0013 else
    0014     VarAttribute={};
    0015 end
    0016
    0017 % select the indices of field variables for 2D plots
    0018 test_1Dplot=get(handles.check_1Dplot,'Value');
    0019 test_scalar=get(handles.check_scalar,'Value');
    0020 test_vector=get(handles.check_vector,'Value');
    0021
    0022 nbvar=0;
    0023 empty_coord_x=0;
    0024 empty_coord_y=0;
    0025 dimname_y={};
    0026 ListVarName={};
    0027 VarDimName={};
    0028 SubVarAttribute={};
    0029 dim_x=0;
    0030 dim_y=0;
    0031 dim_z=0;
    0032 dim_vec_x=0;
    0033 dim_vec_y=0;
    0034 dim_vec_z=0;
    0035 c_index=[];
    0036 if test_1Dplot
    0037      % select ordinate variable(s)
    0038     inputlist=get(handles.ordinate,'String');
    0039     val=get(handles.ordinate,'Value');% selection(s) for ordinate
    0040     VarNameCell=inputlist(val); %names of the variable(s) in the list
    0041     for ivar=1:length(VarNameCell)
    0042         VarIndex=name2index(VarNameCell{ivar},Field.ListVarName);%index of the variable in ListVarName
    0043         dimname_y{ivar}=Field.VarDimName{VarIndex};% name of the corresponding dimension
    0044         if iscell(dimname_y{ivar})
    0045             dimname_y{ivar}=dimname_y{ivar}{1};%take the first dimension in case of a matrix
    0046         end
    0047         if ~strcmp(dimname_y{1},dimname_y{ivar})
    0048             errormsg='unequal dimensions for the set of selected ordinate variables';
    0049             return
    0050         end
    0051         nbvar=nbvar+1;
    0052         ListVarName{nbvar}=Field.ListVarName{VarIndex};
    0053         VarDimName{nbvar}=Field.VarDimName{VarIndex};
    0054         SubVarAttribute{nbvar}=VarAttribute{VarIndex};
    0055         SubVarAttribute{nbvar}.Role='scalar';
    0056     end
    0057     field_var_index=VarIndex; %store the last variable index to determine the absissa dimension if not defiend
    0058
    0059         % select abscissa variable
    0060     inputlist=get(handles.abscissa,'String');
    0061     val=get(handles.abscissa,'Value');% a single selection is expected for abscissa
    0062     VarName=inputlist{val}; %name of the variable in the list
    0063     VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName
    0064 %     dimname_x=[];%default
    0065     if isempty(VarIndex)% default abscissa = matrix index
    0066         coord_x_name=dimname_y{1};% name of the x coordinate = dimension of the plotted quantity
    0067         empty_coord_x=1;
    0068     else
    0069         dimname_x=Field.VarDimName{VarIndex};
    0070         if numel(dimname_x)~=1
    0071             errormsg='abscissa must be a one-dimensional variable';
    0072             return
    0073         end
    0074         if ~isempty(dimname_x) && ~strcmp(dimname_y{1},dimname_x)
    0075             errormsg='inconsistent dimensions for ordinate and abscissa';
    0076             return
    0077         end
    0078         nbvar=nbvar+1;
    0079         ListVarName{nbvar}=Field.ListVarName{VarIndex};
    0080         VarDimName{nbvar}=Field.VarDimName{VarIndex};
    0081         SubVarAttribute{nbvar}=VarAttribute{VarIndex};
    0082         SubVarAttribute{nbvar}.Role='coord_x';
    0083     end
    0084 end
    0085 test3D=strcmp(get(handles.coord_z_scalar,'Visible'),'on')||strcmp(get(handles.coord_z_vectors,'Visible'),'on');
    0086 A_index=[];
    0087 if test_scalar
    0088     %scalar variable
    0089     inputlist=get(handles.scalar,'String');
    0090     if isempty(inputlist)
    0091         errormsg='empty input field';
    0092         return
    0093     end
    0094     val=get(handles.scalar,'Value');%selected indices in the ordinate listbox
    0095     VarNameScalar=inputlist{val}; %name of the variable in the list
    0096     VarIndex=name2index(VarNameScalar,Field.ListVarName);%index of the variable in ListVarName
    0097     dimname_A=Field.VarDimName{VarIndex};
    0098     nbvar=nbvar+1;
    0099     ListVarName{nbvar}=Field.ListVarName{VarIndex};
    0100     A_index=nbvar;
    0101     VarDimName{nbvar}=dimname_A;
    0102     SubVarAttribute{nbvar}=VarAttribute{VarIndex};
    0103     SubVarAttribute{nbvar}.Role='scalar';
    0104     field_var_index=VarIndex; %store the last variable index to determine the absissa dimension if not defiend
    0105
    0106      % select x variable
    0107     inputlist=get(handles.coord_x_scalar,'String');
    0108     val=get(handles.coord_x_scalar,'Value');% a single selection is expected for abscissa
    0109     VarName=inputlist{val}; %name of the variable in the list
    0110     VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName
    0111     if isempty(VarIndex)% default abscissa = matrix index
    0112         coord_x_name=dimname_A{2};% name of the x coordinate = dimension of the plotted quantity
    0113         empty_coord_x=1;
    0114     else
    0115         dimname_x=Field.VarDimName{VarIndex};
    0116          %check consistency of dimensions
    0117         if ~isequal(dimname_x,dimname_A)% case of dimension variables
    0118             for icoord=1:numel(dimname_A)% look for coincidence of dimension with one of the dimensions of the scalar
    0119                 if strcmp(dimname_x,dimname_A{icoord})% a dimension variable
    0120                     dim_x=icoord;
    0121                     break
    0122                 end
    0123             end
    0124             if ~dim_x
    0125                 errormsg='inconsistent dimensions for coordinate x';
    0126                 return
    0127             end
    0128         end
    0129         nbvar=nbvar+1;
    0130         ListVarName{nbvar}=Field.ListVarName{VarIndex};
    0131         VarDimName{nbvar}=dimname_x;
    0132         SubVarAttribute{nbvar}=VarAttribute{VarIndex};
    0133         if dim_x
    0134             SubVarAttribute{nbvar}.Role='dimvar';% dimension variable
    0135         else
    0136             SubVarAttribute{nbvar}.Role='coord_x';%abcissa with unstructured coordinates
    0137         end
    0138     end
    0139
    0140     % select y variable
    0141     inputlist=get(handles.coord_y_scalar,'String');
    0142     val=get(handles.coord_y_scalar,'Value');% a single selection is expected for abscissa
    0143     VarName=inputlist{val}; %name of the variable in the list
    0144     VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName
    0145     if isempty(VarIndex)% default abscissa = matrix index
    0146         coord_y_name=dimname_A{1};% name of the x coordinate = dimension of the plotted quantity
    0147         empty_coord_y=1;
    0148     else
    0149         dimname_y=Field.VarDimName{VarIndex};
    0150          %check consistency of dimensions
    0151         if ~isequal(dimname_y,dimname_A)
    0152             for icoord=1:numel(dimname_A)
    0153                 if strcmp(dimname_y,dimname_A{icoord})%  a dimension variable
    0154                      dim_y=icoord;
    0155                     break
    0156                 end
    0157             end
    0158             if ~dim_y
    0159                 errormsg='inconsistent dimensions for coordinate x';
    0160                 return
    0161             end
    0162         end
    0163         nbvar=nbvar+1;
    0164         ListVarName{nbvar}=Field.ListVarName{VarIndex};
    0165         VarDimName{nbvar}=dimname_y;
    0166         SubVarAttribute{nbvar}=VarAttribute{VarIndex};
    0167         if dim_y
    0168             SubVarAttribute{nbvar}.Role='dimvar';% dimension variable
    0169         else
    0170             SubVarAttribute{nbvar}.Role='coord_y';%ordinate with unstructured coordinates
    0171         end
    0172     end
    0173
    0174         % select z variable
    0175    if test3D
    0176         inputlist=get(handles.coord_z_scalar,'String');
    0177         val=get(handles.coord_z_scalar,'Value');% a single selection is expected for abscissa
    0178         VarName=inputlist{val}; %name of the variable in the list
    0179         VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName
    0180         if isempty(VarIndex)% default abscissa = matrix index
    0181 %             coord_z_name=dimname_A{1};% name of the x coordinate = dimension of the plotted quantity
    0182             empty_coord_z=1;
    0183         else
    0184             dimname_z=Field.VarDimName{VarIndex};
    0185              %check consistency of dimensions
    0186             if ~isequal(dimname_z,dimname_A)
    0187                 for icoord=1:numel(dimname_A)
    0188                     if strcmp(dimname_z,dimname_A{icoord})%  a dimension variable
    0189                          dim_z=icoord;
    0190                         break
    0191                     end
    0192                 end
    0193                 if ~dim_z
    0194                     errormsg='inconsistent dimensions for coordinate z';
    0195                     return
    0196                 end
    0197             end
    0198             nbvar=nbvar+1;
    0199             ListVarName{nbvar}=Field.ListVarName{VarIndex};
    0200             VarDimName{nbvar}=dimname_z;
    0201             SubVarAttribute{nbvar}=VarAttribute{VarIndex};
    0202             if dim_z
    0203                 SubVarAttribute{nbvar}.Role='dimvar';% dimension variable
    0204             else
    0205                 SubVarAttribute{nbvar}.Role='coord_z';%z coordinate with unstructured coordinates
    0206             end
    0207         end
    0208    end
    0209 end
    0210
    0211 if test_vector
    0212     %select u variable
    0213     inputlist=get(handles.vector_x,'String');
    0214     if isempty(inputlist)
    0215         errormsg='empty input field';
    0216         return
    0217     end
    0218     val=get(handles.vector_x,'Value');%selected indices in the ordinate listbox
    0219     VarNameU=inputlist{val}; %name of the variable in the list
    0220     VarIndex=name2index(VarNameU,Field.ListVarName);%index of the variable in ListVarName
    0221     nbvar=nbvar+1;
    0222     u_index=nbvar;
    0223     ListVarName{nbvar}=Field.ListVarName{VarIndex};
    0224     dimname_u=Field.VarDimName{VarIndex};
    0225     VarDimName{nbvar}=dimname_u;
    0226     SubVarAttribute{nbvar}=VarAttribute{VarIndex};
    0227     SubVarAttribute{nbvar}.Role='vector_x';
    0228     field_var_index=VarIndex; %store the last variable index to determine the absissa dimension if not defiend
    0229
    0230     %scalar v variable
    0231     inputlist=get(handles.vector_y,'String');
    0232     val=get(handles.vector_y,'Value');%selected indices in the ordinate listbox
    0233     VarNameV=inputlist{val}; %name of the variable in the list
    0234     VarIndex=name2index(VarNameV,Field.ListVarName);%index of the variable in ListVarName
    0235      %check consistency of dimensions with u
    0236     dimname_v=Field.VarDimName{VarIndex};
    0237     if ~isequal(dimname_v,dimname_u)
    0238        errormsg='inconsistent dimensions for u and v';
    0239         return
    0240     end
    0241     nbvar=nbvar+1;
    0242     v_index=nbvar;
    0243     ListVarName{nbvar}=Field.ListVarName{VarIndex};
    0244     VarDimName{nbvar}=dimname_u;
    0245     SubVarAttribute{nbvar}=VarAttribute{VarIndex};
    0246     SubVarAttribute{nbvar}.Role='vector_y';
    0247
    0248      % select x variable
    0249     inputlist=get(handles.coord_x_vectors,'String');
    0250     val=get(handles.coord_x_vectors,'Value');% a single selection is expected for abscissa
    0251     VarName=inputlist{val}; %name of the variable in the list
    0252     VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName
    0253     if isempty(VarIndex)% default abscissa = matrix index
    0254         coord_x_name=dimname_u{2};% name of the x coordinate = dimension of the plotted quantity
    0255         empty_coord_x=1;
    0256     else
    0257         if ~isequal(Field.VarDimName{VarIndex},dimname_u)
    0258             for icoord=1:numel(dimname_u)
    0259                 if strcmp(Field.VarDimName{VarIndex},dimname_u{icoord})% x not a dimension variable
    0260                     dim_vec_x=icoord;
    0261                     break
    0262                 end
    0263             end
    0264             if ~dim_vec_x
    0265                 errormsg='inconsistent dimensions for u and x' ;
    0266                 return
    0267             end
    0268         end
    0269         nbvar=nbvar+1;
    0270         ListVarName{nbvar}=Field.ListVarName{VarIndex};
    0271         VarDimName{nbvar}=Field.VarDimName{VarIndex};
    0272         SubVarAttribute{nbvar}=VarAttribute{VarIndex};
    0273         if dim_vec_x
    0274             SubVarAttribute{nbvar}.Role='dimvar';% dimension variable
    0275         else
    0276             SubVarAttribute{nbvar}.Role='coord_x';%absissa with unstructured coordinates
    0277         end
    0278     end
    0279
    0280       % select y variable
    0281     inputlist=get(handles.coord_y_vectors,'String');
    0282     val=get(handles.coord_y_vectors,'Value');% a single selection is expected for abscissa
    0283     VarName=inputlist{val}; %name of the variable in the list
    0284     VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName
    0285             %check consistency of dimensions
    0286     if isempty(VarIndex)% default abscissa = matrix index
    0287         coord_y_name=dimname_u{1};% name of the x coordinate = dimension of the plotted quantity
    0288         empty_coord_y=1;
    0289     else
    0290         if ~isequal(Field.VarDimName{VarIndex},dimname_u)
    0291             for icoord=1:numel(dimname_u)
    0292                 if strcmp(Field.VarDimName{VarIndex},dimname_u{icoord})% x not a dimension variable
    0293                     dim_vec_y=1;
    0294                     break
    0295                 end
    0296             end
    0297             if ~dim_vec_y
    0298                 errormsg='inconsistent dimensions for u and y';
    0299                 return
    0300             end
    0301         end
    0302         nbvar=nbvar+1;
    0303         ListVarName{nbvar}=Field.ListVarName{VarIndex};
    0304         VarDimName{nbvar}=Field.VarDimName{VarIndex};
    0305         SubVarAttribute{nbvar}=VarAttribute{VarIndex};
    0306         if dim_vec_y
    0307             SubVarAttribute{nbvar}.Role='dimvar';% dimension variable
    0308         else
    0309             SubVarAttribute{nbvar}.Role='coord_y';%ordinate with unstructured coordinates
    0310         end
    0311     end
    0312
    0313           % select z variable
    0314     if test3D
    0315         inputlist=get(handles.coord_z_vectors,'String');
    0316         val=get(handles.coord_z_vectors,'Value');% a single selection is expected for abscissa
    0317         VarName=inputlist{val}; %name of the variable in the list
    0318         VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName
    0319                 %check consistency of dimensions
    0320         if isempty(VarIndex)% default abscissa = matrix index
    0321             coord_z_name=dimname_u{1};% name of the x coordinate = dimension of the plotted quantity
    0322             empty_coord_z=1;
    0323         else
    0324             if ~isequal(Field.VarDimName{VarIndex},dimname_u)
    0325                 for icoord=1:numel(dimname_u)
    0326                     if strcmp(Field.VarDimName{VarIndex},dimname_u{icoord})% x not a dimension variable
    0327                         dim_vec_z=icoord;
    0328                         break
    0329                     end
    0330                 end
    0331                 if ~dim_vec_z
    0332                     errormsg='inconsistent dimensions for u and z';
    0333                     return
    0334                 end
    0335             end
    0336             nbvar=nbvar+1;
    0337             ListVarName{nbvar}=Field.ListVarName{VarIndex};
    0338             VarDimName{nbvar}=Field.VarDimName{VarIndex};
    0339             SubVarAttribute{nbvar}=VarAttribute{VarIndex};
    0340             if dim_vec_z
    0341                 SubVarAttribute{nbvar}.Role='dimvar';% dimension variable
    0342             else
    0343                 SubVarAttribute{nbvar}.Role='coord_z';%ordinate with unstructured coordinates
    0344             end
    0345         end
    0346
    0347          %scalar w variable
    0348         inputlist=get(handles.vector_z,'String');
    0349         val=get(handles.vector_z,'Value');%selected indices in the ordinate listbox
    0350         VarNameW=inputlist{val}; %name of the variable in the list
    0351         VarIndex=name2index(VarNameW,Field.ListVarName);%index of the variable in ListVarName
    0352          %check consistency of dimensions with u
    0353         dimname_w=Field.VarDimName{VarIndex};
    0354         if ~isequal(dimname_w,dimname_u)
    0355            errormsg='inconsistent dimensions for u and v';
    0356             return
    0357         end
    0358         nbvar=nbvar+1;
    0359         w_index=nbvar;
    0360         ListVarName{nbvar}=Field.ListVarName{VarIndex};
    0361         VarDimName{nbvar}=dimname_u;
    0362         SubVarAttribute{nbvar}=VarAttribute{VarIndex};
    0363         SubVarAttribute{nbvar}.Role='vector_z';
    0364     end
    0365
    0366     % select color variable
    0367     inputlist=get(handles.vec_color,'String');
    0368     val=get(handles.vec_color,'Value');% a single selection is expected for abscissa
    0369     VarNameC=inputlist{val}; %name of the variable in the list
    0370     VarIndex=name2index(VarNameC,Field.ListVarName);%index of the variable in ListVarName
    0371        %check consistency of dimensions with u
    0372     if ~isempty(VarIndex)
    0373         if ~isequal(Field.VarDimName{VarIndex},dimname_u)
    0374             errormsg='inconsistent dimensions for u and v';
    0375             return
    0376         end
    0377         nbvar=nbvar+1;
    0378         c_index=nbvar;
    0379         ListVarName{nbvar}=Field.ListVarName{VarIndex};
    0380         VarDimName{nbvar}=Field.VarDimName{VarIndex};
    0381         SubVarAttribute{nbvar}=VarAttribute{VarIndex};
    0382         SubVarAttribute{nbvar}.Role='scalar';
    0383     end
    0384 end
    0385
    0386
    0387 % get the input field
    0388 inputfield=get(handles.inputfile,'String');
    0389 if exist(inputfield,'file')% read the input data corresponding to the list of selected varaibles
    0390     SubField=nc2struct(inputfield,ListVarName);
    0391 else  % subfield stored in memory
    0392     SubField.ListVarName=ListVarName;
    0393     SubField.VarDimName=VarDimName;
    0394 end
    0395 SubField.ListGlobalAttribute=['InputFile' SubField.ListGlobalAttribute];
    0396 SubField.InputFile=get(handles.inputfile,'String');
    0397 SubField.VarAttribute=SubVarAttribute;
    0398
    0399 %permute indices if coord_y is not the first matrix index
    0400 if dim_x && dim_y && ~isempty(A_index)
    0401     DimCell=SubField.VarDimName{A_index};
    0402     if dim_z
    0403         DimCell(1:3)=DimCell([dim_z dim_y dim_x]);
    0404         dim_end=[4:numel(DimCell)];
    0405         eval(['SubField.' VarNameScalar '=permute(SubField.' VarNameScalar ',[dim_z dim_y dim_x dim_end]);'])
    0406     else
    0407         DimCell(1:2)=DimCell([dim_y dim_x]);
    0408         dim_end=[3:numel(DimCell)];
    0409         eval(['SubField.' VarNameScalar '=permute(SubField.' VarNameScalar ',[dim_y dim_x dim_end]);'])
    0410     end
    0411     SubField.VarDimName{A_index}=DimCell;
    0412 end
    0413
    0414 %permute indices if ccord_y is not the first matrix index
    0415 if dim_vec_x && dim_vec_y && ~isempty(u_index)
    0416     DimCell=SubField.VarDimName{u_index};
    0417     if dim_vec_z
    0418         DimCell(1:3)=DimCell([dim_vec_z dim_vec_y dim_vec_x]);
    0419         dim_end=[4:numel(DimCell)];
    0420         eval(['SubField.' VarNameU '=permute(SubField.' VarNameU ',[dim_z dim_y dim_x dim_end]);'])
    0421         eval(['SubField.' VarNameV '=permute(SubField.' VarNameV ',[dim_z dim_y dim_x dim_end]);'])
    0422         eval(['SubField.' VarNameW '=permute(SubField.' VarNameW ',[dim_z dim_y dim_x dim_end]);'])
    0423         if ~isempty(c_index)
    0424             eval(['SubField.' VarNameC '=permute(SubField.' VarNameC ',[dim_z dim_y dim_x dim_end];]);'])
    0425             SubField.VarDimName{c_index}=DimCell;
    0426         end
    0427         SubField.VarDimName{w_index}=DimCell;
    0428     else
    0429         DimCell(1:2)=DimCell([dim_vec_y dim_vec_x]);
    0430         dim_end=[3:numel(DimCell)];
    0431         eval(['SubField.' VarNameU '=permute(SubField.' VarNameU ',[dim_y dim_x dim_end];]);'])
    0432         eval(['SubField.' VarNameV '=permute(SubField.' VarNameV ',[dim_y dim_x dim_end];]);'])
    0433         if ~isempty(c_index)
    0434             eval(['SubField.' VarNameC '=permute(SubField.' VarNameC ',[dim_y dim_x dim_end];]);'])
    0435             SubField.VarDimName{c_index}=DimCell;
    0436         end
    0437     end
    0438     SubField.VarDimName{u_index}=DimCell;
    0439     SubField.VarDimName{v_index}=DimCell;
    0440 end
    0441
    0442 %add default coord_x and/or coord_y if empty
    0443 if empty_coord_x || empty_coord_y
    0444     VarName=Field.ListVarName{field_var_index};
    0445     eval(['npxy=size(SubField.' VarName ');'])
    0446     Coord_1=[1 npxy(1)];
    0447     Coord_2=[1 npxy(2)];
    0448     testold=0;
    0449 %old convention; use of coord_1 and Coord_2
    0450     if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=field_var_index
    0451         if isfield(Field.VarAttribute{field_var_index},'Coord_2')&& isfield(Field.VarAttribute{field_var_index},'Coord_1')
    0452             Coord_2=Field.VarAttribute{field_var_index}.Coord_2;
    0453             Coord_1=Field.VarAttribute{field_var_index}.Coord_1;
    0454             testold=1;
    0455         end
    0456     end
    0457     if empty_coord_x
    0458         SubField.ListVarName=[{coord_x_name} SubField.ListVarName];
    0459         SubField.VarDimName=[{coord_x_name} SubField.VarDimName];
    0460         if test_scalar || test_vector %2D case
    0461             eval(['SubField.' coord_x_name '=linspace(Coord_2(1),Coord_2(end),npxy(2));'])
    0462         else % 1D plot
    0463             eval(['SubField.' coord_x_name '=linspace(Coord_1(1),Coord_1(end),npxy(1));'])
    0464         end
    0465         if ~testold
    0466             coord_x_attr.units='index';
    0467         else
    0468             coord_x_attr.units='cm';
    0469         end
    0470         SubField.VarAttribute=[{coord_x_attr} SubField.VarAttribute];
    0471     end
    0472     if empty_coord_y
    0473         SubField.ListVarName=[{coord_y_name} SubField.ListVarName];
    0474         SubField.VarDimName=[{coord_y_name} SubField.VarDimName];
    0475         eval(['SubField.' coord_y_name '=linspace(Coord_1(1),Coord_1(end),npxy(1));'])
    0476         if ~testold
    0477             coord_y_attr.units='index';
    0478         else
    0479             coord_y_attr.units='cm';
    0480         end
    0481         SubField.VarAttribute=[{coord_y_attr} SubField.VarAttribute];
    0482     end
    0483 end
    0484
    0485 %-------------------------------------------------
    0486 % give index numbers of the strings str in the list ListvarName
    0487 function VarIndex_y=name2index(cell_str,ListVarName)
    0488 VarIndex_y=[];
    0489 if ischar(cell_str)
    0490     for ivar=1:length(ListVarName)
    0491         varlist=ListVarName{ivar};
    0492         if isequal(varlist,cell_str)
    0493             VarIndex_y= ivar;
    0494             break
    0495         end
    0496     end
    0497 elseif iscell(cell_str)
    0498     for isel=1:length(cell_str)
    0499         varsel=cell_str{isel};
    0500         for ivar=1:length(ListVarName)
    0501             varlist=ListVarName{ivar};
    0502             if isequal(varlist,varsel)
    0503                 VarIndex_y=[VarIndex_y ivar];
    0504             end
    0505         end
    0506     end
    0507 end