aboutsummaryrefslogtreecommitdiff
path: root/src/Write.c
blob: 0c0b37339f7dec9bfb59c30307a996c77328bed6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*@@
   @file      Write.c
   @date      Fri May 21 1999
   @author    Thomas Radke
   @desc 
   Output and trigger routines for FiberBundle output into HDF5 files
   @enddesc 
   @history
   @hauthor Thomas Radke @hdate May 21 1999
   @hdesc Just copied from thorn FlexIO.
   @hendhistory
 @@*/


#include <stdio.h>
#include <stdlib.h>

#include "cctk.h"
#include "cctk_Parameters.h"
#include "StoreNamedData.h"
#include "CactusBase/IOUtil/src/ioGH.h"
#include "StreamedHDF5GH.h"


/* local function prototypes */
void StreamedHDF5i_DumpParameters (cGH *GH, hid_t group);
void StreamedHDF5i_DumpGHExtensions (cGH *GH, hid_t group);


/*@@
  @routine Write
  @author  Paul Walker 
  @date    Feb 1997
  @calledby StreamedHDF5_OutputVarAs, StreamedHDF5_TriggerOutput
  @var     GH
  @vdesc   Pointer to CCTK GH
  @vtype   cGH
  @vio     in
  @vcomment
  @endvar
  @var     index
  @vdesc   index of variable to output
  @vtype   int
  @vio     in
  @vcomment
  @endvar
  @var     alias
  @vdesc   alias name of variable to output
  @vtype   const char *
  @vio     in
  @vcomment
  @endvar
@@*/
void StreamedHDF5_Write (cGH *GH, int index, const char *alias)
{
  DECLARE_CCTK_PARAMETERS
  int vtype;
  int timelevel;
  ioGH *ioUtilGH;
  StreamedHDF5GH *myGH;
  hid_t fid, plist;
#if 0
  hid_t group;
#endif


  /* first, check if variable has storage assigned */
  if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (index)))
  {
    char *fullname = CCTK_FullName (index);
    CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
                "No StreamedHDF5 output for '%s' (no storage)", fullname);
    free (fullname);
    return;
  }

  /* check if variable is of type GF or ARRAY */
  vtype = CCTK_GroupTypeFromVarI (index);
  if (vtype != CCTK_GF && vtype != CCTK_ARRAY)
  {
    char *fullname = CCTK_FullName (index);
    CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
                "No StreamedHDF5 output for '%s' (not an array type)", fullname);
    free (fullname);
    return;
  }

  /* Get the handles for IO and StreamedHDF5 extensions */
  ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")];
  myGH = (StreamedHDF5GH *) GH->extensions [CCTK_GHExtensionHandle ("StreamedHDF5")];

  fid = -1;
  if (CCTK_MyProc (GH) == 0)
  {
    /* filename is not used if we pass a socket descriptor
       but it must not be NULL or an empty string */
    static const char *filename = "bla";


    if (verbose)
      CCTK_VInfo (CCTK_THORNSTRING, "Opening HDF5 output file on port %d",
                  port);

    /* set VFD to stream and open the file */
    CACTUS_IOHDF5_ERROR (plist = H5Pcreate (H5P_FILE_ACCESS));
    CACTUS_IOHDF5_ERROR (H5Pset_fapl_stream (plist, 0, myGH->socket));
    CACTUS_IOHDF5_ERROR (fid = H5Fcreate (filename, H5F_ACC_TRUNC,
                                          H5P_DEFAULT, plist));
    CACTUS_IOHDF5_ERROR (H5Pclose (plist));

#if 0
    /* output global attributes */
    if (verbose)
        CCTK_INFO ("Dumping GH extensions ...");

    CACTUS_IOHDF5_ERROR (group = H5Gcreate (fid, GHEXTENSIONS_GROUP, 0));
    StreamedHDF5i_DumpGHExtensions (GH, group);
    CACTUS_IOHDF5_ERROR (H5Gclose (group));
#endif

  }

  /* get the current timelevel */
  timelevel = CCTK_NumTimeLevelsFromVarI (index) - 1;
  if (timelevel > 0)
    timelevel--;

  /* output the data */
  StreamedHDF5_DumpVar (GH, index, timelevel, fid);

  /* close the file */
  if (fid >= 0)
  {
    if (verbose)
      CCTK_INFO ("Closing HDF5 output file from this iteration");
    CACTUS_IOHDF5_ERROR (H5Fclose (fid));
  }

}