aboutsummaryrefslogtreecommitdiff
path: root/src/GHExtension.c
blob: c541e05ebdb7ebe53b15eb60c34ad35ed0f71c96 (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
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "cctk.h"
#include "cctk_Parameters.h"
#include "cctk_Arguments.h"

#include "IOJpeg.h"

static const char *rcsid = "$Header$";

CCTK_FILEVERSION(CactusIO_IOJpeg_GHExtension_c)

void *IOJpeg_SetupGH (tFleshConfig *config, int convergence_level, cGH *GH);
void IOJpeg_SliceCenterSetup(CCTK_ARGUMENTS);
int IOJpeg_InitGH (cGH *GH);


void *IOJpeg_SetupGH (tFleshConfig *config, int convergence_level, cGH *GH)
{
  int numvars,iv;
  IOJpegGH *newGH;


  /* prevent compiler warnings about unused parameters */
  config = config;
  convergence_level = convergence_level;
  GH = GH;

  numvars = CCTK_NumVars ();

  newGH = (IOJpegGH *) malloc (sizeof (IOJpegGH));
  newGH->do_out2D   = (char *) malloc (numvars * sizeof (char));
  newGH->out2D_last = (int *) malloc (numvars * sizeof (int));

  /* Allocate geometry structure for each grid variable/array */
  newGH->out_geo = (IOJpegGeo_t**) malloc(numvars * sizeof (IOJpegGeo_t));
  for (iv=0;iv<numvars;iv++)
  {
    newGH->out_geo[iv] = (IOJpegGeo_t*) malloc(SLABSKEL_MAXDIM * sizeof (IOJpegGeo_t));
  }

  return (newGH);
}


int IOJpeg_InitGH (cGH *GH)
{
  DECLARE_CCTK_PARAMETERS
  int inum;
  IOJpegGH *myGH;


  myGH = (IOJpegGH *) GH->extensions [CCTK_GHExtensionHandle ("IOJpeg")];

  myGH->out2D_every = out_every > 0 ? out_every : -1;
  if (out2D_every > 0)
  {
    myGH->out2D_every = out2D_every;
  }

  for (inum=0; inum<CCTK_NumVars(); inum++)
  {
    myGH->out2D_last [inum] = -1;
  }

  /* Deal with the output directories */
  /* Check whether "outdirXD" was set.
     If so take this dir otherwise default to "IO::outdir" */
  myGH->outdir2D = CCTK_ParameterQueryTimesSet("out2D_dir",CCTK_THORNSTRING)>0 ?
                    strdup (out2D_dir) : strdup (outdir);

  /* create the output dir */
  if (CCTK_MyProc (GH) == 0)
  {
    int i;
    i = CCTK_CreateDirectory (0755, myGH->outdir2D);
    if (i < 0)
    {
      CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "IOASCII_InitGH: Problem creating 2D output directory '%s'",
                  myGH->outdir2D);
    }
    if (i > 0)
    {
      CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
                  "IOASCII_InitGH: 2D output directory '%s' already exists", 
                  myGH->outdir2D);
    }
  }

  return (0);
}



void IOJpeg_SliceCenterSetup(CCTK_ARGUMENTS)
{
  DECLARE_CCTK_PARAMETERS
  int inum,idim;
  int numvars;
  IOJpegGeo_t geo_default;
  IOJpegGH *myGH;


  myGH = (IOJpegGH *) cctkGH->extensions [CCTK_GHExtensionHandle ("IOJpeg")];

  numvars = CCTK_NumVars ();

  /* Loop over all slab dimension */
  for (idim = 0; idim < SLABSKEL_MAXDIM; idim++)
  {
    IOJpeg_DefaultGeo(cctkGH, idim, &geo_default);

    /* Set the default HDF5 slab geometry for slab with dimension -idim-*/
    for (inum = 0; inum < numvars; inum++)
    {
      myGH->out_geo[inum][idim] = geo_default;
      myGH->out_geo[inum][idim].vdim = CCTK_GroupDimFromVarI (inum);
    }

    /* allocate the flags array for every possible 2D hyperslab */
    myGH->advertised[idim] = (char *) calloc (numvars, 1);
  }

}