aboutsummaryrefslogtreecommitdiff
path: root/src/ParseGeometry.c
blob: b0607080e7cf39bcd1e6d81e9adbe629b6b8695e (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
#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"

void IOJpeg_DefaultGeo(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 = -1;

  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_NumDirection(int sdim, int vdim)
{
  int numdir=-1;
  if (vdim==3) {
    switch (sdim) { 
      case 1: return(3);
      case 2: return(3);
      case 3: return(1);
    }
  } else if (vdim==2) {
    switch (sdim) { 
      case 1: return(2);
      case 2: return(1);
    }
  }
  else if (vdim==1) {
    switch (sdim) { 
      case 1: return(1);
    }
  }
  else printf("Bad dimension: %d \n",vdim);
  return(numdir);
}

int IOJpeg_SetDirection(int vdim, int sdim, int ci, int *direction)
{
  int retval=0;

  if (sdim>vdim) {
    printf("SetDirection: slabdim gt vdim");
    return(-1);
  }
  
  if (vdim==3) {
    if (sdim==2) {
      switch (ci) { 
        case 0: direction[0]=0; direction[1]=1;  break;
        case 1: direction[0]=0; direction[1]=2;  break;
        case 2: direction[0]=1; direction[1]=2;  break;
      }
    }
    else if (sdim==1) {
      switch (ci) { 
        case 0: direction[0]=0; break;
        case 1: direction[0]=1; break;
        case 2: direction[0]=2; break;
      }
    }
  }
  else if (vdim==2) {
    if (sdim==2) {
      direction[0]=0; direction[1]=1; 
    } else if (sdim==1) {
      switch (ci) { 
        case 0: direction[0]=0; break;
        case 1: direction[0]=1; break;
      }
    }
  } else retval = -1;
  return(retval);
}