/* FILE: DB_CNF.C ( DB_Check Non-Fatal ) This file contains routines that set up calls to CODAS database functions and check the resulting error code. There are also routines for checking profile times and block-profile numbers against some range. Your program must #include "use_db.h", the header file for these routines. */ #include "geninc.h" /* DB*() */ #include "ioserv.h" /* error_found(), report_msg(), set_long_bit() */ #include "use_db.h" int dbget_cnf(int type, char *data, unsigned int *n, char *msg) { int ierr; DBGET(&type, data, n, &ierr); error_found(ierr, msg); return(ierr); } int dbget_f_cnf(int type, float *data, unsigned int *n, char *msg) { int ierr; DBGET_F(&type, data, n, &ierr); error_found(ierr, msg); return(ierr); } int dbmove_cnf(int nsteps) { int ierr; DBMOVE(&nsteps, &ierr); switch (ierr) { case SEARCH_BEFORE_BEGINNING: report_msg("INFO: DBMOVE search before beginning\n"); break; case SEARCH_BEYOND_END: report_msg("INFO: DBMOVE search beyond end\n"); break; default: error_found(ierr, "DBMOVE"); } return(ierr); } int dbopen_cnf(int dbid, char *dbname, int accmode, int memmode) { int ierr; char buff[255]; DBOPEN(&dbid, dbname, &accmode, &memmode, &ierr); if (ierr) sprintf(buff, "ERROR: %d opening database %s\n", ierr, dbname); else sprintf(buff, "INFO: database %s opened\n", dbname); report_msg(buff); return(ierr); } void dbclose_cnf(void) { int ierr; DBCLOSE(&ierr); if (error_found(ierr, "closing database")) return; report_msg("INFO: database closed\n"); } int dbsrch_cnf(int search_type, char *search_param) { int ierr; DBSRCH(&search_type, search_param, &ierr); switch (ierr) { case SEARCH_BEFORE_BEGINNING: report_msg("INFO: DBSRCH search before beginning\n"); break; case SEARCH_BEYOND_END: report_msg("INFO: DBSRCH search beyond end\n"); break; default: break; } return(ierr); } int dbset_cnf(int dbid) { int ierr; DBSET(&dbid, &ierr); return(error_found(ierr, "DBSET")); } /*----------------------------------------------------------------------------- FUNCTION: check_prftime Gets time of current profile and compares it with the given end time. PARAMETERS: now = pointer to profile time structure end = pointer to end time structure RETURNS: 0 if profile time is same as end time -1 if profile time is less than end time 1 if profile time is greater than end time 2 if database error */ int check_prftime(YMDHMS_TIME_TYPE *now, YMDHMS_TIME_TYPE *end) { LONG cmp; unsigned int n = sizeof(YMDHMS_TIME_TYPE); if (dbget_cnf(TIME, (char *) now, &n, "getting profile time")) return(2); cmp = TIMCMP(now, end); if (cmp == 0) return(0); if (cmp == 1) return(-1); return(1); } /*----------------------------------------------------------------------------- FUNCTION: check_blkprf Retrieves current block-profile no. and compares with given block- profile no. PARAMETERS: c_blkprf = pointer to block-profile index of current profile e_blkprf = pointer to block-profile index to compare to RETURNS: -1 if c_blkprf < e_blkprf 1 if c_blkprf > e_blkprf 0 if c_blkprf = e_blkprf 2 if database error */ int check_blkprf(int c_blkprf[], int e_blkprf[]) { unsigned int n = 2 * sizeof(int); if (dbget_cnf(BLOCK_PROFILE_INDEX, (char *) c_blkprf, &n, "getting block-profile index")) return(2); if (c_blkprf[0] < e_blkprf[0]) return(-1); /* compare block index */ if (c_blkprf[0] > e_blkprf[0]) return(1); if (c_blkprf[1] < e_blkprf[1]) return(-1); /* compare profile index */ if (c_blkprf[1] > e_blkprf[1]) return(1); return(0); }