[netcdfgroup] different ordering of dim ids -- is this expected?

Hello again,

  Thank you again for the fix for my previous question about the unlimited 
dimension error!

   I have another question regarding different behavior between 4.1.3 and 
4.3.3.1, and am wondering if it is expected behavior.

   Did the ordering of returned dimension ids change between these two versions?

   I wrote another standalone C program to test this outside of our MATLAB 
regression tests.
   In the new NetCDF version 4.3.3.1, this program outputs the group 2 
dimension ids as 0, 1, 2, whereas in our current NetCDF version 4.1.3 this 
outputs the dimension is as 0, 1, 4.
   Hence the group 2 dimension names in 4.3.3.1 display as rt_x1, g2_t1, and 
g2_x1, whereas in 4.1.3 they display as g2_t1, g2_x1, rt_x1.

  Below is the standalone C program.  Again built this with HDF5 1.8.12.

  Thank you!
     Ellen Johnson
     Software Engineer
     Image and Scientific File Formats
     MathWorks

#include <stdio.h>
#include <string.h>
#include <netcdf.h>

/* This is the name of the data file we will create. */
#define FILE_NAME "dimtest.nc"

#define NDIMS 5

/* Handle errors by printing an error message */
#define ERR(e) {printf("Error: %s\n", nc_strerror(e)); return 2;}
int
main()
{
    int i;
    int retval;
    int ncid, gid1, gid2, gid3, gid4, rt_x1_dimid, g2_t1_dimid, g2_x1_dimid, 
g3_v1_dimid, g4_x1_dimid;
    int dimids[NDIMS];
    int ndims_in;
    int dimids_in[5];
    int grpid_in;
    char name_in[100];
    size_t len_in;

    /* create the file */
    if ((retval = nc_create(FILE_NAME, NC_NETCDF4, &ncid)))
        ERR(retval);

    /* at root group, create one regular dimension */
    if ((retval = nc_def_dim(ncid, "rt_x1", 10, &rt_x1_dimid)))
        ERR(retval);

    /* create group 1 */
    if ((retval = nc_def_grp(ncid, "grp1", &gid1)))
        ERR(retval);

    /* create group 2 */
    if ((retval = nc_def_grp(gid1, "grp2", &gid2)))
        ERR (retval);

    /* in group 2 create one unlimited and one regular dimension */
    if ((retval = nc_def_dim(gid2, "g2_t1", NC_UNLIMITED, &g2_t1_dimid)))
        ERR(retval);
    if ((retval = nc_def_dim(gid2, "g2_x1", 10, &g2_x1_dimid)))
        ERR(retval);

    /* create group 3 */
    if ((retval = nc_def_grp(gid1, "grp3", &gid3)))
        ERR (retval);

    /* in group 3 create one regular dimension */
    if ((retval = nc_def_dim(gid3, "group3_x1", 5, &g3_v1_dimid)))
        ERR(retval);

    /* create group 4 */
    if ((retval = nc_def_grp(ncid, "grp4", &gid4)))
        ERR (retval);

    /* in group 4 create one regular dimension */
    if ((retval = nc_def_dim(gid4, "group4_x1", 5, &g4_x1_dimid)))
        ERR(retval);

    /* end define mode */
    if ((retval = nc_enddef(ncid)))
        ERR(retval);

    /* close the file */
    if ((retval = nc_close(ncid)))
        ERR(retval);

    printf("\n\n*** SUCCESS writing example file %s!\n\n", FILE_NAME);

    /* reopen file */
    if ((nc_open(FILE_NAME, NC_NOWRITE, &ncid)))
        ERR(retval);

    /* find group 2 by name */
    if ((retval = nc_inq_ncid(gid1, "grp2", &grpid_in)))
       ERR(retval);

    printf("grpid2 = %d\n", grpid_in);

    /* now, get number of dims for group 2, including parent */
    if ((retval = nc_inq_dimids(gid2, &ndims_in, dimids_in, 1)))
       ERR(retval);

    printf("numdims for group 2 = %d\n", ndims_in);

    /* print the dim ids for group 2, including parent */
    for (i=0; i<ndims_in; i++)
    {
        printf("group 2 dim id %d === %d\n", i, dimids_in[i]);
    }

    /* get the names for group 2 */
    if ((retval = nc_inq_dim(grpid_in, dimids_in[0], name_in, &len_in)))
        ERR(retval);
    printf("name for dimid 0 = %s\n", name_in);
    if ((retval = nc_inq_dim(grpid_in, dimids_in[1], name_in, &len_in)))
        ERR(retval);
    printf("name for dimid 1 = %s\n", name_in);
    if ((retval = nc_inq_dim(grpid_in, dimids_in[2], name_in, &len_in)))
        ERR(retval);
    printf("name for dimid 2 = %s\n", name_in);

    printf("\n\n");

    /* close the file */
    if ((retval = nc_close(ncid)))
        ERR(retval);

    printf("End of test.\n\n");

    return 0;
}



  • 2015 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: