11 #include "protos_kpp.h"
19 /* variable name of molecular nitrogen in KPP file*/
20 char * kpp_n2
= "N2" ;
22 /* variable name of molecular oxygen in KPP file*/
23 char * kpp_o2
= "O2" ;
25 /* variable name of CO2 in KPP file*/
26 char * kpp_co2
= "CO2" ;
28 /* variable name of water vapor in KPP file*/
29 char * kpp_h2o
= "H2O" ;
32 /* variable name of third body in KPP file*/
33 char * kpp_third_body
= "M" ;
37 compare_kpp_to_species ( char * kpp_dirname
)
39 knode_t
* p1
, *p2
, * p
, * pm1
, * pm2
, * p3
, * pm3
, wrf_kpp_equivs
;
40 char name1
[NAMELEN
], name2
[NAMELEN
], name3
[NAMELEN
] ;
41 char equivfilename
[NAMELEN
];
43 char inln
[NAMELEN
], newln
[NAMELEN
];
44 int in_comment
, got_it
;
45 char wrf_name
[NAMELEN
], kpp_name
[NAMELEN
];
49 /* first find matching packages */
52 for ( p1
= KPP_packs
; p1
!= NULL
; p1
= p1
->next
) {
53 for ( p2
= WRFC_packs
; p2
!= NULL
; p2
= p2
->next
) {
55 /* printf(" ... test0 %s %s\n",p1->name, p2->name ); */
58 if ( strcmp (p1
->name
, p2
->name
) == 0) {
62 /* point from a KPP-pack to the corresponding WRFC_pack */
63 p1
->assoc_wrf_pack
= p2
;
73 for ( p1
= KPP_packs
; p1
!= NULL
; p1
= p1
->next
) {
74 p2
= p1
->assoc_wrf_pack
;
75 printf(" ... testing %s %s\n",p1
, p2
);
77 fprintf(stderr
, "\n \n FOUND match between WRF-Chem/KPP for mechanism: %s \n", p2
->name
);
80 for ( pm1
= p1
-> members
; pm1
!= NULL
; pm1
= pm1
->next
) {
87 /* if file *_wrfkpp.equiv exists store contents in wrf_kpp_equivs struct */
89 sprintf( equivfilename
, "%s/%s/%s_wrfkpp.equiv", kpp_dirname
, p2
->name
, p2
->name
);
91 /* printf("%s \n", equivfilename ); */
93 equivFile
= fopen (equivfilename
, "r" );
95 if ( equivFile
== NULL
) {
96 fprintf(stderr
," Did NOT find file %s\n",equivfilename
);
100 fprintf(stderr
," Found file %s\n",equivfilename
);
102 /* loop over lines in wrf_kpp_equiv file */
103 while ( fgets ( inln
, NAMELEN
, equivFile
) != NULL
){
104 if ( DEBUGR
== 1 ) printf(" i %s ", inln
);
108 for(j
= 0; j
< NAMELEN
; j
++) wrf_name
[j
]='\0';
109 for(j
= 0; j
< NAMELEN
; j
++) kpp_name
[j
]='\0';
113 for(j
= 0; j
< NAMELEN
; j
++) newln
[j
]='\0';
115 while ( inln
[n
] != '\0' ){
116 if (inln
[n
] == '!') {
126 if ( DEBUGR
== 1 ) printf(" n %s ", newln
);
127 if ( !in_comment
&& strlen(newln
) > 1 ) {
129 while ( newln
[n
] != '\0' ){
132 while ( newln
[n
] != ' ' ){
133 wrf_name
[i
]=newln
[n
];
141 while ( newln
[n
] != ' ' && newln
[n
] != '\0'){
142 if (newln
[n
] != '\n'){
143 kpp_name
[i
]=newln
[n
];
155 make_upper_case(wrf_name
);
157 make_upper_case(kpp_name
);
159 /* wrf_name=strtok(newln, " ");
160 kpp_name=strtok(NULL, " "); */
161 printf(" kpp_name, wrf_name %s %s \n ", kpp_name
, wrf_name
);
165 /* check whether wrf_name was found in Registry */
166 /* either as associated 4D chem var in a package */
169 for ( pm2
= p2
-> members
; pm2
!= NULL
; pm2
= pm2
->next
) {
171 strcpy( name2
, pm2
->name
);
172 make_upper_case(name2
);
175 fprintf(stderr
,"comp %s %s \n",pm2
->name
, wrf_name
);
177 if ( strcmp(name2
, wrf_name
) == 0 ) {
188 /* (b) or declared as a non-transported radical */
194 for ( pm3
= p3
-> members
; pm3
!= NULL
; pm3
= pm3
->next
) {
197 strcpy( name3
, pm3
->name
);
198 make_upper_case(name3
);
202 fprintf(stderr
,"comp ra %s %s \n",name3
, wrf_name
);
204 if ( strcmp(name3
, wrf_name
) == 0 ) {
214 fprintf(stderr
, "ERROR: variable name %s was found in file %s but not in the Registry \n", wrf_name
, equivfilename
);
219 /*-------------------------------------------------*/
221 /* check whether kpp_name was found in species file and
222 store name from wrf_kpp_equiv file in assoc_wrf_name */
224 for ( pm1
= p1
-> members
; pm1
!= NULL
; pm1
= pm1
->next
) {
227 strcpy( name1
, pm1
->name
);
228 make_upper_case(name1
);
230 if ( strcmp(name1
, kpp_name
) == 0 ) {
232 pm1
->found_match
= 1;
233 strcpy( pm1
->assoc_wrf_name
, wrf_name
);
237 /* still have to check if it is a radical .. */
239 for ( pm3
= p3
-> members
; pm3
!= NULL
; pm3
= pm3
->next
) {
242 strcpy( name3
, pm3
->name
);
243 make_upper_case(name3
);
247 fprintf(stderr
,"comp ra %s %s \n",name3
, wrf_name
);
249 if ( strcmp(name3
, wrf_name
) == 0 ) {
258 fprintf(stderr
,"matching %s %s %i \n",pm1
->name
, kpp_name
, got_it
);
262 fprintf(stderr
,"comp %s %s %i \n",pm1
->name
, kpp_name
, got_it
);
271 fprintf(stderr
, "ERROR: variable name %s was not found in species file in directory %s/%s but it was found in %s \n", kpp_name
, kpp_dirname
, p2
->name
, equivfilename
);
283 /* compare compound names, use variable */
284 for ( pm1
= p1
-> members
; pm1
!= NULL
; pm1
= pm1
->next
) {
288 fprintf(stderr
, " SEARCHING FOR %s \n", pm1
->name
);
292 strcpy( name1
, pm1
->name
);
293 make_upper_case(name1
);
295 for ( pm2
= p2
-> members
; pm2
!= NULL
; pm2
= pm2
->next
) {
298 strcpy( name2
, pm2
->name
);
299 make_upper_case(name2
);
303 if ( strcmp (name1
, name2
) == 0) {
304 /* store matching name of WRF var in members of KPP_packs */
305 strcpy( pm1
->assoc_wrf_name
, pm2
->name
);
306 pm1
->found_match
= 1;
308 fprintf(stderr
, " matching names: %s %s \n", pm1
->name
, pm1
->assoc_wrf_name
);
314 /* the same for radicals */
315 if ( pm1
->found_match
!= 1 ) {
318 fprintf(stderr
, " STILL SEARCHING FOR %s \n", pm1
->name
);
323 for ( pm3
= p3
-> members
; pm3
!= NULL
; pm3
= pm3
->next
) {
326 strcpy( name3
, pm3
->name
);
327 make_upper_case(name3
);
330 /* fprintf(stderr, " comparing radicals %s %s \n", name1, name3); */
332 if ( strcmp (name1
, name3
) == 0) {
333 /* store matching name of WRF var in members of KPP_packs */
334 strcpy( pm1
->assoc_wrf_name
, pm3
->name
);
335 pm1
->found_match
= 1;
338 fprintf(stderr
, " matching radical name : %s %s \n", pm1
->name
, pm1
->assoc_wrf_name
);
348 /* special handling for fixed species */
355 /* take care of water, third body, N2, O2 */
356 for ( pm1
= p1
-> members
; pm1
!= NULL
; pm1
= pm1
->next
) {
357 strcpy( name1
, pm1
->name
);
358 make_upper_case(name1
);
359 if ( strcmp (name1
, kpp_third_body
) == 0) {
360 pm1
->found_match
= 2;
361 strcpy( pm1
->assoc_wrf_name
, "THIRD BODY");
364 if ( strcmp (name1
, kpp_h2o
) == 0) {
365 pm1
->found_match
= 2;
366 strcpy( pm1
->assoc_wrf_name
, "WATER VAPOR");
369 if ( strcmp (name1
, kpp_n2
) == 0) {
370 pm1
->found_match
= 2;
371 strcpy( pm1
->assoc_wrf_name
, "MOLECULAR NITROGEN");
374 if ( strcmp (name1
, kpp_o2
) == 0) {
375 pm1
->found_match
= 2;
376 strcpy( pm1
->assoc_wrf_name
, "MOLECULAR OXYGEN");
379 if ( strcmp (name1
, kpp_co2
) == 0) {
380 pm1
->found_match
= 2;
381 strcpy( pm1
->assoc_wrf_name
, "CO2");
386 if ( p1
-> got_air
!= 1 ) {
387 fprintf(stderr
, "ERROR: variable name for third body in KPP species file is expected to be %s, but was not found in %s species file \n", kpp_third_body
, p2
->name
);
391 if ( got_h2o
!= 1 ) {
392 fprintf(stderr
, "ERROR: variable name for water in KPP species file is expected to be %s, but was not found in %s species file\n", kpp_h2o
, p2
->name
);
405 for ( p1 = KPP_packs ; p1 != NULL ; p1 = p1->next ) {
406 p2 = p1->assoc_wrf_pack;
408 fprintf(stderr, "1 MATCHING PACKS: %s \n", p2->name);
409 for ( pm1 = p1 -> members; pm1 != NULL ; pm1 = pm1->next ) {
411 if ( pm1 -> found_match == 1 ) {
412 fprintf(stderr, " 1 found %s %s \n", pm1->name, pm1 -> assoc_wrf_name );
414 else if ( pm1 -> found_match == 2 ) {
415 fprintf(stderr, " 1 found %s %s \n", pm1->name, pm1 -> assoc_wrf_name );
418 fprintf(stderr, " 0 NOT found %s \n", pm1->name );