/[ascend]/branches/vishnu/models/johnpye/fprops/vishnu/scratch/main.c
ViewVC logotype

Diff of /branches/vishnu/models/johnpye/fprops/vishnu/scratch/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3117 by vishnu, Mon Jun 13 02:22:51 2016 UTC revision 3118 by vishnu, Tue Jun 21 04:47:08 2016 UTC
# Line 9  Line 9 
9    
10  #define MAXC 10  #define MAXC 10
11    
12  #define PATH "incomp_liq_data/ZS55.dat"  #define PATH "incomp_liq_data/Water.dat"
13    
14  #define ABORT \  #define ABORT \
15          printf("\nExiting Program!\n"); \          printf("\nExiting Program!\n"); \
16          exit(0);          exit(0);
17    
18  #define READ(Q) \  #define READ(Q) \
# Line 36  Line 36 
36                  strcpy(test_liq->Q.type,"exponential"); \                  strcpy(test_liq->Q.type,"exponential"); \
37              } \              } \
38          } \          } \
39          if(strcmp(test_liq->Q.type,"notdefined")) { \          if(!strcmp(test_liq->Q.type,"polynomial")||!strcmp(test_liq->Q.type,"exppolynomial")) { \
40              fseek(in,pos,SEEK_SET); \              fseek(in,pos,SEEK_SET); \
41              fgets(word,BUF,in); \              fgets(word,BUF,in); \
42              double coefs[MAXC]; \              double coefs[MAXC]; \
# Line 61  Line 61 
61                  numc--; \                  numc--; \
62                  test_liq->Q.coeff[numc] = coefs[numc]; \                  test_liq->Q.coeff[numc] = coefs[numc]; \
63              } \              } \
64            } \
65            else if(!strcmp(test_liq->Q.type,"exponential")) { \
66                fseek(in,pos,SEEK_SET); \
67                fgets(word,BUF,in); \
68                double coefs[MAXC]; \
69                int numc = 0; \
70                while(!strstr(word,"},")) { \
71                    if(strstr(word,"NRMS")) { \
72                        coefs[numc] = extracted_number(word); \
73                        numc++; \
74                        assert(numc==1); \
75                    } \
76                    else if(strstr(word,"e+")||strstr(word,"e-")) { \
77                        coefs[numc] = to_number(word); \
78                        numc++; \
79                        assert(numc<MAXC);  \
80                    } \
81                    fgets(word,BUF,in); \
82                } \
83                test_liq->Q.coeff = (double*)malloc(numc*sizeof(double)); \
84                test_liq->Q.numc = numc; \
85                while(numc) { \
86                    numc--; \
87                    test_liq->Q.coeff[numc] = coefs[numc]; \
88                } \
89          }          }
90    
91  typedef struct {  typedef struct {
# Line 99  double to_number(char w[BUF]) { Line 124  double to_number(char w[BUF]) {
124      char *token;      char *token;
125        
126      /* get the first token */      /* get the first token */
127      token = strtok(w, " ");      token = strtok(w, " ,");
128    
129      return (atof(token));      return (atof(token));
130    
# Line 128  double eval_exppoly(coefficients c, doub Line 153  double eval_exppoly(coefficients c, doub
153  // eveluation function for exponential type coefficients  // eveluation function for exponential type coefficients
154  double eval_expo(coefficients c, double T, double x) {  double eval_expo(coefficients c, double T, double x) {
155    
156      return exp(c.coeff[1]/(T+c.coeff[2])+c.coeff[3]);      return exp(c.coeff[1]/(T+c.coeff[2])-c.coeff[3]);
157    
158  }    }  
159    
# Line 137  double eval_expo(coefficients c, double Line 162  double eval_expo(coefficients c, double
162      double eval_ ## Q (fprops *fluid, double T, double x) { \      double eval_ ## Q (fprops *fluid, double T, double x) { \
163          assert(T>0&&T>=fluid->T_min&&T<=fluid->T_max); \          assert(T>0&&T>=fluid->T_min&&T<=fluid->T_max); \
164          assert(x>=fluid->x_min&&x<=fluid->x_max); \          assert(x>=fluid->x_min&&x<=fluid->x_max); \
165          if(!strcmp(fluid->Q.type,"polynomial")) return eval_poly(fluid->Q,T,x); \          if(!strcmp(fluid->Q.type,"polynomial")) return eval_poly(fluid->Q,T-fluid->T_base,x-fluid->x_base); \
166          else if(!strcmp(fluid->Q.type,"exppolynomial")) return eval_exppoly(fluid->Q,T,x); \          else if(!strcmp(fluid->Q.type,"exppolynomial")) return eval_exppoly(fluid->Q,T-fluid->T_base,x-fluid->x_base); \
167          else if(!strcmp(fluid->Q.type,"exponential")) return eval_expo(fluid->Q,T,x); \          else if(!strcmp(fluid->Q.type,"exponential")) return eval_expo(fluid->Q,T,0); \
168          else { \          else { \
169              printf("\nType not defined.\n"); \              printf("\nType not defined.\n"); \
170              ABORT \              ABORT \

Legend:
Removed from v.3117  
changed lines
  Added in v.3118

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22