[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question of char



>To: address@hidden
>From: address@hidden 
>Subject: Re: 20000228: question of char
>Organization: ATLANTIDE - Technopôle Brest Iroise
>Keywords: character arrays, relational tables

Alain,

> Thanks for your quickly answer but i think that my example was
> not so good. In fact i have to store Code and the Label of codes
> like this new example :o)

>   netcdf fileTOTO {
>   dimensions:
>           nbData = UNLIMITED ; // (X currently)
>           numberOfChar = 255 ;
>           numberOfField = 2 ;
>           stringlen = 20;
>   variables:
>           char COD_CAPTEUR(nbData, stringlen) ;
>   data:
>  
>   COD_CAPTEUR =
>    "USA","United State of America"
>    "F","France"
>    "RR" "Russ Rew"
>     ....
>    "xxxxx" "xxxxx";

> I thougth it was possible to do something like
> variables:
>           char COD_CAPTEUR(nbData, numberOfField, stringlen) ;
> with nbData the number of couple,
> numberOfField 2 (couple) and stringlen the length of my arrays of char ?

> I thougth it was also possible to see this same result with ncdump.

No, sorry, unfortunately ncdump isn't that smart.  What you want is
support for something like relational tuples, and have ncdump display
them that way.  While it would be possible to modify ncdump to do
this, it hasn't been done.  About the best you can do now is just use
two different variables:

 netcdf fileTOTO {
 dimensions:
         nbData = UNLIMITED ; // (X currently)
         numberOfChar = 255 ;
         abbrevLen = 4;
         expanLen = 30;
 variables:
         char ABBREVIATION(nbData, abbrevLen);
         char EXPANSION(nbData, expanLen);
 data:

  ABBREVIATION = "USA", "F", "RR", "xxxx";
  EXPANSION    = "United State of America", "France", "Russ Rew", "xxxxx";
 }

If you needed to represent the fact that these two variables were
actual field names for the same table, you would have to either
 - use a convention on the variable names, such as TABLE_ABBREVIATION,
   TABLE_EXPANSION,
 - use a common attribute to relate them, such as
     ABBREVIATION:field = 1;
     EXPANSION:field = 2;
 - use a common dimension whose only purpose is to represnt the close
   relation between the fields, as in
      dimensions:
         table = 1;  // variables that use this are fields of the table
      variables:
         char ABBREVIATION(table, nbData, abbrevLen);
         char EXPANSION(table, nbData, expanLen);

None of these is very satisfactory, and ncdump can't understand any of
them.

If you need to represent data like this, another possibility is to use
a richer data model than netCDF's simple multidimensional arrays, for
example HDF5 supports multidimensional arrays of structs and strings,
so it might be ideal for this application.  See

   http://hdf.ncsa.uiuc.edu/HDF5/

--Russ

> 
> Hi Alain,
> 
> > I would like to create a netcdf file with a variable
> > containing two strings which it is like this example
> >
> >
> > netcdf fileTOTO {
> > dimensions:
> >         nbData = UNLIMITED ; // (X currently)
> >         numberOfChar = 255 ;
> >         numberOfField = 2 ;
> > variables:
> >         char COD_CAPTEUR(?????) ;
> > data:
> >
> >  COD_CAPTEUR =
> >   "hello world","hello USA"
> >   "hello France","hello Russ"
> >   "xxxxx" "xxxxx"
> >    ....
> >   "xxxxx" "xxxxx";
> >
> > I don't know how to declare my variable and if it possible ?
> > I'am using C++ with netcdf-3.4 on Sun Solaris 2.6.
> 
> NetCDF supports multidimensional character arrays rather than arrays
> of strings, so if your strings are of different lengths, it will waste
> some space.  If the maximum length of strings in the COD_CAPTEUR
> variable is 20, for example, add an extra "stringlen" dimension of
> length 20:
> 
>  netcdf fileTOTO {
>  dimensions:
>          nbData = UNLIMITED ; // (X currently)
>          numberOfChar = 255 ;
>          numberOfField = 2 ;
>          stringlen = 20;
>  variables:
>          char COD_CAPTEUR(nbData, stringlen) ;
>  data:
> 
>   COD_CAPTEUR =
>    "hello world","hello USA",
>    "hello France","hello Russ",
>    "xxxxx", "xxxxx";
>  }
> 
> The ncdump and ncgen utilities honor the C convention of
> null-terminated strings in such arrays.  In other words, if you create
> a binary netCDF file from the above using "ncgen -b ..." and then
> ncdump the resulting file, it will preserve the strings, but what is
> stored in the file is still a rectangular array of characters.
> 
> --Russ
> 
> _____________________________________________________________________
> 
> Russ Rew                                         UCAR Unidata Program
> address@hidden                     http://www.unidata.ucar.edu