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

[netCDF #FTI-935060]: Questions regarding string fields for NetCDF-4 format



I put together a program that might embody what you are doing.
Does it convey what you are trying to do?

#include <stdlib.h>
#include <stdio.h>
#include <netcdf.h>
#include <string.h>

/* The data file we will create. */
#define FILE_NAME "t.nc"
#define NDIMS 2
#define NX 2
#define NY 2

static const char* data[4] = {"abc", "def", "ghi", "jkl"};

static void
fail(int ret)
{
    fprintf(stderr,"fail: %d:%s\n",ret,nc_strerror(ret));
    exit(1);
}

int
main(int argc, char **argv)
{
    int ret = NC_NOERR;
    int ncid, varid;
    int dimids[NDIMS];
    
    if((ret=nc_create(FILE_NAME, NC_CLOBBER|NC_NETCDF4, &ncid)))
        fail(ret);
    
    if((ret=nc_def_dim(ncid, "nx", NX, &dimids[0])))
        fail(ret);
    if((ret=nc_def_dim(ncid, "ny", NY, &dimids[1])))
        fail(ret);
    
    if((ret=nc_def_var(ncid, "var", NC_STRING, NDIMS, dimids, &varid)))
        fail(ret);
    
    if((ret=nc_enddef(ncid)))
        fail(ret);
    
    if((ret=nc_put_var(ncid, varid, data)))
        fail(ret);
    
    if((ret=nc_close(ncid)))
        fail(ret);
    
    return 0;
}
    

=Dennis Heimbigner
  Unidata


Ticket Details
===================
Ticket ID: FTI-935060
Department: Support netCDF
Priority: Normal
Status: Open
===================
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata 
inquiry tracking system and then made publicly available through the web.  If 
you do not want to have your interactions made available in this way, you must 
let us know in each email you send to us.



NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.