1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <string.h> |
---|
4 | #ifdef _WIN32 |
---|
5 | # define rindex(X,Y) strrchr(X,Y) |
---|
6 | # define index(X,Y) strchr(X,Y) |
---|
7 | #else |
---|
8 | # include <strings.h> |
---|
9 | #endif |
---|
10 | |
---|
11 | #include "protos.h" |
---|
12 | #include "registry.h" |
---|
13 | #include "data.h" |
---|
14 | #include "sym.h" |
---|
15 | |
---|
16 | static int |
---|
17 | set_dim_strs_x ( node_t *node , char ddim[3][2][NAMELEN], char mdim[3][2][NAMELEN], char pdim[3][2][NAMELEN] , char * prepend , int sw_disregard_stag, int sw_reorder, int sw_no_prepend_r1 ) |
---|
18 | { |
---|
19 | int i, j, ii ; |
---|
20 | node_t *p ; |
---|
21 | char d, d1 ; |
---|
22 | char * stag ; |
---|
23 | char r1[NAMELEN] ; |
---|
24 | |
---|
25 | if ( sw_no_prepend_r1 ) { |
---|
26 | strcpy(r1,"") ; |
---|
27 | } else { |
---|
28 | strcpy(r1,"grid%") ; |
---|
29 | } |
---|
30 | if ( node == NULL ) return(1) ; |
---|
31 | for ( i = 0 ; i < 3 ; i++ ) |
---|
32 | for ( j = 0 ; j < 2 ; j++ ) |
---|
33 | { |
---|
34 | strcpy(ddim[i][j],"1") ; |
---|
35 | strcpy(mdim[i][j],"1") ; |
---|
36 | strcpy(pdim[i][j],"1") ; |
---|
37 | } |
---|
38 | |
---|
39 | for ( ii = 0 ; ii < ((node->ndims > 3)?3:node->ndims) ; ii++ ) |
---|
40 | { |
---|
41 | p = node->dims[ii] ; |
---|
42 | if ( sw_reorder ) { |
---|
43 | i = ii ; |
---|
44 | } else { |
---|
45 | switch( p->coord_axis ) |
---|
46 | { |
---|
47 | case(COORD_X) : i = 0 ; break ; |
---|
48 | case(COORD_Y) : i = 2 ; break ; |
---|
49 | case(COORD_Z) : i = 1 ; break ; |
---|
50 | default : break ; |
---|
51 | } |
---|
52 | } |
---|
53 | if ( p->len_defined_how == DOMAIN_STANDARD ) |
---|
54 | { |
---|
55 | char *ornt ; |
---|
56 | if ( node->proc_orient == ALL_X_ON_PROC ) ornt = "x" ; |
---|
57 | else if ( node->proc_orient == ALL_Y_ON_PROC ) ornt = "y" ; |
---|
58 | else ornt = "" ; |
---|
59 | |
---|
60 | if ( p->subgrid ) { |
---|
61 | |
---|
62 | |
---|
63 | switch( p->coord_axis ) |
---|
64 | { |
---|
65 | case(COORD_X) : d = 'i' ; d1 = 'x' ; break ; |
---|
66 | case(COORD_Y) : d = 'j' ; d1 = 'y' ; break ; |
---|
67 | case(COORD_Z) : d = 'k' ; d1 = 'z' ; break ; |
---|
68 | default : break ; |
---|
69 | } |
---|
70 | |
---|
71 | sprintf(ddim[i][0],"%s%cds",prepend,d) ; |
---|
72 | sprintf(ddim[i][1],"MAX(1,%s%cde * %ssr_%c) ",prepend,d,r1,d1) ; |
---|
73 | sprintf(mdim[i][0],"(%s%cms-1)*%ssr_%c+1",prepend,d,r1,d1) ; |
---|
74 | sprintf(mdim[i][1],"MAX(1,%s%cme*%ssr_%c)",prepend,d,r1,d1) ; |
---|
75 | sprintf(pdim[i][0],"(%s%cps-1)*%ssr_%c+1",prepend,d,r1,d1) ; |
---|
76 | sprintf(pdim[i][1],"MAX(1,%s%cpe*%ssr_%c)",prepend,d,r1,d1) ; |
---|
77 | |
---|
78 | } else { |
---|
79 | if ( sw_3dvar_iry_kludge ) { |
---|
80 | switch( p->coord_axis ) |
---|
81 | { |
---|
82 | /* vvv */ |
---|
83 | case(COORD_X) : d = 'i' ; stag = (node->stag_y||sw_disregard_stag)?"%s%cde":"(%s%cde-1)" ; break ; |
---|
84 | case(COORD_Y) : d = 'j' ; stag = (node->stag_x||sw_disregard_stag)?"%s%cde":"(%s%cde-1)" ; break ; |
---|
85 | /* ^^^ */ |
---|
86 | case(COORD_Z) : d = 'k' ; stag = (node->stag_z||sw_disregard_stag)?"%s%cde":"(%s%cde-1)" ; break ; |
---|
87 | default : stag = "1" ; break ; |
---|
88 | } |
---|
89 | } else { |
---|
90 | switch( p->coord_axis ) |
---|
91 | { |
---|
92 | case(COORD_X) : d = 'i' ; stag = (node->stag_x||sw_disregard_stag)?"%s%cde":"(%s%cde-1)" ; break ; |
---|
93 | case(COORD_Y) : d = 'j' ; stag = (node->stag_y||sw_disregard_stag)?"%s%cde":"(%s%cde-1)" ; break ; |
---|
94 | case(COORD_Z) : d = 'k' ; stag = (node->stag_z||sw_disregard_stag)?"%s%cde":"(%s%cde-1)" ; break ; |
---|
95 | default : stag = "1" ; break ; |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | sprintf(ddim[i][0],"%s%cds",prepend,d) ; |
---|
100 | sprintf(ddim[i][1],stag,prepend,d) ; /* note that stag has printf format info in it */ |
---|
101 | sprintf(mdim[i][0],"%s%cms%s",prepend,d,ornt) ; |
---|
102 | sprintf(mdim[i][1],"%s%cme%s",prepend,d,ornt) ; |
---|
103 | sprintf(pdim[i][0],"%s%cps%s",prepend,d,ornt) ; |
---|
104 | if ( ! sw_disregard_stag ) |
---|
105 | sprintf(pdim[i][1],"MIN( %s, %s%cpe%s )",ddim[i][1],prepend,d,ornt) ; |
---|
106 | else |
---|
107 | sprintf(pdim[i][1],"%s%cpe%s",prepend,d,ornt) ; |
---|
108 | } |
---|
109 | } |
---|
110 | else if ( p->len_defined_how == NAMELIST ) |
---|
111 | { |
---|
112 | if ( !strcmp( p->assoc_nl_var_s, "1" ) ) |
---|
113 | { |
---|
114 | sprintf(ddim[i][0],"1") ; |
---|
115 | sprintf(mdim[i][0],"1") ; |
---|
116 | sprintf(pdim[i][0],"1") ; |
---|
117 | } |
---|
118 | else |
---|
119 | { |
---|
120 | sprintf(ddim[i][0],"config_flags%%%s",p->assoc_nl_var_s) ; |
---|
121 | sprintf(mdim[i][0],"config_flags%%%s",p->assoc_nl_var_s) ; |
---|
122 | sprintf(pdim[i][0],"config_flags%%%s",p->assoc_nl_var_s) ; |
---|
123 | } |
---|
124 | sprintf(ddim[i][1],"config_flags%%%s",p->assoc_nl_var_e) ; |
---|
125 | sprintf(mdim[i][1],"config_flags%%%s",p->assoc_nl_var_e) ; |
---|
126 | sprintf(pdim[i][1],"config_flags%%%s",p->assoc_nl_var_e) ; |
---|
127 | } |
---|
128 | else if ( p->len_defined_how == CONSTANT ) |
---|
129 | { |
---|
130 | sprintf(ddim[i][0],"%d",p->coord_start ) ; |
---|
131 | sprintf(ddim[i][1],"%d",p->coord_end ) ; |
---|
132 | sprintf(mdim[i][0],"%d",p->coord_start ) ; |
---|
133 | sprintf(mdim[i][1],"%d",p->coord_end ) ; |
---|
134 | sprintf(pdim[i][0],"%d",p->coord_start ) ; |
---|
135 | sprintf(pdim[i][1],"%d",p->coord_end ) ; |
---|
136 | } |
---|
137 | } |
---|
138 | return(0) ; |
---|
139 | } |
---|
140 | |
---|
141 | int |
---|
142 | set_dim_strs ( node_t *node , char ddim[3][2][NAMELEN], char mdim[3][2][NAMELEN], char pdim[3][2][NAMELEN] , char * prepend , int sw_disregard_stag ) |
---|
143 | { |
---|
144 | set_dim_strs_x ( node , ddim, mdim, pdim, prepend , sw_disregard_stag, 1, 0 ) ; /* 1 = reorder according to strg order */ |
---|
145 | } |
---|
146 | |
---|
147 | /* version that doesn't permute according to index order -- always i, k, then j |
---|
148 | useful for standard argument lists -- e.g. calls to interp in nesting */ |
---|
149 | int |
---|
150 | set_dim_strs2 ( node_t *node , char ddim[3][2][NAMELEN], char mdim[3][2][NAMELEN], char pdim[3][2][NAMELEN] , char * prepend , int sw_disregard_stag ) |
---|
151 | { |
---|
152 | set_dim_strs_x ( node , ddim, mdim, pdim, prepend , sw_disregard_stag, 0, 0 ) ; /* 0 = reorder according to strg order */ |
---|
153 | } |
---|
154 | |
---|
155 | int |
---|
156 | set_dim_strs3 ( node_t *node , char ddim[3][2][NAMELEN], char mdim[3][2][NAMELEN], char pdim[3][2][NAMELEN] , char * prepend , int sw_disregard_stag ) |
---|
157 | { |
---|
158 | set_dim_strs_x ( node , ddim, mdim, pdim, prepend , sw_disregard_stag, 1, 1 ) ; /* 1 = reorder according to strg order */ |
---|
159 | } |
---|