Home > atmlab > gformat > gf_set_data.m

gf_set_data

PURPOSE ^

GF_SET_DATA Sets the data and grid fields

SYNOPSIS ^

function G = gf_set_data(G,data,grids,grid_names)

DESCRIPTION ^

 GF_SET_DATA   Sets the data and grid fields

    To insert the matrix A in G:
      G = gf_set_data( G, A, {grid1,grid2} );

    To set G to a scalar:
      G = gf_set_data( G, 1e3, [] );

 FORMAT   G = gf_set_data(data,grids,grid_names,grid_units)
        
 OUT   G              Modified gformat structure.
 IN    G              Original gformat structure.
       data           Data to be inserted.
       grids          Grids corresponding to data, given as an array of 
                      vectors.
 OPT   grid_names     Empty (default) or an array of strings with name of 
                      each grid.
       grid_units     Empty (default) or an array of strings with unit of 
                      each grid.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

gf_set_data.m

SOURCE CODE ^

0001 % GF_SET_DATA   Sets the data and grid fields
0002 %
0003 %    To insert the matrix A in G:
0004 %      G = gf_set_data( G, A, {grid1,grid2} );
0005 %
0006 %    To set G to a scalar:
0007 %      G = gf_set_data( G, 1e3, [] );
0008 %
0009 % FORMAT   G = gf_set_data(data,grids,grid_names,grid_units)
0010 %
0011 % OUT   G              Modified gformat structure.
0012 % IN    G              Original gformat structure.
0013 %       data           Data to be inserted.
0014 %       grids          Grids corresponding to data, given as an array of
0015 %                      vectors.
0016 % OPT   grid_names     Empty (default) or an array of strings with name of
0017 %                      each grid.
0018 %       grid_units     Empty (default) or an array of strings with unit of
0019 %                      each grid.
0020 
0021 % 2007-10-17   Created by Patrick Eriksson.
0022 
0023 function G = gf_set_data(G,data,grids,grid_names)
0024 %
0025 if nargin < 4, grid_names = []; end
0026 if nargin < 5, grid_units = []; end
0027 
0028 dim = length( grids );
0029 
0030 strict_assert = atmlab('STRICT_ASSERT');
0031 
0032 if strict_assert
0033   rqre_nargin( 3, nargin );
0034   rqre_datatype( data, @isnumeric );
0035   rqre_datatype( grids, {@isempty,@iscell} );
0036   rqre_datatype( grid_names, {@isempty,@iscellstr} );
0037   rqre_datatype( grid_units, {@isempty,@iscellstr} );
0038   if length(grids) < dimens( data )
0039     error( 'Dimensionality of *data* > than number of grids.' );
0040   end
0041 end
0042 
0043 G.DATA = data;
0044 G.DIM  = dim;
0045 
0046 if isempty( grid_names )
0047   grid_names = cell(dim,1);
0048 elseif strict_assert
0049   if length(grid_names) ~= dim 
0050     error('*grid_names* must be empty or have same length as *grids*');
0051   end
0052 end
0053 
0054 if isempty( grid_units )
0055   grid_units = cell(dim,1);
0056 elseif strict_assert
0057   if length(grid_units) ~= dim
0058     error('*grid_units* must be empty or have same length as *grids*');
0059   end
0060 end
0061 
0062 for d = 1 : dim
0063   G = gf_set_grid( G, d, grids{d}, grid_names{d}, grid_units{d} );
0064   if strict_assert
0065     rqre_gridmatch( data, d, grids{d} );
0066   end
0067 end
0068

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005