updated top-level README and version_decl for V4.5 (#1847)
[WRF.git] / tools / set_dim_strs.c
blob91d75b127c678e57c379a06454db2d72ae1f61c1
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
11 #include "protos.h"
12 #include "registry.h"
13 #include "data.h"
14 #include "sym.h"
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 )
19 int i, j, ii ;
20 node_t *p ;
21 char d, d1 ;
22 char * stag ;
23 char r1[NAMELEN] ;
25 if ( sw_no_prepend_r1 ) {
26 strcpy(r1,"") ;
27 } else {
28 strcpy(r1,"grid%") ;
30 if ( node == NULL ) return(1) ;
31 for ( i = 0 ; i < 3 ; i++ )
32 for ( j = 0 ; j < 2 ; j++ )
34 strcpy(ddim[i][j],"1") ;
35 strcpy(mdim[i][j],"1") ;
36 strcpy(pdim[i][j],"1") ;
39 for ( ii = 0 ; ii < ((node->ndims > 3)?3:node->ndims) ; ii++ )
41 p = node->dims[ii] ;
42 if ( sw_reorder ) {
43 i = ii ;
44 } else {
45 switch( p->coord_axis )
47 case(COORD_X) : i = 0 ; break ;
48 case(COORD_Y) : i = 2 ; break ;
49 case(COORD_Z) : i = 1 ; break ;
50 default : break ;
53 if ( p->len_defined_how == DOMAIN_STANDARD )
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 = "" ;
60 if ( p->subgrid ) {
63 switch( p->coord_axis )
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 ;
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) ;
78 } else {
79 if ( sw_3dvar_iry_kludge ) {
80 switch( p->coord_axis )
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 ;
89 } else {
90 switch( p->coord_axis )
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 ;
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) ;
110 else if ( p->len_defined_how == NAMELIST )
112 if ( !strcmp( p->assoc_nl_var_s, "1" ) )
114 sprintf(ddim[i][0],"1") ;
115 sprintf(mdim[i][0],"1") ;
116 sprintf(pdim[i][0],"1") ;
118 else
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) ;
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) ;
128 else if ( p->len_defined_how == CONSTANT )
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 ) ;
138 return(0) ;
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 )
144 set_dim_strs_x ( node , ddim, mdim, pdim, prepend , sw_disregard_stag, 1, 0 ) ; /* 1 = reorder according to strg order */
145 return 0; /* SamT: bug fix: return a value */
148 /* version that doesn't permute according to index order -- always i, k, then j
149 useful for standard argument lists -- e.g. calls to interp in nesting */
151 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 )
153 set_dim_strs_x ( node , ddim, mdim, pdim, prepend , sw_disregard_stag, 0, 0 ) ; /* 0 = reorder according to strg order */
154 return 0; /* SamT: bug fix: return a value */
158 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 )
160 set_dim_strs_x ( node , ddim, mdim, pdim, prepend , sw_disregard_stag, 1, 1 ) ; /* 1 = reorder according to strg order */
161 return 0; /* SamT: bug fix: return a value */