/* This is part of the netCDF package. Copyright 2005 University Corporation for Atmospheric Research/Unidata See COPYRIGHT file for conditions of use. See www.unidata.ucar.edu for more info. Test netcdf-4 string types. $Id: tst_strings.c,v 1.26 2008/04/23 17:01:34 ed Exp $ */ #include #include "netcdf.h" #include #define FILE_NAME "tst_strings.nc" #define DIM_LEN 9 #define ATT_NAME "measure_for_measure_att" #define DIM_NAME "line" #define VAR_NAME "measure_for_measure_var" #define NDIMS 1 int main(int argc, char **argv) { #ifdef USE_PARALLEL MPI_Init(&argc, &argv); #endif printf("\n*** Testing netcdf-4 string type.\n"); printf("*** testing string variable..."); { int var_dimids[NDIMS]; int ndims, nvars, natts, unlimdimid; nc_type var_type; char var_name[NC_MAX_NAME + 1]; int var_natts, var_ndims; int ncid, varid, i, dimids[NDIMS]; char *data_in[DIM_LEN]; char *data[DIM_LEN] = {"Let but your honour know", "Whom I believe to be most strait in virtue", "That, in the working of your own affections", "Had time cohered with place or place with wishing", "Or that the resolute acting of your blood", "Could have attain'd the effect of your own purpose", "Whether you had not sometime in your life", "Err'd in this point which now you censure him", "And pull'd the law upon you."}; if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_dim(ncid, DIM_NAME, DIM_LEN, dimids)) ERR; if (nc_def_var(ncid, VAR_NAME, NC_STRING, NDIMS, dimids, &varid)) ERR; if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != NDIMS || nvars != 1 || natts != 0 || unlimdimid != -1) ERR; if (nc_inq_var(ncid, varid, var_name, &var_type, &var_ndims, var_dimids, &var_natts)) ERR; if (var_type != NC_STRING || strcmp(var_name, VAR_NAME) || var_ndims != NDIMS || var_dimids[0] != dimids[0]) ERR; if (nc_put_var(ncid, varid, data)) ERR; if (nc_close(ncid)) ERR; /* Check it out. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != NDIMS || nvars != 1 || natts != 0 || unlimdimid != -1) ERR; if (nc_inq_var(ncid, varid, var_name, &var_type, &var_ndims, var_dimids, &var_natts)) ERR; if (var_type != NC_STRING || strcmp(var_name, VAR_NAME) || var_ndims != NDIMS || var_dimids[0] != dimids[0]) ERR; if (nc_get_var(ncid, varid, data_in)) ERR; for (i=0; i= SOME_PRES && strcmp(data_in[i], "")) ERR; } /* Must free your data! */ if (nc_free_string(SOME_PRES, (char **)data_in)) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; FINAL_RESULTS; #ifdef USE_PARALLEL MPI_Finalize(); #endif }