aboutsummaryrefslogtreecommitdiff
path: root/src/GHExtension.c
blob: 210db6aa76e612c3845cad6edc8ec1bb2ea847d3 (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
 /*@@
   @file      GHExtension.c
   @date      01 Oct 1999
   @author    Jonghyun Lee
   @desc      IOPanda GH extension stuff
   @enddesc 
   @history
   @endhistory
 @@*/

/*#define DEBUG_IO*/

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

#include "cctk_Flesh.h"
#include "cctk_Groups.h"
#include "cctk_Comm.h"
#include "cctk_Misc.h"
#include "cctk_GHExtensions.h"
#include "cctk_parameters.h"
#include "cctk_WarnLevel.h"
#ifdef	CACTUSPUGH_PUGH
#include "CactusPUGH/PUGH/src/include/pugh.h"
#endif
#include "CactusBase/IOUtil/src/ioGH.h"
#include "ioPandaGH.h"

void Panda_Create(int, int);

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

  numvars = CCTK_NumVars ();

  newGH = (pandaGH *) malloc (sizeof (pandaGH));
  newGH->IO_3Dnum = (int *) malloc (numvars * sizeof (int));
  newGH->IO_3Dlast = (int *) malloc (numvars * sizeof (int));

  return (newGH);
}

int IOPanda_InitGH (cGH *GH)
{
  DECLARE_CCTK_PARAMETERS
  int i;
  ioGH *ioUtilGH;
  pandaGH *myGH; 

  /* get the handles for IOUtil and IOPanda extensions */
  ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")];
  myGH = (pandaGH *) GH->extensions [CCTK_GHExtensionHandle ("IOPanda")];
  
  /* How often to output */
  myGH->IO_3Devery = out_every;
  if (out3D_every > 0)
    myGH->IO_3Devery = out3D_every;

  InitIONum (myGH->IO_3Dnum, out3D_vars);

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

  /* Create the output directories */
  if (myGH->IO_3Devery > 0) {
    if (CCTK_MyProc (GH) == 0) {
      FILE *fp;

      if (CCTK_mkdir (myGH->outpfx_3D) != 0)
        CCTK_WARN (2,"Problem creating IO 3D directory");
      fp = fopen("FILEPREFIX", "w");
      fprintf(fp, "%s", myGH->outpfx_3D);
      fclose(fp);
    }
  }

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

  myGH->fileList_3D = NULL;

  Panda_Create(ioUtilGH->ioproc_every, 1);

  return (0);
}