4 #include <sys/resource.h>
12 typedef struct tuv_node_struct
{
16 struct tuv_node_struct
*next
;
19 typedef struct wrf_node_struct
{
22 struct wrf_node_struct
*next
;
23 struct tuv_node_struct
*tuv_node
;
26 int tuv_match( wrf_node
*head
, char *match_name
);
28 int main( int argc
, char *argv
[], char *env
[] ) {
29 char fname_in
[NAMELEN
], dir
[NAMELEN
], fname_inc
[NAMELEN
];
30 char inln
[NAMELEN
], outln
[NAMELEN
], piece
[JLEN
];
31 char squezzed
[NAMELEN
];
32 char *wrf_jname
, *cwrk
, *tuv_jspec
, *token
;
34 FILE * fp_in
, *fp_set
, *fp_def
;
37 tuv_node
*Tuv_node
, *Tuv_node_wrk
;
39 int l
, m
, n
, nwrf
, ntuv
, nltuv
;
44 strcpy( fname_in
, "" ) ;
49 fprintf(stderr
,"tuv_kpp: Argument = %s\n",mech
);
50 // open and write inc files
52 if( !strcmp(mech
,"LAST") )
53 strcpy(fname_inc
,"../../inc/tuv2wrf_jvals.inc");
55 strcpy(fname_inc
,"../../../../inc/tuv2wrf_jvals.inc");
56 if( (fp_set
= fopen( fname_inc
,"a" )) == NULL
) {
57 fprintf(stderr
,"Can not open %s\n",fname_inc
);
60 if( !strcmp(mech
,"LAST") )
61 strcpy(fname_inc
,"../../inc/tuvdef_jvals.inc");
63 strcpy(fname_inc
,"../../../../inc/tuvdef_jvals.inc");
64 if( (fp_def
= fopen( fname_inc
,"a" )) == NULL
) {
65 fprintf(stderr
,"Can not open %s\n",fname_inc
);
69 if( !strcmp(mech
,"FIRST") ) {
70 fprintf(fp_set
," select case( config_flags%%chem_opt )\n");
71 fprintf(fp_def
," select case( config_flags%%chem_opt )\n");
73 else if( !strcmp(mech
,"LAST") ) {
74 fprintf(fp_set
," end select\n");
75 fprintf(fp_def
," end select\n");
78 fprintf(stderr
,"tuv_kpp: Mechanism = %s\n",mech
);
79 sprintf( fname_in
,"%s.tuv.jmap",mech
);
80 if( (fp_in
= fopen( fname_in
,"r" )) == NULL
) {
81 fprintf(stderr
,"File %s does not exist\n",fname_in
);
85 Wrf_node
= (wrf_node
*)malloc( sizeof(wrf_node
) );
86 if( Wrf_node
== NULL
) {
87 fprintf(stderr
,"Failed to allocate Wrf_node\n");
93 while( fgets( inln
,NAMELEN
,fp_in
) != NULL
) {
95 Wrf_node
->next
= (wrf_node
*)malloc( sizeof(wrf_node
) );
96 if( Wrf_node
== NULL
) {
97 fprintf(stderr
,"Failed to allocate Wrf_node\n");
100 Wrf_node
= Wrf_node
->next
;
102 // remove white space from input line
104 for( m
= 0; m
< strlen( inln
); m
++ ) {
106 squezzed
[l
++] = inln
[m
];
108 squezzed
[l
-1] = '\0';
109 tuv_jspec
= index( squezzed
,':' );
110 if( tuv_jspec
== NULL
) {
111 fprintf(stderr
,"Input j mapping is invalid\n");
116 strcpy( Wrf_node
->name
,squezzed
);
118 Wrf_node
->ndx
= nwrf
;
119 token
= strtok( tuv_jspec
,"+" );
122 if( token
!= NULL
) {
123 Tuv_node_wrk
= (tuv_node
*)malloc( sizeof(tuv_node
) );
124 if( Tuv_node_wrk
== NULL
) {
125 fprintf(stderr
,"Failed to allocate Tuv_node\n");
128 strcpy( Tuv_node_wrk
->name
,token
);
129 n
= tuv_match( Wrf_HEAD
, token
);
132 Tuv_node_wrk
->ndx
= ntuv
;
135 Tuv_node_wrk
->dup
= 1;
136 Tuv_node_wrk
->ndx
= n
;
138 if( nltuv
== 0 ) Wrf_node
->tuv_node
= Tuv_node_wrk
;
139 else Tuv_node
->next
= Tuv_node_wrk
;
140 Tuv_node
= Tuv_node_wrk
;
141 token
= strtok( NULL
,"+" );
150 // enumerate the wrf jspecs
152 // fprintf(stderr,"\n");
153 // fprintf(stderr,"WRF photo rates\n");
154 // for( Wrf_node = Wrf_HEAD; Wrf_node != NULL; Wrf_node = Wrf_node->next ) {
155 // fprintf(stderr,"%s\n",Wrf_node->name);
158 // enumerate the tuv jspecs
160 // fprintf(stderr,"\n");
161 // fprintf(stderr,"TUV photo rates\n");
162 // for( Wrf_node = Wrf_HEAD; Wrf_node != NULL; Wrf_node = Wrf_node->next ) {
163 // for( Tuv_node = Wrf_node->tuv_node; Tuv_node != NULL; Tuv_node = Tuv_node->next ) {
164 // fprintf(stderr,"%s\n",Tuv_node->name);
170 fprintf(fp_set
," case( %s_kpp )\n",mech
);
171 fprintf(fp_def
," case( %s_kpp )\n",mech
);
174 for( Wrf_node
= Wrf_HEAD
; Wrf_node
!= NULL
; Wrf_node
= Wrf_node
->next
) {
175 sprintf(outln
," ph_%s(i,kts:kte,j) = ",Wrf_node
->name
);
176 if( Wrf_node
== Wrf_HEAD
) {
177 fprintf(fp_def
," nj = %d\n",ntuv
);
178 fprintf(fp_def
," allocate( tuv_jname(nj) )\n");
181 for( Tuv_node
= Wrf_node
->tuv_node
; Tuv_node
!= NULL
; Tuv_node
= Tuv_node
->next
) {
183 sprintf(piece
,"tuv_prate(kts:kte,%d)",Tuv_node
->ndx
);
185 sprintf(piece
," + tuv_prate(kts:kte,%d)",Tuv_node
->ndx
);
186 strcat( outln
,piece
);
188 if( !Tuv_node
->dup
) {
190 fprintf(fp_def
," tuv_jname(%d) = '%s'\n",n
,Tuv_node
->name
);
191 if( !strcmp( Tuv_node
->name
,"j_o2" ) )
195 fprintf(fp_set
,"%s\n",outln
);
197 fprintf(fp_def
," j_o2_ndx = %d\n",j_o2_ndx
);
204 int tuv_match( wrf_node
*head
, char *match_name
) {
209 for( wrfnode
= head
; wrfnode
!= NULL
; wrfnode
= wrfnode
->next
) {
210 for( thisnode
= wrfnode
->tuv_node
; thisnode
!= NULL
; thisnode
= thisnode
->next
) {
211 if( !strcmp( thisnode
->name
,match_name
) )
212 return( thisnode
->ndx
);