|
- template<typename T>
- int parseNumber(FILE* input, const char* keyword, const size_t bufLen, T* n){
-
- char buf[bufLen];
- char buf1[bufLen];
- char comment[1];
- char *ret;
-
- while (fgets(buf,bufLen, input)!=NULL){
- comment[0]=buf[0];
- if(strncmp(comment,"#",1)==0){
- //printf("Comment!:%s\n",buf);
- }
- else{
- ret=strtok(buf,"=");
- if(strcmp(ret,keyword)==0){
- /*offset buf by keyword size + 1 for the "="*/
- strncpy (buf1, buf+strlen(keyword)+1, bufLen);
- printf("%30s: ",keyword);
- getFromString(buf1,n);
- rewind(input);
- return(0);
- }
- }
- }
- rewind(input);
- return(-1);
- }
-
- template<typename T>
- int parseArray(FILE* input, const char* keyword, const size_t bufLen,
- const size_t arrLen, T y[]){
-
- char buf[bufLen];
- char buf1[bufLen];
- char comment[1];
- char *ret;
-
- while (fgets(buf,bufLen, input)!=NULL){
- comment[0]=buf[0];
- if(strncmp(comment,"#",1)==0){
- //printf("Comment!:%s\n",buf);
- }
- else{
- ret=strtok(buf,"=");
-
- if(strcmp(ret,keyword)==0){
- /*offset buf by keyword size + 1 for the "="*/
- strncpy (buf1, buf+strlen(keyword)+1, bufLen);
- printf("%30s:\n",keyword);
- ret=strtok(buf1,",");
- size_t j=0;
- while(ret!=NULL){
- if(j<arrLen){
- //y[j]=atof(ret);
- getFromString(ret,&y[j]);
- }
- ret=strtok(NULL,",");
- j++;
- }
- rewind(input);
- if(j!=arrLen){
- printf("Check no: of values entered for %s\n",keyword);
- printf("%lu values required!\n",arrLen);
- return(-1);
- }
- else{
- return(0);
- }
- }
- }
- }
- rewind(input);
- return(-1);
- }
-
-
- /* Extract the droplet species and molefractions from input file using template */
- /* Generic template function */
- template<typename T>
- int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector<T>& dropPara){
- char buf[bufLen];
- char buf1[bufLen];
- char comment[1];
- char *ret;
- T* n;
-
- while (fgets(buf,bufLen, input)!=NULL){
- comment[0]=buf[0];
- if(strncmp(comment,"#",1)==0){
- //printf("Comment!:%s\n",buf);
- }
- else{
- ret=strtok(buf,"=");
- if(strcmp(ret,keyword)==0){
- /*offset buf by keyword size + 1 for the "="*/
- /* Second argument in the strncpy function is the address !!! */
- /* Note: current version of code can only take dropType =0 or 1 */
- strncpy(buf1, buf+strlen(keyword)+1, bufLen);
- printf("%10s: ",keyword);
- if(*dropType ==0){
- getFromString(buf1,n);
- dropPara.push_back(*n);
- }else{
- std::istringstream iss(buf1) ;
- std::string token;
- while(std::getline(iss,token,',')){
- T arg = std::stod(token);
- dropPara.push_back(arg);
- }
- printf("%15.6e,%15.6e\n",dropPara[0],dropPara[1]);
- }
- rewind(input);
- return(0);
- }
- }
- }
- rewind(input);
- return(-1);
- }
-
- /* Specialization for string */
- template<>
- int parseDropSpec<std::string>(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector<std::string>& dropPara);
|