ncdf4a13/nc_test/nc_test.c

Go to the documentation of this file.
00001 /*********************************************************************
00002  *   Copyright 1996-2005, UCAR/Unidata
00003  *   See COPYRIGHT file for copying and redistribution conditions.
00004  *   $Id: nc_test.c,v 1.41 2006/02/01 19:05:08 ed Exp $
00005  *********************************************************************/
00006 
00007 #include "tests.h"
00008 
00009 /*
00010  * Test driver for netCDF-3 interface.  This program performs tests against
00011  * the netCDF-3 specification for all user-level functions in an
00012  * implementation of the netCDF library.
00013  *
00014  * Files:
00015  * The read-only tests read files:
00016  *     test.nc (see below)
00017  *     tests.h (used merely as an example of a non-netCDF file)
00018  * 
00019  * The write tests 
00020  *     read test.nc (see below) 
00021  *     write scratch.nc (deleted after each test)
00022  * 
00023  * The file test.nc is created by running nc_test with the -c (create) option.
00024  * It is described by the following global variables.
00025  */
00026 
00027 /* 
00028  * global variables (defined by function init_gvars) describing file test.nc
00029  */
00030 char dim_name[NDIMS][3];
00031 size_t dim_len[NDIMS];
00032 char var_name[NVARS][2+MAX_RANK];
00033 nc_type var_type[NVARS];
00034 size_t var_rank[NVARS];
00035 int var_dimid[NVARS][MAX_RANK];
00036 size_t var_shape[NVARS][MAX_RANK];
00037 size_t var_nels[NVARS];
00038 size_t var_natts[NVARS];
00039 char att_name[NVARS][MAX_NATTS][2];
00040 char gatt_name[NGATTS][3];
00041 nc_type att_type[NVARS][NGATTS];
00042 nc_type gatt_type[NGATTS];
00043 size_t att_len[NVARS][MAX_NATTS];
00044 size_t gatt_len[NGATTS];
00045 
00046 /* 
00047  * command-line options
00048  */
00049 int  verbose;           /* if 1, print details of tests */
00050 int  max_nmpt;          /* max. number of messages per test */
00051 
00052 /* 
00053  * Misc. global variables
00054  */
00055 int  nfails;            /* number of failures in specific test */
00056 char testfile[NC_MAX_NAME];
00057 char scratch[] = "scratch.nc";  /* writable scratch file */
00058 
00059 #define NC_TEST(func) \
00060     print( "*** Testing " #func " ... ");\
00061     nfails = 0;\
00062     test_ ## func();\
00063     nfailsTotal += nfails;\
00064     if (verbose) \
00065         print("\n"); \
00066     if ( nfails == 0) \
00067         print( "ok\n");\
00068     else\
00069         print( "\n\t### %d FAILURES TESTING %s! ###\n", nfails, #func)
00070 
00071 
00072 #if 1           /* both CRAY MPP and OSF/1 Alpha systems need this */
00073 #include <signal.h>
00074 #endif /* T90 */
00075 
00076 /* Test everything for classic and 64-bit offsetfiles. If netcdf-4 is
00077  * included, that means another whole round of testing. */
00078 #ifdef USE_NETCDF4
00079 #define NUM_FORMATS (3)
00080 #else
00081 #define NUM_FORMATS (2)
00082 #endif
00083 
00084 int
00085 main(int argc, char *argv[])
00086 {
00087     int i;
00088     int  nfailsTotal = 0;        /* total number of failures */
00089 
00090     /* Both CRAY MPP and OSF/1 Alpha systems need this.  Some of the
00091      * extreme test assignments in this program trigger floating point
00092      * exceptions on CRAY T90
00093      */
00094     (void) signal(SIGFPE, SIG_IGN);
00095 
00096     verbose = 0;
00097     max_nmpt = 8;
00098 
00099     /* Initialize global variables defining test file */
00100     init_gvars();
00101 
00102     /* If you uncomment the nc_set_log_level line, you will get a lot
00103      * of debugging info. If you set the number higher, you'll get
00104      * more. 6 is max, 0 shows only errors. 3 is a good place to
00105      * start. */
00106     /*nc_set_log_level(3);*/
00107 
00108     fprintf(stderr, "Testing %d different netCDF formats.\n", NUM_FORMATS);
00109 
00110     /* Go thru formats and run all tests for each of two (for netCDF-3
00111      * only builds), or 3 (for netCDF-4 builds) different formats. Do
00112      * the netCDF-4 format last, however, because, as an additional
00113      * test, the ../nc_test4/tst_nc_test_file program looks at the
00114      * output of this program. */
00115     for (i = 1; i <= NUM_FORMATS; i++)
00116     {
00117        switch (i) 
00118        {
00119           case NC_FORMAT_CLASSIC:
00120              nc_set_default_format(NC_FORMAT_CLASSIC, NULL);
00121              fprintf(stderr, "\n\nSwitching to netCDF classic format.\n");
00122              strcpy(testfile, "nc_test_classic.nc");
00123              break;
00124           case NC_FORMAT_64BIT:
00125              nc_set_default_format(NC_FORMAT_64BIT, NULL);
00126              fprintf(stderr, "\n\nSwitching to 64-bit offset format.\n");
00127              strcpy(testfile, "nc_test_64bit.nc");
00128              break;
00129 #ifdef USE_NETCDF4
00130           case NC_FORMAT_NETCDF4: /* actually it's _CLASSIC. */
00131              nc_set_default_format(NC_FORMAT_NETCDF4_CLASSIC, NULL);
00132              strcpy(testfile, "nc_test_netcdf4.nc");
00133              fprintf(stderr, "\n\nSwitching to netCDF-4 format (with NC_CLASSIC_MODEL).\n");
00134              break;
00135 #endif
00136           default:
00137              fprintf(stderr, "Unexpected format!\n");
00138              return 2;
00139        }
00140 
00141         /* Write the test file, needed for the read-only tests below. */
00142        write_file(testfile);
00143 
00144         /* delete any existing scratch netCDF file */
00145        (void) remove(scratch);
00146 
00147         /* Test read-only functions, using pre-generated test-file */
00148         NC_TEST(nc_strerror);
00149         NC_TEST(nc_open);
00150         NC_TEST(nc_close);
00151         NC_TEST(nc_inq);
00152         NC_TEST(nc_inq_dimid);
00153         NC_TEST(nc_inq_dim);
00154         NC_TEST(nc_inq_dimlen);
00155         NC_TEST(nc_inq_dimname);
00156         NC_TEST(nc_inq_varid);
00157         NC_TEST(nc_inq_var);
00158         NC_TEST(nc_inq_natts);
00159         NC_TEST(nc_inq_ndims);
00160         NC_TEST(nc_inq_nvars);
00161         NC_TEST(nc_inq_unlimdim);
00162         NC_TEST(nc_inq_vardimid);
00163         NC_TEST(nc_inq_varname);
00164         NC_TEST(nc_inq_varnatts);
00165         NC_TEST(nc_inq_varndims);
00166         NC_TEST(nc_inq_vartype);
00167         NC_TEST(nc_get_var_text);
00168         NC_TEST(nc_get_var_uchar);
00169         NC_TEST(nc_get_var_schar);
00170         NC_TEST(nc_get_var_short);
00171         NC_TEST(nc_get_var_int);
00172         NC_TEST(nc_get_var_long);
00173         NC_TEST(nc_get_var_float);
00174         NC_TEST(nc_get_var_double);
00175         NC_TEST(nc_get_var1_text);
00176         NC_TEST(nc_get_var1_uchar);
00177         NC_TEST(nc_get_var1_schar);
00178         NC_TEST(nc_get_var1_short);
00179         NC_TEST(nc_get_var1_int);
00180         NC_TEST(nc_get_var1_long);
00181         NC_TEST(nc_get_var1_float);
00182         NC_TEST(nc_get_var1_double);
00183         NC_TEST(nc_get_var1);
00184         NC_TEST(nc_get_vara_text);
00185         NC_TEST(nc_get_vara_uchar);
00186         NC_TEST(nc_get_vara_schar);
00187         NC_TEST(nc_get_vara_short);
00188         NC_TEST(nc_get_vara_int);
00189         NC_TEST(nc_get_vara_long);
00190         NC_TEST(nc_get_vara_float);
00191         NC_TEST(nc_get_vara_double);
00192         NC_TEST(nc_get_vara);
00193         NC_TEST(nc_get_vars_text);
00194         NC_TEST(nc_get_vars_uchar);
00195         NC_TEST(nc_get_vars_schar);
00196         NC_TEST(nc_get_vars_short);
00197         NC_TEST(nc_get_vars_int);
00198         NC_TEST(nc_get_vars_long);
00199         NC_TEST(nc_get_vars_float);
00200         NC_TEST(nc_get_vars_double);
00201         NC_TEST(nc_get_vars);
00202         NC_TEST(nc_get_varm_text);
00203         NC_TEST(nc_get_varm_uchar);
00204         NC_TEST(nc_get_varm_schar);
00205         NC_TEST(nc_get_varm_short);
00206         NC_TEST(nc_get_varm_int);
00207         NC_TEST(nc_get_varm_long);
00208         NC_TEST(nc_get_varm_float);
00209         NC_TEST(nc_get_varm_double);
00210         NC_TEST(nc_get_varm);
00211         NC_TEST(nc_get_att_text);
00212         NC_TEST(nc_get_att_uchar);
00213         NC_TEST(nc_get_att_schar);
00214         NC_TEST(nc_get_att_short);
00215         NC_TEST(nc_get_att_int);
00216         NC_TEST(nc_get_att_long);
00217         NC_TEST(nc_get_att_float);
00218         NC_TEST(nc_get_att_double);
00219         NC_TEST(nc_get_att);
00220         NC_TEST(nc_inq_att);
00221         NC_TEST(nc_inq_attname);
00222         NC_TEST(nc_inq_attid);
00223         NC_TEST(nc_inq_attlen);
00224         NC_TEST(nc_inq_atttype);
00225 
00226         /* Test write functions */
00227         NC_TEST(nc_create);
00228         NC_TEST(nc_redef);
00229         /* NC_TEST(nc_enddef); *//* redundant */
00230         NC_TEST(nc_sync);
00231         NC_TEST(nc_abort);
00232         NC_TEST(nc_def_dim);
00233         NC_TEST(nc_rename_dim);
00234         NC_TEST(nc_def_var);
00235         NC_TEST(nc_put_var_text);
00236         NC_TEST(nc_put_var_uchar);
00237         NC_TEST(nc_put_var_schar);
00238         NC_TEST(nc_put_var_short);
00239         NC_TEST(nc_put_var_int);
00240         NC_TEST(nc_put_var_long);
00241         NC_TEST(nc_put_var_float);
00242         NC_TEST(nc_put_var_double);
00243         NC_TEST(nc_put_var1_text);
00244         NC_TEST(nc_put_var1_uchar);
00245         NC_TEST(nc_put_var1_schar);
00246         NC_TEST(nc_put_var1_short);
00247         NC_TEST(nc_put_var1_int);
00248         NC_TEST(nc_put_var1_long);
00249         NC_TEST(nc_put_var1_float);
00250         NC_TEST(nc_put_var1_double);
00251         NC_TEST(nc_put_var1);
00252         NC_TEST(nc_put_vara_text);
00253         NC_TEST(nc_put_vara_uchar);
00254         NC_TEST(nc_put_vara_schar);
00255         NC_TEST(nc_put_vara_short);
00256         NC_TEST(nc_put_vara_int);
00257         NC_TEST(nc_put_vara_long);
00258         NC_TEST(nc_put_vara_float);
00259         NC_TEST(nc_put_vara_double);
00260         NC_TEST(nc_put_vara);
00261         NC_TEST(nc_put_vars_text);
00262         NC_TEST(nc_put_vars_uchar);
00263         NC_TEST(nc_put_vars_schar);
00264         NC_TEST(nc_put_vars_short);
00265         NC_TEST(nc_put_vars_int);
00266         NC_TEST(nc_put_vars_long);
00267         NC_TEST(nc_put_vars_float);
00268         NC_TEST(nc_put_vars_double);
00269         NC_TEST(nc_put_vars);
00270         NC_TEST(nc_put_varm_text);
00271         NC_TEST(nc_put_varm_uchar);
00272         NC_TEST(nc_put_varm_schar);
00273         NC_TEST(nc_put_varm_short);
00274         NC_TEST(nc_put_varm_int);
00275         NC_TEST(nc_put_varm_long);
00276         NC_TEST(nc_put_varm_float);
00277         NC_TEST(nc_put_varm_double);
00278         NC_TEST(nc_put_varm);
00279         NC_TEST(nc_rename_var);
00280         NC_TEST(nc_put_att_text);
00281         NC_TEST(nc_put_att_uchar);
00282         NC_TEST(nc_put_att_schar);
00283         NC_TEST(nc_put_att_short);
00284         NC_TEST(nc_put_att_int);
00285         NC_TEST(nc_put_att_long);
00286         NC_TEST(nc_put_att_float);
00287         NC_TEST(nc_put_att_double);
00288         NC_TEST(nc_put_att);
00289         NC_TEST(nc_copy_att);
00290         NC_TEST(nc_rename_att);
00291         NC_TEST(nc_del_att);
00292         NC_TEST(nc_set_default_format);
00293     }
00294 
00295     fprintf(stderr, "\nTotal number of failures: %d\n", nfailsTotal);
00296 
00297     if (nfailsTotal)
00298     {
00299        fprintf(stderr, "nc_test FAILURE!!!\n");
00300        return 2;
00301     }
00302     else
00303        fprintf(stderr, "nc_test SUCCESS!!!\n");
00304 
00305     return 0;
00306 }
00307 

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