aboutsummaryrefslogtreecommitdiff
path: root/src/Output2D.c
blob: a548ce4cc0b64d20e61b71b2586e5d83da40ea12 (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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#include "cctk.h"

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

#include "cctk_Parameters.h"
#include "CactusBase/IOUtil/src/ioutil_Utils.h"
#include "IOJpeg.h"

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

CCTK_FILEVERSION(CactusIO_IOJpeg_Output2D_c)

/* function prototypes */
static void CheckSteerableParameters (IOJpegGH *myGH);
static void SetOutputFlag (int vindex, const char *optstring, void *arg);

 /*@@
   @routine    IOJpeg_Output2DGH
   @date       Thu Sep 14 10:47:58 2000
   @author     Gerd Lanfermann
   @desc 
     Preparing 2D data for output
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
int IOJpeg_Output2DGH (const cGH *GH)
{
  DECLARE_CCTK_PARAMETERS
  int i;
  IOJpegGH *myGH;
  const char *name;
  char *fullname;
  int ierr=0;

  /* Get the GH extension for IOJpeg */
  myGH = (IOJpegGH *) GH->extensions [CCTK_GHExtensionHandle ("IOJpeg")];

  CheckSteerableParameters (myGH);

  if (myGH->out2D_every <= 0)
  {
    return (0);
  }

  /* Loop over all variables */
  for (i = 0; i < CCTK_NumVars (); i++)
  {

    if (IOJpeg_TimeFor2D (GH, i))
    {

      name     = CCTK_VarName (i);
      fullname = CCTK_FullName (i);

      if (!CCTK_Equals(verbose,"no"))
      {
        CCTK_VInfo (CCTK_THORNSTRING, "IOJpeg_Output2DGH: fullname / name = "
                    "%s / %s", fullname, name);
      }

      ierr=IOJpeg_Output2DVarAs (GH, fullname, name);

      free (fullname);

      /* Register variable as having 2D output this iteration */
      myGH->out2D_last [i] = GH->cctk_iteration;
    }
  }
  if (!CCTK_Equals(verbose,"no"))
  {
    CCTK_INFO("IOJpeg_Output2DGH Done");
  }

  return (ierr);
}


int IOJpeg_Output2DVarAs (const cGH *GH, const char *fullname, const char *alias)
{
  DECLARE_CCTK_PARAMETERS
  int vindex,ierr=0;

  vindex = CCTK_VarIndex (fullname);

  /* first, check if variable has storage assigned */
  if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (vindex)))
  {
    CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
                "No IOJpeg 2D output for '%s' (no storage)", fullname);
    return(-1);
  }

  if (!CCTK_Equals(verbose,"no"))
  {
    CCTK_VInfo (CCTK_THORNSTRING, "IOJpeg_Output2DVarAs: fullname, alias, "
                "index = (%s, %s, %d)", fullname, alias, vindex);
  }

  /* Do the 2D output */
  ierr=IOJpeg_Write2D (GH, vindex, alias);

  return (ierr);
}

int IOJpeg_TimeFor2D (const cGH *GH, int vindex)
{
  IOJpegGH *myGH;


  /* Get the GH extension for IOJpeg */
  myGH = (IOJpegGH *) GH->extensions [CCTK_GHExtensionHandle ("IOJpeg")];

  CheckSteerableParameters (myGH);

  /* Check if any output was requested */
  if(myGH->out2D_every <= 0)
  {
    return (0);
  }

  /* Check this variable should be output */
  if (! (myGH->do_out2D [vindex] && GH->cctk_iteration % myGH->out2D_every == 0))
  {
    return (0);
  }


  /* Check variable not already output this iteration */
  if (myGH->out2D_last [vindex] == GH->cctk_iteration)
  {
    CCTK_WARN (2, "Already done 2D output in IOJpeg");
    return (0);
  }

  return (1);
}

int IOJpeg_TriggerOutput2D (const cGH *GH, int vindex)
{
  DECLARE_CCTK_PARAMETERS
  IOJpegGH *myGH;
  const char *varname;
  int ierr=0;

  varname = CCTK_VarName (vindex);

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

  if (!CCTK_Equals(verbose,"no"))
  {
    CCTK_VInfo (CCTK_THORNSTRING, "IOJpeg_TriggerOutput2D: varname, index = "
                "(%s, %d)", varname, vindex);
  }

  /* Do the 2D output */
  ierr=IOJpeg_Write2D (GH, vindex, varname);

  /* Register variable as having 2D output this iteration */
  myGH->out2D_last [vindex] = GH->cctk_iteration;

  return (ierr);
}


/**************************** local functions ******************************/
static void CheckSteerableParameters (IOJpegGH *myGH)
{
  DECLARE_CCTK_PARAMETERS
  int out2D_vars_current_nset;
  int out_old;
  int i;
  static int out2D_vars_lastset = 0;

  out_old = myGH->out2D_every;

  /* How often to output */

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

  /* Report if frequency changed */

  if (myGH->out2D_every != out_old)
  {
    if (CCTK_Equals (newverbose, "standard") ||
        CCTK_Equals (newverbose, "full"))
    {
      CCTK_VInfo (CCTK_THORNSTRING, "IOJpeg_2D: Output every %d iterations",
                  myGH->out2D_every);
    }
    out_old = myGH->out2D_every;
  }

  /* re-parse the 'out2D_vars' parameter if it was changed */

  out2D_vars_current_nset = CCTK_ParameterQueryTimesSet ("out2D_vars",
                                                         CCTK_THORNSTRING);
  if (out2D_vars_current_nset != out2D_vars_lastset)
  {
    memset (myGH->do_out2D, 0, CCTK_NumVars ());
    CCTK_TraverseString (out2D_vars, SetOutputFlag, myGH->do_out2D,
                         CCTK_GROUP_OR_VAR);

    if (CCTK_Equals (newverbose, "standard") ||
        CCTK_Equals (newverbose, "full"))
    {
      for (i=0;i<CCTK_NumVars();i++)
      {
	if (myGH->do_out2D[i])
	{
	  CCTK_VInfo (CCTK_THORNSTRING, "IOJpeg_2D: Output for %s",CCTK_FullName(i));
	}
      }
    }    

    /* Save the last setting of 'out2D_vars' parameter */
    out2D_vars_lastset = out2D_vars_current_nset;
  }
}




/* callback for CCTK_TraverseString() to set the output flag
   for the given variable */
static void SetOutputFlag (int vindex, const char *optstring, void *arg)
{
  char *flags = (char *) arg;


  flags[vindex] = 1;

  if (optstring)
  {
    CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING,
                "Optional string '%s' in variable name ignored", optstring);
  }
}