ncdf4a13/libsrc4/tst_strings.c File Reference

#include <netcdf.h>
#include <nc_tests.h>

Include dependency graph for tst_strings.c:

Go to the source code of this file.

Defines

#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
#define MOBY_LEN   16

Functions

int main (int argc, char **argv)


Define Documentation

#define ATT_NAME   "measure_for_measure_att"
 

Definition at line 15 of file tst_strings.c.

#define DIM_LEN   9
 

Definition at line 14 of file tst_strings.c.

#define DIM_NAME   "line"
 

Definition at line 16 of file tst_strings.c.

#define FILE_NAME   "tst_strings.nc"
 

Definition at line 13 of file tst_strings.c.

#define MOBY_LEN   16
 

Referenced by main().

#define NDIMS   1
 

Definition at line 18 of file tst_strings.c.

#define VAR_NAME   "measure_for_measure_var"
 

Definition at line 17 of file tst_strings.c.


Function Documentation

int main int  argc,
char **  argv
 

Definition at line 21 of file tst_strings.c.

References att_len, ATT_NAME, att_type, DIM_LEN, DIM_NAME, ERR, FILE_NAME, FINAL_RESULTS, MOBY_LEN, natts, nc_close, nc_create, nc_def_dim, nc_def_var, nc_exit, nc_get_att, nc_get_var(), nc_get_var_string(), NC_GLOBAL, nc_inq, nc_inq_att, nc_inq_var, NC_MAX_NAME, NC_NETCDF4, NC_NOWRITE, nc_open, nc_put_att, nc_put_var(), nc_put_var_string(), NC_STRING, ncid, ndims, NDIMS, nvars, SUMMARIZE_ERR, VAR_NAME, var_name, var_natts, and var_type.

00022 {
00023    int ncid, varid, i, dimids[NDIMS];
00024    char *data[DIM_LEN] = {"Let but your honour know",
00025                       "Whom I believe to be most strait in virtue", 
00026                       "That, in the working of your own affections", 
00027                       "Had time cohered with place or place with wishing", 
00028                       "Or that the resolute acting of your blood",
00029                       "Could have attain'd the effect of your own purpose",
00030                       "Whether you had not sometime in your life",
00031                       "Err'd in this point which now you censure him", 
00032                       "And pull'd the law upon you."};
00033    char *data_in[DIM_LEN];
00034 
00035    printf("\n*** Testing netcdf-4 string type.\n");
00036 
00037    /*nc_set_log_level(6);*/
00038    
00039    printf("*** testing string variable...");
00040    {
00041       int var_dimids[NDIMS];
00042       int ndims, nvars, natts, unlimdimid;
00043       nc_type var_type;
00044       char var_name[NC_MAX_NAME + 1];
00045       int var_natts, var_ndims;
00046 
00047       if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
00048       if (nc_def_dim(ncid, DIM_NAME, DIM_LEN, dimids)) ERR;
00049       if (nc_def_var(ncid, VAR_NAME, NC_STRING, NDIMS, dimids, &varid)) ERR;
00050       if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
00051       if (ndims != NDIMS || nvars != 1 || natts != 0 || unlimdimid != -1) ERR;
00052       if (nc_inq_var(ncid, varid, var_name, &var_type, &var_ndims,
00053                      var_dimids, &var_natts)) ERR;
00054       if (var_type != NC_STRING || strcmp(var_name, VAR_NAME) || var_ndims != NDIMS ||
00055           var_dimids[0] != dimids[0]) ERR;
00056       if (nc_put_var(ncid, varid, data)) ERR;
00057       if (nc_close(ncid)) ERR;
00058       nc_exit();
00059       
00060       /* Check it out. */
00061       if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
00062       if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
00063       if (ndims != NDIMS || nvars != 1 || natts != 0 || unlimdimid != -1) ERR;
00064       if (nc_inq_var(ncid, varid, var_name, &var_type, &var_ndims,
00065                      var_dimids, &var_natts)) ERR;
00066       if (var_type != NC_STRING || strcmp(var_name, VAR_NAME) || var_ndims != NDIMS ||
00067           var_dimids[0] != dimids[0]) ERR;
00068       if (nc_get_var(ncid, varid, data_in)) ERR;
00069       for (i=0; i<DIM_LEN; i++)
00070          if (strcmp(data_in[i], data[i])) ERR;
00071       for (i=0; i<DIM_LEN; i++)
00072          free(data_in[i]);
00073       if (nc_close(ncid)) ERR;
00074       nc_exit();
00075    }
00076 
00077    SUMMARIZE_ERR;
00078    printf("*** testing string attribute...");
00079    {
00080       size_t att_len;
00081       int ndims, nvars, natts, unlimdimid;
00082       nc_type att_type;
00083 
00084       if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
00085       if (nc_put_att(ncid, NC_GLOBAL, ATT_NAME, NC_STRING, DIM_LEN, data)) ERR;
00086       if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
00087       if (ndims != 0 || nvars != 0 || natts != 1 || unlimdimid != -1) ERR;
00088       if (nc_inq_att(ncid, NC_GLOBAL, ATT_NAME, &att_type, &att_len)) ERR;
00089       if (att_type != NC_STRING && att_len != DIM_LEN) ERR;
00090       if (nc_close(ncid)) ERR;
00091       nc_exit();
00092       
00093       /* Check it out. */
00094       if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
00095       if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR;
00096       if (ndims != 0 || nvars != 0 || natts != 1 || unlimdimid != -1) ERR;
00097       if (nc_inq_att(ncid, NC_GLOBAL, ATT_NAME, &att_type, &att_len)) ERR;
00098       if (att_type != NC_STRING && att_len != DIM_LEN) ERR;
00099       if (nc_get_att(ncid, NC_GLOBAL, ATT_NAME, data_in)) ERR; 
00100       for (i=0; i<att_len; i++)
00101          if (strcmp(data_in[i], data[i])) ERR;
00102       for (i=0; i<att_len; i++)
00103          free(data_in[i]);
00104       if (nc_close(ncid)) ERR;
00105       nc_exit();
00106    }
00107 
00108    SUMMARIZE_ERR;
00109    printf("*** testing string var functions...");
00110 
00111    {
00112 #define MOBY_LEN 16
00113       char *data[] = {"Perhaps a very little thought will now enable you to account for ",
00114                       "those repeated whaling disasters--some few of which are casually ",
00115                       "chronicled--of this man or that man being taken out of the boat by ",
00116                       "the line, and lost.",
00117                       "For, when the line is darting out, to be seated then in the boat, ",
00118                       "is like being seated in the midst of the manifold whizzings of a ",
00119                       "steam-engine in full play, when every flying beam, and shaft, and wheel, ",
00120                       "is grazing you.",
00121                       "It is worse; for you cannot sit motionless in the heart of these perils, ",
00122                       "because the boat is rocking like a cradle, and you are pitched one way and ",
00123                       "the other, without the slightest warning;",
00124                       "...But why say more?",
00125                       "All men live enveloped in whale-lines.",
00126                       "All are born with halters round their necks; but it is only when caught ",
00127                       "in the swift, sudden turn of death, that mortals realize the silent, subtle, ",
00128                       "ever-present perils of life."};
00129       char *data_in[MOBY_LEN];
00130 
00131       if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
00132       if (nc_def_dim(ncid, DIM_NAME, MOBY_LEN, dimids)) ERR;
00133       if (nc_def_var(ncid, VAR_NAME, NC_STRING, NDIMS, dimids, &varid)) ERR;
00134       if (nc_put_var_string(ncid, varid, (char **)data)) ERR;
00135       if (nc_close(ncid)) ERR;
00136       
00137       /* Check it out. */
00138      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
00139      if (nc_get_var_string(ncid, varid, data_in)) ERR;
00140      for (i=0; i<MOBY_LEN; i++)
00141         if (strcmp(data_in[i], data[i])) ERR;
00142      for (i=0; i<DIM_LEN; i++)
00143         free(data_in[i]);
00144      if (nc_close(ncid)) ERR;
00145    }
00146 
00147    SUMMARIZE_ERR;
00148 
00149    FINAL_RESULTS;
00150 }


Generated on Thu Mar 16 18:11:53 2006 for nco by  doxygen 1.4.4