RegularReader.c

Scans through an HDF5 file and looks for grids with regular vertices.

#include <hdf5.h>

#include <F5/F5uniform.h>
#include <F5/F5iterate.h>

herr_t field_iterator(F5Path*field, const char*fieldname, void *operator_data)
{
double  *time = (double*)(operator_data);

        printf(" --> Field `%s'(t=%lg)\n", fieldname, *time);
        return 0;
}

herr_t grid_iterator(F5Path*grid, const char*gridname, void *operator_data)
{
double  *time = (double*)(operator_data);

        printf("Found Grid `%s' at t=%lg\n", gridname,*time);

        F5iterate_vertex_fields(grid, NULL, field_iterator, operator_data, NULL, NULL);

        return 0;
}

static int F5P_is_regular3D(F5Path*grid, const char*coordinate_system)
{
hsize_t dims[FIBER_MAX_RANK];
int     rank = F5get_extension(grid, dims);

        printf("Grid rank is %d: ", rank);
        if (rank>0)
        {
        int     i;
                for(i=0; i<rank-1; i++)
                        printf("%dx", (int)dims[i] );

                printf("%d\n", (int)dims[rank-1] );
        }

        if (rank==3)
                return 1;

        return 0;
}


herr_t timeslices_iterator(F5Path*myPath, double time, void *user_data)
{
F5_gridproperty_t* (select_grids[]) = { &F5P_is_regular3D, 0 };

        F5iterate_grids(myPath, NULL, grid_iterator, &time, select_grids, 0);

        return 0;
}


int main(int argc, char*argv[])
{
hid_t   file_id;

        if (argc<2) argv[1] = "../ScalarSimple/TimeDependentScalar.f5";
/*      if (argc<2) argv[1] = "../ScalarSimple/StaticScalar.f5"; */
/*      if (argc<2) argv[1] = "../ScalarSimple/MultiScalar.f5"; */

        file_id = H5Fopen(argv[1], H5F_ACC_RDONLY, H5P_DEFAULT);
        if (file_id < 0)
        {
                printf("Could not open `%s'.\n", argv[1]);
                return 1;
        }

        /* Iterate over all time slices within a file. */ 
        F5iterate_timeslices(file_id, NULL, timeslices_iterator, 0);


        H5Fclose( file_id );

        return 0;
}