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