Home > atmlab > arts > netcdf > arts_nc_write_arrayofmatrix.m

arts_nc_write_arrayofmatrix

PURPOSE ^

ARTS_NC_WRITE_ARRAYOFMATRIX Write ArrayOfMatrix to ARTS NetCDF file.

SYNOPSIS ^

function arts_nc_write_arrayofmatrix (filename, v, varargin)

DESCRIPTION ^

 ARTS_NC_WRITE_ARRAYOFMATRIX   Write ArrayOfMatrix to ARTS NetCDF file.

    Writes an ArrayOfMatrix to a NetCDF file for use with Arts.

 FORMAT   arts_nc_write_arrayofmatrix(filename, v, varargin)
        
 IN    filename  Name of NetCDF file.
 IN    v         ArrayOfMatrix variable.
 OPT   varargin  Cell array of name/value pair cells for global attributes

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

arts_nc_write_arrayofmatrix.m

SOURCE CODE ^

0001 % ARTS_NC_WRITE_ARRAYOFMATRIX   Write ArrayOfMatrix to ARTS NetCDF file.
0002 %
0003 %    Writes an ArrayOfMatrix to a NetCDF file for use with Arts.
0004 %
0005 % FORMAT   arts_nc_write_arrayofmatrix(filename, v, varargin)
0006 %
0007 % IN    filename  Name of NetCDF file.
0008 % IN    v         ArrayOfMatrix variable.
0009 % OPT   varargin  Cell array of name/value pair cells for global attributes
0010 
0011 % 2010-02-03   Created by Oliver Lemke.
0012 
0013 function arts_nc_write_arrayofmatrix (filename, v, varargin)
0014 
0015 ncid = netcdf.create (filename, 'NC_CLOBBER');
0016 
0017 attributes = optargs( varargin, { [] } );
0018 
0019 if (~isempty(attributes))
0020       addncattributes (ncid, attributes);
0021 end
0022 
0023 ndim = netcdf.defDim (ncid, 'nelem', length(v));
0024 
0025 vrdims = zeros (length(v), 1, 'int32');
0026 vcdims = zeros (length(v), 1, 'int32');
0027 for i = 1:length(v)
0028     s = size(v{i});
0029     vrdims(i) = s(1);
0030     vcdims(i) = s(2);
0031 end
0032 
0033 ntdim = netcdf.defDim (ncid, 'nelem_total', sum(vrdims.*vcdims));
0034 
0035 ervarid = netcdf.defVar (ncid, 'Matrix_nrows', 'int', ndim);
0036 ecvarid = netcdf.defVar (ncid, 'Matrix_ncols', 'int', ndim);
0037 varid = netcdf.defVar (ncid, 'ArrayOfMatrix', 'double', ntdim);
0038 
0039 netcdf.endDef (ncid);
0040 
0041 netcdf.putVar (ncid, ecvarid, vcdims);
0042 netcdf.putVar (ncid, ervarid, vrdims);
0043 v2=cellfun(@(x) reshape(x', 1, []), v, 'UniformOutput', false);
0044 netcdf.putVar (ncid, varid, [v2{:}]);
0045 
0046 netcdf.close (ncid);

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