comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » writing fixed-length string arrays to netcdf-4
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
writing fixed-length string arrays to netcdf-4 [message #86348] Tue, 29 October 2013 20:11 Go to previous message
Chris O'Dell is currently offline  Chris O'Dell
Messages: 5
Registered: August 2011
Junior Member
Does anyone know if it is possible to write an array of strings to a variable in a netCDF-4 file as some fixed-length string that has a length > 1? Let me show what I mean, and preface this by saying that I understand HDF-5 better, and in HDf-5 you can definitely do this. I understand that netCDF-4 is built on HDF-5.

Let's define a string array:
stringarr = ['Renee','Tyler','Susan']

METHOD 1 for writing to netcdf file:
(length=1 CHAR array)
------------------------------------
id = NCDF_CREATE('myfile.nc', /CLOBBER, /NETCDF4_FORMAT)
dim1 = NCDF_DIMDEF(id,'dim1',n_elements(stringarr))
len_dim = NCDF_DIMDEF(id, 'string length', max(strlen(stringarr)))
vid = NCDF_VARDEF(id, 'Names', [len_dim, dim1], /CHAR)
NCDF_CONTROL, id, /ENDEF
NCDF_VARPUT, id, vid, stringarr
NCDF_CLOSE, id

This results in a 2D array of CHAR, with dimension (5,3).

METHOD 2 for writing to netcdf file:
(variable-length STRING)
------------------------------------
id = NCDF_CREATE('myfile.nc', /CLOBBER, /NETCDF4_FORMAT)
dim1 = NCDF_DIMDEF(id,'dim1',n_elements(stringarr))
vid = NCDF_VARDEF(id, 'Names', [dim1], /STRING)
NCDF_CONTROL, id, /ENDEF
NCDF_VARPUT, id, vid, stringarr
NCDF_CLOSE, id

This results in a 1D array of variable-length strings, with dimension (3).

What I really want is a 1D array of fixed-length strings, each with length=5 (in this example). Anyone know if this is possible?

Thanks!
Chris
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Difficulty in succesfully creating a runtime app
Next Topic: derivative function in IDL similar as DIFF in matlab

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:05:40 PDT 2025

Total time taken to generate the page: 0.00408 seconds