This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
> I am using c++ There is a small C++ example in the netCDF sources, in cxx/nctst.cpp, which has an example of defining a netCDF variable of type ncChar and writing a string into it, with the statement: reftime->put(s, strlen(s)); Here reftime is the variable and s is the string, really an array of char. The netCDF-3 C++ API you are presumably using was written in the early 90's before exceptions, templates, and STL were made part of the C++ standard, so those it may seem primitive. It provides no support for C++ Strings, just C-style char arrays. Because the data also must be accessible to Fortran-77 programs, fixed-size char arrays are used rather than real strings, and you have to provide lengths rather than null termination, as in the call to strlen(s) above. The netCDF-4 data model and interface, on the other hand, supports an actual netCDF string type that corresponds to variable-length strings. But netCDF-4 files written using variable-length strings are not recognized by netCDF-3 programs, so you would have a compatibility problem if you chose to use them. There is a very new and experimental modern C++ interface for netCDF-4 included in the post-4.1 snapshot releases of netCDF, contributed by Lynton Appel of the Culham Centre for Fusion Energy in the UK. I believe it also supports creating and writing netCDF-3 files, but I haven't yet had much chance to work with it and understand all its capabilities. --Russ string type > address@hidden> wrote: > > > Hi Richard, > > > > > I am trying to put in strings into a netcdf file and I am having > > problems. > > > I have download the examples and the documentation and nothing is working > > at > > > the moment. I was wondering do you have any coding examples, that can > > > describe what i need to do. Thank you in advance. > > > > Are you using C, Fortran, Java, or some other programming language? > > > > --Russ > > > > Russ Rew UCAR Unidata Program > > address@hidden http://www.unidata.ucar.edu > > > > > > > > Ticket Details > > =================== > > Ticket ID: WLR-457355 > > Department: Support netCDF > > Priority: Normal > > Status: Closed > > > > > > > -- > Richard L. Messick > NC A&T SU > > Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: WLR-457355 Department: Support netCDF Priority: Normal Status: Closed