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

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

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

revision 823 by johnpye, Wed Aug 16 15:36:12 2006 UTC revision 824 by johnpye, Thu Aug 17 16:30:24 2006 UTC
# Line 57  typedef enum{ Line 57  typedef enum{
57  /**  /**
58      Create a data reader object, with the filename specified. The filename      Create a data reader object, with the filename specified. The filename
59      will be searched for in a specified path, eg ASCENDLIBRARY.      will be searched for in a specified path, eg ASCENDLIBRARY.
60  */        */
61  DataReader *datareader_new(const char *fn){  DataReader *datareader_new(const char *fn){
62      DataReader *d;      DataReader *d;
63        
64      d = ASC_NEW(DataReader);      d = ASC_NEW(DataReader);
65      d->fn = fn;      d->fn = fn;
66      d->fp = NULL;      d->fp = NULL;
# Line 160  int datareader_searchpath_test(struct Fi Line 160  int datareader_searchpath_test(struct Fi
160  };  };
161    
162    
163  /**  /**
164      Initialise the datareader: open the file, check the number of columns, etc.      Initialise the datareader: open the file, check the number of columns, etc.
165      @return 0 on success      @return 0 on success
166    
# Line 201  int datareader_init(DataReader *d){ Line 201  int datareader_init(DataReader *d){
201              fp2 = ospath_searchpath_iterate(sp1, &datareader_searchpath_test, &sd);              fp2 = ospath_searchpath_iterate(sp1, &datareader_searchpath_test, &sd);
202    
203              if(fp2==NULL){              if(fp2==NULL){
204                  CONSOLE_DEBUG("File '%s' not found in search path (error %d)",d->fn,sd.error);                  ERROR_REPORTER_HERE(ASC_USER_ERROR,"File '%s' not found in search path (error %d)",d->fn,sd.error);
205                  ospath_searchpath_free(sp1);                  ospath_searchpath_free(sp1);
206                  return -1;                  return -1;
207              }              }
# Line 239  int datareader_init(DataReader *d){ Line 239  int datareader_init(DataReader *d){
239          fclose(d->f);          fclose(d->f);
240          return 1;          return 1;
241      }      }
242        
243      while(! (*d->eoffn)(d)){      while(! (*d->eoffn)(d)){
244          if((*d->datafn)(d)){          if((*d->datafn)(d)){
245              ERROR_REPORTER_HERE(ASC_PROG_ERR,"Error reading file data in '%s'",d->fn);              ERROR_REPORTER_HERE(ASC_PROG_ERR,"Error reading file data in '%s'",d->fn);
# Line 323  int datareader_locate(DataReader *d, dou Line 323  int datareader_locate(DataReader *d, dou
323    
324  /**  /**
325      Return an interpolated set of output values for the given input values.      Return an interpolated set of output values for the given input values.
326      This should be computed such that the output values are smooth in their      This should be computed such that the output values are smooth in their
327      first derivatives.      first derivatives.
328    
329      The required memory for the inputs and outputs must be allocated by the      The required memory for the inputs and outputs must be allocated by the
# Line 356  int datareader_func(DataReader *d, doubl Line 356  int datareader_func(DataReader *d, doubl
356      (*d->valfn)(d,v1);      (*d->valfn)(d,v1);
357    
358      CONSOLE_DEBUG("LOCATED OK, d->i = %d, t1 = %lf, t2 = %lf, v1=%lf, v2=%lf", d->i, t1[0], t2[0],v1[0],v2[0]);      CONSOLE_DEBUG("LOCATED OK, d->i = %d, t1 = %lf, t2 = %lf, v1=%lf, v2=%lf", d->i, t1[0], t2[0],v1[0],v2[0]);
359        
360      for(i=0;i<d->noutputs;++i){      for(i=0;i<d->noutputs;++i){
361          dt = t2[0] - t1[0];          dt = t2[0] - t1[0];
362          g = (v2[i]-v1[i])/dt;          g = (v2[i]-v1[i])/dt;
363          outputs[i]=v1[i]+g*(t-(*t1));          outputs[i]=v1[i]+g*(t-(*t1));
364          CONSOLE_DEBUG("[%d]: DT = %lf, START = %lf, GRADIENT = %lf, VALUE=%lf",i,dt, v1[i],g,outputs[i]);          CONSOLE_DEBUG("[%d]: DT = %lf, START = %lf, GRADIENT = %lf, VALUE=%lf",i,dt, v1[i],g,outputs[i]);
365      }      }
366        
367      return 0;      return 0;
368  }  }
369    
# Line 389  int datareader_deriv(DataReader *d, doub Line 389  int datareader_deriv(DataReader *d, doub
389          CONSOLE_DEBUG("LOCATION ERROR");          CONSOLE_DEBUG("LOCATION ERROR");
390          ERROR_REPORTER_HERE(ASC_USER_ERROR,"Time value t=%f is out of range",t);          ERROR_REPORTER_HERE(ASC_USER_ERROR,"Time value t=%f is out of range",t);
391          return 1;          return 1;
392      }            }
393    
394      (*d->valfn)(d,v2);      (*d->valfn)(d,v2);
395      --d->i;      --d->i;
396      (*d->valfn)(d,v1);      (*d->valfn)(d,v1);
397        
398      for(i=0;i<d->noutputs;++i){      for(i=0;i<d->noutputs;++i){
399          jacobian[i]=(v2[i]-v1[i])/(*t2-*t1);          jacobian[i]=(v2[i]-v1[i])/(*t2-*t1);
400      }      }
401        
402      return 0;      return 0;
403  }  }
404    

Legend:
Removed from v.823  
changed lines
  Added in v.824

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