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

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

#include "util_String.h"   
#include "IOJpeg.h"
#include "CactusBase/IOASCII/src/ioASCIIGH.h"

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

CCTK_FILEVERSION(CactusIO_IOJpeg_ParseGeometry_c)

void IOJpeg_DefaultGeo(const cGH *GH, int sdim, IOJpegGeo_t *geo) {
  DECLARE_CCTK_PARAMETERS

  asciiioGH *asGH;
  int idim,ti;
  const char *tmp_origin, *tmp_downs, *tmp_length;
  const char *token;

  asGH = (asciiioGH *) GH->extensions 
    [CCTK_GHExtensionHandle ("IOASCII")];

  geo->vdim = -1;
  geo->sdim = sdim;

  for (idim=0;idim<SLABSKEL_MAXDIM;idim++) {
    geo->direction[idim] = idim;
    geo->slab_start[idim]= 0;
    geo->length[idim]    =-1;
    geo->actlen[idim]    =-1;
    geo->downs[idim]     = 1;
  }
  
  /* FIXME: we use spxyz, which is hardcoded to 3D */
  for (idim=0;idim<3;idim++)
    geo->slab_start[idim]=asGH->spxyz[2][(idim+1)%3][idim];
 
  /* Parse the parameter of the requested dimension */
  switch (sdim) {
     case 2: 
      tmp_origin = origin2D; 
      tmp_downs  = downsampling2D;   
      tmp_length = length2D; 
      break;
     default: 
      tmp_origin = origin2D; 
      tmp_downs  = downsampling2D;   
      tmp_length = length2D;  
      break;
  }

  /* Origin, set from parameter only if parameter value .ne. -1 */
  idim=0;
  while((token = Util_StrSep(&tmp_origin,","))) {
    ti=atoi(token);
    if (ti>-1) geo->slab_start[idim++] = ti;
  }
  ti = atoi(tmp_origin);
  if (ti>-1) geo->slab_start[idim] = ti;

  /* Downsample */
  idim=0;
   while((token = Util_StrSep(&tmp_downs,","))) {
    geo->downs[idim++]=atoi(token);
  }
  geo->downs[idim] = atoi(tmp_downs);

  /* Length */
  idim=0;
  while((token = Util_StrSep(&tmp_length,","))) {
    geo->length[idim++]=atoi(token);
  }
  geo->length[idim] = atoi(tmp_length);
}


int IOJpeg_SetDirection (IOJpegGeo_t *geometry, int direction)
{
  int retval = 0;


  if (geometry->vdim == 3)
  {
    if (geometry->sdim == 2)
    {
      switch (direction)
      { 
        case 0: geometry->direction[0]=0; geometry->direction[1]=1;  break;
        case 1: geometry->direction[0]=0; geometry->direction[1]=2;  break;
        case 2: geometry->direction[0]=1; geometry->direction[1]=2;  break;
      }
    }
    else if (geometry->sdim == 1)
    {
      switch (direction)
      {
        case 0: geometry->direction[0]=0; break;
        case 1: geometry->direction[0]=1; break;
        case 2: geometry->direction[0]=2; break;
      }
    }
  }
  else if (geometry->vdim==2)
  {
    if (geometry->sdim == 2)
    {
      geometry->direction[0]=0; geometry->direction[1]=1; 
    }
    else if (geometry->sdim == 1)
    {
      switch (direction)
      {
        case 0: geometry->direction[0]=0; break;
        case 1: geometry->direction[0]=1; break;
      }
    }
  }
  else
  {
    retval = -1;
  }

  return (retval);
}