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

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

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

revision 811 by johnpye, Thu Aug 10 17:08:16 2006 UTC revision 812 by johnpye, Fri Aug 11 04:22:18 2006 UTC
# Line 44  Line 44 
44    GLOBALS    GLOBALS
45  */  */
46    
47  static symchar *dr_symbols[1];  static symchar *dr_symbols[2];
48  #define FILENAME_SYM dr_symbols[0]  #define FILENAME_SYM dr_symbols[0]
49    #define FORMAT_SYM dr_symbols[1]
50    
51  /*------------------------------------------------------------------------------  /*------------------------------------------------------------------------------
52    BINDINGS FOR THE DATA READER TO THE ASCEND EXTERNAL FUNCTIONS API    BINDINGS FOR THE DATA READER TO THE ASCEND EXTERNAL FUNCTIONS API
# Line 55  int asc_datareader_prepare(struct Slv_In Line 56  int asc_datareader_prepare(struct Slv_In
56  int asc_datareader_calc(struct Slv_Interp *slv_interp, int ninputs, int noutputs, double *inputs, double *outputs, double *jacobian);  int asc_datareader_calc(struct Slv_Interp *slv_interp, int ninputs, int noutputs, double *inputs, double *outputs, double *jacobian);
57  int asc_datareader_close(struct Slv_Interp *slv_interp, struct Instance *data, struct gl_list_t *arglist);  int asc_datareader_close(struct Slv_Interp *slv_interp, struct Instance *data, struct gl_list_t *arglist);
58    
 /**  
     This is the function called from "IMPORT extfntest"  
   
     It sets up the functions in this external function library  
 */  
   
59  #ifndef ASC_EXPORT  #ifndef ASC_EXPORT
60  # error "Where is ASC_EXPORT?"  # error "Where is ASC_EXPORT?"
61  #endif  #endif
62    
63    /**
64        This is the function called from "IMPORT datareader"
65    
66        It sets up the functions in this external function library and tells ASCEND
67        how many inputs and outputs it needs.
68    */
69  extern  extern
70  ASC_EXPORT(int) datareader_register(){  ASC_EXPORT(int) datareader_register(){
71      const char *help = "The is the ASCEND Data Reader, for pulling in"      const char *help = "The is the ASCEND Data Reader, for pulling in"
# Line 76  ASC_EXPORT(int) datareader_register(){ Line 77  ASC_EXPORT(int) datareader_register(){
77    
78      (void)CONSOLE_DEBUG("EVALUATION FUNCTION AT %p",asc_datareader_calc);      (void)CONSOLE_DEBUG("EVALUATION FUNCTION AT %p",asc_datareader_calc);
79    
80      result += CreateUserFunctionBlackBox("add_one"      result += CreateUserFunctionBlackBox("datareader"
81          , asc_datareader_prepare          , asc_datareader_prepare
82          , asc_datareader_calc /* value */          , asc_datareader_calc /* value */
83          , asc_datareader_calc /* deriv */          , asc_datareader_calc /* deriv */
84          , NULL /* deriv2 */          , NULL /* deriv2 */
85          , asc_datareader_close /* final */          , asc_datareader_close /* final */
86          , 1,1 /* inputs, outputs */          , 1,2 /* inputs, outputs */
87          , help          , help
88      ); /* returns 0 on success */      ); /* returns 0 on success */
89    
# Line 92  ASC_EXPORT(int) datareader_register(){ Line 93  ASC_EXPORT(int) datareader_register(){
93      return result;      return result;
94  }  }
95    
96    /**
97        This function prepares the data that we will use before starting the solver
98        process.
99    */
100  int asc_datareader_prepare(struct Slv_Interp *slv_interp,  int asc_datareader_prepare(struct Slv_Interp *slv_interp,
101         struct Instance *data,         struct Instance *data,
102         struct gl_list_t *arglist         struct gl_list_t *arglist
103  ){  ){
104      struct Instance *fninst;      struct Instance *fninst, *fmtinst;
105      const char *fn;      const char *fn, *fmt;
106      DataReader *d;      DataReader *d;
107    
108      dr_symbols[0] = AddSymbol("filename");      dr_symbols[0] = AddSymbol("filename");
109        dr_symbols[1] = AddSymbol("format");
110    
111      /* get the data file name (we will look for this file in the ASCENDLIBRARY path) */      /* get the data file name (we will look for this file in the ASCENDLIBRARY path) */
112      fninst = ChildByChar(data,FILENAME_SYM);      fninst = ChildByChar(data,FILENAME_SYM);
# Line 111  int asc_datareader_prepare(struct Slv_In Line 117  int asc_datareader_prepare(struct Slv_In
117          return 1;          return 1;
118      }      }
119      if(InstanceKind(fninst)!=SYMBOL_CONSTANT_INST){      if(InstanceKind(fninst)!=SYMBOL_CONSTANT_INST){
120          ERROR_REPORTER_HERE(ASC_USER_ERROR,"'filename' must be a symbol constant");          ERROR_REPORTER_HERE(ASC_USER_ERROR,"'filename' must be a symbol_constant");
121          return 1;          return 1;
122      }      }
123      fn = SCP(SYMC_INST(fninst)->value);      fn = SCP(SYMC_INST(fninst)->value);
# Line 121  int asc_datareader_prepare(struct Slv_In Line 127  int asc_datareader_prepare(struct Slv_In
127          return 1;          return 1;
128      }      }
129    
130        /* get the data reader format *//**
131        This is the function called from "IMPORT extfntest"
132    
133        It sets up the functions in this external function library
134    */
135    
136        fmtinst = ChildByChar(data,FORMAT_SYM);
137        if(!fmtinst){
138            ERROR_REPORTER_HERE(ASC_USER_ERROR
139                ,"Couldn't locate 'format', please check Data Reader usage."
140            );
141            return 1;
142        }
143        if(InstanceKind(fmtinst)!=SYMBOL_CONSTANT_INST){
144            ERROR_REPORTER_HERE(ASC_USER_ERROR,"'format' must be a symbol_constant");
145            return 1;
146        }
147        fmt = SCP(SYMC_INST(fmtinst)->value);
148        CONSOLE_DEBUG("FORMAT: %s",fmt);
149        if(fmt==NULL || strlen(fmt)==0){
150            ERROR_REPORTER_HERE(ASC_USER_ERROR,"'format' is NULL or empty");
151            return 1;
152        }
153    
154        CONSOLE_DEBUG("Creating the datareader object...");
155    
156      /* create the data reader and tell it the filename */      /* create the data reader and tell it the filename */
157      d = datareader_new(fn);      d = datareader_new(fn);
158    
159        if(fmt!=NULL){
160            if(datareader_set_format(d,fmt)){
161                CONSOLE_DEBUG("Invalid 'format'");
162                return 1;
163            }      
164        }
165        
166      if(datareader_init(d)){      if(datareader_init(d)){
167          CONSOLE_DEBUG("Error initialising data reader");          CONSOLE_DEBUG("Error initialising data reader");
168          return 1;          return 1;

Legend:
Removed from v.811  
changed lines
  Added in v.812

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