2 WRF-Chem to KPP coupler (WKC)
4 Copyright (C) 2006 Marc Salzmann
6 WKC is free software; you can redistribute it and/or modify it under the
7 terms of the GNU General Public License as published by the Free Software
8 Foundation (http://www.gnu.org/copyleft/gpl.html); either version 2 of the
9 License, or (at your option) any later version.
11 WKC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, consult http://www.gnu.org/copyleft/gpl.html or
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
22 Max Planck Institute for Chemistry
23 Department of Atmospheric Chemistry
26 e-mail: salzmann@mpch-mainz.mpg.de
27 www.mpch-mainz.mpg.de/~salzmann/my_home/index.html
29 .....................................................................
31 assumed directory name in KPP corresponds to WRF package name
46 #include "protos_kpp.h"
58 /* for data storage issues see kpp_data.h */
61 /* cd chem/KPP/util/wkc; make -i -r CC="gcc" ; cd ../../../..
62 in ~WRF: chem/KPP/util/wkc/registry_kpp Registry/Registry */
66 gen_kpp ( char * inc_dirname
, char * kpp_dirname
)
71 /* put chem compound names defined in Registry into linked list WRFC_packs */
73 if ( DEBUGR
== 1 ) printf("next: get_wrf_chem_specs \n");
74 get_wrf_chem_specs () ;
75 if ( DEBUGR
== 2 ) write_list_to_screen( WRFC_packs
) ;
80 /* put radical names defined in Registry into linked list WRFC_radicals */
82 if ( DEBUGR
== 1 ) printf("next: get_wrf_radicals \n");
84 if ( DEBUGR
== 2 ) write_list_to_screen( WRFC_radicals
) ;
87 /* put photolysis rates defined in Registry into linked list WRFC_jvals */
89 if ( DEBUGR
== 1 ) printf("next: get_wrf_jvals \n");
91 if ( DEBUGR
== 2 ) write_list_to_screen( WRFC_jvals
) ;
94 /* read KPP species files and put compound names into linked list KPP_packs */
95 if ( DEBUGR
== 1 ) printf("next: get_kpp_chem_specs \n");
96 get_kpp_chem_specs ( kpp_dirname
) ;
97 if ( DEBUGR
== 2 ) {write_list_to_screen( KPP_packs
) ;}
103 /* define pointer from each KPP package to corresponding WRF-Chem chemistry package and check whether variable names are consistent. If *_wrfkpp.equiv file exists in KPP directory use it for name matching */
106 if ( DEBUGR
== 1 ) printf("next: compare_kpp_to_species \n");
107 compare_kpp_to_species ( kpp_dirname
);
113 /* write some output to screen */
114 if ( DEBUGR
== 1 ) printf("next: screen_out \n");
118 /* make sure that wrf and kpp variables match and stop if not. */
119 if ( DEBUGR
== 1 ) printf("next: check_all \n");
120 check_all ( kpp_dirname
);
124 /* add the kpp generated modules to the Makefile in the chem directory */
125 if ( DEBUGR
== 1 ) printf("next: change_chem_Makefile \n");
126 change_chem_Makefile ( );
131 /* write the mechanism driver */
132 if ( DEBUGR
== 1 ) printf("next: gen_kpp_mechanism_driver (writing chem/kpp_mechanism_driver.F) \n");
133 gen_kpp_mechanism_driver ( );
136 if ( DEBUGR
== 1 ) printf("next: gen_call_to_kpp_mechanism_driver (writing inc/call_to_kpp_mech_drive.inc) \n");
137 gen_kpp_call_to_mech_dr ( );
140 /* write arguments for call to KPPs Update_Rconst */
141 if ( DEBUGR
== 1 ) printf("next: gen_kpp_args_to_Update_Rconst (writing inc/args_to_update_rconst.inc and inc/<decls_update_rconst.inc) \n");
142 gen_kpp_args_to_Update_Rconst ( );
145 /* write the interface */
146 if ( DEBUGR
== 1 ) printf("next: gen_kpp_interface (writing several module_kpp_* for each mechanism)\n");
147 gen_kpp_interface ( );
151 if ( DEBUGR
== 1 ) printf("DONE gen_kpp \n");
159 /*---------------------------------------------------------------------*/
161 write_list_to_screen ( knode_t
* starting_point
)
164 for ( l1
= starting_point
; l1
!= NULL
; l1
= l1
->next
)
166 fprintf(stderr
,"-- Mechanism %s ----- \n", l1
->name
);
167 for ( l2
= l1
->members
; l2
!= NULL
; l2
= l2
->next
)
169 fprintf(stderr
,"%s ", l2
->name
);
171 fprintf(stderr
," \n \n ");
175 /*---------------------------------------------------------------------*/
179 knode_t
* p1
, * p2
, * pm1
;
184 for ( p1
= KPP_packs
; p1
!= NULL
; p1
= p1
->next
) {
186 /* fprintf(stderr, "KPP PACK: %s \n", p1->name); */
188 p2
= p1
->assoc_wrf_pack
;
190 fprintf(stderr
, "MATCHING PACK: %s_kpp \n", p2
->name
);
192 for ( pm1
= p1
-> members
; pm1
!= NULL
; pm1
= pm1
->next
) {
194 if ( pm1
-> found_match
== 1 ) {
196 if ( pm1
-> is_radical
== 1 ) {
198 fprintf(stderr
, " 1 found (radical) %s %s \n", pm1
->name
, pm1
-> assoc_wrf_name
);
203 fprintf(stderr
, " 1 found %s %s \n", pm1
->name
, pm1
-> assoc_wrf_name
);
207 else if ( pm1
-> found_match
== 2 ) {
208 fprintf(stderr
, " 1 found (special) %s %s \n", pm1
->name
, pm1
-> assoc_wrf_name
);
211 fprintf(stderr
, " 0 NOT found %s \n", pm1
->name
);
219 /* if ( count == 0 ) {
220 fprintf(stderr, " DIDN'T FIND ANY matching packages \n");
221 fprintf(stderr, " .. add packages to Registry and to chem/KPP/mechanisms \n");
231 /*---------------------------------------------------------------------*/
233 check_all( char* kpp_dirname
)
235 knode_t
* p1
, * p2
, * pm1
;
236 for ( p1
= KPP_packs
; p1
!= NULL
; p1
= p1
->next
) {
237 p2
= p1
->assoc_wrf_pack
;
240 for ( pm1
= p1
-> members
; pm1
!= NULL
; pm1
= pm1
->next
) {
242 if ( pm1
-> found_match
< 1 ) {
245 fprintf(stderr
, "\n FATAL ERROR MAPPING WRF TO KPP SPECIES FOR MECHANISM: %s \n", p2
->name
);
246 fprintf(stderr
, " variable %s NOT FOUND \n", pm1
->name
);
247 fprintf(stderr
, " Please check: \n");
248 fprintf(stderr
, " (a) the Registry \n");
249 fprintf(stderr
, " (b) ./%s/%s/%s.spc\n", kpp_dirname
, p2
->name
, p2
->name
);
250 fprintf(stderr
, " and ./%s/%s/%s_wrfkpp.equiv (if present) \n",kpp_dirname
, p2
->name
, p2
->name
);
251 fprintf(stderr
, " EXITING \n");