00001 //--- 00002 // 00003 // This file is part of sedflux. 00004 // 00005 // sedflux is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 2 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // sedflux is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with sedflux; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 // 00019 //--- 00020 00021 #ifndef __EH_SCANNER_H__ 00022 #define __EH_SCANNER_H__ 00023 00024 #include <glib.h> 00025 #include <utils/eh_symbol_table.h> 00026 #include <utils/eh_data_record.h> 00027 00028 //typedef GHashTable Symbol_table; 00029 00030 #ifdef OLD 00031 typedef struct 00032 { 00033 GHashTable *symbol_table; 00034 GPtrArray *data; 00035 } 00036 Eh_data_record; 00037 00038 typedef struct 00039 { 00040 char *filename; 00041 GHashTable *records; // a table of Eh_data_records 00042 } 00043 Eh_record_file; 00044 #endif 00045 00046 typedef struct 00047 { 00048 char *filename; 00049 char *delimeter; 00050 gboolean row_major; 00051 gint fast_dim; 00052 gboolean with_header; 00053 Eh_data_record* records; 00054 // GPtrArray *records; // an array of Eh_data_records 00055 } 00056 Eh_data_file; 00057 00058 typedef struct 00059 { 00060 char *delimeter; 00061 gint fast_dim; 00062 gboolean row_major; 00063 gboolean with_header; 00064 } 00065 Eh_data_file_attr; 00066 00067 // create a symbol table. 00068 // return value : the newly created symbol table. 00069 //Symbol_table *eh_create_symbol_table(void); 00070 00071 // insert a key/value pair into a symbol table. 00072 // t : a pointer to a symbol table. 00073 // key : a string containing the key. 00074 // value : a string containing the value. 00075 // return value : the newly created symbol table. 00076 //void eh_symbol_table_insert(Symbol_table *t,char *key, char *value); 00077 00078 // replace a key/value pair into a symbol table. 00079 // t : a pointer to a symbol table. 00080 // key : a string containing the key. 00081 // value : a string containing the value. 00082 // return value : the newly created symbol table. 00083 //void eh_symbol_table_replace( Symbol_table* t , char* key , char* value ); 00084 00085 // lookup up a symbol in a symbol table. 00086 // t : a pointer to a symbol table. 00087 // key : a string containing the key to lookup. 00088 // return value : a string containint the value of the key. 00089 //char *eh_symbol_table_lookup(Symbol_table *t,char *key); 00090 00091 // print a key/value pair. intended to be used as a GHFunc. 00092 // key : a key string. 00093 // value : a value string. 00094 // fp : file pointer to print to. 00095 // return value : nothing. 00096 void eh_print_symbol(char *key, char *value, FILE *fp); 00097 00098 // print all of the key/value pairs of a symbol table. 00099 // t : a pointer to a symbol table. 00100 // fp : file pointer to print to. 00101 // return value : nothing. 00102 //void eh_print_symbol_table( Symbol_table *t , FILE *fp); 00103 00104 // print all of the key/value pairs of a symbol table and align them. 00105 // t : a pointer to a symbol table. 00106 // fp : file pointer to print to. 00107 // return value : nothing. 00108 //void eh_print_symbol_table_aligned( Symbol_table *t , FILE *fp); 00109 00110 // get the number of entries in a symbol table 00111 // t : a pointer to a symbol table. 00112 // return value : the number of entries. 00113 //gssize eh_symbol_table_size( Symbol_table *t ); 00114 00115 // destroy a symbol table. 00116 // t : a pointer to a symbol table to destroy. 00117 // return value : nothing. 00118 //Symbol_table* eh_destroy_symbol_table(Symbol_table*); 00119 00120 //void eh_free_symbol_table_labels( Symbol_table *t ); 00121 00122 //Symbol_table* eh_symbol_table_dup( Symbol_table* t ); 00123 //Symbol_table* eh_symbol_table_copy( Symbol_table* dest , Symbol_table* src ); 00124 00125 00126 // merge a bunch of symbol tables into one. 00127 // table1 : the first symbol table to add, which must not be null. 00128 // ... : a NULL terminated list of symbol tables to merge. 00129 // return value : a newly create symbol table composed of all the symbol table arguments. 00130 //Symbol_table *eh_merge_symbol_table( Symbol_table* table1 , ... ); 00131 00132 // open a scanner file. 00133 // filename : the name of the file to open. 00134 // return value : the opened scanner. 00135 GScanner *eh_open_scanner(const char *filename , GError** error ); 00136 00137 void eh_close_scanner( GScanner* ); 00138 00139 // scan a data file. 00140 // filename : the name of the data file to scan. 00141 // delimeter : the delimeter to use to split a row of values. 00142 // row_major : if TRUE, the data is read in row major order. 00143 // with_header : if TRUE, the data is preceded by a header. 00144 // return value : a pointer array containing the data. 00145 GPtrArray *eh_scan_data_file(const char *filename,const char *delimiter,gboolean row_major, gboolean with_header); 00146 00147 // scan a data record. 00148 // s : a scanner set up to read the data. created with eh_open_scanner. 00149 // delimeter : the delimeter to use to split a row of values. 00150 // row_major : if TRUE, the data is read in row major order. 00151 // data : a pointer array to put the data. 00152 // return value : a pointer array of the data. 00153 GPtrArray *eh_scan_data_record(GScanner *s,const char *delimeter, gboolean row_major, GPtrArray *data); 00154 00155 double* eh_scan_ascii_data_line_dbl( GScanner* s , const char* delimeter , gssize *len ); 00156 00157 // scan a line of ascii data. 00158 // s : a scanner set up to read the data. created with eh_open_scanner. 00159 // return value : a string of the line of data. 00160 char *eh_scan_ascii_data_line(GScanner *s); 00161 00162 // scan the records of a record file. 00163 // filename : the name of the file to scan. 00164 // return value : a hash table with a symbol table entry for each record. 00165 //GHashTable *eh_scan_record_file(const char *filename); 00166 00167 // scan a record file for a specific record. 00168 // filename : the name of the file to scan. 00169 // rec_name : the name of the record to search for. 00170 // return value : a symbol table representation of the record. 00171 //Symbol_table *eh_scan_record_file_for( const char *filename , const char *rec_name ); 00172 00173 // scan a key file for a specific group. 00174 // file : the name of the file to scan. 00175 // grp_name : the name of the group to search for. 00176 // tab : if non-NULL, store the key-value pairs in tab. If NULL, create a new symbol table. 00177 // return value : a symbol table representation of the record. 00178 //Symbol_table* eh_scan_key_file_for( const gchar* file , const gchar* grp_name , Symbol_table *tab ); 00179 00180 // scan the next record from a scanner. 00181 // s : a scanner set up to read the data. created with eh_open_scanner. 00182 // symbol_table : a symbol table to add the record entries to. 00183 // return value : the name of the record. 00184 char *eh_scan_next_record(GScanner *s,Eh_symbol_table symbol_table); 00185 00186 // move to the begining of the data of the next record. 00187 // s : a scanner set up to read the data. created with eh_open_scanner. 00188 // return value : the name of the record. 00189 char *eh_seek_record_start(GScanner *s); 00190 00191 // scan a label from a scanner. 00192 // s : a scanner set up to read the data. created with eh_open_scanner. 00193 // return value : a string containing the label read. 00194 char *eh_scan_label(GScanner *s); 00195 00196 // scan a entry from a scanner. 00197 // s : a scanner set up to read the data. created with eh_open_scanner. 00198 // return value : a string containing the entry read. 00199 char *eh_scan_entry(GScanner *s); 00200 00201 // print the symbol tables of a list of symbol tables. intended to be used as a GHFunc. 00202 // rec_name : the name of the record. 00203 // t : the symbol table to print. 00204 // fp : the file to print to. 00205 // return value : nothing. 00206 //void eh_print_record( const char *rec_name , Symbol_table *t , FILE *fp ); 00207 00208 // indicate if the end of a record has been reached. 00209 // s : a scanner set up to read the data. created with eh_open_scanner. 00210 // return value : TRUE if the end of a record has been encountered. 00211 gboolean eh_scanner_eor(GScanner *s); 00212 00213 // create a data record. 00214 // return value : the newly created data record. 00215 //Eh_data_record *eh_create_data_record(); 00216 00217 // free the memory allocated for a data record. 00218 // p : the data record to destroy. 00219 // return value : nothing. 00220 //void eh_free_data_record(Eh_data_record *p); 00221 00222 // print a data record to a file. 00223 // p : a pointer to a data record. 00224 // rec_name : the name of the record. 00225 // delimeter : a pointer to the delimeter. 00226 // row_major : TRUE if the data is written row by row. 00227 // with_header : TRUE if the data is preceded by a header. 00228 // fp : a pointer to a file to print the record. 00229 // record value : nothing. 00230 //void eh_print_data_record( Eh_data_record *p , char *rec_name , char *delimeter , gboolean row_major , gboolean with_header , FILE *fp ); 00231 00232 // get the size of a data record. 00233 // p : a pointer to a data record. 00234 // i : the dimension to get the size of. 00235 // return value : the size of the data matrix in the specified dimension. 00236 //int eh_get_data_record_size(Eh_data_record *p,int i); 00237 00238 // get the symbol table associated with the data record. 00239 // p : a pointer to a data record. 00240 // return value : the symbol table of the data record. 00241 //Symbol_table *eh_get_data_record_sym_table(Eh_data_record *p); 00242 00243 // get a row of data from a data file. 00244 // p : a pointer to a data record. 00245 // row : the row number of the data matrix to return. 00246 // return value : an array of data values. 00247 //GArray *eh_get_data_record_row(Eh_data_record *p,int row); 00248 00249 // insert an array into a data record. 00250 // p : a pointer to a data record. 00251 // row : the row number of the data matrix to add the array. 00252 // a : the array to add. 00253 // return value : nothing. 00254 //void eh_set_data_record_row( Eh_data_record *p , int row , GArray *a ); 00255 00256 // add a label to the symbol table of a data record. 00257 // p : a pointer to a data record. 00258 // a : the array to add. 00259 // return value : nothing. 00260 //void eh_add_data_record_row( Eh_data_record *p , GArray *a ); 00261 00262 // add a label to the symbol table of a data record. 00263 // p : a pointer to a data record. 00264 // label : the label to add. 00265 // value : the value to add. 00266 // return value : nothing. 00267 //void eh_add_data_record_label( Eh_data_record *p , char *label , char *value ); 00268 00269 // get a pointer to a row of data. 00270 // p : a pointer to a data record. 00271 // row : the row number of the data matrix to return. 00272 // type : the type of data. 00273 // return value : a pointer to the data. 00274 /* 00275 #define eh_get_data_record_row_ptr( p , row , type ) \ 00276 ( ((type*)eh_get_data_record_row(p,row)->data) ) 00277 */ 00278 00279 // interpolate the rows of a data record. 00280 // p : a pointer to a data record. 00281 // row : the row to use to interpolate the rest of the data. 00282 // x : the array of points to interpolate to. 00283 // return value : nothing. 00284 //void eh_interpolate_data_record_rows( Eh_data_record *p , int row , GArray *x ); 00285 00286 // open a record file. 00287 // filename : the name of the file (NULL for stdin); 00288 // return value : pointer to the opened record file. 00289 //Eh_record_file *eh_open_record_file( const char *filename ); 00290 00291 // close a record file. 00292 // rec_file : pointer to a record file. 00293 // return value : nothing. 00294 //void eh_close_record_file( Eh_record_file *rec_file ); 00295 00296 // get a record from a record file. 00297 // rec_file : pointer to a record file. 00298 // name : the name of the record to retrieve 00299 // return value : a symbol table of the record. 00300 //Symbol_table *eh_get_record_from_record_file( Eh_record_file *rec_file , const char *name ); 00301 00302 // get a value from a record within a record a file. 00303 // rec_file : pointer to a record file. 00304 // rec_name : the name of the record containing the value. 00305 // label : the label for the value to retrieve. 00306 // return value : the value as a string. 00307 //char *eh_get_value_from_record_file( Eh_record_file *rec_file , const char *rec_name , const char *label ); 00308 00309 // open a data file. 00310 // filename : the name of the file (NULL for stdin); 00311 // attr : attributes to use when opening a data file. use NULL for defaults. 00312 // return value : pointer to the opened data file. 00313 Eh_data_file *eh_open_data_file( const char *filename , Eh_data_file_attr *attr , GError** error ); 00314 00315 // close a data file. 00316 // data_file : pointer to a data file. 00317 // return value : nothing. 00318 void eh_close_data_file( Eh_data_file *data_file ); 00319 00320 // get a row of data from a data file. 00321 // name : the name of the record to retrieve. 00322 // return value : an array containing the row of data. 00323 GArray *eh_get_row_from_data_file( Eh_data_file *data_file , int row ); 00324 00325 // interpolate a row of data from a data file. 00326 // data_file : pointer to a data file. 00327 // interp_data : an array of data of interpolation points. 00328 // return value : the interpolated row. 00329 GArray *eh_interpolate_data_file( Eh_data_file *data_file , GArray *interp_data , int row ); 00330 00331 // get the i-th data record from a data file. 00332 // data_file : pointer to a data file. 00333 // i : the record to get. 00334 // return value : the i-th data record. 00335 //Eh_data_record *eh_get_data_from_file( Eh_data_file *data_file , int i ); 00336 00337 #endif