


PURPOSE: transfer nc variable datatype to string
-------------------------------------------------------------------
USAGE: s = nc_datatype(datatype)
where: datatype is the integer value of the netcdf variable datatype as
returned e.g. by mexnc('inq_var',...,...).
returns a string containing the datatype: 'double', 'int' etc
Note: just a quick and dirty script to minimize allocated memory when
double is not necessary.
Uses: mexnc('TYPELEN',datatype)
MEXCDF: http://mexcdf.sourceforge.net
and obviously netcdf: http://www.unidata.ucar.edu/software/netcdf/
Felix Hebeler, Geography Dept., University Zurich, December 2006.

0001 function str = nc_datatype(datatype) 0002 % PURPOSE: transfer nc variable datatype to string 0003 % ------------------------------------------------------------------- 0004 % USAGE: s = nc_datatype(datatype) 0005 % where: datatype is the integer value of the netcdf variable datatype as 0006 % returned e.g. by mexnc('inq_var',...,...). 0007 % returns a string containing the datatype: 'double', 'int' etc 0008 % 0009 % Note: just a quick and dirty script to minimize allocated memory when 0010 % double is not necessary. 0011 % Uses: mexnc('TYPELEN',datatype) 0012 % MEXCDF: http://mexcdf.sourceforge.net 0013 % and obviously netcdf: http://www.unidata.ucar.edu/software/netcdf/ 0014 % 0015 % Felix Hebeler, Geography Dept., University Zurich, December 2006. 0016 0017 % check the datatype 0018 if nargin ~= 1 0019 msg = sprintf ( '%s: Must have only one input\n', mfilename ); 0020 error ( msg ); 0021 end 0022 0023 if ~isnumeric ( datatype ) 0024 msg = sprintf ( '%s: input must be numeric\n', mfilename ); 0025 error ( msg ); 0026 end 0027 0028 switch ( datatype ) 0029 case 0 0030 str = 'NAT'; 0031 case 1 0032 str = 'BYTE'; 0033 case 2 0034 str = 'UCHAR'; 0035 case 3 0036 str = 'SHORT'; 0037 case 4 0038 str = 'INT'; 0039 case 5 0040 str = 'FLOAT'; 0041 case 6 0042 str = 'DOUBLE'; 0043 otherwise 0044 msg = sprintf ( '%s: unhandled type number %d\n', mfilename, datatype ); 0045 error ( msg ); 0046 end 0047 0048 return 0049 %datatype 1="text",2="uchar",3="schar",4="short",5="int",6="float", and 6="double"