aboutsummaryrefslogtreecommitdiff
path: root/src/GHExtension.c
blob: b11e7ab1e1ec93ec74ac4c3bbd833f6285fb6b5c (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
 /*@@
   @file      GHExtension.c
   @date      Fri May 21 1999
   @author    Thomas Radke
   @desc 
   IOFlexIO GH extension stuff.
   @enddesc 
   @history
   @hauthor Thomas Radke @hdate May 21 1999
   @hdesc Just copied from thorn IO.
   @endhistory
 @@*/

/*#define DEBUG_IO*/

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

#include "flesh.h"
#include "Groups.h"
#include "Comm.h"
#include "Misc.h"
#include "GHExtensions.h"
#include "cctk_parameters.h"
#include "WarnLevel.h"
#ifdef	CACTUSPUGH_PUGH
#include "CactusPUGH/PUGH/src/include/pugh.h"
#endif
#include "CactusBase/IOUtil/src/ioGH.h"
#include "ioFlexGH.h"


void *IOFlexIO_SetupGH (tFleshConfig *config, int convergence_level, cGH *GH)
{
  int i, numvars;
  flexioGH *newGH;

  numvars = CCTK_NumVars ();

  newGH = (flexioGH *) malloc (sizeof (flexioGH));
  newGH->IO_2Dnum = (int *) malloc (numvars * sizeof (int));
  newGH->IO_3Dnum = (int *) malloc (numvars * sizeof (int));
  newGH->IO_2Dlast = (int *) malloc (numvars * sizeof (int));
  newGH->IO_3Dlast = (int *) malloc (numvars * sizeof (int));

  newGH->IEEEfname_3D = (char **) malloc (numvars * sizeof (char **));

  for (i = 0; i < numvars; i++)
    newGH->IEEEfname_3D [i] = (char *) malloc (512 * sizeof (char));
  newGH->IEEEfile_3D = (IOFile *) malloc (numvars * sizeof (IOFile));

  return (newGH);
}

int IOFlexIO_InitGH (cGH *GH)
{
  DECLARE_CCTK_PARAMETERS
  int i;
  ioGH *ioUtilGH;
  flexioGH *myGH; 

  /* get the handles for IOUtil and IOFlexIO extensions */
  ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")];
  myGH = (flexioGH *) GH->extensions [CCTK_GHExtensionHandle ("IOFlexIO")];

  /* How often to output */
  myGH->IO_2Devery = output_every;
  myGH->IO_3Devery = output_every;
  if (output2d_every > 0)
    myGH->IO_2Devery = output2d_every;
  if (output3d_every > 0)
    myGH->IO_3Devery = output3d_every;

  InitIONum (myGH->IO_2Dnum, output2D);
  InitIONum (myGH->IO_3Dnum, output3D);

  /* Deal with the output directories */
  myGH->outpfx_2D = outdir;
  myGH->outpfx_3D = outdir;
  if (!CCTK_Equals(outdir2d,"outdir"))
    myGH->outpfx_2D = outdir2d;
  if (!CCTK_Equals(outdir3d,"outdir"))
    myGH->outpfx_3D = outdir3d;

  /* Create the output directories */
  if (myGH->IO_2Devery > 0) {
    if (CCTK_MyProc (GH) == 0) {
      char *command = (char *) malloc (1024 * sizeof (char));

      sprintf (command, "mkdir -p %s", myGH->outpfx_2D);
      if (system (command) < 0)
        CCTK_WARN (1,"Problem creating IO 2D directory");
      free (command);
    }
  }
  if (myGH->IO_3Devery > 0) {
    if (CCTK_MyProc (GH) == 0) {
      char *command = (char *) malloc (1024 * sizeof (char));

      sprintf (command, "mkdir -p %s", myGH->outpfx_3D);
      if (system (command) < 0)
        CCTK_WARN (1,"Problem creating IO 3D directory");
      free (command);
    }
  }

  for (i=0; i<CCTK_NumVars(); i++)
    myGH->IO_2Dlast [i] = myGH->IO_3Dlast [i] = -1;

  myGH->reuse_fh = reuse_fh;

  /* Only have reuse for chunked data */
  if (myGH->reuse_fh && ! ioUtilGH->unchunked) {
    CCTK_WARN (2, "Cannot reuse handles with unchunked data. "
                  "Ignoring parameter 'reuse_fh'");
    myGH->reuse_fh = 0;
  }

  /* Only have reuse if not one file per slice */
  if (myGH->reuse_fh && onefileperslice) {
    CCTK_WARN (2, "Cannot reuse handles with 'onefileperslice = yes'. "
                  "Ignoring parameter 'reuse_fh'");
    myGH->reuse_fh = 0;
  }

  myGH->filenameList2D = NULL;
  myGH->fileList_3D = NULL;

  return (0);
}

int IOFlexIO_rfrTraverseGH (cGH *GH, int rfrpoint)
{
  return 0;
}