| 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 | |
|---|
| 15 | char * |
|---|
| 16 | dimension_with_colons( char * pre , char * tmp , node_t * p , char * post ) |
|---|
| 17 | { |
|---|
| 18 | int i ; |
|---|
| 19 | if ( p == NULL ) return("") ; |
|---|
| 20 | if ( p->ndims <= 0 && ! p->boundary_array ) return("") ; |
|---|
| 21 | strcpy(tmp,"") ; |
|---|
| 22 | if ( pre != NULL ) strcat(tmp,pre) ; |
|---|
| 23 | if ( p->boundary_array ) |
|---|
| 24 | { |
|---|
| 25 | if ( ! sw_new_bdys ) { strcat( tmp,":,") ; } |
|---|
| 26 | if ( !strcmp( p->use , "_4d_bdy_array_" ) ) { |
|---|
| 27 | strcat( tmp, ":,:,:,:" ) ; /* boundary array for 4d tracer array */ |
|---|
| 28 | } else { |
|---|
| 29 | strcat( tmp, ":,:,:" ) ; /* most always have four dimensions */ |
|---|
| 30 | } |
|---|
| 31 | } |
|---|
| 32 | else |
|---|
| 33 | { |
|---|
| 34 | for ( i = 0 ; i < p->ndims ; i++ ) strcat(tmp,":,") ; |
|---|
| 35 | if ( p->node_kind & FOURD ) strcat(tmp,":,") ; /* add an extra for 4d arrays */ |
|---|
| 36 | tmp[strlen(tmp)-1] = '\0' ; |
|---|
| 37 | } |
|---|
| 38 | if ( post != NULL ) strcat(tmp,post) ; |
|---|
| 39 | return(tmp) ; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | char * |
|---|
| 43 | dimension_with_ones( char * pre , char * tmp , node_t * p , char * post ) |
|---|
| 44 | { |
|---|
| 45 | int i ; |
|---|
| 46 | char r[NAMELEN],s[NAMELEN],four_d[NAMELEN] ; |
|---|
| 47 | char *pp ; |
|---|
| 48 | if ( p == NULL ) return("") ; |
|---|
| 49 | if ( p->ndims <= 0 && ! p->boundary_array ) return("") ; |
|---|
| 50 | strcpy(tmp,"") ; |
|---|
| 51 | if ( pre != NULL ) strcat(tmp,pre) ; |
|---|
| 52 | |
|---|
| 53 | if ( p->boundary_array ) |
|---|
| 54 | { |
|---|
| 55 | if ( ! sw_new_bdys ) { strcpy( tmp,"(1,") ; } |
|---|
| 56 | if ( !strcmp( p->use , "_4d_bdy_array_" ) ) { /* if a boundary array for a 4d tracer */ |
|---|
| 57 | strcpy(s, p->name ) ; /* copy the name and then remove everything after last underscore */ |
|---|
| 58 | if ((pp=rindex( s, '_' )) != NULL ) *pp = '\0' ; |
|---|
| 59 | sprintf( four_d, "num_%s,", s ) ; |
|---|
| 60 | } else { |
|---|
| 61 | strcpy( four_d, "" ) ; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | if ( !strcmp( p->use , "_4d_bdy_array_" ) ) { |
|---|
| 65 | sprintf( r, "1,1,1,%s", four_d ) ; /* boundary array for 4d tracer array */ |
|---|
| 66 | strcat( tmp, r ) ; |
|---|
| 67 | } else { |
|---|
| 68 | strcat( tmp, "1,1,1," ) ; |
|---|
| 69 | } |
|---|
| 70 | tmp[strlen(tmp)-1] = '\0' ; |
|---|
| 71 | } |
|---|
| 72 | else |
|---|
| 73 | { |
|---|
| 74 | for ( i = 0 ; i < p->ndims ; i++ ) strcat(tmp,"1,") ; |
|---|
| 75 | if ( p->node_kind & FOURD ) strcat(tmp,"1,") ; /* add an extra for 4d arrays */ |
|---|
| 76 | tmp[strlen(tmp)-1] = '\0' ; |
|---|
| 77 | } |
|---|
| 78 | if ( post != NULL ) strcat(tmp,post) ; |
|---|
| 79 | return(tmp) ; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | char * |
|---|
| 83 | dimension_with_ranges( char * refarg , char * pre , |
|---|
| 84 | int bdy , /* as defined in data.h */ |
|---|
| 85 | char * tmp , node_t * p , char * post , |
|---|
| 86 | char * nlstructname ) /* added 20020130; |
|---|
| 87 | provides name (with %) of structure in |
|---|
| 88 | which a namelist supplied dimension |
|---|
| 89 | should be dereference from, or "" */ |
|---|
| 90 | { |
|---|
| 91 | int i ; |
|---|
| 92 | char tx[NAMELEN] ; |
|---|
| 93 | char r[NAMELEN],s[NAMELEN],four_d[NAMELEN] ; |
|---|
| 94 | int bdex, xdex, ydex, zdex ; |
|---|
| 95 | node_t *xdim, *ydim, *zdim ; |
|---|
| 96 | char *pp ; |
|---|
| 97 | if ( p == NULL ) return("") ; |
|---|
| 98 | if ( p->ndims <= 0 && !p->boundary_array ) return("") ; |
|---|
| 99 | strcpy(tmp,"") ; |
|---|
| 100 | if ( pre != NULL ) strcat(tmp,pre) ; |
|---|
| 101 | strcpy(r,"") ; |
|---|
| 102 | if ( refarg != NULL ) strcat(r,refarg) ; |
|---|
| 103 | |
|---|
| 104 | if ( p->boundary_array ) |
|---|
| 105 | { |
|---|
| 106 | if ( p->ndims > 0 ) |
|---|
| 107 | { |
|---|
| 108 | xdim = get_dimnode_for_coord( p , COORD_X ) ; |
|---|
| 109 | ydim = get_dimnode_for_coord( p , COORD_Y ) ; |
|---|
| 110 | zdim = get_dimnode_for_coord( p , COORD_Z ) ; |
|---|
| 111 | if ( ydim == NULL ) |
|---|
| 112 | { fprintf(stderr,"dimension_with_ranges: y dimension not specified for %s\n",p->name) ; return("") ; } |
|---|
| 113 | if ( xdim == NULL ) |
|---|
| 114 | { fprintf(stderr,"dimension_with_ranges: x dimension not specified for %s\n",p->name) ; return("") ; } |
|---|
| 115 | |
|---|
| 116 | xdex = xdim->dim_order ; |
|---|
| 117 | ydex = ydim->dim_order ; |
|---|
| 118 | |
|---|
| 119 | if ( !strcmp( p->use , "_4d_bdy_array_" ) ) { /* if a boundary array for a 4d tracer */ |
|---|
| 120 | strcpy(s, p->name ) ; /* copy the name and then remove everything after last underscore */ |
|---|
| 121 | if ((pp=rindex( s, '_' )) != NULL ) *pp = '\0' ; |
|---|
| 122 | sprintf( four_d, "num_%s,", s ) ; |
|---|
| 123 | } else { |
|---|
| 124 | strcpy( four_d, "" ) ; |
|---|
| 125 | } |
|---|
| 126 | if ( sw_new_bdys ) { |
|---|
| 127 | if ( bdy == P_XSB || bdy == P_XEB ) { bdex = ydex ; } |
|---|
| 128 | else if ( bdy == P_YSB || bdy == P_YEB ) { bdex = xdex ; } |
|---|
| 129 | else { fprintf(stderr,"REGISTRY WARNING: internal error %s %d, bdy=%d,%s,%d \n",__FILE__,__LINE__,bdy,p->name,p->boundary) ; } |
|---|
| 130 | if ( zdim != NULL ) { |
|---|
| 131 | zdex = zdim->dim_order ; |
|---|
| 132 | 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 ) ; |
|---|
| 133 | } else { |
|---|
| 134 | sprintf(tx,"%ssm3%d:%sem3%d,1,%sspec_bdy_width,%s", r,bdex,r,bdex,r,four_d ) ; |
|---|
| 135 | } |
|---|
| 136 | } else { |
|---|
| 137 | if ( zdim != NULL ) { |
|---|
| 138 | zdex = zdim->dim_order ; |
|---|
| 139 | 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 ) ; |
|---|
| 140 | } else { |
|---|
| 141 | sprintf(tx,"max(%sed3%d,%sed3%d),1,%sspec_bdy_width,4,%s", r,xdex,r,ydex,r,four_d ) ; |
|---|
| 142 | } |
|---|
| 143 | } |
|---|
| 144 | } |
|---|
| 145 | else |
|---|
| 146 | { |
|---|
| 147 | sprintf(tx,"%sspec_bdy_width,",r ) ; |
|---|
| 148 | } |
|---|
| 149 | strcat(tmp,tx) ; |
|---|
| 150 | } |
|---|
| 151 | else |
|---|
| 152 | { |
|---|
| 153 | for ( i = 0 ; i < p->ndims ; i++ ) |
|---|
| 154 | { |
|---|
| 155 | range_of_dimension( r, tx , i , p , nlstructname ) ; |
|---|
| 156 | strcat(tmp,tx) ; |
|---|
| 157 | strcat(tmp,",") ; |
|---|
| 158 | } |
|---|
| 159 | } |
|---|
| 160 | tmp[strlen(tmp)-1] = '\0' ; |
|---|
| 161 | if ( post != NULL ) strcat(tmp,post) ; |
|---|
| 162 | |
|---|
| 163 | return(tmp) ; |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | int |
|---|
| 167 | range_of_dimension ( char * r , char * tx , int i , node_t * p , char * nlstructname ) |
|---|
| 168 | { |
|---|
| 169 | char s[NAMELEN], e[NAMELEN] ; |
|---|
| 170 | |
|---|
| 171 | get_elem( r , nlstructname , s , i , p , 0 ) ; |
|---|
| 172 | get_elem( r , nlstructname , e , i , p , 1 ) ; |
|---|
| 173 | sprintf(tx,"%s:%s", s , e ) ; |
|---|
| 174 | |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | char * |
|---|
| 178 | index_with_firstelem( char * pre , char * dref , int bdy , /* as defined in data.h */ |
|---|
| 179 | char * tmp , node_t * p , char * post ) |
|---|
| 180 | { |
|---|
| 181 | int i ; |
|---|
| 182 | char tx[NAMELEN] ; |
|---|
| 183 | char tmp2[NAMELEN] ; |
|---|
| 184 | int bdex, xdex, ydex, zdex ; |
|---|
| 185 | node_t *xdim, *ydim, *zdim ; |
|---|
| 186 | char r[NAMELEN] ; |
|---|
| 187 | |
|---|
| 188 | if ( p == NULL ) return("") ; |
|---|
| 189 | if ( p->ndims <= 0 ) return("") ; |
|---|
| 190 | strcpy(tmp,"") ; |
|---|
| 191 | if ( pre != NULL ) strcat(tmp,pre) ; |
|---|
| 192 | |
|---|
| 193 | strcpy(r,"") ; |
|---|
| 194 | if ( dref != NULL ) strcat(r,dref) ; |
|---|
| 195 | |
|---|
| 196 | if ( p->boundary_array ) |
|---|
| 197 | { |
|---|
| 198 | if ( sw_new_bdys ) { |
|---|
| 199 | |
|---|
| 200 | xdim = get_dimnode_for_coord( p , COORD_X ) ; |
|---|
| 201 | ydim = get_dimnode_for_coord( p , COORD_Y ) ; |
|---|
| 202 | zdim = get_dimnode_for_coord( p , COORD_Z ) ; |
|---|
| 203 | if ( ydim == NULL ) |
|---|
| 204 | { fprintf(stderr,"dimension_with_ranges: y dimension not specified for %s\n",p->name) ; return("") ; } |
|---|
| 205 | if ( xdim == NULL ) |
|---|
| 206 | { fprintf(stderr,"dimension_with_ranges: x dimension not specified for %s\n",p->name) ; return("") ; } |
|---|
| 207 | |
|---|
| 208 | xdex = xdim->dim_order ; |
|---|
| 209 | ydex = ydim->dim_order ; |
|---|
| 210 | |
|---|
| 211 | if ( bdy == P_XSB || bdy == P_XEB ) { bdex = ydex ; } |
|---|
| 212 | else if ( bdy == P_YSB || bdy == P_YEB ) { bdex = xdex ; } |
|---|
| 213 | else { fprintf(stderr,"REGISTRY WARNING: internal error %s %d \n",__FILE__,__LINE__) ; } |
|---|
| 214 | if ( p->ndims > 0 ) |
|---|
| 215 | { |
|---|
| 216 | if ( !strcmp( p->use , "_4d_bdy_array_" ) ) { |
|---|
| 217 | sprintf(tmp,"%ssm3%d,%ssm3%d,1,1", r,bdex,r,zdex ) ; |
|---|
| 218 | } else { |
|---|
| 219 | sprintf(tmp,"%ssm3%d,%ssm3%d,1", r,bdex,r,zdex ) ; |
|---|
| 220 | } |
|---|
| 221 | } |
|---|
| 222 | else |
|---|
| 223 | { |
|---|
| 224 | sprintf(tx,"1," ) ; |
|---|
| 225 | strcat(tmp,tx) ; |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | } else { |
|---|
| 229 | if ( p->ndims > 0 ) |
|---|
| 230 | { |
|---|
| 231 | if ( !strcmp( p->use , "_4d_bdy_array_" ) ) { |
|---|
| 232 | strcat(tmp,"1,1,1,1,1,") ; |
|---|
| 233 | } else { |
|---|
| 234 | strcat(tmp,"1,1,1,1,") ; |
|---|
| 235 | } |
|---|
| 236 | } |
|---|
| 237 | else |
|---|
| 238 | { |
|---|
| 239 | sprintf(tx,"1," ) ; |
|---|
| 240 | strcat(tmp,tx) ; |
|---|
| 241 | } |
|---|
| 242 | } |
|---|
| 243 | } |
|---|
| 244 | else |
|---|
| 245 | { |
|---|
| 246 | for ( i = 0 ; i < p->ndims ; i++ ) |
|---|
| 247 | { |
|---|
| 248 | get_elem( dref, "", tx, i, p , 0 ) ; |
|---|
| 249 | strcat( tmp, tx ) ; |
|---|
| 250 | strcat(tmp,",") ; |
|---|
| 251 | } |
|---|
| 252 | } |
|---|
| 253 | tmp[strlen(tmp)-1] = '\0' ; /* remove trailing comma */ |
|---|
| 254 | if ( post != NULL ) strcat(tmp,post) ; |
|---|
| 255 | return(tmp) ; |
|---|
| 256 | } |
|---|
| 257 | |
|---|
| 258 | int |
|---|
| 259 | get_elem ( char * structname , char * nlstructname , char * tx , int i , node_t * p , int first_last ) |
|---|
| 260 | { |
|---|
| 261 | char dref[NAMELEN], nlstruct[NAMELEN] ; |
|---|
| 262 | char d, d1 ; |
|---|
| 263 | |
|---|
| 264 | if ( structname == NULL ) { strcpy( dref, "" ) ;} |
|---|
| 265 | else { strcpy( dref, structname ) ; } |
|---|
| 266 | if ( nlstructname == NULL ) { strcpy( nlstruct, "" ) ;} |
|---|
| 267 | else { strcpy( nlstruct, nlstructname ) ; } |
|---|
| 268 | if ( p->dims[i] != NULL ) |
|---|
| 269 | { |
|---|
| 270 | switch ( p->dims[i]->len_defined_how ) |
|---|
| 271 | { |
|---|
| 272 | case (DOMAIN_STANDARD) : |
|---|
| 273 | { |
|---|
| 274 | char *ornt ; |
|---|
| 275 | if ( p->proc_orient == ALL_X_ON_PROC ) ornt = "x" ; |
|---|
| 276 | else if ( p->proc_orient == ALL_Y_ON_PROC ) ornt = "y" ; |
|---|
| 277 | else ornt = "" ; |
|---|
| 278 | |
|---|
| 279 | switch( p->dims[i]->coord_axis ) |
|---|
| 280 | { |
|---|
| 281 | case(COORD_X) : d = 'i' ; d1 = 'x' ; break ; |
|---|
| 282 | case(COORD_Y) : d = 'j' ; d1 = 'y' ; break ; |
|---|
| 283 | case(COORD_Z) : d = 'k' ; d1 = 'z' ; break ; |
|---|
| 284 | default : break ; |
|---|
| 285 | } |
|---|
| 286 | |
|---|
| 287 | if ( p->dims[i]->subgrid ) |
|---|
| 288 | { |
|---|
| 289 | if ( first_last == 0 ) { /*first*/ |
|---|
| 290 | sprintf(tx,"(%ssm3%d%s-1)*%ssr_%c+1",dref,p->dims[i]->dim_order,ornt,dref,d1) ; |
|---|
| 291 | }else{ /*last*/ |
|---|
| 292 | sprintf(tx,"%sem3%d%s*%ssr_%c" ,dref,p->dims[i]->dim_order,ornt,dref,d1) ; |
|---|
| 293 | } |
|---|
| 294 | } |
|---|
| 295 | else |
|---|
| 296 | { |
|---|
| 297 | sprintf(tx,"%s%cm3%d%s",dref,first_last==0?'s':'e',p->dims[i]->dim_order,ornt) ; |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | break ; |
|---|
| 301 | case (NAMELIST) : |
|---|
| 302 | if ( first_last == 0 ) { if ( !strcmp( p->dims[i]->assoc_nl_var_s , "1" ) ) { |
|---|
| 303 | sprintf(tx,"%s",p->dims[i]->assoc_nl_var_s) ; |
|---|
| 304 | } else { |
|---|
| 305 | sprintf(tx,"%s%s%s",nlstructname,structname,p->dims[i]->assoc_nl_var_s) ; |
|---|
| 306 | } |
|---|
| 307 | } |
|---|
| 308 | else { sprintf(tx,"%s%s%s",nlstructname,structname,p->dims[i]->assoc_nl_var_e) ; } |
|---|
| 309 | break ; |
|---|
| 310 | case (CONSTANT) : |
|---|
| 311 | if ( first_last == 0 ) { sprintf(tx,"%d",p->dims[i]->coord_start) ; } |
|---|
| 312 | else { sprintf(tx,"%d",p->dims[i]->coord_end) ; } |
|---|
| 313 | break ; |
|---|
| 314 | default : break ; |
|---|
| 315 | } |
|---|
| 316 | } |
|---|
| 317 | else |
|---|
| 318 | { |
|---|
| 319 | fprintf(stderr,"WARNING: %s %d: something wrong with internal representation for dim %d\n",__FILE__,__LINE__,i) ; |
|---|
| 320 | } |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | char * |
|---|
| 324 | declare_array_as_pointer( char * tmp , node_t * p ) |
|---|
| 325 | { |
|---|
| 326 | strcpy( tmp , "" ) ; |
|---|
| 327 | if ( p != NULL ) { |
|---|
| 328 | #ifdef USE_ALLOCATABLES |
|---|
| 329 | if ( p->ndims > 0 || p->boundary_array ) strcpy ( tmp, ",ALLOCATABLE" ) ; |
|---|
| 330 | #else |
|---|
| 331 | if ( p->ndims > 0 || p->boundary_array ) strcpy ( tmp, ",POINTER" ) ; |
|---|
| 332 | #endif |
|---|
| 333 | } |
|---|
| 334 | return(tmp); |
|---|
| 335 | } |
|---|
| 336 | |
|---|
| 337 | char * |
|---|
| 338 | field_type( char * tmp , node_t * p ) |
|---|
| 339 | { |
|---|
| 340 | if ( p == NULL ) { |
|---|
| 341 | strcpy( tmp , "" ) ; |
|---|
| 342 | } else if ( p->type == NULL ) { |
|---|
| 343 | strcpy( tmp , "" ) ; |
|---|
| 344 | } else if ( p->type->type_type == SIMPLE ) { |
|---|
| 345 | strcpy( tmp , p->type->name ) ; |
|---|
| 346 | } else { |
|---|
| 347 | sprintf( tmp , "TYPE(%s)", p->type->name ) ; |
|---|
| 348 | } |
|---|
| 349 | return( tmp ) ; |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | char * |
|---|
| 353 | field_name( char * tmp , node_t * p , int tag ) |
|---|
| 354 | { |
|---|
| 355 | if ( p == NULL ) return("") ; |
|---|
| 356 | if ( tag < 1 ) |
|---|
| 357 | { |
|---|
| 358 | strcpy(tmp,p->name) ; |
|---|
| 359 | if ( p->scalar_array_member ) strcpy(tmp,p->use) ; |
|---|
| 360 | } |
|---|
| 361 | else |
|---|
| 362 | { |
|---|
| 363 | sprintf(tmp,"%s_%d",p->name,tag) ; |
|---|
| 364 | if ( p->scalar_array_member ) sprintf(tmp,"%s_%d",p->use,tag) ; |
|---|
| 365 | } |
|---|
| 366 | return( tmp ) ; |
|---|
| 367 | } |
|---|
| 368 | |
|---|
| 369 | char * |
|---|
| 370 | field_name_bdy( char * tmp , node_t * p , int tag, int bdy ) |
|---|
| 371 | { |
|---|
| 372 | if ( p == NULL ) return("") ; |
|---|
| 373 | if ( tag < 1 ) |
|---|
| 374 | { |
|---|
| 375 | strcpy(tmp,p->name) ; |
|---|
| 376 | if ( p->scalar_array_member ) strcpy(tmp,p->use) ; |
|---|
| 377 | if ( p->boundary_array ) strcat(tmp,bdy_indicator(bdy)) ; |
|---|
| 378 | } |
|---|
| 379 | else |
|---|
| 380 | { |
|---|
| 381 | sprintf(tmp,"%s_%d",p->name,tag) ; |
|---|
| 382 | if ( p->scalar_array_member ) sprintf(tmp,"%s_%d",p->use,tag) ; |
|---|
| 383 | if ( p->boundary_array ) strcat(tmp,bdy_indicator(bdy)) ; |
|---|
| 384 | } |
|---|
| 385 | return( tmp ) ; |
|---|
| 386 | } |
|---|
| 387 | |
|---|
| 388 | static char *emp_str = "" ; |
|---|
| 389 | static char *xs_str = "xs" ; |
|---|
| 390 | static char *xe_str = "xe" ; |
|---|
| 391 | static char *ys_str = "ys" ; |
|---|
| 392 | static char *ye_str = "ye" ; |
|---|
| 393 | |
|---|
| 394 | char * |
|---|
| 395 | bdy_indicator( int bdy ) |
|---|
| 396 | { |
|---|
| 397 | char * res ; |
|---|
| 398 | res = emp_str ; |
|---|
| 399 | if ( bdy == P_XSB ) { res = xs_str ; } |
|---|
| 400 | else if ( bdy == P_XEB ) { res = xe_str ; } |
|---|
| 401 | else if ( bdy == P_YSB ) { res = ys_str ; } |
|---|
| 402 | else if ( bdy == P_YEB ) { res = ye_str ; } |
|---|
| 403 | return(res) ; |
|---|
| 404 | } |
|---|
| 405 | |
|---|
| 406 | int |
|---|
| 407 | print_warning( FILE * fp , char * fname ) |
|---|
| 408 | { |
|---|
| 409 | fprintf(fp,"!STARTOFREGISTRYGENERATEDINCLUDE '%s'\n", fname) ; |
|---|
| 410 | fprintf(fp,"!\n") ; |
|---|
| 411 | fprintf(fp,"! WARNING This file is generated automatically by use_registry\n") ; |
|---|
| 412 | fprintf(fp,"! using the data base in the file named Registry.\n") ; |
|---|
| 413 | fprintf(fp,"! Do not edit. Your changes to this file will be lost.\n") ; |
|---|
| 414 | fprintf(fp,"!\n") ; |
|---|
| 415 | return(0) ; |
|---|
| 416 | } |
|---|
| 417 | |
|---|
| 418 | int |
|---|
| 419 | close_the_file( FILE * fp ) |
|---|
| 420 | { |
|---|
| 421 | fprintf(fp,"!ENDOFREGISTRYGENERATEDINCLUDE\n") ; |
|---|
| 422 | fclose(fp) ; |
|---|
| 423 | } |
|---|
| 424 | |
|---|
| 425 | int |
|---|
| 426 | make_entries_uniq ( char * fname ) |
|---|
| 427 | { |
|---|
| 428 | char tempfile[NAMELEN] ; |
|---|
| 429 | /* Had to increase size for SOA from 4096 to 7000 */ |
|---|
| 430 | char commline[7000] ; |
|---|
| 431 | sprintf(tempfile,"regtmp1%d",getpid()) ; |
|---|
| 432 | sprintf(commline,"%s < %s > %s ; %s %s %s ", |
|---|
| 433 | UNIQSORT,fname,tempfile, |
|---|
| 434 | MVCOMM,tempfile,fname ) ; |
|---|
| 435 | return(system(commline)) ; |
|---|
| 436 | } |
|---|
| 437 | |
|---|
| 438 | int |
|---|
| 439 | add_warning ( char * fname ) |
|---|
| 440 | { |
|---|
| 441 | FILE * fp ; |
|---|
| 442 | char tempfile[NAMELEN] ; |
|---|
| 443 | char tempfile1[NAMELEN] ; |
|---|
| 444 | /* Had to increase size for SOA from 4096 to 7000 */ |
|---|
| 445 | char commline[7000] ; |
|---|
| 446 | sprintf(tempfile,"regtmp1%d",getpid()) ; |
|---|
| 447 | sprintf(tempfile1,"regtmp2%d",getpid()) ; |
|---|
| 448 | if (( fp = fopen( tempfile, "w" )) == NULL ) return(1) ; |
|---|
| 449 | print_warning(fp,tempfile) ; |
|---|
| 450 | close_the_file(fp) ; |
|---|
| 451 | sprintf(commline,"%s %s %s > %s ; %s %s %s ; %s %s ", |
|---|
| 452 | CATCOMM,tempfile,fname,tempfile1, |
|---|
| 453 | MVCOMM,tempfile1,fname, |
|---|
| 454 | RMCOMM,tempfile) ; |
|---|
| 455 | return(system(commline)) ; |
|---|
| 456 | } |
|---|
| 457 | |
|---|
| 458 | /* DESTRUCTIVE */ |
|---|
| 459 | char * |
|---|
| 460 | make_upper_case ( char * str ) |
|---|
| 461 | { |
|---|
| 462 | char * p ; |
|---|
| 463 | if ( str == NULL ) return (NULL) ; |
|---|
| 464 | for ( p = str ; *p ; p++ ) *p = toupper(*p) ; |
|---|
| 465 | return(str) ; |
|---|
| 466 | } |
|---|
| 467 | |
|---|
| 468 | /* DESTRUCTIVE */ |
|---|
| 469 | char * |
|---|
| 470 | make_lower_case ( char * str ) |
|---|
| 471 | { |
|---|
| 472 | char * p ; |
|---|
| 473 | if ( str == NULL ) return (NULL) ; |
|---|
| 474 | for ( p = str ; *p ; p++ ) *p = tolower(*p) ; |
|---|
| 475 | return(str) ; |
|---|
| 476 | } |
|---|
| 477 | |
|---|
| 478 | /* Routines for keeping typedef history -ajb */ |
|---|
| 479 | |
|---|
| 480 | static int NumTypeDefs ; |
|---|
| 481 | static char typedefs[MAX_TYPEDEFS][NAMELEN] ; |
|---|
| 482 | |
|---|
| 483 | int |
|---|
| 484 | init_typedef_history() |
|---|
| 485 | { |
|---|
| 486 | NumTypeDefs = 0 ; |
|---|
| 487 | return(0) ; |
|---|
| 488 | } |
|---|
| 489 | |
|---|
| 490 | int |
|---|
| 491 | get_num_typedefs() |
|---|
| 492 | { |
|---|
| 493 | return( NumTypeDefs ) ; |
|---|
| 494 | } |
|---|
| 495 | |
|---|
| 496 | char * |
|---|
| 497 | get_typename_i(int i) |
|---|
| 498 | { |
|---|
| 499 | if ( i >= 0 && i < NumTypeDefs ) return( typedefs[i] ) ; |
|---|
| 500 | return(NULL) ; |
|---|
| 501 | } |
|---|
| 502 | |
|---|
| 503 | int |
|---|
| 504 | add_typedef_name ( char * name ) |
|---|
| 505 | { |
|---|
| 506 | if ( name == NULL ) return(1) ; |
|---|
| 507 | if ( get_typedef_name ( name ) == NULL ) |
|---|
| 508 | { |
|---|
| 509 | if ( NumTypeDefs >= MAX_TYPEDEFS ) return(1) ; |
|---|
| 510 | strcpy( typedefs[NumTypeDefs++] , name ) ; |
|---|
| 511 | } |
|---|
| 512 | return(0) ; |
|---|
| 513 | } |
|---|
| 514 | |
|---|
| 515 | char * |
|---|
| 516 | get_typedef_name ( char * name ) |
|---|
| 517 | { |
|---|
| 518 | int i ; |
|---|
| 519 | if ( name == NULL ) return(NULL) ; |
|---|
| 520 | for ( i = 0 ; i < NumTypeDefs ; i++ ) |
|---|
| 521 | { |
|---|
| 522 | if ( !strcmp(name,typedefs[i]) ) return( typedefs[i] ) ; |
|---|
| 523 | } |
|---|
| 524 | return(NULL) ; |
|---|
| 525 | } |
|---|
| 526 | |
|---|
| 527 | int |
|---|
| 528 | associated_with_4d_array( node_t * p ) |
|---|
| 529 | { |
|---|
| 530 | int res = 0 ; |
|---|
| 531 | node_t * possble ; |
|---|
| 532 | char * last_underscore ; |
|---|
| 533 | char name_copy[128] ; |
|---|
| 534 | if ( p != NULL ) |
|---|
| 535 | { |
|---|
| 536 | /* check this variable and see if it is a boundary variable that is associated with a 4d array */ |
|---|
| 537 | strcpy( name_copy, p->name ) ; |
|---|
| 538 | if (( last_underscore = rindex( name_copy , '_' )) != NULL ) { |
|---|
| 539 | if ( !strcmp( last_underscore , "_b" ) || !strcmp( last_underscore , "_bt" ) ) { |
|---|
| 540 | *last_underscore = '\0' ; |
|---|
| 541 | if (( possble = get_entry( name_copy , Domain.fields )) != NULL ) { |
|---|
| 542 | res = possble->node_kind & FOURD ; |
|---|
| 543 | } |
|---|
| 544 | } |
|---|
| 545 | } |
|---|
| 546 | } |
|---|
| 547 | return(res) ; |
|---|
| 548 | } |
|---|
| 549 | |
|---|
| 550 | char * |
|---|
| 551 | array_size_expression ( char * refarg , char * pre , |
|---|
| 552 | int bdy , /* as defined in data.h */ |
|---|
| 553 | char * tmp , node_t * p , char * post , |
|---|
| 554 | char * nlstructname ) /* provides name (with %) of structure in |
|---|
| 555 | which a namelist supplied dimension |
|---|
| 556 | should be dereference from, or "" */ |
|---|
| 557 | { |
|---|
| 558 | int i ; |
|---|
| 559 | char tx[NAMELEN] ; |
|---|
| 560 | char r[NAMELEN],s[NAMELEN],four_d[NAMELEN] ; |
|---|
| 561 | int bdex, xdex, ydex, zdex ; |
|---|
| 562 | node_t *xdim, *ydim, *zdim ; |
|---|
| 563 | char *pp ; |
|---|
| 564 | if ( p == NULL ) return("") ; |
|---|
| 565 | if ( p->ndims <= 0 && !p->boundary_array ) return("") ; |
|---|
| 566 | strcpy(tmp,"") ; |
|---|
| 567 | if ( pre != NULL ) strcat(tmp,pre) ; |
|---|
| 568 | strcpy(r,"") ; |
|---|
| 569 | if ( refarg != NULL ) strcat(r,refarg) ; |
|---|
| 570 | |
|---|
| 571 | if ( p->boundary_array ) |
|---|
| 572 | { |
|---|
| 573 | if ( p->ndims > 0 ) |
|---|
| 574 | { |
|---|
| 575 | xdim = get_dimnode_for_coord( p , COORD_X ) ; |
|---|
| 576 | ydim = get_dimnode_for_coord( p , COORD_Y ) ; |
|---|
| 577 | zdim = get_dimnode_for_coord( p , COORD_Z ) ; |
|---|
| 578 | if ( ydim == NULL ) |
|---|
| 579 | { fprintf(stderr,"dimension_with_ranges: y dimension not specified for %s\n",p->name) ; return("") ; } |
|---|
| 580 | if ( xdim == NULL ) |
|---|
| 581 | { fprintf(stderr,"dimension_with_ranges: x dimension not specified for %s\n",p->name) ; return("") ; } |
|---|
| 582 | |
|---|
| 583 | xdex = xdim->dim_order ; |
|---|
| 584 | ydex = ydim->dim_order ; |
|---|
| 585 | |
|---|
| 586 | if ( !strcmp( p->use , "_4d_bdy_array_" ) ) { /* if a boundary array for a 4d tracer */ |
|---|
| 587 | strcpy(s, p->name ) ; /* copy the name and then remove everything after last underscore */ |
|---|
| 588 | if ((pp=rindex( s, '_' )) != NULL ) *pp = '\0' ; |
|---|
| 589 | sprintf( four_d, "*num_%s,", s ) ; |
|---|
| 590 | } else { |
|---|
| 591 | strcpy( four_d, "" ) ; |
|---|
| 592 | } |
|---|
| 593 | if ( sw_new_bdys ) { |
|---|
| 594 | if ( bdy == P_XSB || bdy == P_XEB ) { bdex = ydex ; } |
|---|
| 595 | else if ( bdy == P_YSB || bdy == P_YEB ) { bdex = xdex ; } |
|---|
| 596 | else { fprintf(stderr,"REGISTRY WARNING: internal error %s %d, bdy=%d,%s,%d \n",__FILE__,__LINE__,bdy,p->name,p->boundary) ; } |
|---|
| 597 | if ( zdim != NULL ) { |
|---|
| 598 | zdex = zdim->dim_order ; |
|---|
| 599 | sprintf(tx,"(%sem3%d-%ssm3%d+1)*(%sem3%d-%ssm3%d+1)*(%sspec_bdy_width)%s", r,bdex,r,bdex,r,zdex,r,zdex,r,four_d ) ; |
|---|
| 600 | } else { |
|---|
| 601 | sprintf(tx,"(%sem3%d-%ssm3%d+1)*(%sspec_bdy_width)%s", r,bdex,r,bdex,r,four_d ) ; |
|---|
| 602 | } |
|---|
| 603 | } else { |
|---|
| 604 | if ( zdim != NULL ) { |
|---|
| 605 | zdex = zdim->dim_order ; |
|---|
| 606 | sprintf(tx,"max(%sed3%d,%sed3%d)*(%sed3%d-%ssd3%d+1)*%sspec_bdy_width*4*%s", r,xdex,r,ydex,r,zdex,r,zdex,r,four_d ) ; |
|---|
| 607 | } else { |
|---|
| 608 | sprintf(tx,"max(%sed3%d,%sed3%d)*%sspec_bdy_width*4*%s", r,xdex,r,ydex,r,four_d ) ; |
|---|
| 609 | } |
|---|
| 610 | if ( tx[strlen(tx)-1] == '*' ) tx[strlen(tx)-1] = '\0' ; /* chop trailing * if four_d is "" */ |
|---|
| 611 | } |
|---|
| 612 | } |
|---|
| 613 | else |
|---|
| 614 | { |
|---|
| 615 | sprintf(tx,"%sspec_bdy_width,",r ) ; |
|---|
| 616 | } |
|---|
| 617 | strcat(tmp,tx) ; |
|---|
| 618 | } |
|---|
| 619 | else |
|---|
| 620 | { |
|---|
| 621 | for ( i = 0 ; i < p->ndims ; i++ ) |
|---|
| 622 | { |
|---|
| 623 | dimension_size_expression( r, tx , i , p , nlstructname ) ; |
|---|
| 624 | strcat(tmp,tx) ; |
|---|
| 625 | strcat(tmp,")*(") ; |
|---|
| 626 | } |
|---|
| 627 | } |
|---|
| 628 | if ( tmp[strlen(tmp)-1] == '(' ) { |
|---|
| 629 | tmp[strlen(tmp)-3] = '\0' ; /* get rid of trailing )*( */ |
|---|
| 630 | } else if ( tmp[strlen(tmp)-1] == ',' ) { |
|---|
| 631 | tmp[strlen(tmp)-1] = '\0' ; |
|---|
| 632 | } |
|---|
| 633 | if ( post != NULL ) strcat(tmp,post) ; |
|---|
| 634 | |
|---|
| 635 | return(tmp) ; |
|---|
| 636 | } |
|---|
| 637 | |
|---|
| 638 | int |
|---|
| 639 | dimension_size_expression ( char * r , char * tx , int i , node_t * p , char * nlstructname ) |
|---|
| 640 | { |
|---|
| 641 | char s[NAMELEN], e[NAMELEN] ; |
|---|
| 642 | |
|---|
| 643 | get_elem( r , nlstructname , s , i , p , 0 ) ; |
|---|
| 644 | get_elem( r , nlstructname , e , i , p , 1 ) ; |
|---|
| 645 | sprintf(tx,"((%s)-(%s)+1)", e , s ) ; |
|---|
| 646 | |
|---|
| 647 | } |
|---|
| 648 | |
|---|
| 649 | void |
|---|
| 650 | reset_mask ( unsigned int * mask , int e ) |
|---|
| 651 | { |
|---|
| 652 | int w ; |
|---|
| 653 | unsigned int m, n ; |
|---|
| 654 | |
|---|
| 655 | w = e / (8*sizeof(int)-1) ; |
|---|
| 656 | n = 1 ; |
|---|
| 657 | m = ~( n << e % (8*sizeof(int)-1) ) ; |
|---|
| 658 | if ( w >= 0 && w < IO_MASK_SIZE ) { |
|---|
| 659 | mask[w] &= m ; |
|---|
| 660 | } |
|---|
| 661 | } |
|---|
| 662 | |
|---|
| 663 | void |
|---|
| 664 | set_mask ( unsigned int * mask , int e ) |
|---|
| 665 | { |
|---|
| 666 | int w ; |
|---|
| 667 | unsigned int m, n ; |
|---|
| 668 | |
|---|
| 669 | w = e / (8*sizeof(int)-1) ; |
|---|
| 670 | n = 1 ; |
|---|
| 671 | m = ( n << e % (8*sizeof(int)-1) ) ; |
|---|
| 672 | if ( w >= 0 && w < IO_MASK_SIZE ) { |
|---|
| 673 | mask[w] |= m ; |
|---|
| 674 | } |
|---|
| 675 | } |
|---|
| 676 | |
|---|
| 677 | int |
|---|
| 678 | get_mask ( unsigned int * mask , int e ) |
|---|
| 679 | { |
|---|
| 680 | int w ; |
|---|
| 681 | unsigned int m, n ; |
|---|
| 682 | |
|---|
| 683 | w = e / (8*sizeof(int)-1) ; /* 8 is number of bits per byte */ |
|---|
| 684 | if ( w >= 0 && w < IO_MASK_SIZE ) { |
|---|
| 685 | m = mask[w] ; |
|---|
| 686 | n = ( 1 << e % (8*sizeof(int)-1) ) ;; |
|---|
| 687 | return ( (m & n) != 0 ) ; |
|---|
| 688 | } else { |
|---|
| 689 | return(0) ; |
|---|
| 690 | } |
|---|
| 691 | } |
|---|
| 692 | |
|---|
| 693 | #if 0 |
|---|
| 694 | main() |
|---|
| 695 | { |
|---|
| 696 | unsigned int m[5] ; |
|---|
| 697 | int i, ii ; |
|---|
| 698 | |
|---|
| 699 | for ( i = 0 ; i < 5*32 ; i++ ) { |
|---|
| 700 | for ( ii = 0 ; ii < 5 ; ii++ ) { m[ii] = 0xffffffff ; } |
|---|
| 701 | reset_mask( m, i ) ; |
|---|
| 702 | for ( ii = 4 ; ii >= 0 ; ii-- ) { printf(" %08x ", m[ii]) ; } |
|---|
| 703 | printf("\n") ; |
|---|
| 704 | } |
|---|
| 705 | |
|---|
| 706 | for ( i = 0 ; i < 5*32 ; i++ ) { |
|---|
| 707 | for ( ii = 0 ; ii < 5 ; ii++ ) { m[ii] = 0x0 ; } |
|---|
| 708 | set_mask( m, i ) ; |
|---|
| 709 | for ( ii = 4 ; ii >= 0 ; ii-- ) { printf(" %08x ", m[ii]) ; } |
|---|
| 710 | printf("\n") ; |
|---|
| 711 | } |
|---|
| 712 | |
|---|
| 713 | for ( ii = 0 ; ii < 5 ; ii++ ) { m[ii] = 0x0 ; } |
|---|
| 714 | set_mask( m, 82 ) ; |
|---|
| 715 | for ( i = 0 ; i < 5*32 ; i++ ) { |
|---|
| 716 | printf("%d %0d\n",i,get_mask(m,i) ) ; |
|---|
| 717 | } |
|---|
| 718 | } |
|---|
| 719 | #endif |
|---|