[1] | 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 | |
---|
| 16 | int |
---|
| 17 | gen_scalar_indices ( char * dirname ) |
---|
| 18 | { |
---|
| 19 | FILE * fp, *fp5[7] ; |
---|
| 20 | char fname[NAMELEN], fname5[NAMELEN] ; |
---|
| 21 | char * fn = "scalar_indices.inc" ; |
---|
| 22 | char * fn2 = "scalar_tables.inc" ; |
---|
| 23 | char * fn3 = "scalar_tables_init.inc" ; |
---|
| 24 | char * fn4 = "scalar_indices_init.inc" ; |
---|
| 25 | int i ; |
---|
| 26 | |
---|
| 27 | char fn5[7][NAMELEN] ; |
---|
| 28 | |
---|
| 29 | strcpy( fn5[0], "in_use_for_config_ac.inc" ) ; /* hashing to make the run time function being generated faster */ |
---|
| 30 | strcpy( fn5[1], "in_use_for_config_df.inc" ) ; |
---|
| 31 | strcpy( fn5[2], "in_use_for_config_gk.inc" ) ; |
---|
| 32 | strcpy( fn5[3], "in_use_for_config_ln.inc" ) ; |
---|
| 33 | strcpy( fn5[4], "in_use_for_config_os.inc" ) ; |
---|
| 34 | strcpy( fn5[5], "in_use_for_config_tw.inc" ) ; |
---|
| 35 | strcpy( fn5[6], "in_use_for_config_xz.inc" ) ; |
---|
| 36 | |
---|
| 37 | strcpy( fname, fn ) ; |
---|
| 38 | if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; } |
---|
| 39 | if ((fp = fopen( fname , "w" )) == NULL ) return(1) ; |
---|
| 40 | print_warning(fp,fname) ; |
---|
| 41 | |
---|
| 42 | for ( i = 0 ; i < 7 ; i++ ) { |
---|
| 43 | strcpy( fname5, fn5[i] ) ; |
---|
| 44 | if ( strlen(dirname) > 0 ) { sprintf(fname5,"%s/%s",dirname,fn5[i]) ; } |
---|
| 45 | if ((fp5[i] = fopen( fname5 , "w" )) == NULL ) return(1) ; |
---|
| 46 | print_warning(fp5[i],fname5) ; |
---|
| 47 | } |
---|
| 48 | gen_scalar_indices1 ( fp, fp5 ) ; |
---|
| 49 | close_the_file( fp ) ; |
---|
| 50 | for ( i = 0 ; i < 7 ; i++ ) { |
---|
| 51 | close_the_file( fp5[i] ) ; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | strcpy( fname, fn2 ) ; |
---|
| 55 | if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn2) ; } |
---|
| 56 | if ((fp = fopen( fname , "w" )) == NULL ) { fprintf(stderr,"returning\n") ; return(1) ; } |
---|
| 57 | print_warning(fp,fname) ; |
---|
| 58 | gen_scalar_tables ( fp ) ; |
---|
| 59 | close_the_file( fp ) ; |
---|
| 60 | |
---|
| 61 | strcpy( fname, fn3 ) ; |
---|
| 62 | if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn3) ; } |
---|
| 63 | if ((fp = fopen( fname , "w" )) == NULL ) { fprintf(stderr,"returning\n") ; return(1) ; } |
---|
| 64 | print_warning(fp,fname) ; |
---|
| 65 | gen_scalar_tables_init ( fp ) ; |
---|
| 66 | close_the_file( fp ) ; |
---|
| 67 | |
---|
| 68 | strcpy( fname, fn4 ) ; |
---|
| 69 | if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn4) ; } |
---|
| 70 | if ((fp = fopen( fname , "w" )) == NULL ) { fprintf(stderr,"returning\n") ; return(1) ; } |
---|
| 71 | print_warning(fp,fname) ; |
---|
| 72 | gen_scalar_indices_init ( fp ) ; |
---|
| 73 | close_the_file( fp ) ; |
---|
| 74 | |
---|
| 75 | return(0) ; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | int |
---|
| 79 | gen_scalar_tables ( FILE * fp ) |
---|
| 80 | { |
---|
| 81 | node_t * p ; |
---|
| 82 | for ( p = FourD ; p != NULL ; p=p->next4d ) |
---|
| 83 | { |
---|
| 84 | fprintf(fp," INTEGER, TARGET :: %s_index_table( param_num_%s, max_domains )\n",p->name,p->name ) ; |
---|
| 85 | fprintf(fp," INTEGER, TARGET :: %s_num_table( max_domains )\n", p->name ) ; |
---|
| 86 | fprintf(fp," TYPE(streamrec), TARGET :: %s_streams_table( max_domains, param_num_%s )\n", p->name,p->name ) ; |
---|
| 87 | fprintf(fp," LOGICAL, TARGET :: %s_boundary_table( max_domains, param_num_%s )\n", p->name,p->name ) ; |
---|
| 88 | fprintf(fp," CHARACTER*256, TARGET :: %s_dname_table( max_domains, param_num_%s )\n", p->name,p->name ) ; |
---|
| 89 | fprintf(fp," CHARACTER*256, TARGET :: %s_desc_table( max_domains, param_num_%s )\n", p->name,p->name ) ; |
---|
| 90 | fprintf(fp," CHARACTER*256, TARGET :: %s_units_table( max_domains, param_num_%s )\n", p->name,p->name ) ; |
---|
| 91 | } |
---|
| 92 | return(0) ; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | int |
---|
| 96 | gen_scalar_tables_init ( FILE * fp ) |
---|
| 97 | { |
---|
| 98 | node_t * p ; |
---|
| 99 | for ( p = FourD ; p != NULL ; p=p->next4d ) |
---|
| 100 | { |
---|
| 101 | fprintf(fp," %s_num_table( j ) = 1\n",p->name ) ; |
---|
| 102 | } |
---|
| 103 | return(0) ; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | int |
---|
| 107 | gen_scalar_indices_init ( FILE * fp ) |
---|
| 108 | { |
---|
| 109 | node_t * p ; |
---|
| 110 | for ( p = FourD ; p != NULL ; p=p->next4d ) |
---|
| 111 | { |
---|
| 112 | fprintf(fp," num_%s = %s_num_table( idomain )\n",p->name,p->name ) ; |
---|
| 113 | } |
---|
| 114 | return(0) ; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | int |
---|
| 118 | gen_scalar_indices1 ( FILE * fp, FILE ** fp2 ) |
---|
| 119 | { |
---|
| 120 | node_t * p, * memb , * pkg, * rconfig, * fourd, *x ; |
---|
| 121 | char * c , *pos1, *pos2 ; |
---|
| 122 | char assoc_namelist_var[NAMELEN], assoc_namelist_choice[NAMELEN], assoc_4d[NAMELEN_LONG], fname[NAMELEN_LONG] ; |
---|
| 123 | char scalars_str[NAMELEN_LONG] ; |
---|
| 124 | char * scalars ; |
---|
| 125 | int i ; |
---|
| 126 | |
---|
| 127 | for ( p = FourD ; p != NULL ; p = p->next ) |
---|
| 128 | { for ( memb = p->members ; memb != NULL ; memb = memb->next ) |
---|
| 129 | { if ( strcmp(memb->name,"-") ) fprintf(fp," P_%s = 1 ; F_%s = .FALSE. \n", memb->name, memb->name ) ; } } |
---|
| 130 | |
---|
| 131 | for ( pkg = Packages ; pkg != NULL ; pkg = pkg->next ) |
---|
| 132 | { |
---|
| 133 | strcpy( assoc_namelist_var , pkg->pkg_assoc ) ; |
---|
| 134 | |
---|
| 135 | if ((c = index( assoc_namelist_var , '=' ))==NULL) continue ; |
---|
| 136 | *c = '\0' ; c += 2 ; |
---|
| 137 | strcpy( assoc_namelist_choice , c ) ; |
---|
| 138 | if ((rconfig=get_rconfig_entry ( assoc_namelist_var )) == NULL ) |
---|
| 139 | { fprintf(stderr, |
---|
| 140 | "WARNING: There is no associated namelist variable %s\n", |
---|
| 141 | assoc_namelist_var) ; continue ; } |
---|
| 142 | fprintf(fp," IF (model_config_rec%%%s%s==%s)THEN\n", |
---|
| 143 | assoc_namelist_var, |
---|
| 144 | (atoi(rconfig->nentries)!=1)?"(idomain)":"", /* a little tricky; atoi of nentries will be '0' for a string like max_domains */ |
---|
| 145 | assoc_namelist_choice) ; |
---|
| 146 | strcpy(scalars_str,pkg->pkg_4dscalars) ; |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | if ((scalars = strtok_rentr(scalars_str,";", &pos1)) != NULL) |
---|
| 150 | { |
---|
| 151 | while ( scalars != NULL ) { |
---|
| 152 | |
---|
| 153 | if ((c = strtok_rentr(scalars,":",&pos2)) != NULL) strcpy(assoc_4d,c) ; /* get name of associated 4d array */ |
---|
| 154 | if (strcmp(c,"-")) { |
---|
| 155 | if ( (fourd=get_4d_entry( assoc_4d )) != NULL || !strcmp( assoc_4d, "state" ) ) { |
---|
| 156 | for ( c = strtok_rentr(NULL,",",&pos2) ; c != NULL ; c = strtok_rentr(NULL,",",&pos2) ) |
---|
| 157 | { |
---|
| 158 | if ( fourd != NULL && ( ( x = get_entry( c , fourd->members )) != NULL ) ) { |
---|
| 159 | fprintf(fp," IF ( %s_index_table( PARAM_%s , idomain ) .lt. 1 ) THEN\n",assoc_4d,c) ; |
---|
| 160 | fprintf(fp," %s_num_table(idomain) = %s_num_table(idomain) + 1\n",assoc_4d,assoc_4d) ; |
---|
| 161 | fprintf(fp," P_%s = %s_num_table(idomain)\n",c,assoc_4d) ; |
---|
| 162 | fprintf(fp," %s_index_table( PARAM_%s , idomain ) = P_%s\n",assoc_4d,c,c) ; |
---|
| 163 | fprintf(fp," ELSE\n") ; |
---|
| 164 | fprintf(fp," P_%s = %s_index_table( PARAM_%s , idomain )\n",c,assoc_4d,c) ; |
---|
| 165 | fprintf(fp," END IF\n") ; |
---|
| 166 | { |
---|
| 167 | char fourd_bnd[NAMELEN] ; |
---|
| 168 | /* check for the existence of a fourd boundary array associated with this 4D array */ |
---|
| 169 | /* set io_mask accordingly for gen_wrf_io to know that it should generate i/o for _b and _bt */ |
---|
| 170 | /* arrays */ |
---|
| 171 | sprintf(fourd_bnd,"%s_b",assoc_4d) ; |
---|
| 172 | if ( get_entry( fourd_bnd ,Domain.fields) != NULL ) { |
---|
| 173 | x->boundary = 1 ; |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | fprintf(fp," %s_boundary_table( idomain, P_%s ) = %s\n",assoc_4d,c, (x->boundary==1)?".TRUE.":".FALSE." ) ; |
---|
| 177 | fprintf(fp," %s_dname_table( idomain, P_%s ) = '%s'\n",assoc_4d,c,x->dname) ; |
---|
| 178 | fprintf(fp," %s_desc_table( idomain, P_%s ) = '%s'\n",assoc_4d,c,x->descrip) ; |
---|
| 179 | fprintf(fp," %s_units_table( idomain, P_%s ) = '%s'\n",assoc_4d,c,x->units) ; |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | for ( i = 0 ; i < IO_MASK_SIZE ; i++ ) { |
---|
| 183 | fprintf(fp," %s_streams_table( idomain, P_%s )%%stream(%d) = %d ! %08x \n",assoc_4d,c, |
---|
| 184 | i+1,x->io_mask[i],x->io_mask[i] ) ; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | fprintf(fp," F_%s = .TRUE.\n",c) ; |
---|
| 188 | } else if ((p = get_entry( c , Domain.fields )) != NULL ) { |
---|
| 189 | int tag, fo ; |
---|
| 190 | for ( tag = 1 ; tag <= p->ntl ; tag++ ) |
---|
| 191 | { |
---|
| 192 | if ( !strcmp ( p->use , "_4d_bdy_array_") ) { |
---|
| 193 | strcpy(fname,p->name) ; |
---|
| 194 | } else { |
---|
| 195 | strcpy(fname,field_name(t4,p,(p->ntl>1)?tag:0)) ; |
---|
| 196 | } |
---|
| 197 | make_lower_case(fname) ; |
---|
| 198 | |
---|
| 199 | fo = 0 ; |
---|
| 200 | if ( 'x' <= fname[0] ) { fo = 6 ; } |
---|
| 201 | else if ( 't' <= fname[0] ) { fo = 5 ; } |
---|
| 202 | else if ( 'o' <= fname[0] ) { fo = 4 ; } |
---|
| 203 | else if ( 'l' <= fname[0] ) { fo = 3 ; } |
---|
| 204 | else if ( 'g' <= fname[0] ) { fo = 2 ; } |
---|
| 205 | else if ( 'd' <= fname[0] ) { fo = 1 ; } |
---|
| 206 | else { fo = 0 ; } |
---|
| 207 | |
---|
| 208 | fprintf(fp2[fo],"IF(TRIM(vname).EQ.'%s')THEN\n",fname) ; |
---|
| 209 | fprintf(fp2[fo]," IF(uses.EQ.0)THEN\n"); |
---|
| 210 | fprintf(fp2[fo]," in_use = model_config_rec%%%s%s.EQ.%s\n",assoc_namelist_var,(atoi(rconfig->nentries)!=1)?"(id)":"",assoc_namelist_choice) ; |
---|
| 211 | fprintf(fp2[fo]," uses = 1\n") ; |
---|
| 212 | fprintf(fp2[fo]," ELSE\n") ; |
---|
| 213 | fprintf(fp2[fo]," in_use = in_use.OR.model_config_rec%%%s%s.EQ.%s\n",assoc_namelist_var,(atoi(rconfig->nentries)!=1)?"(id)":"",assoc_namelist_choice) ; |
---|
| 214 | fprintf(fp2[fo]," ENDIF\n") ; |
---|
| 215 | fprintf(fp2[fo],"ENDIF\n") ; |
---|
| 216 | |
---|
| 217 | } |
---|
| 218 | } else { |
---|
| 219 | fprintf(stderr, "WARNING: %s is not a member of 4D array %s\n",c,assoc_4d);continue; |
---|
| 220 | } |
---|
| 221 | } |
---|
| 222 | } else { |
---|
| 223 | fprintf(stderr, "WARNING: There is no 4D array named %s\n",assoc_4d);continue ; |
---|
| 224 | } |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | scalars = strtok_rentr(NULL,";", &pos1) ; |
---|
| 228 | |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | fprintf(fp," END IF\n") ; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | return(0) ; |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | |
---|