Droplet Lagrangian Transient One-dimensional Reacting Code Implementation of both liquid and gas phase governing equations.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include "parse.h"
  2. void getFromString (const char* buf, int* n){
  3. *n=atoi(buf);
  4. printf("%d\n",*n);
  5. }
  6. void getFromString (const char* buf, size_t* n){
  7. *n=(size_t)(atoi(buf));
  8. printf("%lu\n",*n);
  9. }
  10. void getFromString (const char* buf, double* n){
  11. *n=(double)(atof(buf));
  12. printf("%15.6e\n",*n);
  13. }
  14. void getFromString (const char* buf, char* n){
  15. sscanf(buf,"%s",n);
  16. printf("%s\n",n);
  17. }
  18. std::string getFromString(const char* buf){
  19. std::string n(buf);
  20. printf("%s\n",n.c_str());
  21. return n;
  22. }
  23. /* Extract droplet species and mole fractions */
  24. int parseDrop(FILE* input, const char* keyword,char dropSpec[][10],double dropMole[],const size_t bufLen){
  25. char buf[bufLen];
  26. char buf1[bufLen];
  27. char comment[1];
  28. char *ret;
  29. while (fgets(buf,bufLen, input)!=NULL){
  30. comment[0]=buf[0];
  31. if(strncmp(comment,"#",1)==0){
  32. }
  33. else{
  34. strcpy(buf1,buf);
  35. ret=strtok(buf,"=");
  36. //DEBUG
  37. //printf("Current KEYWORD in input: %20s \n",ret);
  38. if(strcmp(ret,keyword)==0){
  39. char* modifiedFuel = NULL;
  40. char* equalSign = strstr(buf1,"=");
  41. if(equalSign!= NULL){
  42. modifiedFuel = new char [strlen(equalSign)+1];
  43. strcpy(modifiedFuel,equalSign+1);
  44. //DEBUG
  45. //printf("modifiedFuel:%20s \n",modifiedFuel);
  46. char* token = strtok(modifiedFuel,",");
  47. int index = 0 ;
  48. char* list[2];
  49. while(token!= NULL){
  50. //DEBUG
  51. //printf("TOKEN :%20s \n",token);
  52. list[index] = token;
  53. token = strtok(NULL,",");
  54. index++;
  55. }
  56. //for (int i=0;i<2;i++){
  57. // printf("%20s",list[i]);
  58. //}
  59. for(int i=0;i<2;i++){
  60. char* name= strtok(list[i],":");
  61. char* value = strtok(NULL,":");
  62. //DEBUG
  63. // printf("Name:%10s,Value:%10s \n",name,value);
  64. strcpy(dropSpec[i],name);
  65. dropMole[i]=std::stod(value);
  66. // printf("In the dropArray,Name:%10s,Value:%.3f\n",dropSpec[i],dropMole[i]);
  67. }
  68. delete[] modifiedFuel;
  69. }
  70. printf("%10s:%10s:%.3f,%10s:%.3f\n",keyword,dropSpec[0],dropMole[0],dropSpec[1],dropMole[1]);
  71. //printf("IF statement is execuated. \n");
  72. rewind(input);
  73. //delete[] modifiedFuel;
  74. return(0);
  75. }
  76. }
  77. }
  78. rewind(input);
  79. return(-1);
  80. }
  81. ///* Specialization for string */
  82. //template<>
  83. //int parseDropSpec<std::string>(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector<std::string>& dropPara){
  84. // char buf[bufLen];
  85. // char buf1[bufLen];
  86. // char comment[1];
  87. // char *ret;
  88. //
  89. // while (fgets(buf,bufLen, input)!=NULL){
  90. // comment[0]=buf[0];
  91. // if(strncmp(comment,"#",1)==0){
  92. // //printf("Comment!:%s\n",buf);
  93. // }
  94. // else{
  95. // ret=strtok(buf,"=");
  96. // if(strcmp(ret,keyword)==0){
  97. // /*offset buf by keyword size + 1 for the "="*/
  98. // /* Second argument in the strncpy function is the address !!! */
  99. // /* Note: current version of code can only take dropType =0 or 1 */
  100. // strncpy(buf1, buf+strlen(keyword)+1, bufLen);
  101. // printf("%10s: ",keyword);
  102. // if(*dropType ==0){
  103. // /* Convert from char* to string */
  104. // std::string str(buf1);
  105. // dropPara.push_back(str);
  106. // printf("%s\n",dropPara[0].c_str());
  107. // }else{
  108. // std::istringstream iss(buf1) ;
  109. // std::string token;
  110. // while(std::getline(iss,token,',')){
  111. // //std::stod(token);
  112. // dropPara.push_back(token);
  113. // }
  114. // printf("%s,%s\n",dropPara[0].c_str(),dropPara[1].c_str());
  115. // }
  116. // rewind(input);
  117. // return(0);
  118. // }
  119. // }
  120. // }
  121. // rewind(input);
  122. // return(-1);
  123. //}