/[ascend]/trunk/models/johnpye/datareader/tmy3.c
ViewVC logotype

Diff of /trunk/models/johnpye/datareader/tmy3.c

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

revision 2595 by jpye, Fri Apr 13 23:42:36 2012 UTC revision 2596 by jpye, Sat Apr 14 06:06:41 2012 UTC
# Line 90  typedef struct Tmy3Data_struct{ Line 90  typedef struct Tmy3Data_struct{
90    
91  #define DATA(D) ((Tmy3Data *)(D->data))  #define DATA(D) ((Tmy3Data *)(D->data))
92    
93  struct Tmy3Location_struct{  typedef struct Tmy3Location_struct{
94      char stationcode[101];      char stationcode[101];
95      char stationname[101];      char stationname[101];
96      char state[20];      char state[20];
# Line 102  struct Tmy3Location_struct{ Line 102  struct Tmy3Location_struct{
102    
103  //example header line:  //example header line:
104  //723815,"DAGGETT BARSTOW-DAGGETT AP",CA,-8.0,34.850,-116.800,586  //723815,"DAGGETT BARSTOW-DAGGETT AP",CA,-8.0,34.850,-116.800,586
105  int parseLocation(parse *p, struct Tmy3Location *loc){  int parseLocation(parse *p, Tmy3Location *loc){
106      return      return
107          (parseStrExcept(p,",",loc->stationcode,100)          (parseStrExcept(p,",",loc->stationcode,100)
108          && parseThisString(p,",\"")          && parseThisString(p,",\"")
109          && parseStrExcept(p,"\"",loc->stationname,100)          && parseStrExcept(p,"\"",loc->stationname,100)
110          && parseThisString(p,",")          && parseThisString(p,"\",")
111          && parseStrExcept(p,",",loc->state,100)          && parseStrExcept(p,",",loc->state,100)
112          && parseThisString(p,",")          && parseThisString(p,",")
113          && parseDouble(p,&(loc->timezone))          && parseDouble(p,&(loc->timezone))
# Line 126  int parseLocation(parse *p, struct Tmy3L Line 126  int parseLocation(parse *p, struct Tmy3L
126      @return 0 on success      @return 0 on success
127  */  */
128  int datareader_tmy3_header(DataReader *d){  int datareader_tmy3_header(DataReader *d){
129      struct EeLocation loc;      Tmy3Location loc;
130      d->data = ASC_NEW(EeData);      d->data = ASC_NEW(Tmy3Data);
131      DATA(d)->p = parseCreateFile(d->f);      DATA(d)->p = parseCreateFile(d->f);
132      parse *p = DATA(d)->p;      parse *p = DATA(d)->p;
133        char rubbish[2049];
134    
135      if(!(      if(!(
136          parseLocation(p,&loc)          parseLocation(p,&loc)
137          // FIXME add ignore whole next line          && parseStrExcept(p,"\r\n",rubbish,2048)
138            && parseEOL(p)
139      )){      )){
140          ERROR_REPORTER_HERE(ASC_PROG_ERROR,"Parser error in header part of file");          ERROR_REPORTER_HERE(ASC_PROG_ERROR,"Parser error in header part of file");
141      }      }
# Line 151  int datareader_tmy3_header(DataReader *d Line 153  int datareader_tmy3_header(DataReader *d
153      /* set the number of inputs and outputs */      /* set the number of inputs and outputs */
154      d->ninputs = 1;      d->ninputs = 1;
155      d->noutputs = 7;      d->noutputs = 7;
   
156      return 0;      return 0;
157  }  }
158    
# Line 180  int datareader_tmy3_eof(DataReader *d){ Line 181  int datareader_tmy3_eof(DataReader *d){
181      @return 0 on success      @return 0 on success
182  */  */
183  int datareader_tmy3_data(DataReader *d){  int datareader_tmy3_data(DataReader *d){
184      CONSOLE_DEBUG("Reading data, i = %d",d->i);      //CONSOLE_DEBUG("Reading data, i = %d",d->i);
185      unsigned year,month,day,hour,minute;      unsigned year,month,day,hour,minute;
     char uncerts[101];  
186      Tmy3Point row;      Tmy3Point row;
187    
188      // in the following 'C' are char fiels, 'I' are integer fields;      // in the following 'C' are char fiels, 'I' are integer fields;
# Line 211  int datareader_tmy3_data(DataReader *d){ Line 211  int datareader_tmy3_data(DataReader *d){
211      X I(65_RainDepth) X I(66_RainDuration) X C(67_Rains) X C(68_Raine)      X I(65_RainDepth) X I(66_RainDuration) X C(67_Rains) X C(68_Raine)
212    
213  #define CHARDECL(NAME) char tmy3_field_##NAME;  #define CHARDECL(NAME) char tmy3_field_##NAME;
214  #define INTDECL(NAME) unsigned int tmy3_field_##NAME;  #define NUMDECL(NAME) double tmy3_field_##NAME;
215  #define NUTHIN_HERE  #define NUTHIN_HERE
216      NUMFIELDS(CHARDECL,INTDECL,NUTHIN_HERE);      NUMFIELDS(CHARDECL,NUMDECL,NUTHIN_HERE);
217  #undef CHARDECL  #undef CHARDECL
218  #undef INTDECL  #undef NUMDECL
219  #undef NUTHIN_HERE  #undef NUTHIN_HERE
220    
221      // TODO what to do with 'missing' values??      // TODO what to do with 'missing' values??
222      parse *p = DATA(d)->p;      parse *p = DATA(d)->p;
223    
224  #define PARSEINT(NAME) parseSignedNumber(p,&tmy3_field_##NAME)  #define PARSEINT(NAME) parseDouble(p,&tmy3_field_##NAME)
225  #define PARSECHAR(NAME) parseAChar(p,&tmy3_field_##NAME)  #define PARSECHAR(NAME) parseAChar(p,&tmy3_field_##NAME)
226  #define ANDTHEN && parseThisString(p,",") &&  #define ANDTHEN && parseThisString(p,",") &&
227    
# Line 255  int datareader_tmy3_data(DataReader *d){ Line 255  int datareader_tmy3_data(DataReader *d){
255  #undef PARSECHAR  #undef PARSECHAR
256    
257      // TODO add check for data for Feb 29... just in case?      // TODO add check for data for Feb 29... just in case?
   
258      row.t = ((day_of_year_specific(day,month,year) - 1)*24.0 + (hour - 1))*3600.0 + minute*60.;      row.t = ((day_of_year_specific(day,month,year) - 1)*24.0 + (hour - 1))*3600.0 + minute*60.;
259        row.T = tmy3_field_32_T * 0.1;
260        row.p = tmy3_field_41_P * 100.;
261        row.rh = tmy3_field_38_RH * 0.01;
262        row.DNI = tmy3_field_8_DNI * 1.;
263        row.GHI = tmy3_field_5_GHI * 1.;
264        row.v_wind = tmy3_field_47_WS * 0.1;
265        row.d_wind = tmy3_field_44_WD * 3.14159265358 / 180. ;
266    
267      DATA(d)->rows[d->i] = row;      DATA(d)->rows[d->i] = row;
268    
# Line 266  int datareader_tmy3_data(DataReader *d){ Line 272  int datareader_tmy3_data(DataReader *d){
272      return 0;      return 0;
273  }  }
274    
275  int datareader_ee_time(DataReader *d, double *t){  int datareader_tmy3_time(DataReader *d, double *t){
276      *t = DATA(d)->rows[d->i].t;      *t = DATA(d)->rows[d->i].t;
277      return 0;      return 0;
278  }  }
279    
280  #define ROW DATA(d)->rows[d->i]  #define ROW DATA(d)->rows[d->i]
281    
282  int datareader_ee_vals(DataReader *d, double *v){  int datareader_tmy3_vals(DataReader *d, double *v){
283  #if EE_DEBUG  #if TMY3_DEBUG
284      CONSOLE_DEBUG("At t=%f d, T = %lf, DNI = %f Wh/m2"      CONSOLE_DEBUG("At t=%f d, T = %lf, DNI = %f Wh/m2"
285          ,(ROW.t / 3600. / 24.),ROW.T, ROW.DNI          ,(ROW.t / 3600. / 24.),ROW.T, ROW.DNI
286      );      );
287  #endif  #endif
   
288      v[0]=ROW.T;      v[0]=ROW.T;
289      v[1]=ROW.p;      v[1]=ROW.p;
290      v[2]=ROW.rh;      v[2]=ROW.rh;
291      v[3]=ROW.DNI;      v[3]=ROW.DNI;
292      v[4]=ROW.Gd;      v[4]=ROW.GHI;
293      v[5]=ROW.d_wind;      v[5]=ROW.d_wind;
294      v[6]=ROW.v_wind;      v[6]=ROW.v_wind;
295      return 0;      return 0;
296  }  }
297    
298    

Legend:
Removed from v.2595  
changed lines
  Added in v.2596

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