From fda130251a25a36cb4c673be79ac1e898da7919e Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 10 Jan 2018 09:41:54 -0700 Subject: [PATCH] now assume frame=0 for darray read if frame was not set --- src/clib/pio_darray_int.c | 27 +++++++++++++++++++++++++-- src/clib/pioc.c | 1 - tests/cunit/test_darray_1d.c | 8 +++----- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/clib/pio_darray_int.c b/src/clib/pio_darray_int.c index ea4c23b2de9..dedd854a77a 100644 --- a/src/clib/pio_darray_int.c +++ b/src/clib/pio_darray_int.c @@ -805,10 +805,16 @@ int pio_read_darray_nc(file_desc_t *file, io_desc_t *iodesc, int vid, void *iobu the mpitype. */ region = iodesc->firstregion; - /* ??? */ + /* There are different numbers of dims in the decomposition + * and the file. */ if (fndims > ndims) { ndims++; + + /* If the user did not call setframe, use a default frame + * of 0. This is required for backward compatibility. */ + if (vdesc->record < 0) + vdesc->record = 0; } /* For each regions, read the data. */ @@ -833,7 +839,8 @@ int pio_read_darray_nc(file_desc_t *file, io_desc_t *iodesc, int vid, void *iobu else bufptr=(void *)((char *)iobuf + iodesc->mpitype_size * region->loffset); - LOG((2, "%d %d %d", iodesc->llen - region->loffset, iodesc->llen, region->loffset)); + LOG((2, "iodesc->llen - region->loffset %d, iodesc->llen %d, region->loffset %d vdesc->record %d", + iodesc->llen - region->loffset, iodesc->llen, region->loffset, vdesc->record)); /* Get the start/count arrays. */ if (vdesc->record >= 0 && fndims > 1) @@ -862,6 +869,11 @@ int pio_read_darray_nc(file_desc_t *file, io_desc_t *iodesc, int vid, void *iobu } } +#ifdef LOGGING + for (int i = 1; i < ndims; i++) + LOG((3, "start[%d] %d count[%d] %d", i, start[i], i, count[i])); +#endif /* LOGGING */ + /* Do the read. */ switch (file->iotype) { @@ -1023,6 +1035,11 @@ int pio_read_darray_nc_serial(file_desc_t *file, io_desc_t *iodesc, int vid, if ((ierr = PIOc_inq_varndims(file->pio_ncid, vid, &fndims))) return pio_err(ios, file, ierr, __FILE__, __LINE__); + /* If setframe was not called, use a default value of 0. This is + * required for backward compatibility. */ + if (fndims == ndims + 1 && vdesc->record < 0) + vdesc->record = 0; + /* Confirm that we are being called with the correct ndims. */ pioassert((fndims == ndims && vdesc->record < 0) || (fndims == ndims + 1 && vdesc->record >= 0), @@ -1043,6 +1060,12 @@ int pio_read_darray_nc_serial(file_desc_t *file, io_desc_t *iodesc, int vid, the mpitype. */ region = iodesc->firstregion; + /* If setframe was not set before this call, assume a value of + * 0. This is required for backward compatibility. */ + if (fndims > ndims) + if (vdesc->record < 0) + vdesc->record = 0; + /* Put together start/count arrays for all regions. */ for (int regioncnt = 0; regioncnt < iodesc->maxregions; regioncnt++) { diff --git a/src/clib/pioc.c b/src/clib/pioc.c index c49a811a1ee..1f83c597e02 100644 --- a/src/clib/pioc.c +++ b/src/clib/pioc.c @@ -220,7 +220,6 @@ int PIOc_setframe(int ncid, int varid, int frame) /* Set the record dimension value for this variable. This will be * used by the write_darray functions. */ - /* file->varlist[varid].record = frame; */ vdesc->record = frame; return PIO_NOERR; diff --git a/tests/cunit/test_darray_1d.c b/tests/cunit/test_darray_1d.c index 189d2e3e9bb..1344ec53072 100644 --- a/tests/cunit/test_darray_1d.c +++ b/tests/cunit/test_darray_1d.c @@ -579,11 +579,9 @@ int test_darray_fill_unlim(int iosysid, int ioid, int pio_type, int num_flavors, if (!(test_data_in = malloc(type_size * arraylen))) ERR(PIO_ENOMEM); - /* Set the record number for the unlimited dimension. */ - if ((ret = PIOc_setframe(ncid, varid, 0))) - ERR(ret); - - /* Read the data. */ + /* Read the data. We don't have to set the record number for + * the unlimited dimension. If we don't set it, PIO will + * assume a value of 0. */ if ((ret = PIOc_read_darray(ncid, varid, ioid, arraylen, test_data_in))) ERR(ret);