misc.c

References to this file elsewhere.
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 static int NumCores ;
445 static char dyncores[MAX_DYNCORES][NAMELEN] ;
446 
447 int
448 init_core_table()
449 {
450   NumCores = 0 ;
451   return(0) ;
452 }
453 
454 int
455 get_num_cores()
456 {
457   return( NumCores ) ;
458 }
459 
460 char *
461 get_corename_i(int i)
462 {
463   if ( i >= 0 && i < NumCores ) return( dyncores[i] ) ;
464   return(NULL) ;
465 }
466 
467 int
468 add_core_name ( char * name )
469 {
470   if ( name == NULL ) return(1) ;
471   if (get_core_name ( name ) == NULL )
472   {
473     if ( NumCores >= MAX_DYNCORES ) return(1) ;
474     strcpy( dyncores[NumCores++] , name ) ;
475   }
476   return(0) ;
477 }
478 
479 char *
480 get_core_name ( char * name )
481 {
482   int i ;
483   if ( name == NULL ) return(NULL) ;
484   for ( i = 0 ; i < NumCores ; i++ )
485   {
486     if ( !strcmp(name,dyncores[i]) ) return( dyncores[i] ) ; 
487   }
488   return(NULL) ;
489 }
490 
491 /* DESTRUCTIVE */
492 char *
493 make_upper_case ( char * str )
494 {
495   char * p ;
496   if ( str == NULL ) return (NULL) ;
497   for ( p = str ; *p ; p++ ) *p = toupper(*p) ; 
498   return(str) ;
499 }
500 
501 /* DESTRUCTIVE */
502 char *
503 make_lower_case ( char * str )
504 {
505   char * p ;
506   if ( str == NULL ) return (NULL) ;
507   for ( p = str ; *p ; p++ ) *p = tolower(*p) ; 
508   return(str) ;
509 }
510 
511 /* Routines for keeping typedef history  -ajb */
512 
513 static int NumTypeDefs ;
514 static char typedefs[MAX_TYPEDEFS][NAMELEN] ;
515 
516 int
517 init_typedef_history()
518 {
519   NumTypeDefs = 0 ;
520   return(0) ;
521 }
522 
523 int
524 get_num_typedefs()
525 {
526   return( NumTypeDefs ) ;
527 }
528 
529 char *
530 get_typename_i(int i)
531 {
532   if ( i >= 0 && i < NumTypeDefs ) return( typedefs[i] ) ;
533   return(NULL) ;
534 }
535 
536 int
537 add_typedef_name ( char * name )
538 {
539   if ( name == NULL ) return(1) ;
540   if ( get_typedef_name ( name ) == NULL )
541   {
542     if ( NumTypeDefs >= MAX_TYPEDEFS ) return(1) ;
543     strcpy( typedefs[NumTypeDefs++] , name ) ;
544   }
545   return(0) ;
546 }
547 
548 char *
549 get_typedef_name ( char * name )
550 {
551   int i ;
552   if ( name == NULL ) return(NULL) ;
553   for ( i = 0 ; i < NumTypeDefs ; i++ )
554   {
555     if ( !strcmp(name,typedefs[i]) ) return( typedefs[i] ) ; 
556   }
557   return(NULL) ;
558 }
559 
560 int
561 associated_with_4d_array( node_t * p ) 
562 {
563   int res = 0 ;
564   node_t * possble ;
565   char * last_underscore ;
566   char name_copy[128] ;
567   if ( p != NULL )
568   {
569     /* check this variable and see if it is a boundary variable that is associated with a 4d array */
570     strcpy( name_copy, p->name ) ;
571     if (( last_underscore = rindex( name_copy , '_' )) != NULL ) {
572       if ( !strcmp( last_underscore , "_b" ) || !strcmp( last_underscore , "_bt" ) ) {
573         *last_underscore = '\0' ;
574         if (( possble = get_entry( name_copy , Domain.fields )) != NULL ) {
575           res = possble->node_kind & FOURD ;
576         }
577       }
578     }
579   }
580   return(res) ;
581 }
582 
583 char *
584 array_size_expression ( char * refarg , char * pre , 
585                        int bdy , /* as defined in data.h */
586                        char * tmp , node_t * p , char * post ,
587                        char * nlstructname  )   /* provides name (with %) of structure in
588 						   which a namelist supplied dimension
589                                                    should be dereference from, or ""  */
590 {
591   int i ;
592   char tx[NAMELEN] ;
593   char r[NAMELEN],s[NAMELEN],four_d[NAMELEN] ;
594   int   bdex, xdex, ydex, zdex ;
595   node_t *xdim, *ydim, *zdim ;
596   char *pp ;
597   if ( p == NULL ) return("") ;
598   if ( p->ndims <= 0 && !p->boundary_array ) return("") ;
599   strcpy(tmp,"") ;
600   if ( pre != NULL ) strcat(tmp,pre) ;
601   strcpy(r,"") ;
602   if ( refarg != NULL ) strcat(r,refarg) ;
603 
604   if ( p->boundary_array )
605   {
606     if ( p->ndims > 0 )
607     {
608       xdim = get_dimnode_for_coord( p , COORD_X ) ;
609       ydim = get_dimnode_for_coord( p , COORD_Y ) ;
610       zdim = get_dimnode_for_coord( p , COORD_Z ) ;
611       if ( ydim == NULL )
612        { fprintf(stderr,"dimension_with_ranges: y dimension not specified for %s\n",p->name) ; return("") ; }
613       if ( xdim == NULL )
614        { fprintf(stderr,"dimension_with_ranges: x dimension not specified for %s\n",p->name) ; return("") ; }
615       
616       xdex = xdim->dim_order ;
617       ydex = ydim->dim_order ;
618 
619       if ( !strcmp( p->use , "_4d_bdy_array_" ) ) {   /* if a boundary array for a 4d tracer */
620         strcpy(s, p->name ) ;  /* copy the name and then remove everything after last underscore */
621         if ((pp=rindex( s, '_' )) != NULL ) *pp = '\0' ;
622         sprintf( four_d, "*num_%s,", s  ) ;
623       } else {
624         strcpy( four_d, "" ) ;
625       }
626       if ( sw_new_bdys ) {
627         if      ( bdy == P_XSB || bdy == P_XEB ) { bdex = ydex ; } 
628         else if ( bdy == P_YSB || bdy == P_YEB ) { bdex = xdex ; }
629         else { fprintf(stderr,"REGISTRY WARNING: internal error %s %d, bdy=%d,%s,%d \n",__FILE__,__LINE__,bdy,p->name,p->boundary) ; }
630         if ( zdim != NULL ) {
631           zdex = zdim->dim_order ;
632           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 ) ;
633         } else {
634           sprintf(tx,"(%sem3%d-%ssm3%d+1)*(%sspec_bdy_width)%s", r,bdex,r,bdex,r,four_d ) ;
635         }
636       } else {
637         if ( zdim != NULL ) {
638           zdex = zdim->dim_order ;
639           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 ) ;
640         } else {
641           sprintf(tx,"max(%sed3%d,%sed3%d)*%sspec_bdy_width*4*%s", r,xdex,r,ydex,r,four_d ) ;
642         }
643         if ( tx[strlen(tx)-1] == '*' ) tx[strlen(tx)-1] = '\0' ;  /* chop trailing * if four_d is "" */
644       }
645     }
646     else
647     {
648       sprintf(tx,"%sspec_bdy_width,",r ) ;
649     }
650     strcat(tmp,tx) ;
651   }
652   else
653   {
654     for ( i = 0 ; i < p->ndims ; i++ )
655     {
656       dimension_size_expression( r, tx , i , p , nlstructname ) ;
657       strcat(tmp,tx) ;
658       strcat(tmp,")*(") ;
659     }
660   }
661   if ( tmp[strlen(tmp)-1] == '(' ) {
662      tmp[strlen(tmp)-3] = '\0' ;  /* get rid of trailing )*( */
663   } else if ( tmp[strlen(tmp)-1] == ',' ) {
664      tmp[strlen(tmp)-1] = '\0' ;
665   }
666   if ( post != NULL ) strcat(tmp,post)  ;
667 
668   return(tmp) ;
669 }
670 
671 int
672 dimension_size_expression ( char * r , char * tx , int i , node_t * p , char * nlstructname )
673 {
674    char s[NAMELEN], e[NAMELEN] ;
675 
676    get_elem( r , nlstructname , s , i , p , 0 ) ;
677    get_elem( r , nlstructname , e , i , p , 1 ) ;
678    sprintf(tx,"((%s)-(%s)+1)", e , s ) ;
679 
680 }