12 enum sw_ranges
{ COLON_RANGE
, ARGADJ
, GRIDREF
} ;
13 enum sw_pointdecl
{ POINTERDECL
, NOPOINTERDECL
} ;
16 gen_state_struct ( char * dirname
)
20 char * fn
= "state_struct.inc" ;
23 if ( strlen(dirname
) > 0 ) { sprintf(fname
,"%s/%s",dirname
,fn
) ; }
24 if ((fp
= fopen( fname
, "w" )) == NULL
) return(1) ;
25 print_warning(fp
,fname
) ;
26 gen_decls ( fp
, &Domain
, COLON_RANGE
, POINTERDECL
, FIELD
| RCONFIG
| FOURD
, DRIVER_LAYER
) ;
27 close_the_file( fp
) ;
32 gen_state_subtypes ( char * dirname
)
36 char * fn
= "state_subtypes.inc" ;
39 if ( strlen(dirname
) > 0 ) { sprintf(fname
,"%s/%s",dirname
,fn
) ; }
41 if ((fp
= fopen( fname
, "w" )) == NULL
) return(1) ;
42 print_warning(fp
,fname
) ;
43 gen_state_subtypes1( fp
, &Domain
, COLON_RANGE
, POINTERDECL
, FIELD
| RCONFIG
| FOURD
) ;
49 gen_dummy_decls ( char * dn
)
53 char * fn
= "dummy_decl.inc" ;
55 if ( dn
== NULL
) return(1) ;
56 if ( strlen(dn
) > 0 ) { sprintf(fname
,"%s/%s",dn
,fn
) ; }
57 else { sprintf(fname
,"%s",fn
) ; }
58 if ((fp
= fopen( fname
, "w" )) != NULL
) {
59 print_warning(fp
,fname
) ;
60 gen_decls ( fp
, &Domain
, GRIDREF
, NOPOINTERDECL
, FIELD
| FOURD
, MEDIATION_LAYER
) ;
61 fprintf(fp
,"#undef COPY_IN\n") ;
62 fprintf(fp
,"#undef COPY_OUT\n") ;
63 close_the_file( fp
) ;
69 gen_dummy_decls_new ( char * dn
)
73 char * fn
= "dummy_new_decl.inc" ;
75 if ( dn
== NULL
) return(1) ;
76 if ( strlen(dn
) > 0 ) { sprintf(fname
,"%s/%s",dn
,fn
) ; }
77 else { sprintf(fname
,"%s",fn
) ; }
78 if ((fp
= fopen( fname
, "w" )) != NULL
) {
79 print_warning(fp
,fname
) ;
80 gen_decls ( fp
, &Domain
, GRIDREF
, NOPOINTERDECL
, FOURD
| FIELD
| BDYONLY
, MEDIATION_LAYER
) ;
81 fprintf(fp
,"#undef COPY_IN\n") ;
82 fprintf(fp
,"#undef COPY_OUT\n") ;
83 close_the_file( fp
) ;
90 gen_i1_decls ( char * dn
)
93 char fname
[NAMELEN
], post
[NAMELEN
] ;
94 char * fn
= "i1_decl.inc" ;
98 if ( dn
== NULL
) return(1) ;
99 if ( strlen(dn
) > 0 ) { sprintf(fname
,"%s/%s",dn
,fn
) ; }
100 else { sprintf(fname
,"%s",fn
) ; }
101 if ((fp
= fopen( fname
, "w" )) != NULL
) {
102 print_warning(fp
,fname
) ;
103 gen_decls ( fp
, &Domain
, GRIDREF
, NOPOINTERDECL
, I1
, MEDIATION_LAYER
) ;
105 /* now generate tendencies for 4d vars if specified */
106 for ( p
= FourD
; p
!= NULL
; p
= p
->next
)
108 if ( p
->node_kind
& FOURD
&& p
->has_scalar_array_tendencies
)
110 sprintf(fname
,"%s_tend",p
->name
) ;
111 sprintf(post
,",num_%s)",p
->name
) ;
112 dimspec
=dimension_with_ranges( "grid%",",DIMENSION(",-1,t2
,p
,post
,"" ) ;
113 /* type dim pdecl name */
114 fprintf(fp
, "%-10s%-20s%-10s :: %s\n",
115 field_type( t1
, p
) ,
119 sprintf(fname
,"%s_old",p
->name
) ;
120 sprintf(post
,",num_%s)",p
->name
) ;
121 dimspec
=dimension_with_ranges( "grid%",",DIMENSION(",-1,t2
,p
,post
,"" ) ;
122 /* type dim pdecl name */
123 fprintf(fp
, "#ifndef NO_I1_OLD\n") ;
124 fprintf(fp
, "%-10s%-20s%-10s :: %s\n",
125 field_type( t1
, p
) ,
129 fprintf(fp
, "#endif\n") ;
132 close_the_file( fp
) ;
138 gen_decls ( FILE * fp
, node_t
* node
, int sw_ranges
, int sw_point
, int mask
, int layer
)
142 char fname
[NAMELEN
], post
[NAMELEN
] ;
146 if ( node
== NULL
) return(1) ;
148 bdyonly
= mask
& BDYONLY
;
150 /* make two passes; the first is for scalars, second for arrays. */
151 /* do it this way so that the scalars get declared first (some compilers complain */
152 /* if a scalar is used to declare an array before it's declared) */
154 for ( ipass
= 0 ; ipass
< 2 ; ipass
++ )
156 for ( p
= node
->fields
; p
!= NULL
; p
= p
->next
)
158 if ( p
->node_kind
& mask
)
160 /* add an extra dimension to the 4d arrays. */
161 /* note the call to dimension_with_colons, below, does this by itself */
162 /* but dimension_with_ranges needs help (since the last arg is not just a colon) */
164 if ( p
->node_kind
& FOURD
) {
165 sprintf(post
,",num_%s)",field_name(t4
,p
,0)) ;
170 for ( tag
= 1 ; tag
<= p
->ntl
; tag
++ )
172 strcpy(fname
,field_name(t4
,p
,(p
->ntl
>1)?tag
:0)) ;
174 if ( ! p
->boundary_array
|| ! sw_new_bdys
) {
178 dimspec
=dimension_with_colons( ",DIMENSION(",t2
,p
,")" ) ; break ;
180 dimspec
=dimension_with_ranges( "grid%",",DIMENSION(",-1,t2
,p
,post
,"" ) ; break ;
182 dimspec
=dimension_with_ranges( "",",DIMENSION(",-1,t2
,p
,post
,"" ) ; break ;
185 dimspec
="dummy" ; /* allow fall through on next tests. dimension with ranges will be called again anyway for bdy arrays */
188 if ( !strcmp( dimspec
, "" ) && ipass
== 1 ) continue ; /* short circuit scalars on 2nd pass */
189 if ( strcmp( dimspec
, "" ) && ipass
== 0 ) continue ; /* short circuit arrays on 2nd pass */
190 if ( bdyonly
&& p
->node_kind
& FIELD
&& ! p
->boundary_array
) continue ; /* short circuit all fields except bdy arrrays */
192 if ( p
->boundary_array
&& sw_new_bdys
) {
193 if ( layer
== DRIVER_LAYER
|| associated_with_4d_array(p
) ) {
195 for ( bdy
= 1; bdy
<=4 ; bdy
++ ) {
199 dimspec
=dimension_with_colons( ",DIMENSION(",t2
,p
,")" ) ; break ;
201 dimspec
=dimension_with_ranges( "grid%",",DIMENSION(",bdy
,t2
,p
,post
,"" ) ; break ;
203 dimspec
=dimension_with_ranges( "",",DIMENSION(",bdy
,t2
,p
,post
,"" ) ; break ;
205 /* type dim pdecl name */
206 fprintf(fp
, "%-10s%-20s%-10s :: %s%s\n",
207 field_type( t1
, p
) ,
209 (sw_point
==POINTERDECL
)?declare_array_as_pointer(t3
,p
):"" ,
210 fname
, bdy_indicator( bdy
) ) ;
217 dimspec
=dimension_with_colons( ",DIMENSION(",t2
,p
,")" ) ; break ;
219 dimspec
=dimension_with_ranges( "grid%",",DIMENSION(",-1,t2
,p
,post
,"" ) ; break ;
221 dimspec
=dimension_with_ranges( "",",DIMENSION(",-1,t2
,p
,post
,"" ) ; break ;
223 /* type dim pdecl name */
224 fprintf(fp
, "%-10s%-20s%-10s :: %s\n",
225 field_type( t1
, p
) ,
227 (sw_point
==POINTERDECL
)?declare_array_as_pointer(t3
,p
):"" ,
238 gen_state_subtypes1 ( FILE * fp
, node_t
* node
, int sw_ranges
, int sw_point
, int mask
)
243 char TypeName
[NAMELEN
] ;
244 char tempname
[NAMELEN
] ;
245 if ( node
== NULL
) return(1) ;
246 for ( p
= node
->fields
; p
!= NULL
; p
= p
->next
)
248 if ( p
->type
!= NULL
)
249 if ( p
->type
->type_type
== DERIVED
)
251 new = 1 ; /* determine if this is a new type -ajb */
252 strcpy( tempname
, p
->type
->name
) ;
253 for ( i
= 0 ; i
< get_num_typedefs() ; i
++ )
255 strcpy( TypeName
, get_typename_i(i
) ) ;
256 if ( ! strcmp( TypeName
, tempname
) ) new = 0 ;
259 if ( new ) /* add this type to the history and generate declarations -ajb */
261 add_typedef_name ( tempname
) ;
262 gen_state_subtypes1 ( fp
, p
->type
, sw_ranges
, sw_point
, mask
) ;
263 fprintf(fp
,"TYPE %s\n",p
->type
->name
) ;
264 gen_decls ( fp
, p
->type
, sw_ranges
, sw_point
, mask
, DRIVER_LAYER
) ;
265 fprintf(fp
,"END TYPE %s\n",p
->type
->name
) ;
272 /* old version of gen_state_subtypes1 -ajb */
275 gen_state_subtypes1 ( FILE * fp , node_t * node , int sw_ranges , int sw_point , int mask )
279 if ( node == NULL ) return(1) ;
280 for ( p = node->fields ; p != NULL ; p = p->next )
282 if ( p->type != NULL )
283 if ( p->type->type_type == DERIVED )
285 gen_state_subtypes1 ( fp , p->type , sw_ranges , sw_point , mask ) ;
286 fprintf(fp,"TYPE %s\n",p->type->name) ;
287 gen_decls ( fp , "", p->type , sw_ranges , sw_point , mask , DRIVER_LAYER ) ;
288 fprintf(fp,"END TYPE %s\n",p->type->name) ;