aboutsummaryrefslogtreecommitdiff
path: root/src/GHExtension.c
blob: df3d69c182d7e3f8c551c2b9621641250bfe30e6 (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
 /*@@
   @file      GHExtension.c
   @date      Friday 18th September
   @author    Gabrielle Allen
   @desc 
   IO GH extension stuff.
   @enddesc 
 @@*/

/* #define DEBUG_IO */

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

#include "cctk.h"
#include "cctk_Parameters.h"
#include "iobasicGH.h"

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

CCTK_FILEVERSION(CactusBase_IOBasic_GHExtension_c)

void *IOBasic_SetupGH (tFleshConfig *config, int convergence_level, cGH *GH)
{
  int i;
  iobasicGH *newGH;

  newGH = (iobasicGH *) malloc (sizeof (iobasicGH));
  newGH->infovals = (CCTK_REAL **) 
    malloc (CCTK_NumVars () * sizeof (CCTK_REAL *));
  for (i=0;i<CCTK_NumVars ();i++) 
  {
    newGH->infovals[i] = (CCTK_REAL *) malloc (2  * sizeof (CCTK_REAL));
  }

  newGH->do_outScalar = (char *) malloc (CCTK_NumVars () * sizeof (char));
  newGH->outScalar_last = (int *) malloc (CCTK_NumVars () * sizeof (int));

  newGH->do_outInfo = (char *) malloc (CCTK_NumVars () * sizeof (char));
  newGH->outInfo_last = (int *) malloc (CCTK_NumVars () * sizeof (int));

  return newGH;
}

int IOBasic_InitGH (cGH *GH)
{
  int i;
  iobasicGH *myGH; 
  DECLARE_CCTK_PARAMETERS

  /* get the handles for IOBasic extensions */
  myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")];
  myGH->filenameListScalar = NULL;

  /* How often to output */
  myGH->outInfo_every  = out_every > 0 ? out_every : -1;
  if (outInfo_every > 0)
  {
    myGH->outInfo_every = outInfo_every;
  }

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

  /* Check whether "outdirScalar" was set.
     If so take this dir otherwise default to "IO::outdir" */
  if (CCTK_ParameterQueryTimesSet ("outdirScalar", CCTK_THORNSTRING) > 0)
  {
    myGH->outdirScalar = strdup (outdirScalar);
  }  
  else
  {
    myGH->outdirScalar = strdup (outdir);
  }

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

  for (i=0; i<CCTK_NumVars(); i++)
  {
    myGH->outScalar_last[i] = -1;
    myGH->outInfo_last [i]  = -1;
    myGH->infovals[i][0]    = 0.0;
    myGH->infovals[i][1]    = 0.0;
  }

  myGH->filenameListScalar = NULL;

  /* Provide Information */
  if (CCTK_Equals(newverbose,"standard") || CCTK_Equals(newverbose,"full"))
  {
    if (myGH->outInfo_every > 0)
    {
      CCTK_VInfo("IOBasic","Info: Output every %d iterations",
		 myGH->outInfo_every);
    }
    else
    {
      CCTK_VInfo("IOBasic","Info: No output requested");
    }
    CCTK_INFO("Info: Output to screen (standard output)");
    if (myGH->outScalar_every > 0)
    {
      CCTK_VInfo("IOBasic","Scalar: Output every %d iterations",
		 myGH->outScalar_every);
    }
    else
    {
      CCTK_VInfo("IOBasic","Scalar: No output requested");
    }
    CCTK_VInfo("IOBasic","Scalar: Output to directory %s",myGH->outdirScalar);
  }

  return 0;
}