11 #include "protos_kpp.h"
19 get_kpp_chem_specs ( char* kpp_dirname
)
23 knode_t
* q
, * member
;
25 struct dirent
* entry
;
27 char fulldirname
[NAMELEN
], spcfilename
[NAMELEN
];
28 char inln
[NAMELEN
], kpp_spec
[NAMELEN
];
30 int in_comment
, got_it
;
34 /* http://users.actcom.co.il/~choo/lupg/tutorials/handling-files/handling-files.html#directory_struct */
38 dir
= opendir(kpp_dirname
);
40 fprintf(stderr
, "WARNING from gen_kpp: Cannot read directory: %s \n", kpp_dirname
);
46 /* loop through sub directories in KPP directory */
48 while ((entry
= readdir(dir
))) {
51 if ( strcmp(entry
->d_name
, ".") == 0)
53 if ( strcmp(entry
->d_name
, "..") == 0)
58 sprintf( fulldirname
, "%s/%s", kpp_dirname
, entry
->d_name
);
60 printf("%s \n", fulldirname
);
62 /* check if the given entry is a directory. */
63 if (stat(fulldirname
, &dir_stat
) == -1) {
64 fprintf(stderr
, "WAA\n\n");
65 perror("WARNING from gen_kpp: ");
70 /* check if KPP species file is present. */
72 sprintf( spcfilename
, "%s/%s/%s.spc", kpp_dirname
, entry
->d_name
, entry
->d_name
);
75 ;fprintf(stderr
, " spcfilename: %s \n",spcfilename
);
77 spcFile
= fopen (spcfilename
, "r" );
79 if ( spcFile
== NULL
) {
80 fprintf(stderr
,"WARNING from gen_kpp: File %s not found. Skipping. \n", spcfilename
);
84 printf(" Found %s \n", spcfilename
);
89 /*----------------------------------------------------*/
92 /* put KPP packagename into linked list */
96 strcpy( q
->name
, entry
->d_name
);
97 add_knode_to_end( q
, &(KPP_packs
) ) ;
99 /* loop over lines in KPP species file */
100 while ( fgets ( inln
, NAMELEN
, spcFile
) != NULL
){
101 if ( DEBUGR
== 1 ){ printf("%s ", inln
); }
102 /* strip from comments (loop through letters) */
109 for(j
= 0; j
< NAMELEN
; j
++) kpp_spec
[j
]='\0';
110 while ( inln
[n
] != '\0' ){
111 if ( inln
[n
] == '{') in_comment
=1;
112 if ( in_comment
== 0 ) {
113 if (inln
[n
] == '=' || inln
[n
] == '#') {
116 if ( got_it
== 0 && inln
[n
] != ' '){
117 /* printf("%c %i \n ", inln[n], in_comment ); */
119 kpp_spec
[nn
]=inln
[n
];
125 if (inln
[n
] == '}') in_comment
=0;
130 /* printf("spec: %s \n ", kpp_spec); */
132 if (kpp_spec
[0] != '\0' && got_it
== 1 ) {
135 printf("spec: %s \n ", kpp_spec
);
136 fprintf(stderr
," p, name %s %s \n", q
->name
, kpp_spec
);
139 member
= new_knode( ) ;
140 strcpy( member
->name
, kpp_spec
) ;
141 member
->next
= NULL
;
142 add_knode_to_end( member
, &(q
->members
) ) ;