/*************************************************************** CHECK_DB.C Functions that simplify common CODAS access calls from C. Header: use_db.h Library: use_db_x.lib ****************************************************************/ #include "geninc.h" /* DB*() */ /*************************************************************** Note: DBGET and DBGET_F will return ierr as INVALID_TYPE_REQUEST (not multiplied by 1000) if a request is made for profile data (ID from 0-99) of a type that is not in the data list. To the user, this is functionally the same as the situation in which the data type is in the data list, but zero bytes are stored. Therefore the two functions check_dbget_f and check_db_get trap this error and convert it to a return of zero bytes. Similarly, check_dbsrch handles the errors SEARCH_BEFORE BEGINNING and SEARCH_BEYOND_END with just a warning message. The function "lock_on_time" (called by DBSRCH when searching by time) correctly sets the db to the beginning and ending profiles, respectively, in case of these errors. In all of these functions, we are relying on check_error, which calls exit(), to handle the serious errors. This is the simplest thing to do, and should have no major disadvantages when data are being read. When data are being written, it would probably be better to use the milder error_found routine, and handle the errors in the calling program by ending profiles and blocks as needed, and then closing the database. If this is desired, use the functions in db_cnf.c. ******************************************************************************/ unsigned int check_dbget(int type, char *x, unsigned int n, char *err_msg) { int ierr; DBGET(&type, x, &n, &ierr); if (ierr == INVALID_TYPE_REQUEST) return(0); if (DBERROR(&ierr, err_msg)) exit(-1); return(n); } void check_dbset(int dbid, char *err_msg) { int ierr; DBSET(&dbid, &ierr); if (DBERROR(&ierr, err_msg)) exit(-1); } void check_dbopen(int dbid, char *dbname, int access, int mem_mode) { int ierr; DBOPEN(&dbid, dbname, &access, &mem_mode, &ierr); if (DBERROR(&ierr, "DBOPEN")) exit(-1); } void check_dbsrch(int search_type, char *search_parameters) { int ierr; DBSRCH(&search_type, search_parameters, &ierr); switch (ierr) { case 0: break; case SEARCH_BEFORE_BEGINNING: printf("INFO: Search before beginning\n"); break; case SEARCH_BEYOND_END: printf("INFO: Search beyond end\n"); break; default: DBERROR(&ierr, "check_dbsrch"); exit(-1); } } void check_dbmove(int nsteps) { int ierr; DBMOVE(&nsteps, &ierr); switch (ierr) { case 0: break; case SEARCH_BEFORE_BEGINNING: /* non-fatal */ printf("INFO: Search before beginning\n"); break; case SEARCH_BEYOND_END: /* non-fatal */ printf("INFO: Search beyond end\n"); break; default: /* fatal */ DBERROR(&ierr, "check_dbsrch"); exit(-1); } } void flag_data(FLOAT data[], UBYTE profile_flags[], int n, UBYTE mask) { int i; for (i = 0; i < n; i++) if (profile_flags[i] & mask) data[i] = BADFLOAT; }