Ejemplo n.º 1
0
static void
test_large_short_var(const char *testfile) {
    int ncid, varid, dimids[NUMDIMS];
    int int_val_in, int_val_out = 99;
    size_t index[2];
    int cflag = NC_CLOBBER;

    if (nc_create(testfile, cflag, &ncid)) ERR;
    if (nc_def_dim(ncid, "dim3", DIM3, &dimids[0])) ERR;
    if (nc_def_dim(ncid, "dim4", DIM4, &dimids[1])) ERR;
    if (nc_def_var(ncid, "var", NC_SHORT, NUMDIMS, dimids, &varid)) ERR;
    if (nc_enddef(ncid)) ERR;
    index[0] = 0;
    index[1] = 1;
    if (nc_put_var1_int(ncid, varid, index, &int_val_out)) ERR;
    if (nc_close(ncid)) ERR;
    if (nc_open(testfile, NC_NOWRITE, &ncid)) ERR;
    if (nc_inq_varid(ncid, "var", &varid)) ERR;
    if (nc_get_var1_int(ncid, varid, index, &int_val_in)) ERR;
    if (int_val_in != int_val_out)
	ERR;
#ifndef NOFILL
    index[0] = 1;
    index[1] = 2;
    if (nc_get_var1_int(ncid, varid, index, &int_val_in)) ERR;
    if (int_val_in != NC_FILL_SHORT)
	ERR;
#endif
    if (nc_close(ncid)) ERR;
}
Ejemplo n.º 2
0
/*
 * In netCDF-3.6.2, a divide by zero occurs on 32-bit platforms when
 * creating a variable for which the product of dimensions is exactly
 * 2**32.  Check that this bug has been fixed.
 */
static int
test_big_var(const char *testfile) {
    int ncid, varid, dimids[NUMDIMS];
    int cflag = NC_CLOBBER;
    nc_type type = NC_BYTE;
    size_t index[NUMDIMS];
    signed char nval = 99;
    int nval_in;

    /* Define the file with one large variable. */
    if (nc_create(testfile, cflag, &ncid)) ERR;
    if (nc_set_fill(ncid, NC_NOFILL, NULL)) ERR;
    if (nc_def_dim(ncid, "dim1", DIM1, &dimids[0])) ERR;
    if (nc_def_dim(ncid, "dim2", DIM2 - 1, &dimids[1])) ERR;
    if (nc_def_var(ncid, "var", type, NUMDIMS, dimids, &varid)) ERR;
    if (nc_enddef(ncid)) ERR;

    /* Write one datum, near the end of the variable. */
    index[0] = DIM1 - 1;
    index[1] = DIM2 - 2;
    if (nc_put_var1_schar(ncid, varid, index, &nval)) ERR;
    if (nc_close(ncid)) ERR;

    /* Reopen the file and check that datum. */
    if (nc_open(testfile, NC_NOWRITE, &ncid)) ERR;
    if (nc_inq_varid(ncid, "var", &varid)) ERR;
    if (nc_get_var1_int(ncid, varid, index, &nval_in)) ERR;
    if (nval != nval_in)
	ERR;
    if (nc_close(ncid)) ERR;
    return 0;
}
Ejemplo n.º 3
0
/* 
 * In netCDF-3.6.2, an assertion failure occurs on 32-bit platforms
 * when creating a byte variable for which the product of dimensions
 * is greater than 2**32.  Check that this bug has been fixed.
 */
static int
test_big_var(const char *testfile) 
{
    int ncid, varid, dimids[NUMDIMS];
    size_t index[NUMDIMS];
    int nval = 99;
    int nval_in;

    /* Create a file with one big variable. */
    if (nc_create(testfile, NC_CLOBBER, &ncid)) ERR;
    if (nc_set_fill(ncid, NC_NOFILL, NULL)) ERR;
    if (nc_def_dim(ncid, "dim1", DIM1, &dimids[0])) ERR;
    if (nc_def_dim(ncid, "dim2", DIM2 - 1, &dimids[1])) ERR;
    if (nc_def_var(ncid, "var", NC_BYTE, NUMDIMS, dimids, &varid)) ERR;
    if (nc_enddef(ncid)) ERR;
    index[0] = DIM1 - 1;
    index[1] = DIM2 - 2;
    if (nc_put_var1_int(ncid, varid, index, &nval)) ERR;
    if (nc_close(ncid)) ERR;

    /* Open the file and check it. */
    if (nc_open(testfile, NC_NOWRITE, &ncid)) ERR;
    if (nc_inq_varid(ncid, "var", &varid)) ERR;
    if (nc_get_var1_int(ncid, varid, index, &nval_in)) ERR;
    if (nval != nval_in) ERR;
    if (nc_close(ncid)) ERR;
    return 0;
}
Ejemplo n.º 4
0
/* 
 * In netCDF-3.6.2, a divide by zero occurs on 32-bit platforms when
 * creating a variable for which the product of dimensions is exactly
 * 2**32.  Check that this bug has been fixed. 
 */
static void
test_big_var(const char *testfile) {
    int ncid, varid, dimids[NUMDIMS];
    int cflag = NC_CLOBBER;
    nc_type type = NC_BYTE;
    size_t index[NUMDIMS];
    signed char nval = 99;
    int nval_in;
    
    if (nc_create(testfile, cflag, &ncid)) ERR;
    if (nc_set_fill(ncid, NC_NOFILL, NULL)) ERR;
    if (nc_def_dim(ncid, "dim1", DIM1, &dimids[0])) ERR;
    if (nc_def_dim(ncid, "dim2", DIM2 - 1, &dimids[1])) ERR;
    if (nc_def_var(ncid, "var", type, NUMDIMS, dimids, &varid)) ERR;
    if (nc_enddef(ncid)) ERR;
    index[0] = DIM1 - 1;
    index[1] = DIM2 - 2;
    if (nc_put_var1_schar(ncid, varid, index, &nval)) ERR;
    if (nc_close(ncid)) ERR;
    if (nc_open(testfile, NC_NOWRITE, &ncid)) ERR;
    if (nc_inq_varid(ncid, "var", &varid)) ERR;
    if (nc_get_var1_int(ncid, varid, index, &nval_in)) ERR;
    if (nval != nval_in)
	ERR;
    if (nc_close(ncid)) ERR;
}
Ejemplo n.º 5
0
int ex_get_file_type(int exoid,
                     char *ftype
                     )
{
  const char   *func_name="ex_get_file_type";

  int  status;
  int     varid;
  int  lftype;

  char    errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  if ((status = nc_inq_varid(exoid, VAR_FILE_TYPE, &varid)) != NC_NOERR) {

    /* If no file type is found, assume parallel */
    ftype[0] = 'p';
    ftype[1] = '\0';

    return (EX_NOERR);
  }

  if ((status = nc_get_var1_int(exoid, varid, NULL, &lftype)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get variable \"%s\" from file ID %d",
            VAR_FILE_TYPE, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  /* Set the appropriate character */
  if (lftype == 0)       strcpy(ftype, "p");
  else if (lftype == 1)  strcpy(ftype, "s");

  return (EX_NOERR);
}
Ejemplo n.º 6
0
int
main(int argc, char **argv)
{
    int ncid, spockid, kirkid, dimids[NUMDIMS];
    int int_val_in, int_val_out = 99;
    double double_val_in, double_val_out = 1.79769313486230e+308; /* from ncx.h */
    size_t index[2] = {QTR_CLASSIC_MAX-1, 0};

    /* These are for the revolutionary generals tests. */
    int cromwellid, collinsid, washingtonid;
    int napoleanid, dimids_gen[4], dimids_gen1[4];

    /* All create modes will be anded to this. All tests will be run
       twice, with and without NC_SHARE.*/
    int cmode_run;
    int cflag = NC_CLOBBER;

    int res; 

    printf("\n*** Testing large files, quickly.\n");

    for (cmode_run=0; cmode_run<2; cmode_run++)
    {
 	/* On second pass, try using NC_SHARE. */
	if (cmode_run == 1) 
	{
	    cflag |= NC_SHARE;
	    printf("*** Turned on NC_SHARE for subsequent tests.\n");
	}

	/* Create a netCDF 64-bit offset format file. Write a value. */
	printf("*** Creating %s for 64-bit offset large file test...", FILE_NAME);
	if ((res = nc_create(FILE_NAME, cflag|NC_64BIT_OFFSET, &ncid)))
	    ERR;

	if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
	    ERR;
	if ((res = nc_def_dim(ncid, "longdim", QTR_CLASSIC_MAX, dimids)))
	    ERR;
	if ((res = nc_def_var(ncid, "spock", NC_DOUBLE, NUMDIMS, 
			      dimids, &spockid)))
	    ERR;
	if ((res = nc_def_var(ncid, "kirk", NC_DOUBLE, NUMDIMS, 
			      dimids, &kirkid)))
	    ERR;
	if ((res = nc_enddef(ncid)))
	    ERR;
	if ((res = nc_put_var1_double(ncid, kirkid, index, &double_val_out)))
	    ERR;
	if ((res = nc_close(ncid)))
	    ERR;
	printf("ok\n");

	/* How about a meteorological data file about the weather
	   experience by various generals of revolutionary armies? 

	   This has 3 dims, 4 vars. The dimensions are such that this will
	   (just barely) not fit in a classic format file. The first three
	   vars are cromwell, 536870911 bytes, washington, 2*536870911
	   bytes, and napolean, 536870911 bytes. That's a grand total of
	   2147483644 bytes. Recall our magic limit for the combined size
	   of all fixed vars: 2 GiB - 4 bytes, or 2147483644. So you would
	   think these would exactly fit, unless you realized that
	   everything is rounded to a 4 byte boundary, so you need to add
	   some bytes for that (how many?), and that pushes us over the
	   limit.
      
	   We will create this file twice, once to ensure it succeeds (with
	   64-bit offset format), and once to make sure it fails (with
	   classic format). Then some variations to check record var
	   boundaries. 
	*/
	printf("*** Now a 64-bit offset, large file, fixed var test...");
	if ((res = nc_create(FILE_NAME, cflag|NC_64BIT_OFFSET, &ncid)))
	    ERR;
	if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
	    ERR;
	if ((res = nc_def_dim(ncid, "revolutionary_fervor", 
			      QTR_CLASSIC_MAX, &dimids_gen[0])))
	    ERR;
	if ((res = nc_def_dim(ncid, "post_revoultionary_hangover", 
			      QTR_CLASSIC_MAX, &dimids_gen[1])))
	    ERR;
	if ((res = nc_def_dim(ncid, "ruthlessness", 100, &dimids_gen[2])))
	    ERR;
	if ((res = nc_def_var(ncid, "Cromwell", NC_BYTE, 1, &dimids_gen[0],
			      &cromwellid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 1, &dimids_gen[1], 
			      &washingtonid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 1, &dimids_gen[0], 
			      &napoleanid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 1, &dimids_gen[2], 
			      &collinsid)))
	    ERR;
	if ((res = nc_enddef(ncid)))
	    ERR;
	printf("ok\n");

	/* Write a value or two just for fun. */
	/*index[0] = QTR_CLASSIC_MAX - 296;
	if ((res = nc_put_var1_int(ncid, napoleanid, index, &int_val_out)))
	    ERR;
	if ((res = nc_get_var1_int(ncid, napoleanid, index, &int_val_in)))
	    ERR;
	if (int_val_in != int_val_out)
	BAIL2;*/
	printf("*** Now writing some values...");
	index[0] = QTR_CLASSIC_MAX - 295;
	if ((res = nc_put_var1_int(ncid, napoleanid, index, &int_val_out)))
	    ERR;
	if ((res = nc_get_var1_int(ncid, napoleanid, index, &int_val_in)))
	    ERR;
	if (int_val_in != int_val_out)
	   ERR;

	index[0] = QTR_CLASSIC_MAX - 1;
	if ((res = nc_put_var1_int(ncid, napoleanid, index, &int_val_out)))
	    ERR;
	if ((res = nc_get_var1_int(ncid, napoleanid, index, &int_val_in)))
	    ERR;
	if (int_val_in != int_val_out)
	    ERR;

	index[0] = QTR_CLASSIC_MAX - 1;
	if ((res = nc_put_var1_int(ncid, washingtonid, index, &int_val_out)))
	    ERR;
	if ((res = nc_get_var1_int(ncid, washingtonid, index, &int_val_in)))
	    ERR;
	if (int_val_in != int_val_out)
	    ERR;

	if ((res = nc_close(ncid)))
	    ERR;
	printf("ok\n");

	/* This time it should fail, because we're trying to cram this into
	   a classic format file. nc_enddef will detect our violations and
	   give an error. We've*/
	printf("*** Now a classic file which will fail...");
	if ((res = nc_create(FILE_NAME, cflag, &ncid)))
	    ERR;
	if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
	    ERR;
	if ((res = nc_def_dim(ncid, "revolutionary_fervor", 
			      QTR_CLASSIC_MAX, &dimids_gen[0])))
	    ERR;
	if ((res = nc_def_dim(ncid, "post_revoultionary_hangover", 
			      QTR_CLASSIC_MAX, &dimids_gen[1])))
	    ERR;
	if ((res = nc_def_dim(ncid, "ruthlessness", 100, &dimids_gen[2])))
	    ERR;
	if ((res = nc_def_var(ncid, "Cromwell", NC_BYTE, 1, &dimids_gen[0],
			      &cromwellid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 1, &dimids_gen[1], 
			      &washingtonid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 1, &dimids_gen[0], 
			      &napoleanid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 1, &dimids_gen[2], 
			      &collinsid)))
	    ERR;
	if ((res = nc_enddef(ncid)) != NC_EVARSIZE)
	    ERR;
	if ((res = nc_close(ncid)) != NC_EVARSIZE)
	    ERR;
	printf("ok\n");

	/* This will create some max sized 64-bit offset format fixed vars. */
	printf("*** Now a 64-bit offset, simple fixed var create test...");
	if ((res = nc_create(FILE_NAME, cflag|NC_64BIT_OFFSET, &ncid)))
	    ERR;
	if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
	    ERR;
	if ((res = nc_def_dim(ncid, "revolutionary_fervor", 
			      MAX_CLASSIC_BYTES, &dimids_gen[0])))
	    ERR;
	if ((res = nc_def_var(ncid, "Cromwell", NC_SHORT, 1, dimids_gen,
			      &cromwellid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Napolean", NC_SHORT, 1, dimids_gen, 
			      &napoleanid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 1, dimids_gen, 
			      &collinsid)))
	    ERR;
	if ((res = nc_enddef(ncid)))
	    ERR;
	if ((res = nc_close(ncid)))
	    ERR;
	printf("ok\n");

	/* This will exceed the 64-bit offset format limits for one of the
	   fixed vars. */
	printf("*** Now a 64-bit offset, over-sized file that will fail...");
	if ((res = nc_create(FILE_NAME, cflag|NC_64BIT_OFFSET, &ncid)))
	    ERR;
	if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
	    ERR;
	/* max dim size is MAX_CLASSIC_BYTES. */
	if ((res = nc_def_dim(ncid, "revolutionary_fervor", 
			      MAX_CLASSIC_BYTES, dimids_gen)))
	    ERR;
	if ((res = nc_def_var(ncid, "Cromwell", NC_DOUBLE, 1, dimids_gen,
			      &cromwellid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 1, dimids_gen, 
			      &washingtonid)))
	    if ((res = nc_enddef(ncid)) != NC_EVARSIZE)
		ERR;
	if ((res = nc_close(ncid)) != NC_EVARSIZE)
	    ERR;
	printf("ok\n");

	/* Now let's see about record vars. First create a 64-bit offset
	   file with three rec variables, each with the same numbers as
	   defined above for the fixed var tests. This should all work. */
	printf("*** Now a 64-bit offset, record var file...");
	if ((res = nc_create(FILE_NAME, cflag|NC_64BIT_OFFSET, &ncid)))
	    ERR;
	if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
	    ERR;
	if ((res = nc_def_dim(ncid, "political_trouble", 
			      NC_UNLIMITED, &dimids_gen[0])))
	    ERR;
	if ((res = nc_def_dim(ncid, "revolutionary_fervor", 
			      QTR_CLASSIC_MAX, &dimids_gen[1])))
	    ERR;
	if ((res = nc_def_dim(ncid, "post_revoultionary_hangover", 
			      QTR_CLASSIC_MAX, &dimids_gen[2])))
	    ERR;
	if ((res = nc_def_dim(ncid, "ruthlessness", 100, &dimids_gen[3])))
	    ERR;
	if ((res = nc_def_var(ncid, "Cromwell", NC_BYTE, 2, dimids_gen,
			      &cromwellid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 2, dimids_gen, 
			      &washingtonid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 2, dimids_gen, 
			      &napoleanid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 1, &dimids_gen[2], 
			      &collinsid)))
	    ERR;
	if ((res = nc_enddef(ncid)))
	    ERR;
	if ((res = nc_close(ncid)))
	    ERR;
	printf("ok\n");

	/* Now try this record file in classic format. It should fail and
	   the enddef. Too many bytes in the first record.*/
	printf("*** Now a classic file that's too big and will fail...");
	if ((res = nc_create(FILE_NAME, cflag, &ncid)))
	    ERR;
	if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
	    ERR;
	if ((res = nc_def_dim(ncid, "political_trouble", 
			      NC_UNLIMITED, &dimids_gen[0])))
	    ERR;
	if ((res = nc_def_dim(ncid, "revolutionary_fervor", 
			      QTR_CLASSIC_MAX, &dimids_gen[1])))
	    ERR;
	if ((res = nc_def_dim(ncid, "post_revoultionary_hangover", 
			      QTR_CLASSIC_MAX, &dimids_gen[2])))
	    ERR;
	if ((res = nc_def_dim(ncid, "ruthlessness", 100, &dimids_gen[3])))
	    ERR;
	if ((res = nc_def_var(ncid, "Cromwell", NC_BYTE, 2, dimids_gen,
			      &cromwellid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 2, dimids_gen, 
			      &washingtonid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 2, dimids_gen, 
			      &napoleanid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 1, &dimids_gen[2], 
			      &collinsid)))
	    ERR;
	if ((res = nc_enddef(ncid)) != NC_EVARSIZE)
	    ERR;
	if ((res = nc_close(ncid)) != NC_EVARSIZE)
	    ERR;
	printf("ok\n");

	/* Now try this record file in classic format. It just barely
	   passes at the enddef. Almost, but not quite, too many bytes in
	   the first record. Since I'm adding a fixed variable (Collins), 
	   I don't get the last record size exemption. */ 
	printf("*** Now a classic file with recs and one fixed will fail...");
	if ((res = nc_create(FILE_NAME, cflag, &ncid)))
	    ERR;
	if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
	    ERR;
	if ((res = nc_def_dim(ncid, "political_trouble", 
			      NC_UNLIMITED, &dimids_gen[0])))
	    ERR;
	if ((res = nc_def_dim(ncid, "revolutionary_fervor", 
			      MAX_CLASSIC_BYTES, &dimids_gen[1])))
	    ERR;
	if ((res = nc_def_dim(ncid, "ruthlessness", 100, &dimids_gen[2])))
	    ERR;
	if ((res = nc_def_var(ncid, "Cromwell", NC_BYTE, 2, dimids_gen,
			      &cromwellid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 1, &dimids_gen[2], 
			      &collinsid)))
	    ERR;
	if ((res = nc_enddef(ncid)))
	    ERR;
	if ((res = nc_close(ncid)))
	    ERR;
	printf("ok\n");

	/* Try a classic file with several records, and the last record var
	   with a record size greater than our magic number of 2 GiB - 4
	   bytes. We'll start with just one oversized record var. This
	   should work. Cromwell has been changed to NC_DOUBLE, and that
	   increases his size to 2147483644 (the max dimension size) times
	   8, or about 16 GB per record. Zowie! (Mind you, Cromwell
	   certainly had a great deal of revolutionary fervor.)
	*/ 
	printf("*** Now a classic file with one large rec var...");
	if ((res = nc_create(FILE_NAME, cflag, &ncid)))
	    ERR;
	if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
	    ERR;
	if ((res = nc_def_dim(ncid, "political_trouble", 
			      NC_UNLIMITED, &dimids_gen[0])))
	    ERR;
	if ((res = nc_def_dim(ncid, "revolutionary_fervor",  
			      MAX_CLASSIC_BYTES, &dimids_gen[1])))  
	    ERR;
	if ((res = nc_def_var(ncid, "Cromwell", NC_DOUBLE, 2, dimids_gen,
			      &cromwellid)))
	    ERR;
	if ((res = nc_enddef(ncid)))
	    ERR;
	index[0] = 0;
	index[1] = MAX_CLASSIC_BYTES - 1;
	if ((res = nc_put_var1_double(ncid, cromwellid, index, &double_val_out)))
	    ERR;
	if ((res = nc_get_var1_double(ncid, cromwellid, index, &double_val_in)))
	    ERR;
	if (double_val_in != double_val_out)
	    ERR;
	if ((res = nc_close(ncid)))
	    ERR;
	printf("ok\n");
   
	/* This is a classic format file with an extra-large last record
	   var. */
	printf("*** Now a classic file with extra-large last record var...");
	if ((res = nc_create(FILE_NAME, cflag, &ncid)))
	    ERR;
	if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
	    ERR;
	if ((res = nc_def_dim(ncid, "political_trouble", 
			      NC_UNLIMITED, &dimids_gen[0])))
	    ERR;
	if ((res = nc_def_dim(ncid, "revolutionary_fervor",  
			      MAX_CLASSIC_BYTES, &dimids_gen[1])))  
	    ERR;
	dimids_gen1[0] = dimids_gen[0];
	if ((res = nc_def_dim(ncid, "post_revoultionary_hangover", 
			      5368, &dimids_gen1[1])))
	    ERR;
	if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 2, dimids_gen1, 
			      &washingtonid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 2, dimids_gen1, 
			      &napoleanid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 2, dimids_gen1, 
			      &collinsid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Cromwell", NC_DOUBLE, 2, dimids_gen,
			      &cromwellid)))
	    ERR;
	if ((res = nc_enddef(ncid)))
	    ERR;
	index[0] = 0;
	index[1] = MAX_CLASSIC_BYTES - 1;
	if ((res = nc_put_var1_double(ncid, cromwellid, index, &double_val_out)))
	    ERR;
	if ((res = nc_get_var1_double(ncid, cromwellid, index, &double_val_in)))
	    ERR;
	if (double_val_in != double_val_out)
	    ERR;
	if ((res = nc_close(ncid)))
	    ERR;
	printf("ok\n");

	/* This is a classic format file with an extra-large second to last
	   record var. But this time it won't work, because the size
	   exemption only applies to the last record var. Note that one
	   dimension is small (5000). */
	printf("*** Now a classic file xtra-large 2nd to last var that will fail...");
	if ((res = nc_create(FILE_NAME, cflag, &ncid)))
	    ERR;
	if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
	    ERR;
	if ((res = nc_def_dim(ncid, "political_trouble", 
			      NC_UNLIMITED, &dimids_gen[0])))
	    ERR;
	if ((res = nc_def_dim(ncid, "revolutionary_fervor",  
			      MAX_CLASSIC_BYTES, &dimids_gen[1])))  
	    ERR;
	dimids_gen1[0] = dimids_gen[0];
	if ((res = nc_def_dim(ncid, "post_revoultionary_hangover", 
			      5000, &dimids_gen1[1])))
	    ERR;
	if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 2, dimids_gen1, 
			      &washingtonid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 2, dimids_gen1, 
			      &napoleanid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Cromwell", NC_DOUBLE, 2, dimids_gen,
			      &cromwellid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 2, dimids_gen1, 
			      &collinsid)))
	    ERR;
	if ((res = nc_enddef(ncid)) != NC_EVARSIZE)
	    ERR;
	if ((res = nc_close(ncid)) != NC_EVARSIZE)
	    ERR;
	printf("ok\n");

	/* Now try an extra large second to last ver with 64-bit
	   offset. This won't work either, because the cromwell var is so
	   large. It exceeds the 4GiB - 4 byte per record limit for record
	   vars. */
	printf("*** Now a 64-bit offset file with too-large rec var that will fail...");
	if ((res = nc_create(FILE_NAME, cflag|NC_64BIT_OFFSET, &ncid)))
	    ERR;
	if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
	    ERR;
	if ((res = nc_def_dim(ncid, "political_trouble", 
			      NC_UNLIMITED, &dimids_gen[0])))
	    ERR;
	if ((res = nc_def_dim(ncid, "revolutionary_fervor",  
			      MAX_CLASSIC_BYTES, &dimids_gen[1])))  
	    ERR;
	dimids_gen1[0] = dimids_gen[0];
	if ((res = nc_def_dim(ncid, "post_revoultionary_hangover", 
			      5368, &dimids_gen1[1])))
	    ERR;
	if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 2, dimids_gen1, 
			      &washingtonid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Napolean", NC_BYTE, 2, dimids_gen1, 
			      &napoleanid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Cromwell", NC_DOUBLE, 2, dimids_gen,
			      &cromwellid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 2, dimids_gen1, 
			      &collinsid)))
	    ERR;
	if ((res = nc_enddef(ncid)) != NC_EVARSIZE)
	    ERR;
	if ((res = nc_close(ncid)) != NC_EVARSIZE)
	    ERR;
	printf("ok\n");

	/* A 64-bit offset record file that just fits... */
	printf("*** Now a 64 bit-offset file that just fits...");
	if ((res = nc_create(FILE_NAME, cflag|NC_64BIT_OFFSET, &ncid)))
	    ERR;
	if ((res = nc_set_fill(ncid, NC_NOFILL, NULL)))
	    ERR;
	if ((res = nc_def_dim(ncid, "political_trouble", 
			      NC_UNLIMITED, &dimids_gen[0])))
	    ERR;
	if ((res = nc_def_dim(ncid, "revolutionary_fervor",  
			      MAX_CLASSIC_BYTES, &dimids_gen[1])))  
	    ERR;
	dimids_gen1[0] = dimids_gen[0];
	if ((res = nc_def_dim(ncid, "post_revoultionary_hangover", 
			      MAX_CLASSIC_BYTES, &dimids_gen1[1])))
	    ERR;
	if ((res = nc_def_var(ncid, "Washington", NC_SHORT, 2, dimids_gen1, 
			      &washingtonid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Napolean", NC_SHORT, 2, dimids_gen1, 
			      &napoleanid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Cromwell", NC_SHORT, 2, dimids_gen,
			      &cromwellid)))
	    ERR;
	if ((res = nc_def_var(ncid, "Collins", NC_DOUBLE, 2, dimids_gen1, 
			      &collinsid)))
	    ERR;
	if ((res = nc_enddef(ncid)))
	    ERR;
	index[0] = 0;
	index[1] = MAX_CLASSIC_BYTES - 1;
	if ((res = nc_put_var1_int(ncid, cromwellid, index, &int_val_out)))
	    ERR;
	if ((res = nc_get_var1_int(ncid, cromwellid, index, &int_val_in)))
	    ERR;
	if (int_val_in != int_val_out)
	    ERR;
	if ((res = nc_close(ncid)))
	    ERR;
	printf("ok\n");
    } /* end of cmode run */

    /* Wow! Everything worked! */
    printf("\n*** All large file tests were successful.\n");

    /* Delete the huge data file we created. */
    (void) remove(FILE_NAME); 

    printf("*** Success ***\n");

    return 0;
}
Ejemplo n.º 7
0
sta_struct *decode_fsl2(int cdfid, long miss, int *iret)
{
int ndims,nvars,natts,nunlim;
int tmpint[20];
int ier,i,j,unlimsiz;
int wmoStaNum_id,wmoStaNum,staName_id;
char staName[20];
int staLat_id,staLon_id,staElev_id,timeObs_id,levels_id;
int uwnd_id,vwnd_id,wwnd_id,uv_qual_id,w_qual_id,levelMode_id;
int sigma_uv_id,sigma_w_id;
int sfc_sped_id,sfc_drct_id,sfc_pres_id,sfc_temp_id,sfc_relh_id,sfc_rain_id;
float staLat,staLon,staElev,level;
float uwnd,vwnd,wwnd,sigma_uv,sigma_w;
int uv_qual,w_qual,levelMode;
float sfc_sped,sfc_drct,sfc_pres,sfc_temp,sfc_relh,sfc_rain;
double timeObs;
nc_type xtype;
int nvdims,nvatts,time_interval;
size_t dimsiz,var_i[5],vc[5],namelen;
float ufill,vfill,wfill;
float pfill,tfill,dfill,sfill,rfill,rrfill;
float fmiss,e;

time_t obs_time;
char timestr[80],*atttext;
int year,month,day,hour,minute;
struct tm *gmt_time=NULL,new_time;
sta_struct *stadat,*head=NULL;
prof_data *plev,*plast;


udebug("decoding fsl2\0");
fmiss = (float)miss;

ier = nc_inq(cdfid,&ndims,&nvars,&natts,&nunlim);

ier = nc_inq_atttype(cdfid,NC_GLOBAL,"avgTimePeriod",&xtype);
if(xtype == NC_CHAR)
   {
   ier = nc_inq_attlen(cdfid,NC_GLOBAL,"avgTimePeriod",&namelen);
   udebug("AvgTimPeriod name len is %d",namelen);
   atttext = (char *)malloc(namelen + 1);
   ier = nc_get_att_text(cdfid,NC_GLOBAL,"avgTimePeriod",atttext);
   sscanf(atttext,"%d",tmpint);
   udebug("AvgTimPeriod type is NC_CHAR %s VAL %d",atttext,tmpint[0]);
   free(atttext);
   }
else
   {
   ier = nc_get_att_int(cdfid,NC_GLOBAL,"avgTimePeriod",tmpint);
   }
udebug("AvgTimPeriod is %d\0",tmpint[0]);
time_interval = tmpint[0];

ier = 0;
ier += nc_inq_varid(cdfid,"wmoStaNum",&wmoStaNum_id);
ier += nc_inq_varid(cdfid,"staName",&staName_id);
ier += nc_inq_varid(cdfid,"staLat",&staLat_id);
ier += nc_inq_varid(cdfid,"staLon",&staLon_id);
ier += nc_inq_varid(cdfid,"staElev",&staElev_id);
ier += nc_inq_varid(cdfid,"timeObs",&timeObs_id);
ier += nc_inq_varid(cdfid,"levels",&levels_id);
ier += nc_inq_varid(cdfid,"uComponent",&uwnd_id);
ier += nc_inq_varid(cdfid,"vComponent",&vwnd_id);
ier += nc_inq_varid(cdfid,"wComponent",&wwnd_id);
ier += nc_get_att_float(cdfid,uwnd_id,"_FillValue",&ufill);
ier += nc_get_att_float(cdfid,vwnd_id,"_FillValue",&vfill);
ier += nc_get_att_float(cdfid,wwnd_id,"_FillValue",&wfill);

ier += nc_inq_varid(cdfid,"uvQualityCode",&uv_qual_id);
ier += nc_inq_varid(cdfid,"wQualityCode",&w_qual_id);
ier += nc_inq_varid(cdfid,"windSpeedStdDev",&sigma_uv_id);
ier += nc_inq_varid(cdfid,"wStdDev",&sigma_w_id);
ier += nc_inq_varid(cdfid,"levelMode",&levelMode_id);

ier += nc_inq_varid(cdfid,"windSpeedSfc",&sfc_sped_id);
ier += nc_inq_varid(cdfid,"windDirSfc",&sfc_drct_id);
ier += nc_inq_varid(cdfid,"pressure",&sfc_pres_id);
ier += nc_inq_varid(cdfid,"temperature",&sfc_temp_id);
ier += nc_inq_varid(cdfid,"relHumidity",&sfc_relh_id);
ier += nc_inq_varid(cdfid,"rainRate",&sfc_rain_id);
ier += nc_get_att_float(cdfid,sfc_sped_id,"_FillValue",&sfill);
ier += nc_get_att_float(cdfid,sfc_drct_id,"_FillValue",&dfill);
ier += nc_get_att_float(cdfid,sfc_pres_id,"_FillValue",&pfill);
ier += nc_get_att_float(cdfid,sfc_temp_id,"_FillValue",&tfill);
ier += nc_get_att_float(cdfid,sfc_relh_id,"_FillValue",&rfill);
ier += nc_get_att_float(cdfid,sfc_rain_id,"_FillValue",&rrfill);

if(ier != 0)
   {
   uerror("could not get station information\0");
   *iret = -1;
   return(NULL);
   }

ier = nc_inq_vardimid(cdfid,staName_id,tmpint);
ier += nc_inq_dimlen(cdfid,tmpint[1],&namelen);

tmpint[0] = 0;tmpint[1] = 0;
ier += nc_inq_var(cdfid,wmoStaNum_id,NULL, &xtype, &nvdims, tmpint, &nvatts);
ier += nc_inq_dimlen(cdfid,tmpint[0],&dimsiz);
if(ier == 0)
   unlimsiz = dimsiz;
   for(i=0;i<unlimsiz;i++)
      {
      var_i[0] = i; var_i[1] = 0; vc[0] = 1; vc[1] = namelen-1;
      memset(staName,'\0',20);
      ier = nc_get_vara_text(cdfid,staName_id,var_i,vc,staName);
      ier = nc_get_var1_int(cdfid,wmoStaNum_id,var_i,&wmoStaNum);
      ier = nc_get_var1_float(cdfid,staLat_id,var_i,&staLat);
      ier = nc_get_var1_float(cdfid,staLon_id,var_i,&staLon);
      ier = nc_get_var1_float(cdfid,staElev_id,var_i,&staElev);
      ier = nc_get_var1_float(cdfid,sfc_sped_id,var_i,&sfc_sped);
      ier = nc_get_var1_float(cdfid,sfc_drct_id,var_i,&sfc_drct);
      ier = nc_get_var1_float(cdfid,sfc_pres_id,var_i,&sfc_pres);
      ier = nc_get_var1_float(cdfid,sfc_temp_id,var_i,&sfc_temp);
      ier = nc_get_var1_float(cdfid,sfc_relh_id,var_i,&sfc_relh);
      ier = nc_get_var1_float(cdfid,sfc_rain_id,var_i,&sfc_rain);
      ier = nc_get_var1_double(cdfid,timeObs_id,var_i,&timeObs);
      obs_time = (time_t) timeObs;
      gmt_time = gmtime(&obs_time);
      new_time = *gmt_time;
      timestr[0] = '\0';
      strftime(timestr,80,"%Y %m %d %H %M",&new_time);
      sscanf(timestr,"%d %d %d %d %d",&year,&month,&day,&hour,&minute);
      udebug("Station %3d %8d %s = %6.2f %7.2f %5.0f %s\0",i,wmoStaNum,
         staName,staLat,staLon,staElev,timestr);

      stadat = (sta_struct *)malloc(sizeof(sta_struct));
      if(stadat == NULL)
         {
         uerror("Could not allocate station data structure\0");
         exit(-2);
         }
      stadat->wmoStaNum = wmoStaNum;
      stadat->staName = (char *)malloc(strlen(staName)+1);
      strcpy(stadat->staName,staName);
      stadat->staLat = staLat;      
      stadat->staLon = staLon;      
      stadat->staElev = staElev;      
      stadat->timeObs = timeObs;      
      stadat->year = year;
      stadat->month = month;
      stadat->day = day;
      stadat->hour = hour;
      stadat->minute = minute;
      stadat->time_interval = time_interval;
      stadat->pdata = NULL;
      stadat->rdata = NULL;
      stadat->sfc_pres = fmiss;
      stadat->sfc_temp = fmiss;
      stadat->sfc_sped = fmiss;
      stadat->sfc_drct = fmiss;
      stadat->sfc_relh = fmiss;
      stadat->sfc_rain_rate = fmiss;
      stadat->sfc_rain_amt = fmiss;
      stadat->sfc_dwpc = fmiss;
      if(sfc_pres != pfill) stadat->sfc_pres = sfc_pres;
      if(sfc_temp != tfill) stadat->sfc_temp = sfc_temp - 273.15;
      if(sfc_sped != sfill) stadat->sfc_sped = sfc_sped;
      if(sfc_drct != dfill) stadat->sfc_drct = sfc_drct;
      if(sfc_relh != rfill) stadat->sfc_relh = sfc_relh;
      if(sfc_rain != rrfill) stadat->sfc_rain_rate = sfc_rain;
      if((stadat->sfc_temp != fmiss)&&(stadat->sfc_relh != fmiss))
         {
         VAPOR_PRES(stadat->sfc_temp+273.15,&e);
         e = e * (stadat->sfc_relh / 100.);
         t_from_e(e,&stadat->sfc_dwpc);
         stadat->sfc_dwpc = stadat->sfc_dwpc - 273.15;
         }

      ier = nc_inq_var(cdfid,levels_id,NULL, &xtype, &nvdims, tmpint, &nvatts);
      if(ier == 0)
         {
         ier = nc_inq_dimlen(cdfid,tmpint[0],&dimsiz);
         stadat->numlevs = dimsiz;
         plast = stadat->pdata;
         for(j=0;j<stadat->numlevs;j++)
            {
            var_i[0] = j;
            ier = nc_get_var1_float(cdfid,levels_id,var_i,&level);
            ier = nc_get_var1_int(cdfid,levelMode_id,var_i,&levelMode);
            var_i[0] = i;
            var_i[1] = j;
            ier = nc_get_var1_float(cdfid,uwnd_id,var_i,&uwnd);
            ier = nc_get_var1_float(cdfid,vwnd_id,var_i,&vwnd);
            ier = nc_get_var1_float(cdfid,wwnd_id,var_i,&wwnd);
            ier = nc_get_var1_int(cdfid,uv_qual_id,var_i,&uv_qual);
            ier = nc_get_var1_int(cdfid,w_qual_id,var_i,&w_qual);
            ier = nc_get_var1_float(cdfid,sigma_uv_id,var_i,&sigma_uv);
            ier = nc_get_var1_float(cdfid,sigma_w_id,var_i,&sigma_w);
            plev = (prof_data *)malloc(sizeof(prof_data));
            if(plev != NULL)
               {
               plev->level = level;
               if(uwnd == ufill) uwnd = fmiss;
               if(vwnd == vfill) vwnd = fmiss;
               if(wwnd == wfill) wwnd = fmiss;
               if(uv_qual != 0) 
                  {
                  uwnd = fmiss;
                  vwnd = fmiss;
                  }
               if(w_qual != 0) wwnd = fmiss;
               if((uwnd == fmiss)||(vwnd == fmiss))
                  sigma_uv = fmiss;
               if(wwnd == fmiss) sigma_w = fmiss;
               plev->u = uwnd; plev->v = vwnd; plev->w = wwnd;
               plev->sigma_uv = sigma_uv;
               plev->sigma_w = sigma_w;
               plev->levmode = levelMode;
               plev->nextlev = NULL;
               if(plast == NULL)
                  stadat->pdata = plev;
               else
                  plast->nextlev = plev;
               plast = plev;
               }
            }
         }
      else
         stadat->numlevs = 0;

      stadat->next = head;
      head = stadat;
      }

return(head);

} 
Ejemplo n.º 8
0
/*
 * Get a single numeric value from a variable of an open netCDF file.
 */
static void
c_ncvgt1 (
    int			ncid,	/* netCDF ID */
    int	 		varid,	/* variable ID */
    const size_t*	indices,/* multidim index of data to be read */
    void*		value,	/* pointer to data value to be read */
    int*		rcode	/* returned error code */
)
{
    int		status;
    nc_type	datatype;

    if ((status = nc_inq_vartype(ncid, varid, &datatype)) == 0)
    {
	switch (datatype)
	{
	case NC_CHAR:
	    status = NC_ECHAR;
	    break;
	case NC_BYTE:
#	    if NF_INT1_IS_C_SIGNED_CHAR
		status = nc_get_var1_schar(ncid, varid, indices,
					   (signed char*)value);
#	    elif NF_INT1_IS_C_SHORT
		status = nc_get_var1_short(ncid, varid, indices,
					   (short*)value);
#	    elif NF_INT1_IS_C_INT
		status = nc_get_var1_int(ncid, varid, indices,
					   (int*)value);
#	    elif NF_INT1_IS_C_LONG
		status = nc_get_var1_long(ncid, varid, indices,
					   (long*)value);
#	    endif
	    break;
	case NC_SHORT:
#	    if NF_INT2_IS_C_SHORT
		status = nc_get_var1_short(ncid, varid, indices,
					   (short*)value);
#	    elif NF_INT2_IS_C_INT
		status = nc_get_var1_int(ncid, varid, indices,
					   (int*)value);
#	    elif NF_INT2_IS_C_LONG
		status = nc_get_var1_long(ncid, varid, indices,
					   (long*)value);
#	    endif
	    break;
	case NC_INT:
#	    if NF_INT_IS_C_INT
		status = nc_get_var1_int(ncid, varid, indices,
					   (int*)value);
#	    elif NF_INT_IS_C_LONG
		status = nc_get_var1_long(ncid, varid, indices,
					   (long*)value);
#	    endif
	    break;
	case NC_FLOAT:
#	    if NF_REAL_IS_C_FLOAT
		status = nc_get_var1_float(ncid, varid, indices,
					   (float*)value);
#	    elif NF_REAL_IS_C_DOUBLE
		status = nc_get_var1_double(ncid, varid, indices,
					   (double*)value);
#	    endif
	    break;
	case NC_DOUBLE:
#	    if NF_DOUBLEPRECISION_IS_C_FLOAT
		status = nc_get_var1_float(ncid, varid, indices,
					   (float*)value);
#	    elif NF_DOUBLEPRECISION_IS_C_DOUBLE
		status = nc_get_var1_double(ncid, varid, indices,
					   (double*)value);
#	    endif
	    break;
	}
    }

    if (status == 0)
	*rcode = 0;
    else
    {
	nc_advise("NCVGT1", status, "");
	*rcode = ncerr;
    }
}
Ejemplo n.º 9
0
/*! \internal */
int
cpy_var_val(int in_id,int out_id,char *var_nm)
/*
   int in_id: input netCDF input-file ID
   int out_id: input netCDF output-file ID
   char *var_nm: input variable name
 */
{
  /* Routine to copy the variable data from an input netCDF file
   * to an output netCDF file. 
   */

  int *dim_id;
  int idx;
  int nbr_dim;
  int var_in_id;
  int var_out_id;
  size_t *dim_cnt;
  size_t *dim_sz;
  size_t *dim_srt;
  size_t var_sz=1L;
  nc_type var_type_in, var_type_out;

  void *void_ptr = NULL;

  /* Get the var_id for the requested variable from both files. */
  (void)nc_inq_varid(in_id, var_nm, &var_in_id);
  (void)nc_inq_varid(out_id,var_nm, &var_out_id);
 
  /* Get the number of dimensions for the variable. */
  (void)nc_inq_vartype( out_id, var_out_id, &var_type_out);
  (void)nc_inq_varndims(out_id, var_out_id, &nbr_dim);

  (void)nc_inq_vartype( in_id,   var_in_id, &var_type_in);
  (void)nc_inq_varndims(in_id,   var_in_id, &nbr_dim);
 
  /* Allocate space to hold the dimension IDs */
  dim_cnt = malloc(nbr_dim*sizeof(size_t));

  dim_id=malloc(nbr_dim*sizeof(int));

  dim_sz=malloc(nbr_dim*sizeof(size_t));

  dim_srt=malloc(nbr_dim*sizeof(size_t));
 
  /* Get the dimension IDs from the input file */
  (void)nc_inq_vardimid(in_id, var_in_id, dim_id);
 
  /* Get the dimension sizes and names from the input file */
  for(idx=0;idx<nbr_dim;idx++){
  /* NB: For the unlimited dimension, ncdiminq() returns the maximum
     value used so far in writing data for that dimension.
     Thus if you read the dimension sizes from the output file, then
     the ncdiminq() returns dim_sz=0 for the unlimited dimension
     until a variable has been written with that dimension. This is
     the reason for always reading the input file for the dimension
     sizes. */

    (void)nc_inq_dimlen(in_id,dim_id[idx],dim_cnt+idx);

    /* Initialize the indicial offset and stride arrays */
    dim_srt[idx]=0L;
    var_sz*=dim_cnt[idx];
  } /* end loop over dim */

  /* Allocate enough space to hold the variable */
  if (var_sz > 0)
      void_ptr=malloc(var_sz * type_size(var_type_in));

  /* Get the variable */

  /* if variable is float or double, convert if necessary */

  if(nbr_dim==0){  /* variable is a scalar */

    if (var_type_in == NC_INT && var_type_out == NC_INT) {
      nc_get_var1_int(in_id,  var_in_id,  0L, void_ptr);
      nc_put_var1_int(out_id, var_out_id, 0L, void_ptr);
    }

    else if (var_type_in == NC_INT64 && var_type_out == NC_INT64) {
      nc_get_var1_longlong(in_id,  var_in_id,  0L, void_ptr);
      nc_put_var1_longlong(out_id, var_out_id, 0L, void_ptr);
    }

    else if (var_type_in == NC_FLOAT) {
      nc_get_var1_float(in_id,  var_in_id,  0L, void_ptr);
      nc_put_var1_float(out_id, var_out_id, 0L, void_ptr);
    }

    else if (var_type_in == NC_DOUBLE) {
      nc_get_var1_double(in_id,  var_in_id,  0L, void_ptr);
      nc_put_var1_double(out_id, var_out_id, 0L, void_ptr);
    }

    else if (var_type_in == NC_CHAR) {
      nc_get_var1_text(in_id,  var_in_id,  0L, void_ptr);
      nc_put_var1_text(out_id, var_out_id, 0L, void_ptr);
    }

    else {
      assert(1==0);
    }
  } else { /* variable is a vector */

    if (var_type_in == NC_INT && var_type_out == NC_INT) {
      (void)nc_get_var_int(in_id,  var_in_id,  void_ptr);
      (void)nc_put_var_int(out_id, var_out_id, void_ptr);
    }

    else if (var_type_in == NC_INT64 && var_type_out == NC_INT64) {
      (void)nc_get_var_longlong(in_id,  var_in_id,  void_ptr);
      (void)nc_put_var_longlong(out_id, var_out_id, void_ptr);
    }

    else if (var_type_in == NC_FLOAT) {
      (void)nc_get_var_float(in_id,  var_in_id,  void_ptr);
      (void)nc_put_var_float(out_id, var_out_id, void_ptr);
    }

    else if (var_type_in == NC_DOUBLE) {
      (void)nc_get_var_double(in_id,  var_in_id,  void_ptr);
      (void)nc_put_var_double(out_id, var_out_id, void_ptr);
    }

    else if (var_type_in == NC_CHAR) {
      (void)nc_get_var_text(in_id,  var_in_id,  void_ptr);
      (void)nc_put_var_text(out_id, var_out_id, void_ptr);
    }

    else {
      assert(1==0);
    }
  } /* end if variable is an array */

  /* Free the space that held the dimension IDs */
  (void)free(dim_cnt);
  (void)free(dim_id);
  (void)free(dim_sz);
  (void)free(dim_srt);

  /* Free the space that held the variable */
  (void)free(void_ptr);

  return(EX_NOERR);

} /* end cpy_var_val() */
Ejemplo n.º 10
0
void init_ncdf_atmos(Atmosphere *atmos, Geometry *geometry, NCDF_Atmos_file *infile)
/* Initialises the input atmosphere file, gets dimensions and variable ids. 
   Also performs other basic RH initialisations like readAbundance       */
{ 
  const char routineName[] = "init_ncdf";
  struct  stat statBuffer;
  int ierror, ncid, x_varid, y_varid, z_varid, has_B, sn_varid;
  size_t nn;
  size_t start[] = {0, 0};
  size_t count[] = {1, 1};
  char *filename;


  /* --- Get abundances of background elements --      -------------- */

  readAbundance(atmos);

  /* --- Open input file for model atmosphere --       -------------- */
  if ((ierror = nc_open_par(input.atmos_input ,NC_NOWRITE | NC_MPIIO, mpi.comm, 
			    mpi.info, &infile->ncid))) ERR(ierror,routineName);

  ncid = infile->ncid;

  /* Is magnetic field included? */
  if ((ierror = nc_get_att_int( ncid, NC_GLOBAL, "has_B", &has_B))) 
    ERR(ierror,routineName);

  atmos->Stokes = FALSE;
  if ((has_B) && (strcmp(input.Stokes_input, "none"))) atmos->Stokes = TRUE;


  /* Get the dimids and values */
  if ((ierror = nc_inq_dimid( ncid, "nx", &infile->nx_id)))       ERR(ierror,routineName);
  if ((ierror = nc_inq_dimlen(ncid, infile->nx_id, &infile->nx))) ERR(ierror,routineName);

  if ((ierror = nc_inq_dimid( ncid, "ny", &infile->ny_id)))       ERR(ierror,routineName);
  if ((ierror = nc_inq_dimlen(ncid, infile->ny_id, &infile->ny))) ERR(ierror,routineName);

  if ((ierror = nc_inq_dimid( ncid, "nz", &infile->nz_id)))       ERR(ierror,routineName);
  if ((ierror = nc_inq_dimlen(ncid, infile->nz_id, &infile->nz))) ERR(ierror,routineName);

  if ((ierror = nc_inq_dimid( ncid, "nhydr", &infile->nhyd_id)))  ERR(ierror,routineName);
  if ((ierror = nc_inq_dimlen(ncid, infile->nhyd_id, &nn)))       ERR(ierror,routineName);

  /* get some values in atmos/geometry structures */
  geometry->Ndep = (int)  infile->nz;
  atmos->Nspace  = (long) infile->nz;
  atmos->NHydr   = (int)  nn;


  if (atmos->NHydr < 2  &&  !atmos->H_LTE) {
    sprintf(messageStr, "NHydr has to be at least 2, not %d to run with"
	    " NLTE hydrogen populations in background\n", atmos->NHydr);
    Error(ERROR_LEVEL_2, routineName, messageStr);
  }

  /* Get the varids */
  if ((ierror=nc_inq_varid(ncid, TEMP_NAME, &infile->T_varid)))  ERR(ierror,routineName);
  if ((ierror=nc_inq_varid(ncid, NE_NAME,   &infile->ne_varid))) ERR(ierror,routineName);
  if ((ierror=nc_inq_varid(ncid, VZ_NAME,   &infile->vz_varid))) ERR(ierror,routineName);
  if ((ierror=nc_inq_varid(ncid, NH_NAME,   &infile->nh_varid))) ERR(ierror,routineName);
  if ((ierror=nc_inq_varid(ncid, "z",       &z_varid)))          ERR(ierror,routineName);
  if ((ierror=nc_inq_varid(ncid, "y",       &y_varid)))          ERR(ierror,routineName);
  if ((ierror=nc_inq_varid(ncid, "x",       &x_varid)))          ERR(ierror,routineName);
  if ((ierror=nc_inq_varid(ncid, SNAPNAME,  &sn_varid)))         ERR(ierror,routineName);
  
  /* Microturbulence, get ID if variable found */
  if ((ierror=nc_inq_varid(ncid, VTURB_NAME, &infile->vturb_varid))) {
    /* exception for variable not found (errcode -49)*/
    if (ierror == -49) infile->vturb_varid = -1; else ERR(ierror,routineName);
  }

  if (atmos->Stokes) {
      if ((ierror = nc_inq_varid(ncid, BX_NAME, &infile->Bx_varid)))
	ERR(ierror,routineName);
      if ((ierror = nc_inq_varid(ncid, BY_NAME, &infile->By_varid)))
	ERR(ierror,routineName);
      if ((ierror = nc_inq_varid(ncid, BZ_NAME, &infile->Bz_varid)))
	ERR(ierror,routineName);
  }

  /* read things that don't depend on x, y */
  start[0] = input.p15d_nt; count[0] = 1;
  start[1] = 0;             count[1] = infile->nz;

  geometry->height = (double *) malloc(infile->nz * sizeof(double));
  if ((ierror = nc_get_vara_double(ncid, z_varid, start, count, geometry->height))) 
    ERR(ierror,routineName);

  infile->y   = (double *) malloc(infile->ny * sizeof(double));
  if ((ierror = nc_get_var_double(ncid, y_varid, infile->y))) ERR(ierror,routineName);
  infile->x   = (double *) malloc(infile->nx * sizeof(double));
  if ((ierror = nc_get_var_double(ncid, x_varid, infile->x))) ERR(ierror,routineName);

  if ((ierror = nc_get_var1_int(ncid, sn_varid, start, &mpi.snap_number)))
    ERR(ierror,routineName);

  /* allocate arrays */
  geometry->vel = (double *) malloc(atmos->Nspace * sizeof(double));
  atmos->T      = (double *) malloc(atmos->Nspace * sizeof(double));
  atmos->ne     = (double *) malloc(atmos->Nspace * sizeof(double));
  atmos->vturb  = (double *) calloc(atmos->Nspace , sizeof(double)); /* default zero */
  atmos->nHtot  = (double *) malloc(atmos->Nspace * sizeof(double));

  if (atmos->Stokes) {
    atmos->B       = (double *) malloc(atmos->Nspace * sizeof(double));
    atmos->gamma_B = (double *) malloc(atmos->Nspace * sizeof(double));
    atmos->chi_B   = (double *) malloc(atmos->Nspace * sizeof(double));
  }

  /* some other housekeeping */ 
  geometry->vboundary[TOP]    = ZERO;
  geometry->vboundary[BOTTOM] = THERMALIZED;
  geometry->scale             = GEOMETRIC;

  /* --- Construct atmosID from filename and last modification date - */
  // NOTE: perhaps later this should be built into the NetCDF file (description attr?)
  stat(input.atmos_input, &statBuffer);
  if ((filename = strrchr(input.atmos_input, '/')) != NULL)
    filename++;
  else
    filename = input.atmos_input;
  sprintf(atmos->ID, "%s (%.24s)", filename,
	  asctime(localtime(&statBuffer.st_mtime)));


  /* --- Get angle-quadrature and copy geometry independent quantity
         wmu to atmos structure. --                    -------------- */

  getAngleQuad(geometry);
  atmos->wmu = geometry->wmu;


  /* --- set up pointers for background opacities --- */

  atmos->chi_b = NULL;
  atmos->eta_b = NULL;
  atmos->sca_b = NULL;

  return;

}
int ex_get_processor_elem_maps(int  exoid,
			       void_int *elem_mapi,
			       void_int *elem_mapb,
			       int  processor
			       )
{
  const char  *func_name="ex_get_processor_elem_maps";

  char    ftype[2];
  int     dimid, varid, status;
  size_t  start[1], count[1];
  int64_t varidx[2];
  int  emstat;

  char   errmsg[MAX_ERR_LENGTH];

  /* Get the file type */
  if (ex_get_file_type(exoid, ftype) != EX_NOERR) {
    exerrval = EX_MSG;
    sprintf(errmsg,
            "Error: unable to find file type for file ID %d",
            exoid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }

  /* Check the status of the internal element map */
  if ((status = nc_inq_varid(exoid, VAR_INT_E_STAT, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to find variable ID for \"%s\" in file ID %d",
            VAR_INT_E_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (ftype[0] == 'p')
    start[0] = 0;
  else
    start[0] = processor;

  if ((status = nc_get_var1_int(exoid, varid, start, &emstat)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get status for \"%s\" from file ID %d",
            VAR_INT_E_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (emstat == 1) {
    /* get the index */
    if (ex_get_idx(exoid, VAR_ELEM_MAP_INT_IDX, varidx, processor) == -1) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to find index variable, \"%s\", in file ID %d",
              VAR_ELEM_MAP_INT_IDX, exoid);
      ex_err(func_name, errmsg, exerrval);

      return (EX_FATAL);
    }

    if (varidx[1] == -1) {
      /* Get the size of the internal element map */
      if ((status = nc_inq_dimid(exoid, DIM_NUM_INT_ELEMS, &dimid)) != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to find dimension ID for \"%s\" in file ID %d",
                DIM_NUM_INT_ELEMS, exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }

      if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
		"Error: failed to find length of dimension \"%s\" in file ID %d",
                DIM_NUM_INT_ELEMS, exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }

      varidx[1] = count[0];
    }

    /* Get the map */
    if ((status = nc_inq_varid(exoid, VAR_ELEM_MAP_INT, &varid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to find variable ID for \"%s\" in file ID %d",
              VAR_ELEM_MAP_INT, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    start[0] = varidx[0];
    count[0] = varidx[1] - varidx[0];
    if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
      status = nc_get_vara_longlong(exoid, varid, start, count, elem_mapi);
    } else {
      status = nc_get_vara_int(exoid, varid, start, count, elem_mapi);
    }

    if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to get variable \"%s\" from file ID %d",
              VAR_ELEM_MAP_INT, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

  } /* End "if (emstat == 1)" */

  /* Check the status of the internal element map */
  if ((status = nc_inq_varid(exoid, VAR_BOR_E_STAT, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to find variable ID for \"%s\" in file ID %d",
            VAR_BOR_E_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (ftype[0] == 'p')
    start[0] = 0;
  else
    start[0] = processor;

  if ((status = nc_get_var1_int(exoid, varid, start, &emstat)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to get status for \"%s\" from file ID %d",
	    VAR_INT_E_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (emstat == 1) {
    /* get the index */
    if (ex_get_idx(exoid, VAR_ELEM_MAP_BOR_IDX, varidx, processor) == -1) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to find index variable, \"%s\", in file ID %d",
	      VAR_ELEM_MAP_BOR_IDX, exoid);
      ex_err(func_name, errmsg, exerrval);

      return (EX_FATAL);
    }

    if (varidx[1] == -1) {
      /* Get the size of the border element map */
      if ((status = nc_inq_dimid(exoid, DIM_NUM_BOR_ELEMS, &dimid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to find dimension ID for \"%s\" in file ID %d",
		DIM_NUM_BOR_ELEMS, exoid);
	ex_err(func_name, errmsg, exerrval);
	return (EX_FATAL);
      }

      if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to find length of dimension \"%s\" in file ID %d",
		DIM_NUM_BOR_ELEMS, exoid);
	ex_err(func_name, errmsg, exerrval);
	return (EX_FATAL);
      }

      varidx[1] = count[0];
    }

    /* Get the map */
    if ((status = nc_inq_varid(exoid, VAR_ELEM_MAP_BOR, &varid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to find variable ID for \"%s\" in file ID %d",
	      VAR_ELEM_MAP_BOR, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    start[0] = varidx[0];
    count[0] = varidx[1] - varidx[0];
    if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
      status = nc_get_vara_longlong(exoid, varid, start, count, elem_mapb);
    } else {
      status = nc_get_vara_int(exoid, varid, start, count, elem_mapb);
    }

    if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to get variable \"%s\" from file ID %d",
	      VAR_ELEM_MAP_BOR, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }
  } /* End "if (emstat == 1)" */

  return (EX_NOERR);
}
Ejemplo n.º 12
0
int ex_put_node_cmap(int  exoid,
                     ex_entity_id  map_id,
                     void_int *node_ids,
                     void_int *proc_ids,
                     int  processor
                     )
{
  const char   *func_name="ex_put_node_cmap";

  int     map_idx, varid, dimid, status;
  size_t  start[1], count[1], ret_val;
  int64_t varidx[2];
  int     value;

  char    errmsg[MAX_ERR_LENGTH];
/*-----------------------------Execution begins-----------------------------*/

  exerrval = 0; /* clear error code */

  /* get the index for the comm map information variables */
  if (ex_get_idx(exoid, VAR_N_COMM_INFO_IDX, varidx, processor) == -1) {
    sprintf(errmsg,
            "Error: failed to find index variable, \"%s\", in file ID %d",
            VAR_N_COMM_INFO_IDX, exoid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }

  /* Get the index for this map_id */
  if ((map_idx=ne_id_lkup(exoid, VAR_N_COMM_IDS, varidx, map_id)) == -1) {
    sprintf(errmsg,
            "Error: failed to find index for variable \"%s\" in file ID %d",
            VAR_N_COMM_IDS, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  /*
   * Find out if this is a NULL comm map by checking it's entry in
   * the status vector.
   */
  if ((status = nc_inq_varid(exoid, VAR_N_COMM_STAT, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to find variable ID for \"%s\" in file ID %d",
            VAR_N_COMM_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  start[0] = map_idx;
  if ((status = nc_get_var1_int(exoid, varid, start, &value)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: unable to get variable \"%s\" from file ID %d",
            VAR_N_COMM_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (value == 0) return(EX_NOERR);   /* NULL set */

  /* now I need to get the comm map data index */
  if (ex_get_idx(exoid, VAR_N_COMM_DATA_IDX, varidx, map_idx) == -1) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to find index variable, \"%s\", in file ID %d",
            VAR_N_COMM_DATA_IDX, exoid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }

  /* check if I need to get the dimension of the cmap data */
  if (varidx[1] == -1) {
    /* Get the size of the comm maps */
    if ((status = nc_inq_dimid(exoid, DIM_NCNT_CMAP, &dimid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to get dimension ID for \"%s\" in file ID %d",
              DIM_NCNT_CMAP, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    if ((status = nc_inq_dimlen(exoid, dimid, &ret_val)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to find length of dimension \"%s\" in file ID %d",
              DIM_NCNT_CMAP, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    varidx[1] = ret_val;
  } /* "if (varidx[1]==-1)" */

  start[0] = varidx[0];
  count[0] = varidx[1] - varidx[0];
  
  /* Output the node IDs for this comm map */
  if ((status = nc_inq_varid(exoid, VAR_N_COMM_NIDS, &varid )) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to find variable ID for \"%s\" in file ID %d",
            VAR_N_COMM_NIDS, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
    status = nc_put_vara_longlong(exoid, varid, start, count, node_ids);
  } else {
    status = nc_put_vara_int(exoid, varid, start, count, node_ids);
  }
  if (status != NC_NOERR) {
    fprintf(stderr, "Start, Count = %lu\t%lu\n", (unsigned long)start[0], (unsigned long)count[0]);
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to output vector \"%s\" in file ID %d",
            VAR_N_COMM_NIDS, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  /* Output the processor IDs for this map */
  if ((status = nc_inq_varid(exoid, VAR_N_COMM_PROC, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to find variable ID for \"%s\" in file ID %d",
            VAR_N_COMM_PROC, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
    status = nc_put_vara_longlong(exoid, varid, start, count, proc_ids);
  } else {
    status = nc_put_vara_int(exoid, varid, start, count, proc_ids);
  }
  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to output variable \"%s\" in file ID %d",
            VAR_N_COMM_PROC, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  return (EX_NOERR);
}
Ejemplo n.º 13
0
int ex_get_cmap_params(int  exoid,
                       void_int *node_cmap_ids,
                       void_int *node_cmap_node_cnts,
                       void_int *elem_cmap_ids,
                       void_int *elem_cmap_elem_cnts,
                       int  processor
		       )
{
  const char   *func_name="ex_get_cmap_params";

  size_t  cnt, num_n_comm_maps, num_e_comm_maps, start[1], count[1];
  int64_t cmap_info_idx[2], cmap_data_idx[2];
  int     nmstat;
  int     status, map_idx, varid, dimid;

  char    errmsg[MAX_ERR_LENGTH];
  /*-----------------------------Execution begins-----------------------------*/

  exerrval = 0;	/* clear error code */

  /*****************************************************************************/
  /*****************************************************************************/
  /*                    Nodal communication map(s)                             */
  /*****************************************************************************/
  /*****************************************************************************/

  /* get the cmap information variables index */
  if (ex_get_idx(exoid, VAR_N_COMM_INFO_IDX, cmap_info_idx, processor) == -1) {
    sprintf(errmsg,
            "Error: failed to find index variable, \"%s\", in file ID %d",
            VAR_N_COMM_INFO_IDX, exoid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }

  /* Get the number of nodal communications maps in the file */
  if ((status = nc_inq_dimid(exoid, DIM_NUM_N_CMAPS, &dimid)) == NC_NOERR) {
    /* check if I need to get the dimension of the nodal comm map */
    if (cmap_info_idx[1] == -1) {
      if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
		"Error: failed to find length of dimension \"%s\" in file ID %d",
                DIM_NUM_N_CMAPS, exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }

      /* set the end value for the node map */
      cmap_info_idx[1] = count[0];
    }  /* End "if (cmap_info_idx[1] == -1) */

    num_n_comm_maps = cmap_info_idx[1] - cmap_info_idx[0];

    if (num_n_comm_maps > 0) {
      count[0] = num_n_comm_maps;

      /* Get the variable ID for the vector of nodal comm map IDs */
      if ((status = nc_inq_varid(exoid, VAR_N_COMM_IDS, &varid)) != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to get variable ID for \"%s\" in file ID %d",
                VAR_N_COMM_IDS, exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }

      /* Get the vector of nodal communication map IDs */
      if (node_cmap_ids != NULL) {
        start[0] = cmap_info_idx[0];
	if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
	  status = nc_get_vara_longlong(exoid, varid, start, count, node_cmap_ids);
	} else {
	  status = nc_get_vara_int(exoid, varid, start, count, node_cmap_ids);
	}

        if (status != NC_NOERR) {
          exerrval = status;
          sprintf(errmsg,
                  "Error: failed to get variable \"%s\" from file ID %d",
                  VAR_N_COMM_IDS, exoid);
          ex_err(func_name, errmsg, exerrval);
          return (EX_FATAL);
        }

        if ((status = nc_inq_varid(exoid, VAR_N_COMM_STAT, &varid)) != NC_NOERR) {
          exerrval = status;
          sprintf(errmsg,
		  "Error: failed to find variable ID for \"%s\" from file ID %d",
                  VAR_N_COMM_STAT, exoid);
          ex_err(func_name, errmsg, exerrval);
          return (EX_FATAL);
        }

        if (node_cmap_node_cnts != NULL) {

          /* Get the node counts in each of the nodal communication maps */
          for(cnt=0; cnt < num_n_comm_maps; cnt++) {
	    int64_t cmap_id;
	    if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
	      cmap_id = ((int64_t*)node_cmap_ids)[cnt];
	    } else {
	      cmap_id = ((int*)node_cmap_ids)[cnt];
	    }

            if ((map_idx=ne_id_lkup(exoid, VAR_N_COMM_IDS, cmap_info_idx, cmap_id)) < 0) {
              exerrval = EX_MSG;
              sprintf(errmsg,
		      "Error: failed to find nodal comm map with ID %"PRId64" in file ID %d",
                      cmap_id, exoid);
              ex_err(func_name, errmsg, exerrval);
              return (EX_FATAL);
            }

            /* Check the status of the node map */
            start[0] = map_idx;
            if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) {
              exerrval = status;
              sprintf(errmsg,
		      "Error: failed to get status for \"%s\" from file ID %d",
                      VAR_N_COMM_STAT, exoid);
              ex_err(func_name, errmsg, exerrval);
              return (EX_FATAL);
            }

            if (nmstat == 1) {

              /* get the cmap information variables index */
              if (ex_get_idx(exoid, VAR_N_COMM_DATA_IDX, cmap_data_idx,
                             map_idx) == -1) {
                exerrval = status;
                sprintf(errmsg,
			"Error: failed to find index variable, \"%s\", in file ID %d",
                        VAR_N_COMM_DATA_IDX, exoid);
                ex_err(func_name, errmsg, exerrval);

                return (EX_FATAL);
              }

              if (cmap_data_idx[1] == -1) {
                /*
                 * Find the dimension ID of the variable containing the
                 * node count
                 */
                if ((status = nc_inq_dimid(exoid, DIM_NCNT_CMAP, &dimid)) != NC_NOERR) {
                  exerrval = status;
                  sprintf(errmsg,
			  "Error: failed to find dimension ID for \"%s\" in file ID %d",
                          DIM_NCNT_CMAP, exoid);
                  ex_err(func_name, errmsg, exerrval);
                  return (EX_FATAL);
                }

		/* Find the value of the number of nodes in this nodal comm map */
                if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
                  exerrval = status;
                  sprintf(errmsg,
			  "Error: failed to find length of dimension \"%s\" in file ID %d",
                          DIM_NCNT_CMAP, exoid);
                  ex_err(func_name, errmsg, exerrval);
                  return (EX_FATAL);
                }

                cmap_data_idx[1] = count[0];
              }

	      if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
		((int64_t*)node_cmap_node_cnts)[cnt] = cmap_data_idx[1] - cmap_data_idx[0];
	      } else {
		((int*)node_cmap_node_cnts)[cnt] = cmap_data_idx[1] - cmap_data_idx[0];
	      }
            }
            else
	      if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
		((int64_t*)node_cmap_node_cnts)[cnt] = 0;
	      } else {
		((int*)node_cmap_node_cnts)[cnt] = 0;
	      }
          }  /* "for(cnt=0; cnt < num_n_comm_maps; cnt++)" */
        }  /* "if (node_cmap_node_cnts != NULL)" */
      }  /* "if (node_cmap_ids != NULL)" */
    }  /* "if (num_n_comm_maps > 0)" */
  } /* End "if ((dimid = nc_inq_dimid(exoid, DIM_NUM_N_CMAPS)) != -1)" */

  /*****************************************************************************/
  /*****************************************************************************/
  /*                Elemental communication map(s)                             */
  /*****************************************************************************/
  /*****************************************************************************/

  /* get the cmap information variables index */
  if (ex_get_idx(exoid, VAR_E_COMM_INFO_IDX, cmap_info_idx, processor) == -1) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to find index variable, \"%s\", in file ID %d",
            VAR_E_COMM_INFO_IDX, exoid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }

  /* Get the number of elemental communications maps in the file */
  if ((status = nc_inq_dimid(exoid, DIM_NUM_E_CMAPS, &dimid)) == NC_NOERR) {
    /* check if I need to get the dimension of the nodal comm map */
    if (cmap_info_idx[1] == -1) {
      if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
		"Error: failed to find length of dimension \"%s\" in file ID %d",
                DIM_NUM_E_CMAPS, exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }

      /* set the end value for the node map */
      cmap_info_idx[1] = count[0];
    }  /* End "if (cmap_info_idx[1] == -1) */

    num_e_comm_maps = cmap_info_idx[1] - cmap_info_idx[0];

    if (num_e_comm_maps > 0) {
      count[0] = num_e_comm_maps;

      /* Get the variable ID for the vector of nodal comm map IDs */
      if ((status = nc_inq_varid(exoid, VAR_E_COMM_IDS, &varid)) != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to get variable ID for \"%s\" in file ID %d",
                VAR_E_COMM_IDS, exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }

      /* Get the vector of elemental communication map IDs */
      if (elem_cmap_ids != NULL) {
        start[0] = cmap_info_idx[0];
	if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
	  status = nc_get_vara_longlong(exoid, varid, start, count, elem_cmap_ids);
	} else {
	  status = nc_get_vara_int(exoid, varid, start, count, elem_cmap_ids);
	}
        if (status != NC_NOERR) {
          exerrval = status;
          sprintf(errmsg,
                  "Error: failed to get variable \"%s\" from file ID %d",
                  VAR_E_COMM_IDS, exoid);
          ex_err(func_name, errmsg, exerrval);
          return (EX_FATAL);
        }

        if ((status = nc_inq_varid(exoid, VAR_E_COMM_STAT, &varid)) != NC_NOERR) {
          exerrval = status;
          sprintf(errmsg,
		  "Error: failed to find variable ID for \"%s\" from file ID %d",
                  VAR_E_COMM_STAT, exoid);
          ex_err(func_name, errmsg, exerrval);
          return (EX_FATAL);
        }

        if (elem_cmap_elem_cnts != NULL) {
          /*
           * Get the element counts in each of the elemental
           * communication maps
           */
          for(cnt=0; cnt < num_e_comm_maps; cnt++) {
	    int64_t cmap_id;
	    if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
	      cmap_id = ((int64_t*)elem_cmap_ids)[cnt];
	    } else {
	      cmap_id = ((int*)elem_cmap_ids)[cnt];
	    }

            if ((map_idx=ne_id_lkup(exoid, VAR_E_COMM_IDS, cmap_info_idx,
				    cmap_id)) < 0) {
              exerrval = EX_MSG;
              sprintf(errmsg,
		      "Error: failed to find elemental comm map with ID %"PRId64" in file ID %d",
                      cmap_id, exoid);
              ex_err(func_name, errmsg, exerrval);
              return (EX_FATAL);
            }

            /* Check the status of the requested elemental map */
            start[0] = map_idx;
            if ((status = nc_get_var1_int(exoid, varid, start, &nmstat)) != NC_NOERR) {
              exerrval = status;
              sprintf(errmsg,
                      "Error: failed to get status for \"%s\" from file ID %d",
                      VAR_E_COMM_STAT, exoid);
              ex_err(func_name, errmsg, exerrval);
              return (EX_FATAL);
            }

            if (nmstat == 1) {

              /* get the cmap information variables index */
              if (ex_get_idx(exoid, VAR_E_COMM_DATA_IDX, cmap_data_idx,
                             map_idx) == -1) {
                exerrval = status;
                sprintf(errmsg,
			"Error: failed to find index variable, \"%s\", in file ID %d",
			VAR_E_COMM_DATA_IDX, exoid);
                ex_err(func_name, errmsg, exerrval);

                return (EX_FATAL);
              }

              if (cmap_data_idx[1] == -1) {
                /*
                 * Find the dimension ID of the variable containing the
                 * element count
                 */
                if ((status = nc_inq_dimid(exoid, DIM_ECNT_CMAP, &dimid)) != NC_NOERR) {
                  exerrval = status;
                  sprintf(errmsg,
			  "Error: failed to find dimension ID for \"%s\" in file ID %d",
                          DIM_ECNT_CMAP, exoid);
                  ex_err(func_name, errmsg, exerrval);
                  return (EX_FATAL);
                }

                /*
                 * Find the value of the number of elements in this elemental
                 * comm map
                 */
                if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
                  exerrval = status;
                  sprintf(errmsg,
			  "Error: failed to find length of dimension \"%s\" in file ID %d",
                          DIM_ECNT_CMAP, exoid);
                  ex_err(func_name, errmsg, exerrval);
                  return (EX_FATAL);
                }
                cmap_data_idx[1] = count[0];
              }
	      if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
		((int64_t*)elem_cmap_elem_cnts)[cnt] = cmap_data_idx[1] - cmap_data_idx[0];
	      } else {
		((int*)elem_cmap_elem_cnts)[cnt] = cmap_data_idx[1] - cmap_data_idx[0];
	      }
            }
            else
	      if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
		((int64_t*)elem_cmap_elem_cnts)[cnt] = 0;
	      } else {
		((int*)elem_cmap_elem_cnts)[cnt] = 0;
	      }
          }  /* "for(cnt=0; cnt < num_e_comm_maps; cnt++)" */
        }  /* "if (elem_cmap_elem_cnts != NULL)" */
      }  /* "if (elem_cmap_ids != NULL)" */
    }  /* "if (num_e_comm_maps > 0)" */
  } /* End "if ((dimid = nc_inq_dimid(exoid, DIM_NUM_E_CMAPS(processor))) != -1)" */
  return (EX_NOERR);
}
Ejemplo n.º 14
0
/*ARGSUSED*/
int
main(int argc, char *argv[])
{
	int cmode=NC_CLOBBER, omode, ret;
	int	 id;
	char buf[256];
#ifdef SYNCDEBUG
	char *str = "one";
#endif
	int ii;
	size_t ui;
	const struct tcdfvar *tvp = testvars;
	union getret got;
	const size_t initialsz = 8192;
	size_t chunksz = 8192;
	size_t align = 8192/32;

	MPI_Init(&argc, &argv);

        /* cmode |= NC_PNETCDF |NC_64BIT_OFFSET; */
        cmode != NC_PNETCDF |NC_64BIT_DATA;
	ret = nc_create_par(fname,cmode, MPI_COMM_WORLD, MPI_INFO_NULL, &id);
	if(ret != NC_NOERR)  {
		fprintf(stderr,"Error %s in file %s at line %d\n",nc_strerror(ret),__FILE__,__LINE__);
		exit(ret);
        }
	
	assert( nc_put_att_text(id, NC_GLOBAL,
		"TITLE", 12, "another name") == NC_NOERR);
	assert( nc_get_att_text(id, NC_GLOBAL,
		"TITLE", buf) == NC_NOERR);
/*	(void) printf("title 1 \"%s\"\n", buf); */
	assert( nc_put_att_text(id, NC_GLOBAL,
		"TITLE", strlen(fname), fname) == NC_NOERR);
	assert( nc_get_att_text(id, NC_GLOBAL,
		"TITLE", buf) == NC_NOERR);
	buf[strlen(fname)] = 0;
/*	(void) printf("title 2 \"%s\"\n", buf); */
	assert( strcmp(fname, buf) == 0);

	createtestdims(id, NUM_DIMS, sizes, dim_names);
	testdims(id, NUM_DIMS, sizes, dim_names);

	createtestvars(id, testvars, NUM_TESTVARS); 

 	{
 	int ifill = -1; double dfill = -9999;
 	assert( nc_put_att_int(id, Long_id,
 		_FillValue, NC_INT, 1, &ifill) == NC_NOERR);
 	assert( nc_put_att_double(id, Double_id,
 		_FillValue, NC_DOUBLE, 1, &dfill) == NC_NOERR);
 	}

#ifdef REDEF
	assert( nc__enddef(id, 0, align, 0, 2*align) == NC_NOERR );
	assert( nc_put_var1_int(id, Long_id, indices[3], &birthday) 
		== NC_NOERR );
	fill_seq(id);
	assert( nc_redef(id) == NC_NOERR );
/*	assert( nc_rename_dim(id,2, "a long dim name") == NC_NOERR); */
#endif

	assert( nc_rename_dim(id,1, "IXX") == NC_NOERR);
	assert( nc_inq_dim(id, 1, buf, &ui) == NC_NOERR);
	/* (void) printf("dimrename: %s\n", buf); */
	assert( nc_rename_dim(id,1, dim_names[1]) == NC_NOERR);

#ifdef ATTRX
	assert( nc_rename_att(id, 1, "UNITS", "units") == NC_NOERR);
	assert( nc_del_att(id, 4, "FIELDNAM")== NC_NOERR);
	assert( nc_del_att(id, 2, "SCALEMIN")== NC_NOERR);
	assert( nc_del_att(id, 2, "SCALEMAX")== NC_NOERR);
#endif /* ATTRX */

	assert( nc__enddef(id, 0, align, 0, 2*align) == NC_NOERR );

#ifndef REDEF
	fill_seq(id);
	assert( nc_put_var1_int(id, Long_id, indices[3], &birthday)== NC_NOERR );
#endif

	assert( nc_put_vara_schar(id, Byte_id, s_start, s_edges,
		(signed char *)sentence)
		== NC_NOERR);
	assert( nc_put_var1_schar(id, Byte_id, indices[6], (signed char *)(chs+1))
		== NC_NOERR);
	assert( nc_put_var1_schar(id, Byte_id, indices[5], (signed char *)chs)
		== NC_NOERR);

	assert( nc_put_vara_text(id, Char_id, s_start, s_edges, sentence)
		== NC_NOERR);
	assert( nc_put_var1_text(id, Char_id, indices[6], (chs+1))
		== NC_NOERR) ;
	assert( nc_put_var1_text(id, Char_id, indices[5], chs)
		== NC_NOERR);

	assert( nc_put_var1_short(id, Short_id, indices[4], shs)
		== NC_NOERR);

	assert( nc_put_var1_float(id, Float_id, indices[2], &e)
		== NC_NOERR);

	assert( nc_put_var1_double(id, Double_id, indices[1], &zed)
		== NC_NOERR);
	assert( nc_put_var1_double(id, Double_id, indices[0], &pinot)
		== NC_NOERR);


#ifdef SYNCDEBUG
	(void) printf("Hit Return to sync\n");
	gets(str);
	nc_sync(id,0);
	(void) printf("Sync done. Hit Return to continue\n");
	gets(str);
#endif /* SYNCDEBUG */

	ret = nc_close(id);
	/* (void) printf("nc_close ret = %d\n\n", ret); */


/*
 *	read it
 */
        omode = NC_NOWRITE;
        omode = NC_NOWRITE | NC_PNETCDF;
	if(ret != NC_NOERR)
	{
   	    (void) printf("Could not open %s: %s\n", fname,
			nc_strerror(ret));
   	    exit(1);
	}
	/* (void) printf("reopen id = %d for filename %s\n", */
	/* 	id, fname); */

	/*	NC	*/ 
	/* (void) printf("NC "); */
	assert( nc_inq(id, &(cdesc->num_dims), &(cdesc->num_vars),
		&(cdesc->num_attrs), &(cdesc->xtendim) ) == NC_NOERR);
	assert((size_t) cdesc->num_dims == num_dims);
	assert(cdesc->num_attrs == 1);
	assert(cdesc->num_vars == NUM_TESTVARS);
	/* (void) printf("done\n"); */
	
	/*	GATTR	*/
	/* (void) printf("GATTR "); */

	assert( nc_inq_attname(id, NC_GLOBAL, 0, adesc->mnem) == 0);
	assert(strcmp("TITLE",adesc->mnem) == 0);
	assert( nc_inq_att(id, NC_GLOBAL, adesc->mnem, &(adesc->type), &(adesc->len))== NC_NOERR);
	assert( adesc->type == NC_CHAR );
	assert( adesc->len == strlen(fname) );
	assert( nc_get_att_text(id, NC_GLOBAL, "TITLE", buf)== NC_NOERR);
	buf[adesc->len] = 0;
	assert( strcmp(fname, buf) == 0);

	/*	VAR	*/
	/* (void) printf("VAR "); */
	assert( cdesc->num_vars == NUM_TESTVARS );

	for(ii = 0; ii < cdesc->num_vars; ii++, tvp++ ) 
	{
		int jj;
		assert( nc_inq_var(id, ii,
			vdesc->mnem,
			&(vdesc->type),
			&(vdesc->ndims),
			vdesc->dims,
			&(vdesc->num_attrs)) == NC_NOERR);
		if(strcmp(tvp->mnem , vdesc->mnem) != 0)
		{
			(void) printf("attr %d mnem mismatch %s, %s\n",
				ii, tvp->mnem, vdesc->mnem);
			continue;
		}
		if(tvp->type != vdesc->type)
		{
			(void) printf("attr %d type mismatch %d, %d\n",
				ii, (int)tvp->type, (int)vdesc->type);
			continue;
		}
		for(jj = 0; jj < vdesc->ndims; jj++ )
		{
			if(tvp->dims[jj] != vdesc->dims[jj] )
			{
		(void) printf(
		"inconsistent dim[%d] for variable %d: %d != %d\n",
		jj, ii, tvp->dims[jj], vdesc->dims[jj] );
			continue;
			}
		}

		/* VATTR */
		/* (void) printf("VATTR\n"); */
		for(jj=0; jj<vdesc->num_attrs; jj++ ) 
		{
			assert( nc_inq_attname(id, ii, jj, adesc->mnem) == NC_NOERR);
			if( strcmp(adesc->mnem, reqattr[jj]) != 0 )
			{
				(void) printf("var %d attr %d mismatch %s != %s\n",
					ii, jj, adesc->mnem, reqattr[jj] );
				break;
			}
		}

		if( nc_inq_att(id, ii, reqattr[0], &(adesc->type), &(adesc->len))
			!= -1) {
		assert( adesc->type == NC_CHAR );
		assert( adesc->len == strlen(tvp->units) );
	 	assert( nc_get_att_text(id,ii,reqattr[0],buf)== NC_NOERR); 
		buf[adesc->len] = 0;
		assert( strcmp(tvp->units, buf) == 0);
		}

		if(
			nc_inq_att(id, ii, reqattr[1], &(adesc->type), &(adesc->len))
			!= -1)
		{
		assert( adesc->type == NC_DOUBLE );
		assert( adesc->len == 1 );
	 	assert( nc_get_att_double(id, ii, reqattr[1], &got.dbl)== NC_NOERR);
		chkgot(adesc->type, got, tvp->validmin);
		}

		if(
			nc_inq_att(id, ii, reqattr[2], &(adesc->type), &(adesc->len))
			!= -1)
		{
		assert( adesc->type == NC_DOUBLE );
		assert( adesc->len == 1 );
	 	assert( nc_get_att_double(id, ii, reqattr[2], &got.dbl)== NC_NOERR);
		chkgot(adesc->type, got, tvp->validmax);
		}

		if(
			nc_inq_att(id, ii, reqattr[3], &(adesc->type), &(adesc->len))
			!= -1)
		{
		assert( adesc->type == NC_DOUBLE );
		assert( adesc->len ==1 );
	 	assert( nc_get_att_double(id, ii, reqattr[3], &got.dbl)== NC_NOERR);
		chkgot(adesc->type, got, tvp->scalemin);
		}

		if(
			nc_inq_att(id, ii, reqattr[4], &(adesc->type), &(adesc->len))
			!= -1)
		{
		assert( adesc->type == NC_DOUBLE );
		assert( adesc->len == 1 );
	 	assert( nc_get_att_double(id, ii, reqattr[4], &got.dbl)== NC_NOERR);
		chkgot(adesc->type, got, tvp->scalemax);
		}

		if( nc_inq_att(id, ii, reqattr[5], &(adesc->type), &(adesc->len))== NC_NOERR)
		{
		assert( adesc->type == NC_CHAR );
		assert( adesc->len == strlen(tvp->fieldnam) );
	 	assert( nc_get_att_text(id,ii,reqattr[5],buf)== NC_NOERR); 
		buf[adesc->len] = 0;
		assert( strcmp(tvp->fieldnam, buf) == 0);
		}
	}

	/* (void) printf("fill_seq "); */
	check_fill_seq(id);
	/* (void) printf("Done\n"); */

	assert( nc_get_var1_double(id, Double_id, indices[0], &got.dbl)== NC_NOERR);
	/* (void) printf("got val = %f\n", got.dbl ); */

	assert( nc_get_var1_double(id, Double_id, indices[1], &got.dbl)== NC_NOERR);
	/* (void) printf("got val = %f\n", got.dbl ); */

	assert( nc_get_var1_float(id, Float_id, indices[2], &got.fl[0])== NC_NOERR);
	/* (void) printf("got val = %f\n", got.fl[0] ); */

	assert( nc_get_var1_int(id, Long_id, indices[3], &got.in[0])== NC_NOERR);
	/* (void) printf("got val = %d\n", got.in[0] ); */

	assert( nc_get_var1_short(id, Short_id, indices[4], &got.sh[0])== NC_NOERR);
	/* (void) printf("got val = %d\n", got.sh[0] ); */

	assert( nc_get_var1_text(id, Char_id, indices[5], &got.by[0]) == NC_NOERR);
	/* (void) printf("got NC_CHAR val = %c (0x%02x) \n", */
		 /* got.by[0] , got.by[0]); */

	assert( nc_get_var1_text(id, Char_id, indices[6], &got.by[0]) == NC_NOERR);
	/* (void) printf("got NC_CHAR val = %c (0x%02x) \n", */
	/* 	 got.by[0], got.by[0] ); */

	(void) memset(buf,0,sizeof(buf));
	assert( nc_get_vara_text(id, Char_id, s_start, s_edges, buf) == NC_NOERR);
	/* (void) printf("got NC_CHAR val = \"%s\"\n", buf); */

	assert( nc_get_var1_schar(id, Byte_id, indices[5],
			(signed char *)&got.by[0])== NC_NOERR);
	/* (void) printf("got val = %c (0x%02x) \n", got.by[0] , got.by[0]); */

	assert( nc_get_var1_schar(id, Byte_id, indices[6],
			(signed char *)&got.by[0])== NC_NOERR);
	/* (void) printf("got val = %c (0x%02x) \n", got.by[0], got.by[0] ); */

	(void) memset(buf,0,sizeof(buf));
	assert( nc_get_vara_schar(id, Byte_id, s_start, s_edges,
			(signed char *)buf)== NC_NOERR );
	/* (void) printf("got val = \"%s\"\n", buf); */

	{
		double dbuf[NUM_RECS * SIZE_1 * SIZE_2];
		assert(nc_get_var_double(id, Float_id, dbuf) == NC_NOERR);
		/* (void) printf("got vals = %f ... %f\n", dbuf[0], */
		/* 	 dbuf[NUM_RECS * SIZE_1 * SIZE_2 -1] ); */
	}

	ret = nc_close(id);
	/* (void) printf("re nc_close ret = %d\n", ret); */

	MPI_Finalize();
	return 0;
}
Ejemplo n.º 15
0
int ex_get_prop (int   exoid,
                 ex_entity_type obj_type,
                 ex_entity_id   obj_id,
                 const char *prop_name,
                 void_int  *value)
{
   int status;
   int num_props, i, propid;
   int found = EX_FALSE;
   size_t start[1]; 
   char name[MAX_VAR_NAME_LENGTH+1];
   char tmpstr[MAX_STR_LENGTH+1];

   char errmsg[MAX_ERR_LENGTH];

   exerrval  = 0; /* clear error code */

   /* open appropriate variable, depending on obj_type and prop_name */
   num_props = ex_get_num_props(exoid,obj_type);

   for (i=1; i<=num_props; i++) {
     switch (obj_type){
       case EX_ELEM_BLOCK:
         strcpy (name, VAR_EB_PROP(i));
         break;
       case EX_EDGE_BLOCK:
         strcpy (name, VAR_ED_PROP(i));
         break;
       case EX_FACE_BLOCK:
         strcpy (name, VAR_FA_PROP(i));
         break;
       case EX_NODE_SET:
         strcpy (name, VAR_NS_PROP(i));
         break;
       case EX_EDGE_SET:
         strcpy (name, VAR_ES_PROP(i));
         break;
       case EX_FACE_SET:
         strcpy (name, VAR_FS_PROP(i));
         break;
       case EX_ELEM_SET:
         strcpy (name, VAR_ELS_PROP(i));
         break;
       case EX_SIDE_SET:
         strcpy (name, VAR_SS_PROP(i));
         break;
       case EX_ELEM_MAP:
         strcpy (name, VAR_EM_PROP(i));
         break;
       case EX_FACE_MAP:
         strcpy (name, VAR_FAM_PROP(i));
         break;
       case EX_EDGE_MAP:
         strcpy (name, VAR_EDM_PROP(i));
         break;
       case EX_NODE_MAP:
         strcpy (name, VAR_NM_PROP(i));
         break;
       default:
         exerrval = EX_BADPARAM;
         sprintf(errmsg, "Error: object type %d not supported; file id %d",
           obj_type, exoid);
         ex_err("ex_get_prop",errmsg,exerrval);
         return(EX_FATAL);
     }

     if ((status = nc_inq_varid(exoid, name, &propid)) != NC_NOERR) {
       exerrval = status;
       sprintf(errmsg,
          "Error: failed to locate property array %s in file id %d",
               name, exoid);
       ex_err("ex_get_prop",errmsg,exerrval);
       return (EX_FATAL);
     }

     /*   compare stored attribute name with passed property name   */
     memset(tmpstr, 0, MAX_STR_LENGTH+1);
     if ((status = nc_get_att_text(exoid, propid, ATT_PROP_NAME, tmpstr)) != NC_NOERR) {
       exerrval = status;
       sprintf(errmsg,
              "Error: failed to get property name in file id %d", exoid);
       ex_err("ex_get_prop",errmsg,exerrval);
       return (EX_FATAL);
     }

     if (strcmp(tmpstr, prop_name) == 0) {
       found = EX_TRUE;
       break;
     }
   }

   /* if property is not found, return warning */
   if (!found) {
     exerrval = EX_BADPARAM;
     sprintf(errmsg,
       "Warning: %s property %s not defined in file id %d",
	     ex_name_of_object(obj_type), prop_name, exoid);
     ex_err("ex_get_prop",errmsg,exerrval);
     return (EX_WARN);
   }

   /* find index into property array using obj_id; read value from property */
   /* array at proper index; ex_id_lkup returns an index that is 1-based,   */
   /* but netcdf expects 0-based arrays so subtract 1                       */
   start[0] = ex_id_lkup (exoid, obj_type, obj_id);
   if (exerrval != 0)  {
     if (exerrval == EX_NULLENTITY) {
       sprintf(errmsg,
              "Warning: %s id %"PRId64" is NULL in file id %d",
               ex_name_of_object(obj_type), obj_id, exoid);
       ex_err("ex_get_prop",errmsg,EX_NULLENTITY);
       return (EX_WARN);
     } else {
       exerrval = status;
       sprintf(errmsg,
             "Error: failed to locate id %"PRId64" in %s property array in file id %d",
               obj_id, ex_name_of_object(obj_type), exoid);
       ex_err("ex_get_prop",errmsg,exerrval);
       return (EX_FATAL);
     }
   }
   start[0] = start[0] - 1;

   if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
     long long l_val;
     status = nc_get_var1_longlong (exoid, propid, start, &l_val);
     if (status == NC_NOERR) {
       int64_t *val = (int64_t*)value;
       *val = l_val;
     }
   } else {
     int     i_val;
     status = nc_get_var1_int (exoid, propid, start, &i_val);
     if (status == NC_NOERR) {
       int *val = (int*)value;
       *val = i_val;
     }
   }

   if (status != NC_NOERR) {
     exerrval = status;
     sprintf(errmsg,
            "Error: failed to read value in %s property array in file id %d",
             ex_name_of_object(obj_type), exoid);
     ex_err("ex_get_prop",errmsg,exerrval);
     return (EX_FATAL);
   }

   return (EX_NOERR);
}
Ejemplo n.º 16
0
int extract_unary_single(int mpi_rank,int mpi_size, int ncid,int vlid,int ncidout,int vlidout,int ndims,nc_type vtype,size_t *shape,size_t *begins,size_t *ends, ptrdiff_t *strides,size_t preLen,size_t *outLen){
	
	int i,j,res;
	size_t *divider=(size_t *)malloc(sizeof(size_t)*ndims);    //input divider 
	size_t *dividerOut=(size_t *)malloc(sizeof(size_t)*ndims); // output divider
	size_t *start=(size_t*)malloc(sizeof(size_t)*ndims);     //start position for reading element from input file
	size_t *startOut=(size_t*)malloc(sizeof(size_t)*ndims);  //start position for writing element to output file
	size_t *shapeOut=(size_t*)malloc(sizeof(size_t)*ndims);  //output dimension shape

	int lenOut=1;
	for(i=0;i<ndims;++i){
		shapeOut[i]=(ends[i]-begins[i])/strides[i]+1;	
		lenOut*=shapeOut[i];
	}
	if(outLen!=NULL)
		*outLen=lenOut;
	getDivider(ndims,shape,divider);
	getDivider(ndims,shapeOut,dividerOut);

	/* decide element boundary for each mpi process */
	size_t beginOut;
	size_t endOut;
	if(lenOut>=mpi_size){                              
		beginOut=mpi_rank*(lenOut/mpi_size);
		if(mpi_rank!=mpi_size-1)
			endOut=(mpi_rank+1)*(lenOut/mpi_size);
		else
			endOut=lenOut;
	}else{ //mpi_size is bigger than lenOut
		if(mpi_rank<lenOut){
			beginOut=mpi_rank;
			endOut=mpi_rank+1;
		}else{
			beginOut=0;
			endOut=0;
		}
	}

	printf("mpi_rank %d, beginOut %d, endOut %d\n",mpi_rank,beginOut,endOut);
	void *data=malloc(sizeof(double));
	size_t rem,remIn;
	for(i=beginOut;i<endOut;++i){
		rem=i+preLen;
		remIn=i;
		for(j=0;j<ndims;++j){
			startOut[j]=rem/dividerOut[j];
			start[j]=begins[j]+(remIn/dividerOut[j])*strides[j];
			rem=rem%dividerOut[j];
			remIn=remIn%dividerOut[j];
		}

	switch(vtype){
		case NC_BYTE:
			if((res=nc_get_var1_uchar(ncid,vlid,start,data)))
				BAIL(res);
			if((res=nc_put_var1_uchar(ncidout,vlidout,startOut,(unsigned char *)data)))
				BAIL(res);
			break;
		case NC_CHAR:
			if((res=nc_get_var1_schar(ncid,vlid,start,(signed char *)data)))
				BAIL(res);
			if((res=nc_put_var1_schar(ncidout,vlidout,startOut,(signed char *)data)))
				BAIL(res);
			break;
		case NC_SHORT:
			if((res=nc_get_var1_short(ncid,vlid,start,data)))
				BAIL(res);
			if((res=nc_put_var1_short(ncidout,vlidout,startOut,(short *)data)))
				BAIL(res);
			break;
		case NC_INT:
			if((res=nc_get_var1_int(ncid,vlid,start,(int *)data)))
				BAIL(res);
			if((res=nc_put_var1_int(ncidout,vlidout,startOut,(int *)data)))
				BAIL(res);
			break;
		case NC_FLOAT:
			if((res=nc_get_var1_float(ncid,vlid,start,data)))
				BAIL(res);
			if((res=nc_put_var1_float(ncidout,vlidout,startOut,(float *)data)))
				BAIL(res);
			break;
		case NC_DOUBLE:
			if((res=nc_get_var1_double(ncid,vlid,start,data)))
				BAIL(res);
			if((res=nc_put_var1_double(ncidout,vlidout,startOut,(double *)data)))
				BAIL(res);
			break;
		default:
			printf("Unknown data type\n");
			}
		}

	/*free resourses*/
	free(divider);
	free(dividerOut);
	free(start);
	free(startOut);
	free(shapeOut);
	free(data);
	return 0;
}
Ejemplo n.º 17
0
int ex_get_processor_node_maps(int exoid, void_int *node_mapi, void_int *node_mapb,
                               void_int *node_mape, int processor)
{
  const char *func_name = "ex_get_processor_node_maps";

  char    ftype[2];
  int     status, varid, dimid;
  size_t  start[1], count[1];
  int64_t varidx[2];
  int     nmstat;

  char errmsg[MAX_ERR_LENGTH];
  /*-----------------------------Execution begins-----------------------------*/

  ex_check_valid_file_id(exoid);

  exerrval = 0; /* clear error code */

  /* Get the file type */
  if (ex_get_file_type(exoid, ftype) != EX_NOERR) {
    exerrval = EX_MSG;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unable to find file type for file ID %d", exoid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }

  /* Get the status of this node map */
  if ((status = nc_inq_varid(exoid, VAR_INT_N_STAT, &varid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" from file ID %d",
             VAR_INT_N_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (ftype[0] == 'p') {
    start[0] = 0;
  }
  else {
    start[0] = processor;
  }

  if (nc_get_var1_int(exoid, varid, start, &nmstat) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get status for \"%s\" in file ID %d",
             VAR_INT_N_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (nmstat == 1) {
    /* get the index */
    if (ex_get_idx(exoid, VAR_NODE_MAP_INT_IDX, varidx, processor) == -1) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to find index variable, \"%s\", in file ID %d", VAR_NODE_MAP_INT_IDX,
               exoid);
      ex_err(func_name, errmsg, exerrval);

      return (EX_FATAL);
    }

    /* check if I need to get the dimension */
    if (varidx[1] == -1) {
      if ((status = nc_inq_dimid(exoid, DIM_NUM_INT_NODES, &dimid)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_INT_NODES,
                 exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }

      if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to find length of dimension \"%s\" in file ID %d",
                 DIM_NUM_INT_NODES, exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }
      varidx[1] = count[0];
    }

    if ((status = nc_inq_varid(exoid, VAR_NODE_MAP_INT, &varid)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
               VAR_NODE_MAP_INT, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    start[0] = varidx[0];
    count[0] = varidx[1] - varidx[0];
    if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
      status = nc_get_vara_longlong(exoid, varid, start, count, node_mapi);
    }
    else {
      status = nc_get_vara_int(exoid, varid, start, count, node_mapi);
    }
    if (status != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d",
               VAR_NODE_MAP_INT, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

  } /* End "if (nmstat == 1)" */

  /* Get the status of this node map */
  if ((status = nc_inq_varid(exoid, VAR_BOR_N_STAT, &varid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" from file ID %d",
             VAR_BOR_N_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (ftype[0] == 'p') {
    start[0] = 0;
  }
  else {
    start[0] = processor;
  }

  if (nc_get_var1_int(exoid, varid, start, &nmstat) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get status for \"%s\" from file ID %d",
             VAR_BOR_N_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (nmstat == 1) {
    /* get the index */
    if (ex_get_idx(exoid, VAR_NODE_MAP_BOR_IDX, varidx, processor) == -1) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to find index variable, \"%s\", in file ID %d", VAR_NODE_MAP_BOR_IDX,
               exoid);
      ex_err(func_name, errmsg, exerrval);

      return (EX_FATAL);
    }

    /* check if I need to get the dimension */
    if (varidx[1] == -1) {
      if ((status = nc_inq_dimid(exoid, DIM_NUM_BOR_NODES, &dimid)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_BOR_NODES,
                 exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }

      if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to find length of dimension \"%s\" in file ID %d",
                 DIM_NUM_BOR_NODES, exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }
      varidx[1] = count[0];
    }

    if ((status = nc_inq_varid(exoid, VAR_NODE_MAP_BOR, &varid)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
               VAR_NODE_MAP_BOR, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    start[0] = varidx[0];
    count[0] = varidx[1] - varidx[0];
    if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
      status = nc_get_vara_longlong(exoid, varid, start, count, node_mapb);
    }
    else {
      status = nc_get_vara_int(exoid, varid, start, count, node_mapb);
    }
    if (status != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d",
               VAR_NODE_MAP_BOR, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }
  } /* End "if (nmstat == 1)" */

  /* Get the status of this node map */
  if ((status = nc_inq_varid(exoid, VAR_EXT_N_STAT, &varid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" from file ID %d",
             VAR_EXT_N_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (ftype[0] == 'p') {
    start[0] = 0;
  }
  else {
    start[0] = processor;
  }

  if (nc_get_var1_int(exoid, varid, start, &nmstat) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get status for \"%s\" from file ID %d",
             VAR_EXT_N_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (nmstat == 1) {
    /* get the index */
    if (ex_get_idx(exoid, VAR_NODE_MAP_EXT_IDX, varidx, processor) == -1) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to find index variable, \"%s\", in file ID %d", VAR_NODE_MAP_EXT_IDX,
               exoid);
      ex_err(func_name, errmsg, exerrval);

      return (EX_FATAL);
    }

    /* check if I need to get the dimension */
    if (varidx[1] == -1) {
      if ((status = nc_inq_dimid(exoid, DIM_NUM_EXT_NODES, &dimid)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to find dimension ID for \"%s\" in file ID %d", DIM_NUM_EXT_NODES,
                 exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }

      if ((status = nc_inq_dimlen(exoid, dimid, count)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to find length of dimension \"%s\" in file ID %d",
                 DIM_NUM_EXT_NODES, exoid);
        ex_err(func_name, errmsg, exerrval);
        return (EX_FATAL);
      }
      varidx[1] = count[0];
    }

    if ((status = nc_inq_varid(exoid, VAR_NODE_MAP_EXT, &varid)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
               VAR_NODE_MAP_EXT, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    start[0] = varidx[0];
    count[0] = varidx[1] - varidx[0];
    if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
      status = nc_get_vara_longlong(exoid, varid, start, count, node_mape);
    }
    else {
      status = nc_get_vara_int(exoid, varid, start, count, node_mape);
    }
    if (status != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d",
               VAR_NODE_MAP_EXT, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }
  } /* End "if (nmstat == 1)" */
  return (EX_NOERR);
}
int
main(int argc, char **argv)
{
   printf("\n*** Testing HDF4/NetCDF-4 interoperability...\n");
   printf("*** testing that netCDF can read a HDF4 file with some ints...");
   {
#define PRES_NAME "pres"
#define LAT_LEN 3
#define LON_LEN 2
#define DIMS_2 2

      int32 sd_id, sds_id;
      int32 dim_size[DIMS_2] = {LAT_LEN, LON_LEN};
      int32 start[DIMS_2] = {0, 0}, edge[DIMS_2] = {LAT_LEN, LON_LEN};
      int ncid, nvars_in, ndims_in, natts_in, unlimdim_in;
      size_t len_in;
      int data_out[LAT_LEN][LON_LEN], data_in[LAT_LEN][LON_LEN];
      size_t nstart[DIMS_2] = {0, 0}, ncount[DIMS_2] = {LAT_LEN, LON_LEN};
      size_t nindex[DIMS_2] = {0, 0};
      int scalar_data_in = 0;
      int i, j;

      /* Create some data. */
      for (i = 0; i < LAT_LEN; i++)
	 for (j = 0; j < LON_LEN; j++)
	    data_out[i][j] = j;

      /* Create a file with one SDS, containing our phony data. */
      sd_id = SDstart(FILE_NAME, DFACC_CREATE);
      sds_id = SDcreate(sd_id, PRES_NAME, DFNT_INT32, DIMS_2, dim_size);
      if (SDwritedata(sds_id, start, NULL, edge, (void *)data_out)) ERR;
      if (SDendaccess(sds_id)) ERR;
      if (SDend(sd_id)) ERR;

      /* Now open with netCDF and check the contents. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; 
      if (nc_inq(ncid, &ndims_in, &nvars_in, &natts_in, &unlimdim_in)) ERR; 
      if (ndims_in != 2 || nvars_in != 1 || natts_in != 0 || unlimdim_in != -1) ERR;
      if (nc_inq_dim(ncid, 0, NULL, &len_in)) ERR;
      if (len_in != LAT_LEN) ERR;
      if (nc_inq_dim(ncid, 1, NULL, &len_in)) ERR;
      if (len_in != LON_LEN) ERR;
      
      /* Read the data through a vara function from the netCDF API. */
      if (nc_get_vara(ncid, 0, nstart, ncount, data_in)) ERR;
      for (i = 0; i < LAT_LEN; i++)
	 for (j = 0; j < LON_LEN; j++)
	    if (data_in[i][j] != data_out[i][j]) ERR;

      /* Reset for next test. */
      for (i = 0; i < LAT_LEN; i++)
	 for (j = 0; j < LON_LEN; j++)
	    data_in[i][j] = -88;

      /* Read the data through a vara_int function from the netCDF API. */
      if (nc_get_vara_int(ncid, 0, nstart, ncount, data_in)) ERR;
      for (i = 0; i < LAT_LEN; i++)
	 for (j = 0; j < LON_LEN; j++)
	    if (data_in[i][j] != data_out[i][j]) ERR;

      /* Reset for next test. */
      for (i = 0; i < LAT_LEN; i++)
	 for (j = 0; j < LON_LEN; j++)
	    data_in[i][j] = -88;

      /* Read the data through a var_int function from the netCDF API. */
      if (nc_get_var_int(ncid, 0, data_in)) ERR;
      for (i = 0; i < LAT_LEN; i++)
	 for (j = 0; j < LON_LEN; j++)
	    if (data_in[i][j] != data_out[i][j]) ERR;

      /* Read the data through a var1 function from the netCDF API. */
      for (i = 0; i < LAT_LEN; i++)
	 for (j = 0; j < LON_LEN; j++)
	 {
	    nindex[0] = i;
	    nindex[1] = j;
	    if (nc_get_var1(ncid, 0, nindex, &scalar_data_in)) ERR;
	    if (scalar_data_in != data_out[i][j]) ERR;
	    scalar_data_in = -88; /* reset */
	    if (nc_get_var1_int(ncid, 0, nindex, &scalar_data_in)) ERR;
	    if (scalar_data_in != data_out[i][j]) ERR;
	 }

      if (nc_close(ncid)) ERR; 
   }
   SUMMARIZE_ERR;
   printf("*** testing with a more complex HDF4 file...");
   {
#define Z_LEN 3
#define Y_LEN 2
#define X_LEN 5
#define DIMS_3 3
#define NUM_TYPES 8

      int32 sd_id, sds_id;
      int32 dim_size[DIMS_3] = {Z_LEN, Y_LEN, X_LEN};
      int dimids_in[DIMS_3];
      int ncid, nvars_in, ndims_in, natts_in, unlimdim_in;
      size_t len_in;
      nc_type type_in;
      int hdf4_type[NUM_TYPES] = {DFNT_FLOAT32, DFNT_FLOAT64, 
				  DFNT_INT8, DFNT_UINT8, DFNT_INT16, 
				  DFNT_UINT16, DFNT_INT32, DFNT_UINT32};
      int netcdf_type[NUM_TYPES] = {NC_FLOAT, NC_DOUBLE, 
				  NC_BYTE, NC_UBYTE, NC_SHORT, 
				  NC_USHORT, NC_INT, NC_UINT};
      char tmp_name[NC_MAX_NAME + 1], name_in[NC_MAX_NAME + 1];
      char dim_name[NC_MAX_NAME + 1][DIMS_3] = {"z", "y", "x"};
      int d, t;

      /* Create a HDF4 SD file. */
      sd_id = SDstart (FILE_NAME, DFACC_CREATE);

      /* Create some HDF4 datasets. */
      for (t = 0; t < NUM_TYPES; t++)
      {
	 sprintf(tmp_name, "hdf4_dataset_type_%d", t);
	 if ((sds_id = SDcreate(sd_id, tmp_name, hdf4_type[t], 
				DIMS_3, dim_size)) == FAIL) ERR;	    
	 /* Set up dimensions. By giving them the same names for each
	  * dataset, I am specifying that they are shared
	  * dimensions. */
	 for (d = 0; d < DIMS_3; d++)
	 {
	    int32 dimid;
	    if ((dimid = SDgetdimid(sds_id, d)) == FAIL) ERR;
	    if (SDsetdimname(dimid, dim_name[d])) ERR;
	 }
	 if (SDendaccess(sds_id)) ERR;
      }
      if (SDend(sd_id)) ERR;

      /* Open the file with netCDF and check it out. */
      if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
      if (nc_inq(ncid, &ndims_in, &nvars_in, &natts_in, &unlimdim_in)) ERR;
      if (ndims_in != DIMS_3 || nvars_in != NUM_TYPES || natts_in != 0 || unlimdim_in != -1) ERR;
      if (nc_inq_dim(ncid, 0, NULL, &len_in)) ERR;
      if (len_in != Z_LEN) ERR;
      if (nc_inq_dim(ncid, 1, NULL, &len_in)) ERR;
      if (len_in != Y_LEN) ERR;
      if (nc_inq_dim(ncid, 2, NULL, &len_in)) ERR;
      if (len_in != X_LEN) ERR;
      for (t = 0; t < NUM_TYPES; t++)
      {
	 if (nc_inq_var(ncid, t, name_in, &type_in, &ndims_in, 
			dimids_in, &natts_in)) ERR;
	 if (type_in != netcdf_type[t] || ndims_in != DIMS_3 ||
	     dimids_in[0] != 0 || dimids_in[2] != 2 || dimids_in[2] != 2 || 
	     natts_in != 0) ERR;
      }
      
      if (nc_close(ncid)) ERR;
   }
   SUMMARIZE_ERR;
   FINAL_RESULTS;
}