/*! \file Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 University Corporation for Atmospheric Research/Unidata. See \ref copyright file for more info. */ /* Create a netcdf-4 file with horrendously large metadata. */ #include "config.h" #include #include #include #include #include #include #ifdef HAVE_GETOPT_H #include #endif #undef DEBUG /* Total number of groups is NGROUPS^TREEDEPTH TREEDEPTH = Depth of the group tree NGROUPS = Number subgroups per group NGROUPATTRS = Number group attributes per group NDIMS = Number dimensions per group NTYPES = Number user types per group NVARS = Number of variables per group VARRANK = Rank of variables: must be <= NDIMS NVARATTRS = Number attributes per variable */ /* Define the Defaults */ #if 1 #define TREEDEPTH 6 #define NGROUPS 2 #define NGROUPATTRS 100 #define NDIMS 100 #define NTYPES 10 #define NVARS 100 #define VARRANK 2 #define NVARATTRS 500 #endif /* Alternate Defaults for testing*/ #if 0 #define TREEDEPTH 2 #define NGROUPS 2 #define NGROUPATTRS 2 #define NDIMS 2 #define NTYPES 2 #define NVARS 2 #define VARRANK 2 #define NVARATTRS NGROUPATTRS #endif #define FILE "bigmeta.nc" #define CHECK(expr) assert((expr) == NC_NOERR) static int treedepth = TREEDEPTH; static int ngroups = NGROUPS; static int ngroupattrs = NGROUPATTRS; static int ndims = NDIMS; static int ntypes = NTYPES; static int nvars = NVARS; static int varrank = VARRANK; static int nvarattrs = NVARATTRS; /* Define the getopt tags */ #define OPT_UNKNOWN 0 #define OPT_TREEDEPTH 1 #define OPT_NGROUPS 2 #define OPT_NGROUPATTRS 3 #define OPT_NDIMS 4 #define OPT_NTYPES 5 #define OPT_NVARS 6 #define OPT_VARRANK 7 #define OPT_NVARATTRS 8 static struct option options[] = { {"treedepth", 1, NULL, OPT_TREEDEPTH}, {"ngroups", 1, NULL, OPT_NGROUPS}, {"ngroupattrs", 1, NULL, OPT_NGROUPATTRS}, {"ndims", 1, NULL, OPT_NDIMS}, {"ntypes", 1, NULL, OPT_NTYPES}, {"nvars", 1, NULL, OPT_NVARS}, {"varrank", 1, NULL, OPT_VARRANK}, {"nvarattrs", 1, NULL, OPT_NVARATTRS}, {NULL, 0, NULL, 0} }; /**************************************************/ static void reportparameters(void) { fprintf(stderr,"--treedepth=%d\n",treedepth); fprintf(stderr,"--ngroups=%d\n",ngroups); fprintf(stderr,"--ngroupattrs=%d\n",ngroupattrs); fprintf(stderr,"--ndims=%d\n",ndims); fprintf(stderr,"--ntypes=%d\n",ntypes); fprintf(stderr,"--nvars=%d\n",nvars); fprintf(stderr,"--varrank=%d\n",varrank); fprintf(stderr,"--nvarattrs=%d\n",nvarattrs); fflush(stderr); } /* Build a compound type with two fields */ static void buildcmpdtype(int grpid, int typindex) { char name[NC_MAX_NAME+1]; int typid; snprintf(name,NC_MAX_NAME,"cmpd%d",typindex); CHECK(nc_def_compound(grpid, 2*sizeof(int), name, &typid)); CHECK(nc_insert_compound(grpid, typid, "f1", 0, NC_INT)); CHECK(nc_insert_compound(grpid, typid, "f2", sizeof(int), NC_INT)); } /* Build an enum type with two members */ static void buildenumtype(int grpid, int typindex) { char name[NC_MAX_NAME+1]; int typid; int val0 = 17; int val1 = 37; snprintf(name,NC_MAX_NAME,"enum%d",typindex); CHECK(nc_def_enum(grpid, NC_INT, name, &typid)); CHECK(nc_insert_enum(grpid, typid, "m0", &val0)); CHECK(nc_insert_enum(grpid, typid, "m1", &val1)); } /* Build attributes for either group or var */ static void buildatts(int grpid, int varid) { char name[NC_MAX_NAME+1]; int i, count; count = (varid == NC_GLOBAL? ngroupattrs : nvarattrs); for(i=0;i compound, odd => enum */ for(i=0;i 1) { while ((tag = getopt_long_only(argc, argv, "", options, NULL)) >= 0) { #ifdef DEBUG fprintf(stderr,"arg=%s value=%s\n",argv[optind-1],optarg); #endif switch (tag) { case OPT_TREEDEPTH: treedepth = atoi(optarg); break; case OPT_NGROUPS: ngroups = atoi(optarg); break; case OPT_NGROUPATTRS: ngroupattrs = atoi(optarg); break; case OPT_NDIMS: ndims = atoi(optarg); break; case OPT_NTYPES: ntypes = atoi(optarg); break; case OPT_NVARS: nvars = atoi(optarg); break; case OPT_VARRANK: varrank = atoi(optarg); break; case OPT_NVARATTRS: nvarattrs = atoi(optarg); break; case ':': fprintf(stderr,"missing argument\n"); exit(1); case '?': default: fprintf(stderr,"unknown option\n"); exit(1); } } } reportparameters(); starttime = 0; endtime = 0; time(&starttime); CHECK(nc_create(FILE, NC_NETCDF4, &ncid)); /* Build subgroups */ for(i=0;i