[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: variable string in attribute and char variables
- Subject: Re: variable string in attribute and char variables
- Date: Mon, 03 Feb 2003 14:14:27 -0700
>To: address@hidden
>From: Igor Pesenson <address@hidden>
>Subject: Re: 20030203: subject
>Organization: Lawrence Berkeley National Laboratory
>Keywords: 200302031956.h13Ju0623075
Igor,
Here's a reply to your second question:
> 2) We are using a rather awkward qc flag that is 15 binary characters
> long. For example: 000010000000000. So I'm assuming I have to use string
> values since otherwise the leading zeros would be truncated. But I'm
> getting confused as to correct notation for this. Currently, my code is:
>
> //...create file, declare other attributes, etc...
> nc_status=nc_def_var(ncid,"warn_flag",NC_CHAR,1,&idimid,&ivarid[31]);
> //...some time later...
> nc_status=nc_put_var1_text(ncid,ivarid[31],&rh_index,&warn_flag);
>
> What I'd like to see is:
> warn_flag = 00001000000000000, 000000000100000, etc...
>
> What I get is :
> warn_flag =
> "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
>
> 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
>
> 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
>
> 00000000000000000000000000000000000000000000000000000000000000000000" ;
>
> I've tried several different ways of doing this, but can't quite get it.
> Any advice would be much appreciated.
If you make warn_flag a 2-dimensional variable instead of
1-dimensional, I think you will get what you want. For example, if I
use the CDL file:
netcdf igor2{
dimensions:
nwarnings = 5;
warn_len = 15;
variables:
char warn_flag(nwarnings,warn_len);
data:
warn_flag = "000010000000000", "000000000100000",
"100000000000000", "000000000000001", "000000000010000";
}
to generate a netCDF file using "ncgen -b igor2.cdl", then invoke
ncdump on the resulting netCDF file, I get:
$ ncdump igor2.nc
netcdf igor2 {
dimensions:
nwarnings = 5 ;
warn_len = 15 ;
variables:
char warn_flag(nwarnings, warn_len) ;
data:
warn_flag =
"000010000000000",
"000000000100000",
"100000000000000",
"000000000000001",
"000000000010000" ;
}
--Russ
_____________________________________________________________________
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu