Merge remote-tracking branch 'origin/release-v4.6.1'
[WRF.git] / chem / KPP / util / wkc / change_chem_Makefile.c
blob1b2676cb7c65f982118b402a0b0da3730f650469
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
6 #include "protos.h"
7 #include "protos_kpp.h"
8 #include "kpp_data.h"
13 void
14 change_chem_Makefile ( )
16 knode_t * p1, * p2, * pm1;
17 FILE * ch_Makefile, * t_Makefile;
18 char inln[NAMELEN];
19 char kname[NAMELEN];
20 char * org_Mf = "chem/Makefile_org";
21 char * t_Mf = "chem/Makefile.temp";
22 char * Mf = "chem/Makefile";
23 char cp_command[NAMELEN];
24 char sub_string[NAMELEN];
25 char *p_string;
26 int slen;
27 int nchem_opts = 0;
28 int chem_opts_cnt;
33 ch_Makefile = fopen(org_Mf, "r" );
34 t_Makefile = fopen(t_Mf, "w" );
37 sprintf( cp_command,"cp %s %s",t_Mf,Mf);
39 fprintf(t_Makefile,"# \n");
40 fprintf(t_Makefile,"# MANUAL CHANGES TO THIS FILE WILL BE LOST \n");
41 fprintf(t_Makefile,"# ... EDIT Makefile_org INSTEAD ...\n");
42 fprintf(t_Makefile,"# this file was written by gen_kpp.c \n\n");
46 /* loop over lines in chem/Makefile */
47 while ( fgets ( inln , NAMELEN , ch_Makefile ) != NULL ){
49 /* printf("%s ", inln ); */
50 fprintf(t_Makefile, "%s", inln);
52 /* if ( strncmp(inln, "MODULES",6) == 0){ */
54 if ( strncmp(inln, " module_data_sorgam_vbs",29) == 0){
56 for ( p1 = KPP_packs ; p1 != NULL ; p1 = p1->next ) {
57 p2 = p1->assoc_wrf_pack;
58 if ( p2 ) {
60 strcpy( kname, p1->name );
61 fprintf(t_Makefile, " module_kpp_%s_Integr.o \\\n",kname );
62 fprintf(t_Makefile, " module_kpp_%s_Precision.o \\\n",kname );
63 fprintf(t_Makefile, " module_kpp_%s_Parameters.o \\\n",kname );
64 fprintf(t_Makefile, " module_kpp_%s_Jacobian.o \\\n",kname );
65 fprintf(t_Makefile, " module_kpp_%s_JacobianSP.o \\\n",kname );
66 fprintf(t_Makefile, " module_kpp_%s_Update_Rconst.o \\\n",kname );
67 fprintf(t_Makefile, " module_kpp_%s_interface.o \\\n",kname );
70 fprintf(t_Makefile, " module_wkppc_constants.o \\\n");
73 if ( strncmp(inln, "# DEPENDENCIES",14) == 0){
75 for ( p1 = KPP_packs ; p1 != NULL ; p1 = p1->next,nchem_opts++ ) {
77 p2 = p1->assoc_wrf_pack;
79 if ( p2 ) {
81 strcpy( kname, p1->name );
83 fprintf(t_Makefile, "module_kpp_%s_Parameters.o: module_kpp_%s_Precision.o \n\n",kname, kname );
84 fprintf(t_Makefile, "module_kpp_%s_Update_Rconst.o: module_kpp_%s_Parameters.o \n\n",kname, kname );
85 fprintf(t_Makefile, "module_kpp_%s_Jacobian.o: module_kpp_%s_Parameters.o module_kpp_%s_JacobianSP.o \n\n",kname, kname, kname );
86 fprintf(t_Makefile, "module_kpp_%s_Integr.o: module_kpp_%s_Parameters.o module_kpp_%s_Jacobian.o module_kpp_%s_JacobianSP.o module_kpp_%s_Update_Rconst.o module_wkppc_constants.o \n\n",kname, kname, kname, kname, kname );
87 fprintf(t_Makefile, "module_kpp_%s_interface.o: module_kpp_%s_Parameters.o module_kpp_%s_Precision.o module_kpp_%s_Integr.o module_kpp_%s_Update_Rconst.o module_wkppc_constants.o \n\n",kname, kname, kname, kname, kname );
93 fprintf(t_Makefile, "module_wkkpc_constants.o:\n\n");
95 p_string = sub_string;
96 chem_opts_cnt = 0;
97 sprintf( sub_string,"kpp_mechanism_driver.o: " );
98 for ( p1 = KPP_packs ; p1 != NULL ; p1 = p1->next ) {
99 p2 = p1->assoc_wrf_pack;
100 if ( p2 ) {
101 chem_opts_cnt++;
102 strcpy( kname, p1->name );
103 slen = strlen( sub_string );
104 sprintf( p_string+slen,"module_kpp_%s_interface.o ",kname );
105 slen = strlen( sub_string );
106 if( slen > 90 ) {
107 if( chem_opts_cnt < nchem_opts ) sprintf( p_string+slen,"\\");
108 fprintf(t_Makefile, "%s\n", sub_string );
109 sprintf( sub_string,"\t" );
113 slen = strlen( sub_string );
114 if( slen > 1 ) fprintf(t_Makefile, "%s\n\n", sub_string );
117 if ( strncmp(inln, "OBJS",3) == 0){
118 fprintf(t_Makefile, "\tkpp_mechanism_driver.o \\\n");
125 fclose( t_Makefile );
126 fclose( ch_Makefile );
129 system(cp_command);