11 dimension_with_colons( char * pre
, char * tmp
, node_t
* p
, char * post
)
14 if ( p
== NULL
) return("") ;
15 if ( p
->ndims
<= 0 && ! p
->boundary_array
) return("") ;
17 if ( pre
!= NULL
) strcat(tmp
,pre
) ;
18 if ( p
->boundary_array
)
20 if ( ! sw_new_bdys
) { strcat( tmp
,":,") ; }
21 if ( !strcmp( p
->use
, "_4d_bdy_array_" ) ) {
22 strcat( tmp
, ":,:,:,:" ) ; /* boundary array for 4d tracer array */
24 strcat( tmp
, ":,:,:" ) ; /* most always have four dimensions */
29 for ( i
= 0 ; i
< p
->ndims
; i
++ ) strcat(tmp
,":,") ;
30 if ( p
->node_kind
& FOURD
) strcat(tmp
,":,") ; /* add an extra for 4d arrays */
31 tmp
[strlen(tmp
)-1] = '\0' ;
33 if ( post
!= NULL
) strcat(tmp
,post
) ;
38 dimension_with_ones( char * pre
, char * tmp
, node_t
* p
, char * post
)
41 char r
[NAMELEN
],s
[NAMELEN
],four_d
[NAMELEN
] ;
43 if ( p
== NULL
) return("") ;
44 if ( p
->ndims
<= 0 && ! p
->boundary_array
) return("") ;
46 if ( pre
!= NULL
) strcat(tmp
,pre
) ;
48 if ( p
->boundary_array
)
50 if ( ! sw_new_bdys
) { strcpy( tmp
,"(1,") ; }
51 if ( !strcmp( p
->use
, "_4d_bdy_array_" ) ) { /* if a boundary array for a 4d tracer */
52 strcpy(s
, p
->name
) ; /* copy the name and then remove everything after last underscore */
53 if ((pp
=rindex( s
, '_' )) != NULL
) *pp
= '\0' ;
54 sprintf( four_d
, "num_%s,", s
) ;
56 strcpy( four_d
, "" ) ;
59 if ( !strcmp( p
->use
, "_4d_bdy_array_" ) ) {
60 sprintf( r
, "1,1,1,%s", four_d
) ; /* boundary array for 4d tracer array */
63 strcat( tmp
, "1,1,1," ) ;
65 tmp
[strlen(tmp
)-1] = '\0' ;
69 for ( i
= 0 ; i
< p
->ndims
; i
++ ) strcat(tmp
,"1,") ;
70 if ( p
->node_kind
& FOURD
) strcat(tmp
,"1,") ; /* add an extra for 4d arrays */
71 tmp
[strlen(tmp
)-1] = '\0' ;
73 if ( post
!= NULL
) strcat(tmp
,post
) ;
78 dimension_with_ranges( char * refarg
, char * pre
,
79 int bdy
, /* as defined in data.h */
80 char * tmp
, node_t
* p
, char * post
,
81 char * nlstructname
) /* added 20020130;
82 provides name (with %) of structure in
83 which a namelist supplied dimension
84 should be dereference from, or "" */
88 char r
[NAMELEN
],s
[NAMELEN
],four_d
[NAMELEN
] ;
89 int bdex
, xdex
, ydex
, zdex
;
90 node_t
*xdim
, *ydim
, *zdim
;
92 if ( p
== NULL
) return("") ;
93 if ( p
->ndims
<= 0 && !p
->boundary_array
) return("") ;
95 if ( pre
!= NULL
) strcat(tmp
,pre
) ;
97 if ( refarg
!= NULL
) strcat(r
,refarg
) ;
99 if ( p
->boundary_array
)
103 xdim
= get_dimnode_for_coord( p
, COORD_X
) ;
104 ydim
= get_dimnode_for_coord( p
, COORD_Y
) ;
105 zdim
= get_dimnode_for_coord( p
, COORD_Z
) ;
107 { fprintf(stderr
,"dimension_with_ranges: y dimension not specified for %s\n",p
->name
) ; return("") ; }
109 { fprintf(stderr
,"dimension_with_ranges: x dimension not specified for %s\n",p
->name
) ; return("") ; }
111 xdex
= xdim
->dim_order
;
112 ydex
= ydim
->dim_order
;
114 if ( !strcmp( p
->use
, "_4d_bdy_array_" ) ) { /* if a boundary array for a 4d tracer */
115 strcpy(s
, p
->name
) ; /* copy the name and then remove everything after last underscore */
116 if ((pp
=rindex( s
, '_' )) != NULL
) *pp
= '\0' ;
117 sprintf( four_d
, "num_%s,", s
) ;
119 strcpy( four_d
, "" ) ;
122 if ( bdy
== P_XSB
|| bdy
== P_XEB
) { bdex
= ydex
; }
123 else if ( bdy
== P_YSB
|| bdy
== P_YEB
) { bdex
= xdex
; }
124 else { fprintf(stderr
,"REGISTRY WARNING: internal error %s %d, bdy=%d,%s,%d \n",__FILE__
,__LINE__
,bdy
,p
->name
,p
->boundary
) ; }
125 if ( zdim
!= NULL
) {
126 zdex
= zdim
->dim_order
;
127 sprintf(tx
,"%ssm3%d:%sem3%d,%ssm3%d:%sem3%d,%sspec_bdy_width,%s", r
,bdex
,r
,bdex
,r
,zdex
,r
,zdex
,r
,four_d
) ;
129 sprintf(tx
,"%ssm3%d:%sem3%d,1,%sspec_bdy_width,%s", r
,bdex
,r
,bdex
,r
,four_d
) ;
132 if ( zdim
!= NULL
) {
133 zdex
= zdim
->dim_order
;
134 sprintf(tx
,"max(%sed3%d,%sed3%d),%ssd3%d:%sed3%d,%sspec_bdy_width,4,%s", r
,xdex
,r
,ydex
,r
,zdex
,r
,zdex
,r
,four_d
) ;
136 sprintf(tx
,"max(%sed3%d,%sed3%d),1,%sspec_bdy_width,4,%s", r
,xdex
,r
,ydex
,r
,four_d
) ;
142 sprintf(tx
,"%sspec_bdy_width,",r
) ;
148 for ( i
= 0 ; i
< p
->ndims
; i
++ )
150 range_of_dimension( r
, tx
, i
, p
, nlstructname
) ;
155 tmp
[strlen(tmp
)-1] = '\0' ;
156 if ( post
!= NULL
) strcat(tmp
,post
) ;
162 range_of_dimension ( char * r
, char * tx
, int i
, node_t
* p
, char * nlstructname
)
164 char s
[NAMELEN
], e
[NAMELEN
] ;
166 get_elem( r
, nlstructname
, s
, i
, p
, 0 ) ;
167 get_elem( r
, nlstructname
, e
, i
, p
, 1 ) ;
168 sprintf(tx
,"%s:%s", s
, e
) ;
173 index_with_firstelem( char * pre
, char * dref
, int bdy
, /* as defined in data.h */
174 char * tmp
, node_t
* p
, char * post
)
179 int bdex
, xdex
, ydex
, zdex
;
180 node_t
*xdim
, *ydim
, *zdim
;
183 if ( p
== NULL
) return("") ;
184 if ( p
->ndims
<= 0 ) return("") ;
186 if ( pre
!= NULL
) strcat(tmp
,pre
) ;
189 if ( dref
!= NULL
) strcat(r
,dref
) ;
191 if ( p
->boundary_array
)
195 xdim
= get_dimnode_for_coord( p
, COORD_X
) ;
196 ydim
= get_dimnode_for_coord( p
, COORD_Y
) ;
197 zdim
= get_dimnode_for_coord( p
, COORD_Z
) ;
199 { fprintf(stderr
,"dimension_with_ranges: y dimension not specified for %s\n",p
->name
) ; return("") ; }
201 { fprintf(stderr
,"dimension_with_ranges: x dimension not specified for %s\n",p
->name
) ; return("") ; }
203 xdex
= xdim
->dim_order
;
204 ydex
= ydim
->dim_order
;
206 if ( bdy
== P_XSB
|| bdy
== P_XEB
) { bdex
= ydex
; }
207 else if ( bdy
== P_YSB
|| bdy
== P_YEB
) { bdex
= xdex
; }
208 else { fprintf(stderr
,"REGISTRY WARNING: internal error %s %d \n",__FILE__
,__LINE__
) ; }
211 if ( !strcmp( p
->use
, "_4d_bdy_array_" ) ) {
212 sprintf(tmp
,"%ssm3%d,%ssm3%d,1,1", r
,bdex
,r
,zdex
) ;
214 sprintf(tmp
,"%ssm3%d,%ssm3%d,1", r
,bdex
,r
,zdex
) ;
226 if ( !strcmp( p
->use
, "_4d_bdy_array_" ) ) {
227 strcat(tmp
,"1,1,1,1,1,") ;
229 strcat(tmp
,"1,1,1,1,") ;
241 for ( i
= 0 ; i
< p
->ndims
; i
++ )
243 get_elem( dref
, "", tx
, i
, p
, 0 ) ;
248 tmp
[strlen(tmp
)-1] = '\0' ; /* remove trailing comma */
249 if ( post
!= NULL
) strcat(tmp
,post
) ;
253 get_elem ( char * structname
, char * nlstructname
, char * tx
, int i
, node_t
* p
, int first_last
)
255 char dref
[NAMELEN
], nlstruct
[NAMELEN
], r1
[NAMELEN
] ;
256 char r
[NAMELEN
], d
, d1
;
258 if ( structname
== NULL
) { strcpy( dref
, "" ) ;}
259 else { strcpy( dref
, structname
) ; }
260 if ( nlstructname
== NULL
) { strcpy( nlstruct
, "" ) ;}
261 else { strcpy( nlstruct
, nlstructname
) ; }
262 if ( p
->dims
[i
] != NULL
)
264 switch ( p
->dims
[i
]->len_defined_how
)
266 case (DOMAIN_STANDARD
) :
269 if ( p
->proc_orient
== ALL_X_ON_PROC
) ornt
= "x" ;
270 else if ( p
->proc_orient
== ALL_Y_ON_PROC
) ornt
= "y" ;
273 switch( p
->dims
[i
]->coord_axis
)
275 case(COORD_X
) : d
= 'i' ; d1
= 'x' ; break ;
276 case(COORD_Y
) : d
= 'j' ; d1
= 'y' ; break ;
277 case(COORD_Z
) : d
= 'k' ; d1
= 'z' ; break ;
281 if ( p
->dims
[i
]->subgrid
)
283 fprintf( stderr
, "%d p->coord_axis %d %c %c \n" ,i
,p
->coord_axis
, d
, d1
) ;
284 if ( first_last
== 0 ) { /*first*/
285 sprintf(tx
,"(%ssm3%d%s-1)*%ssr_%c+1",r
,p
->dims
[i
]->dim_order
,ornt
,r1
,d1
) ;
287 sprintf(tx
,"%sem3%d%s*%ssr_%c" ,r
,p
->dims
[i
]->dim_order
,ornt
,r1
,d1
) ;
292 sprintf(tx
,"%s%cm3%d%s",dref
,first_last
==0?'s':'e',p
->dims
[i
]->dim_order
,ornt
) ;
297 if ( first_last
== 0 ) { if ( !strcmp( p
->dims
[i
]->assoc_nl_var_s
, "1" ) ) {
298 sprintf(tx
,"%s",p
->dims
[i
]->assoc_nl_var_s
) ;
300 sprintf(tx
,"%s%s%s",nlstructname
,structname
,p
->dims
[i
]->assoc_nl_var_s
) ;
303 else { sprintf(tx
,"%s%s%s",nlstructname
,structname
,p
->dims
[i
]->assoc_nl_var_e
) ; }
306 if ( first_last
== 0 ) { sprintf(tx
,"%d",p
->dims
[i
]->coord_start
) ; }
307 else { sprintf(tx
,"%d",p
->dims
[i
]->coord_end
) ; }
314 fprintf(stderr
,"WARNING: %s %d: something wrong with internal representation for dim %d\n",__FILE__
,__LINE__
,i
) ;
319 declare_array_as_pointer( char * tmp
, node_t
* p
)
323 if ( p
->ndims
> 0 || p
->boundary_array
) strcpy ( tmp
, ",POINTER" ) ;
328 field_type( char * tmp
, node_t
* p
)
332 } else if ( p
->type
== NULL
) {
334 } else if ( p
->type
->type_type
== SIMPLE
) {
335 strcpy( tmp
, p
->type
->name
) ;
337 sprintf( tmp
, "TYPE(%s)", p
->type
->name
) ;
343 field_name( char * tmp
, node_t
* p
, int tag
)
345 if ( p
== NULL
) return("") ;
348 strcpy(tmp
,p
->name
) ;
349 if ( p
->scalar_array_member
) strcpy(tmp
,p
->use
) ;
353 sprintf(tmp
,"%s_%d",p
->name
,tag
) ;
354 if ( p
->scalar_array_member
) sprintf(tmp
,"%s_%d",p
->use
,tag
) ;
360 field_name_bdy( char * tmp
, node_t
* p
, int tag
, int bdy
)
362 if ( p
== NULL
) return("") ;
365 strcpy(tmp
,p
->name
) ;
366 if ( p
->scalar_array_member
) strcpy(tmp
,p
->use
) ;
367 if ( p
->boundary_array
) strcat(tmp
,bdy_indicator(bdy
)) ;
371 sprintf(tmp
,"%s_%d",p
->name
,tag
) ;
372 if ( p
->scalar_array_member
) sprintf(tmp
,"%s_%d",p
->use
,tag
) ;
373 if ( p
->boundary_array
) strcat(tmp
,bdy_indicator(bdy
)) ;
378 static char *emp_str
= "" ;
379 static char *xs_str
= "xs" ;
380 static char *xe_str
= "xe" ;
381 static char *ys_str
= "ys" ;
382 static char *ye_str
= "ye" ;
385 bdy_indicator( int bdy
)
389 if ( bdy
== P_XSB
) { res
= xs_str
; }
390 else if ( bdy
== P_XEB
) { res
= xe_str
; }
391 else if ( bdy
== P_YSB
) { res
= ys_str
; }
392 else if ( bdy
== P_YEB
) { res
= ye_str
; }
397 print_warning( FILE * fp
, char * fname
)
399 fprintf(fp
,"!STARTOFREGISTRYGENERATEDINCLUDE '%s'\n", fname
) ;
401 fprintf(fp
,"! WARNING This file is generated automatically by use_registry\n") ;
402 fprintf(fp
,"! using the data base in the file named Registry.\n") ;
403 fprintf(fp
,"! Do not edit. Your changes to this file will be lost.\n") ;
408 close_the_file( FILE * fp
)
410 fprintf(fp
,"!ENDOFREGISTRYGENERATEDINCLUDE\n") ;
415 make_entries_uniq ( char * fname
)
417 char tempfile
[NAMELEN
] ;
418 char commline
[4096] ;
419 sprintf(tempfile
,"regtmp1%d",getpid()) ;
420 sprintf(commline
,"%s < %s > %s ; %s %s %s ",
421 UNIQSORT
,fname
,tempfile
,
422 MVCOMM
,tempfile
,fname
) ;
423 return(system(commline
)) ;
427 add_warning ( char * fname
)
430 char tempfile
[NAMELEN
] ;
431 char tempfile1
[NAMELEN
] ;
432 char commline
[4096] ;
433 sprintf(tempfile
,"regtmp1%d",getpid()) ;
434 sprintf(tempfile1
,"regtmp2%d",getpid()) ;
435 if (( fp
= fopen( tempfile
, "w" )) == NULL
) return(1) ;
436 print_warning(fp
,tempfile
) ;
438 sprintf(commline
,"%s %s %s > %s ; %s %s %s ; %s %s ",
439 CATCOMM
,tempfile
,fname
,tempfile1
,
440 MVCOMM
,tempfile1
,fname
,
442 return(system(commline
)) ;
445 static int NumCores
;
446 static char dyncores
[MAX_DYNCORES
][NAMELEN
] ;
462 get_corename_i(int i
)
464 if ( i
>= 0 && i
< NumCores
) return( dyncores
[i
] ) ;
469 add_core_name ( char * name
)
471 if ( name
== NULL
) return(1) ;
472 if (get_core_name ( name
) == NULL
)
474 if ( NumCores
>= MAX_DYNCORES
) return(1) ;
475 strcpy( dyncores
[NumCores
++] , name
) ;
481 get_core_name ( char * name
)
484 if ( name
== NULL
) return(NULL
) ;
485 for ( i
= 0 ; i
< NumCores
; i
++ )
487 if ( !strcmp(name
,dyncores
[i
]) ) return( dyncores
[i
] ) ;
494 make_upper_case ( char * str
)
497 if ( str
== NULL
) return (NULL
) ;
498 for ( p
= str
; *p
; p
++ ) *p
= toupper(*p
) ;
504 make_lower_case ( char * str
)
507 if ( str
== NULL
) return (NULL
) ;
508 for ( p
= str
; *p
; p
++ ) *p
= tolower(*p
) ;
512 /* Routines for keeping typedef history -ajb */
514 static int NumTypeDefs
;
515 static char typedefs
[MAX_TYPEDEFS
][NAMELEN
] ;
518 init_typedef_history()
527 return( NumTypeDefs
) ;
531 get_typename_i(int i
)
533 if ( i
>= 0 && i
< NumTypeDefs
) return( typedefs
[i
] ) ;
538 add_typedef_name ( char * name
)
540 if ( name
== NULL
) return(1) ;
541 if ( get_typedef_name ( name
) == NULL
)
543 if ( NumTypeDefs
>= MAX_TYPEDEFS
) return(1) ;
544 strcpy( typedefs
[NumTypeDefs
++] , name
) ;
550 get_typedef_name ( char * name
)
553 if ( name
== NULL
) return(NULL
) ;
554 for ( i
= 0 ; i
< NumTypeDefs
; i
++ )
556 if ( !strcmp(name
,typedefs
[i
]) ) return( typedefs
[i
] ) ;
562 associated_with_4d_array( node_t
* p
)
566 char * last_underscore
;
567 char name_copy
[128] ;
570 /* check this variable and see if it is a boundary variable that is associated with a 4d array */
571 strcpy( name_copy
, p
->name
) ;
572 if (( last_underscore
= rindex( name_copy
, '_' )) != NULL
) {
573 if ( !strcmp( last_underscore
, "_b" ) || !strcmp( last_underscore
, "_bt" ) ) {
574 *last_underscore
= '\0' ;
575 if (( possble
= get_entry( name_copy
, Domain
.fields
)) != NULL
) {
576 res
= possble
->node_kind
& FOURD
;