xref: /petsc/src/sys/classes/viewer/impls/hdf5/hdf5v.c (revision ce94432eddcd14845bc7e8083b7f8ea723b9bf7d)
15c6c1daeSBarry Smith #include <petsc-private/viewerimpl.h>    /*I   "petscsys.h"   I*/
25c6c1daeSBarry Smith #include <hdf5.h>
35c6c1daeSBarry Smith 
45c6c1daeSBarry Smith typedef struct GroupList {
55c6c1daeSBarry Smith   const char       *name;
65c6c1daeSBarry Smith   struct GroupList *next;
75c6c1daeSBarry Smith } GroupList;
85c6c1daeSBarry Smith 
95c6c1daeSBarry Smith typedef struct {
105c6c1daeSBarry Smith   char          *filename;
115c6c1daeSBarry Smith   PetscFileMode btype;
125c6c1daeSBarry Smith   hid_t         file_id;
135c6c1daeSBarry Smith   PetscInt      timestep;
145c6c1daeSBarry Smith   GroupList     *groups;
155c6c1daeSBarry Smith } PetscViewer_HDF5;
165c6c1daeSBarry Smith 
175c6c1daeSBarry Smith #undef __FUNCT__
185c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFileClose_HDF5"
195c6c1daeSBarry Smith static PetscErrorCode PetscViewerFileClose_HDF5(PetscViewer viewer)
205c6c1daeSBarry Smith {
215c6c1daeSBarry Smith   PetscViewer_HDF5 *hdf5 = (PetscViewer_HDF5*)viewer->data;
225c6c1daeSBarry Smith   PetscErrorCode   ierr;
235c6c1daeSBarry Smith 
245c6c1daeSBarry Smith   PetscFunctionBegin;
255c6c1daeSBarry Smith   ierr = PetscFree(hdf5->filename);CHKERRQ(ierr);
26a297a907SKarl Rupp   if (hdf5->file_id) H5Fclose(hdf5->file_id);
275c6c1daeSBarry Smith   PetscFunctionReturn(0);
285c6c1daeSBarry Smith }
295c6c1daeSBarry Smith 
305c6c1daeSBarry Smith #undef __FUNCT__
315c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDestroy_HDF5"
325c6c1daeSBarry Smith PetscErrorCode PetscViewerDestroy_HDF5(PetscViewer viewer)
335c6c1daeSBarry Smith {
345c6c1daeSBarry Smith   PetscViewer_HDF5 *hdf5 = (PetscViewer_HDF5*) viewer->data;
355c6c1daeSBarry Smith   PetscErrorCode   ierr;
365c6c1daeSBarry Smith 
375c6c1daeSBarry Smith   PetscFunctionBegin;
385c6c1daeSBarry Smith   ierr = PetscViewerFileClose_HDF5(viewer);CHKERRQ(ierr);
39a297a907SKarl Rupp   if (hdf5->groups)
405c6c1daeSBarry Smith     while (hdf5->groups) {
415c6c1daeSBarry Smith       GroupList *tmp = hdf5->groups->next;
425c6c1daeSBarry Smith 
435c6c1daeSBarry Smith       ierr         = PetscFree(hdf5->groups->name);CHKERRQ(ierr);
445c6c1daeSBarry Smith       ierr         = PetscFree(hdf5->groups);CHKERRQ(ierr);
455c6c1daeSBarry Smith       hdf5->groups = tmp;
465c6c1daeSBarry Smith     }
475c6c1daeSBarry Smith   ierr = PetscFree(hdf5);CHKERRQ(ierr);
485c6c1daeSBarry Smith   PetscFunctionReturn(0);
495c6c1daeSBarry Smith }
505c6c1daeSBarry Smith 
515c6c1daeSBarry Smith EXTERN_C_BEGIN
525c6c1daeSBarry Smith #undef __FUNCT__
535c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFileSetMode_HDF5"
545c6c1daeSBarry Smith PetscErrorCode  PetscViewerFileSetMode_HDF5(PetscViewer viewer, PetscFileMode type)
555c6c1daeSBarry Smith {
565c6c1daeSBarry Smith   PetscViewer_HDF5 *hdf5 = (PetscViewer_HDF5*) viewer->data;
575c6c1daeSBarry Smith 
585c6c1daeSBarry Smith   PetscFunctionBegin;
595c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
605c6c1daeSBarry Smith   hdf5->btype = type;
615c6c1daeSBarry Smith   PetscFunctionReturn(0);
625c6c1daeSBarry Smith }
635c6c1daeSBarry Smith EXTERN_C_END
645c6c1daeSBarry Smith 
655c6c1daeSBarry Smith EXTERN_C_BEGIN
665c6c1daeSBarry Smith #undef __FUNCT__
675c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFileSetName_HDF5"
685c6c1daeSBarry Smith PetscErrorCode  PetscViewerFileSetName_HDF5(PetscViewer viewer, const char name[])
695c6c1daeSBarry Smith {
705c6c1daeSBarry Smith   PetscViewer_HDF5 *hdf5 = (PetscViewer_HDF5*) viewer->data;
715c6c1daeSBarry Smith #if defined(PETSC_HAVE_H5PSET_FAPL_MPIO)
725c6c1daeSBarry Smith   MPI_Info          info = MPI_INFO_NULL;
735c6c1daeSBarry Smith #endif
745c6c1daeSBarry Smith   hid_t             plist_id;
755c6c1daeSBarry Smith   herr_t            herr;
765c6c1daeSBarry Smith   PetscErrorCode    ierr;
775c6c1daeSBarry Smith 
785c6c1daeSBarry Smith   PetscFunctionBegin;
795c6c1daeSBarry Smith   ierr = PetscStrallocpy(name, &hdf5->filename);CHKERRQ(ierr);
805c6c1daeSBarry Smith   /* Set up file access property list with parallel I/O access */
815c6c1daeSBarry Smith   plist_id = H5Pcreate(H5P_FILE_ACCESS);
825c6c1daeSBarry Smith #if defined(PETSC_HAVE_H5PSET_FAPL_MPIO)
83*ce94432eSBarry Smith   herr = H5Pset_fapl_mpio(plist_id, PetscObjectComm((PetscObject)viewer), info);CHKERRQ(herr);
845c6c1daeSBarry Smith #endif
855c6c1daeSBarry Smith   /* Create or open the file collectively */
865c6c1daeSBarry Smith   switch (hdf5->btype) {
875c6c1daeSBarry Smith   case FILE_MODE_READ:
885c6c1daeSBarry Smith     hdf5->file_id = H5Fopen(name, H5F_ACC_RDONLY, plist_id);
895c6c1daeSBarry Smith     break;
905c6c1daeSBarry Smith   case FILE_MODE_APPEND:
915c6c1daeSBarry Smith     hdf5->file_id = H5Fopen(name, H5F_ACC_RDWR, plist_id);
925c6c1daeSBarry Smith     break;
935c6c1daeSBarry Smith   case FILE_MODE_WRITE:
945c6c1daeSBarry Smith     hdf5->file_id = H5Fcreate(name, H5F_ACC_TRUNC, H5P_DEFAULT, plist_id);
955c6c1daeSBarry Smith     break;
965c6c1daeSBarry Smith   default:
975c6c1daeSBarry Smith     SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER, "Must call PetscViewerFileSetMode() before PetscViewerFileSetName()");
985c6c1daeSBarry Smith   }
995c6c1daeSBarry Smith   if (hdf5->file_id < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB, "H5Fcreate failed for %s", name);
1005c6c1daeSBarry Smith   viewer->format = PETSC_VIEWER_NOFORMAT;
1015c6c1daeSBarry Smith   H5Pclose(plist_id);
1025c6c1daeSBarry Smith   PetscFunctionReturn(0);
1035c6c1daeSBarry Smith }
1045c6c1daeSBarry Smith EXTERN_C_END
1055c6c1daeSBarry Smith 
1065c6c1daeSBarry Smith EXTERN_C_BEGIN
1075c6c1daeSBarry Smith #undef __FUNCT__
1085c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerCreate_HDF5"
1095c6c1daeSBarry Smith PetscErrorCode  PetscViewerCreate_HDF5(PetscViewer v)
1105c6c1daeSBarry Smith {
1115c6c1daeSBarry Smith   PetscViewer_HDF5 *hdf5;
1125c6c1daeSBarry Smith   PetscErrorCode   ierr;
1135c6c1daeSBarry Smith 
1145c6c1daeSBarry Smith   PetscFunctionBegin;
1155c6c1daeSBarry Smith   ierr = PetscNewLog(v, PetscViewer_HDF5, &hdf5);CHKERRQ(ierr);
1165c6c1daeSBarry Smith 
1175c6c1daeSBarry Smith   v->data         = (void*) hdf5;
1185c6c1daeSBarry Smith   v->ops->destroy = PetscViewerDestroy_HDF5;
1195c6c1daeSBarry Smith   v->ops->flush   = 0;
1205c6c1daeSBarry Smith   v->iformat      = 0;
1215c6c1daeSBarry Smith   hdf5->btype     = (PetscFileMode) -1;
1225c6c1daeSBarry Smith   hdf5->filename  = 0;
1235c6c1daeSBarry Smith   hdf5->timestep  = -1;
1240298fd71SBarry Smith   hdf5->groups    = NULL;
1255c6c1daeSBarry Smith 
1265c6c1daeSBarry Smith   ierr = PetscObjectComposeFunctionDynamic((PetscObject)v,"PetscViewerFileSetName_C","PetscViewerFileSetName_HDF5",
1275c6c1daeSBarry Smith                                            PetscViewerFileSetName_HDF5);CHKERRQ(ierr);
1285c6c1daeSBarry Smith   ierr = PetscObjectComposeFunctionDynamic((PetscObject)v,"PetscViewerFileSetMode_C","PetscViewerFileSetMode_HDF5",
1295c6c1daeSBarry Smith                                            PetscViewerFileSetMode_HDF5);CHKERRQ(ierr);
1305c6c1daeSBarry Smith   PetscFunctionReturn(0);
1315c6c1daeSBarry Smith }
1325c6c1daeSBarry Smith EXTERN_C_END
1335c6c1daeSBarry Smith 
1345c6c1daeSBarry Smith #undef __FUNCT__
1355c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerHDF5Open"
1365c6c1daeSBarry Smith /*@C
1375c6c1daeSBarry Smith    PetscViewerHDF5Open - Opens a file for HDF5 input/output.
1385c6c1daeSBarry Smith 
1395c6c1daeSBarry Smith    Collective on MPI_Comm
1405c6c1daeSBarry Smith 
1415c6c1daeSBarry Smith    Input Parameters:
1425c6c1daeSBarry Smith +  comm - MPI communicator
1435c6c1daeSBarry Smith .  name - name of file
1445c6c1daeSBarry Smith -  type - type of file
1455c6c1daeSBarry Smith $    FILE_MODE_WRITE - create new file for binary output
1465c6c1daeSBarry Smith $    FILE_MODE_READ - open existing file for binary input
1475c6c1daeSBarry Smith $    FILE_MODE_APPEND - open existing file for binary output
1485c6c1daeSBarry Smith 
1495c6c1daeSBarry Smith    Output Parameter:
1505c6c1daeSBarry Smith .  hdf5v - PetscViewer for HDF5 input/output to use with the specified file
1515c6c1daeSBarry Smith 
1525c6c1daeSBarry Smith    Level: beginner
1535c6c1daeSBarry Smith 
1545c6c1daeSBarry Smith    Note:
1555c6c1daeSBarry Smith    This PetscViewer should be destroyed with PetscViewerDestroy().
1565c6c1daeSBarry Smith 
1575c6c1daeSBarry Smith    Concepts: HDF5 files
1585c6c1daeSBarry Smith    Concepts: PetscViewerHDF5^creating
1595c6c1daeSBarry Smith 
1605c6c1daeSBarry Smith .seealso: PetscViewerASCIIOpen(), PetscViewerSetFormat(), PetscViewerDestroy(),
1615c6c1daeSBarry Smith           VecView(), MatView(), VecLoad(), MatLoad(),
1625c6c1daeSBarry Smith           PetscFileMode, PetscViewer
1635c6c1daeSBarry Smith @*/
1645c6c1daeSBarry Smith PetscErrorCode  PetscViewerHDF5Open(MPI_Comm comm, const char name[], PetscFileMode type, PetscViewer *hdf5v)
1655c6c1daeSBarry Smith {
1665c6c1daeSBarry Smith   PetscErrorCode ierr;
1675c6c1daeSBarry Smith 
1685c6c1daeSBarry Smith   PetscFunctionBegin;
1695c6c1daeSBarry Smith   ierr = PetscViewerCreate(comm, hdf5v);CHKERRQ(ierr);
1705c6c1daeSBarry Smith   ierr = PetscViewerSetType(*hdf5v, PETSCVIEWERHDF5);CHKERRQ(ierr);
1715c6c1daeSBarry Smith   ierr = PetscViewerFileSetMode(*hdf5v, type);CHKERRQ(ierr);
1725c6c1daeSBarry Smith   ierr = PetscViewerFileSetName(*hdf5v, name);CHKERRQ(ierr);
1735c6c1daeSBarry Smith   PetscFunctionReturn(0);
1745c6c1daeSBarry Smith }
1755c6c1daeSBarry Smith 
1765c6c1daeSBarry Smith #undef __FUNCT__
1775c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerHDF5GetFileId"
1785c6c1daeSBarry Smith /*@C
1795c6c1daeSBarry Smith   PetscViewerHDF5GetFileId - Retrieve the file id, this file ID then can be used in direct HDF5 calls
1805c6c1daeSBarry Smith 
1815c6c1daeSBarry Smith   Not collective
1825c6c1daeSBarry Smith 
1835c6c1daeSBarry Smith   Input Parameter:
1845c6c1daeSBarry Smith . viewer - the PetscViewer
1855c6c1daeSBarry Smith 
1865c6c1daeSBarry Smith   Output Parameter:
1875c6c1daeSBarry Smith . file_id - The file id
1885c6c1daeSBarry Smith 
1895c6c1daeSBarry Smith   Level: intermediate
1905c6c1daeSBarry Smith 
1915c6c1daeSBarry Smith .seealso: PetscViewerHDF5Open()
1925c6c1daeSBarry Smith @*/
1935c6c1daeSBarry Smith PetscErrorCode  PetscViewerHDF5GetFileId(PetscViewer viewer, hid_t *file_id)
1945c6c1daeSBarry Smith {
1955c6c1daeSBarry Smith   PetscViewer_HDF5 *hdf5 = (PetscViewer_HDF5*) viewer->data;
1965c6c1daeSBarry Smith 
1975c6c1daeSBarry Smith   PetscFunctionBegin;
1985c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
1995c6c1daeSBarry Smith   if (file_id) *file_id = hdf5->file_id;
2005c6c1daeSBarry Smith   PetscFunctionReturn(0);
2015c6c1daeSBarry Smith }
2025c6c1daeSBarry Smith 
2035c6c1daeSBarry Smith #undef __FUNCT__
2045c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerHDF5PushGroup"
2055c6c1daeSBarry Smith /*@C
2065c6c1daeSBarry Smith   PetscViewerHDF5PushGroup - Set the current HDF5 group for output
2075c6c1daeSBarry Smith 
2085c6c1daeSBarry Smith   Not collective
2095c6c1daeSBarry Smith 
2105c6c1daeSBarry Smith   Input Parameters:
2115c6c1daeSBarry Smith + viewer - the PetscViewer
2125c6c1daeSBarry Smith - name - The group name
2135c6c1daeSBarry Smith 
2145c6c1daeSBarry Smith   Level: intermediate
2155c6c1daeSBarry Smith 
2165c6c1daeSBarry Smith .seealso: PetscViewerHDF5Open(),PetscViewerHDF5PopGroup(),PetscViewerHDF5GetGroup()
2175c6c1daeSBarry Smith @*/
2185c6c1daeSBarry Smith PetscErrorCode  PetscViewerHDF5PushGroup(PetscViewer viewer, const char *name)
2195c6c1daeSBarry Smith {
2205c6c1daeSBarry Smith   PetscViewer_HDF5 *hdf5 = (PetscViewer_HDF5*) viewer->data;
2215c6c1daeSBarry Smith   GroupList        *groupNode;
2225c6c1daeSBarry Smith   PetscErrorCode   ierr;
2235c6c1daeSBarry Smith 
2245c6c1daeSBarry Smith   PetscFunctionBegin;
2255c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
2265c6c1daeSBarry Smith   PetscValidCharPointer(name,2);
2275c6c1daeSBarry Smith   ierr = PetscMalloc(sizeof(GroupList), &groupNode);CHKERRQ(ierr);
2285c6c1daeSBarry Smith   ierr = PetscStrallocpy(name, (char**) &groupNode->name);CHKERRQ(ierr);
229a297a907SKarl Rupp 
2305c6c1daeSBarry Smith   groupNode->next = hdf5->groups;
2315c6c1daeSBarry Smith   hdf5->groups    = groupNode;
2325c6c1daeSBarry Smith   PetscFunctionReturn(0);
2335c6c1daeSBarry Smith }
2345c6c1daeSBarry Smith 
2355c6c1daeSBarry Smith #undef __FUNCT__
2365c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerHDF5PopGroup"
2375c6c1daeSBarry Smith /*@C
2385c6c1daeSBarry Smith   PetscViewerHDF5PopGroup - Return the current HDF5 group for output to the previous value
2395c6c1daeSBarry Smith 
2405c6c1daeSBarry Smith   Not collective
2415c6c1daeSBarry Smith 
2425c6c1daeSBarry Smith   Input Parameter:
2435c6c1daeSBarry Smith . viewer - the PetscViewer
2445c6c1daeSBarry Smith 
2455c6c1daeSBarry Smith   Level: intermediate
2465c6c1daeSBarry Smith 
2475c6c1daeSBarry Smith .seealso: PetscViewerHDF5Open(),PetscViewerHDF5PushGroup(),PetscViewerHDF5GetGroup()
2485c6c1daeSBarry Smith @*/
2495c6c1daeSBarry Smith PetscErrorCode  PetscViewerHDF5PopGroup(PetscViewer viewer)
2505c6c1daeSBarry Smith {
2515c6c1daeSBarry Smith   PetscViewer_HDF5 *hdf5 = (PetscViewer_HDF5*) viewer->data;
2525c6c1daeSBarry Smith   GroupList        *groupNode;
2535c6c1daeSBarry Smith   PetscErrorCode   ierr;
2545c6c1daeSBarry Smith 
2555c6c1daeSBarry Smith   PetscFunctionBegin;
2565c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
2575c6c1daeSBarry Smith   if (!hdf5->groups) SETERRQ(((PetscObject) viewer)->comm, PETSC_ERR_ARG_WRONGSTATE, "HDF5 group stack is empty, cannot pop");
2585c6c1daeSBarry Smith   groupNode    = hdf5->groups;
2595c6c1daeSBarry Smith   hdf5->groups = hdf5->groups->next;
2605c6c1daeSBarry Smith   ierr         = PetscFree(groupNode->name);CHKERRQ(ierr);
2615c6c1daeSBarry Smith   ierr         = PetscFree(groupNode);CHKERRQ(ierr);
2625c6c1daeSBarry Smith   PetscFunctionReturn(0);
2635c6c1daeSBarry Smith }
2645c6c1daeSBarry Smith 
2655c6c1daeSBarry Smith #undef __FUNCT__
2665c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerHDF5GetGroup"
2675c6c1daeSBarry Smith /*@C
2680298fd71SBarry Smith   PetscViewerHDF5GetGroup - Get the current HDF5 group for output. If none has been assigned, returns NULL.
2695c6c1daeSBarry Smith 
2705c6c1daeSBarry Smith   Not collective
2715c6c1daeSBarry Smith 
2725c6c1daeSBarry Smith   Input Parameter:
2735c6c1daeSBarry Smith . viewer - the PetscViewer
2745c6c1daeSBarry Smith 
2755c6c1daeSBarry Smith   Output Parameter:
2765c6c1daeSBarry Smith . name - The group name
2775c6c1daeSBarry Smith 
2785c6c1daeSBarry Smith   Level: intermediate
2795c6c1daeSBarry Smith 
2805c6c1daeSBarry Smith .seealso: PetscViewerHDF5Open(),PetscViewerHDF5PushGroup(),PetscViewerHDF5PopGroup()
2815c6c1daeSBarry Smith @*/
2825c6c1daeSBarry Smith PetscErrorCode  PetscViewerHDF5GetGroup(PetscViewer viewer, const char **name)
2835c6c1daeSBarry Smith {
2845c6c1daeSBarry Smith   PetscViewer_HDF5 *hdf5 = (PetscViewer_HDF5 *) viewer->data;
2855c6c1daeSBarry Smith 
2865c6c1daeSBarry Smith   PetscFunctionBegin;
2875c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
2885c6c1daeSBarry Smith   PetscValidCharPointer(name,2);
289a297a907SKarl Rupp   if (hdf5->groups) *name = hdf5->groups->name;
2900298fd71SBarry Smith   else *name = NULL;
2915c6c1daeSBarry Smith   PetscFunctionReturn(0);
2925c6c1daeSBarry Smith }
2935c6c1daeSBarry Smith 
2945c6c1daeSBarry Smith #undef __FUNCT__
2955c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerHDF5IncrementTimestep"
2965c6c1daeSBarry Smith /*@C
2975c6c1daeSBarry Smith   PetscViewerHDF5IncrementTimestep - Increments the current timestep for the HDF5 output. Fields are stacked in time.
2985c6c1daeSBarry Smith 
2995c6c1daeSBarry Smith   Not collective
3005c6c1daeSBarry Smith 
3015c6c1daeSBarry Smith   Input Parameter:
3025c6c1daeSBarry Smith . viewer - the PetscViewer
3035c6c1daeSBarry Smith 
3045c6c1daeSBarry Smith   Level: intermediate
3055c6c1daeSBarry Smith 
3065c6c1daeSBarry Smith .seealso: PetscViewerHDF5Open(), PetscViewerHDF5SetTimestep(), PetscViewerHDF5GetTimestep()
3075c6c1daeSBarry Smith @*/
3085c6c1daeSBarry Smith PetscErrorCode PetscViewerHDF5IncrementTimestep(PetscViewer viewer)
3095c6c1daeSBarry Smith {
3105c6c1daeSBarry Smith   PetscViewer_HDF5 *hdf5 = (PetscViewer_HDF5*) viewer->data;
3115c6c1daeSBarry Smith 
3125c6c1daeSBarry Smith   PetscFunctionBegin;
3135c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
3145c6c1daeSBarry Smith   ++hdf5->timestep;
3155c6c1daeSBarry Smith   PetscFunctionReturn(0);
3165c6c1daeSBarry Smith }
3175c6c1daeSBarry Smith 
3185c6c1daeSBarry Smith #undef __FUNCT__
3195c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerHDF5SetTimestep"
3205c6c1daeSBarry Smith /*@C
3215c6c1daeSBarry Smith   PetscViewerHDF5SetTimestep - Set the current timestep for the HDF5 output. Fields are stacked in time. A timestep
3225c6c1daeSBarry Smith   of -1 disables blocking with timesteps.
3235c6c1daeSBarry Smith 
3245c6c1daeSBarry Smith   Not collective
3255c6c1daeSBarry Smith 
3265c6c1daeSBarry Smith   Input Parameters:
3275c6c1daeSBarry Smith + viewer - the PetscViewer
3285c6c1daeSBarry Smith - timestep - The timestep number
3295c6c1daeSBarry Smith 
3305c6c1daeSBarry Smith   Level: intermediate
3315c6c1daeSBarry Smith 
3325c6c1daeSBarry Smith .seealso: PetscViewerHDF5Open(), PetscViewerHDF5IncrementTimestep(), PetscViewerHDF5GetTimestep()
3335c6c1daeSBarry Smith @*/
3345c6c1daeSBarry Smith PetscErrorCode  PetscViewerHDF5SetTimestep(PetscViewer viewer, PetscInt timestep)
3355c6c1daeSBarry Smith {
3365c6c1daeSBarry Smith   PetscViewer_HDF5 *hdf5 = (PetscViewer_HDF5*) viewer->data;
3375c6c1daeSBarry Smith 
3385c6c1daeSBarry Smith   PetscFunctionBegin;
3395c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
3405c6c1daeSBarry Smith   hdf5->timestep = timestep;
3415c6c1daeSBarry Smith   PetscFunctionReturn(0);
3425c6c1daeSBarry Smith }
3435c6c1daeSBarry Smith 
3445c6c1daeSBarry Smith #undef __FUNCT__
3455c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerHDF5GetTimestep"
3465c6c1daeSBarry Smith /*@C
3475c6c1daeSBarry Smith   PetscViewerHDF5GetTimestep - Get the current timestep for the HDF5 output. Fields are stacked in time.
3485c6c1daeSBarry Smith 
3495c6c1daeSBarry Smith   Not collective
3505c6c1daeSBarry Smith 
3515c6c1daeSBarry Smith   Input Parameter:
3525c6c1daeSBarry Smith . viewer - the PetscViewer
3535c6c1daeSBarry Smith 
3545c6c1daeSBarry Smith   Output Parameter:
3555c6c1daeSBarry Smith . timestep - The timestep number
3565c6c1daeSBarry Smith 
3575c6c1daeSBarry Smith   Level: intermediate
3585c6c1daeSBarry Smith 
3595c6c1daeSBarry Smith .seealso: PetscViewerHDF5Open(), PetscViewerHDF5IncrementTimestep(), PetscViewerHDF5SetTimestep()
3605c6c1daeSBarry Smith @*/
3615c6c1daeSBarry Smith PetscErrorCode  PetscViewerHDF5GetTimestep(PetscViewer viewer, PetscInt *timestep)
3625c6c1daeSBarry Smith {
3635c6c1daeSBarry Smith   PetscViewer_HDF5 *hdf5 = (PetscViewer_HDF5*) viewer->data;
3645c6c1daeSBarry Smith 
3655c6c1daeSBarry Smith   PetscFunctionBegin;
3665c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
3675c6c1daeSBarry Smith   PetscValidPointer(timestep,2);
3685c6c1daeSBarry Smith   *timestep = hdf5->timestep;
3695c6c1daeSBarry Smith   PetscFunctionReturn(0);
3705c6c1daeSBarry Smith }
3715c6c1daeSBarry Smith 
3725c6c1daeSBarry Smith #if defined(oldhdf4stuff)
3735c6c1daeSBarry Smith #undef __FUNCT__
3745c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerHDF5WriteSDS"
3755c6c1daeSBarry Smith PetscErrorCode  PetscViewerHDF5WriteSDS(PetscViewer viewer, float *xf, int d, int *dims,int bs)
3765c6c1daeSBarry Smith {
3775c6c1daeSBarry Smith   int              i;
3785c6c1daeSBarry Smith   PetscViewer_HDF5 *vhdf5 = (PetscViewer_HDF5*)viewer->data;
3795c6c1daeSBarry Smith   int32            sds_id,zero32[3],dims32[3];
3805c6c1daeSBarry Smith 
3815c6c1daeSBarry Smith   PetscFunctionBegin;
3825c6c1daeSBarry Smith   for (i = 0; i < d; i++) {
3835c6c1daeSBarry Smith     zero32[i] = 0;
3845c6c1daeSBarry Smith     dims32[i] = dims[i];
3855c6c1daeSBarry Smith   }
3865c6c1daeSBarry Smith   sds_id = SDcreate(vhdf5->sd_id, "Vec", DFNT_FLOAT32, d, dims32);
3875c6c1daeSBarry Smith   if (sds_id < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"SDcreate failed");
3885c6c1daeSBarry Smith   SDwritedata(sds_id, zero32, 0, dims32, xf);
3895c6c1daeSBarry Smith   SDendaccess(sds_id);
3905c6c1daeSBarry Smith   PetscFunctionReturn(0);
3915c6c1daeSBarry Smith }
3925c6c1daeSBarry Smith 
3935c6c1daeSBarry Smith #endif
394