Droplet Lagrangian Transient One-dimensional Reacting Code Implementation of both liquid and gas phase governing equations.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

80 строки
2.7KB

  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. /*Extract droplet species and mole fractions*/
  19. int parseDrop(FILE* input, const char* keyword,char dropSpec[][10],double dropMole[],const size_t bufLen){
  20. char buf[bufLen];
  21. char buf1[bufLen];
  22. char comment[1];
  23. char *ret;
  24. while (fgets(buf,bufLen, input)!=NULL){
  25. comment[0]=buf[0];
  26. if(strncmp(comment,"#",1)==0){
  27. }
  28. else{
  29. strcpy(buf1,buf);
  30. ret=strtok(buf,"=");
  31. //DEBUG
  32. //printf("Current KEYWORD in input: %20s \n",ret);
  33. if(strcmp(ret,keyword)==0){
  34. char* modifiedFuel = NULL;
  35. char* equalSign = strstr(buf1,"=");
  36. if(equalSign!= NULL){
  37. modifiedFuel = new char [strlen(equalSign)+1];
  38. strcpy(modifiedFuel,equalSign+1);
  39. //DEBUG
  40. //printf("modifiedFuel:%20s \n",modifiedFuel);
  41. char* token = strtok(modifiedFuel,",");
  42. int index = 0 ;
  43. char* list[2];
  44. while(token!= NULL){
  45. //DEBUG
  46. //printf("TOKEN :%20s \n",token);
  47. list[index] = token;
  48. token = strtok(NULL,",");
  49. index++;
  50. }
  51. //for (int i=0;i<2;i++){
  52. // printf("%20s",list[i]);
  53. //}
  54. for(int i=0;i<2;i++){
  55. char* name= strtok(list[i],":");
  56. char* value = strtok(NULL,":");
  57. //DEBUG
  58. // printf("Name:%10s,Value:%10s \n",name,value);
  59. strcpy(dropSpec[i],name);
  60. dropMole[i]=std::stod(value);
  61. // printf("In the dropArray,Name:%10s,Value:%.3f\n",dropSpec[i],dropMole[i]);
  62. }
  63. delete[] modifiedFuel;
  64. }
  65. printf("%10s:%10s:%.3f,%10s:%.3f\n",keyword,dropSpec[0],dropMole[0],dropSpec[1],dropMole[1]);
  66. //printf("IF statement is execuated. \n");
  67. rewind(input);
  68. //delete[] modifiedFuel;
  69. return(0);
  70. }
  71. }
  72. }
  73. rewind(input);
  74. return(-1);
  75. }