NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
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 russ@xxxxxxxxxxxxxxxx http://www.unidata.ucar.edu
netcdfgroup
archives: