#include "dbinc.h" /***************************************************************************** * * * COMMON OCEANOGRAPHIC DATA ACCESS SYSTEM (CODAS) * * * * WRITTEN BY: RAMON CABRERA, ERIC FIRING, and JULIE RANADA * * JOINT INSTITUTE FOR MARINE AND ATMOSPHERIC RESEARCH * * 1000 POPE ROAD MSB 404 * * HONOLULU, HI 96822 * * * * VERSION: 3.00 * * * * DATE: APRIL 1989 * * * *****************************************************************************/ /* FILE: dbmove.c */ /*---------------------------------------------------------------------------- FUNCTION: DBMOVE It resets the database pointer to *steps profiles from the current profile. PARAMETERS: *steps = number of profiles to advance *ierr = error code RETURNS: VOID */ void DBMOVE(int *steps, int *ierr) { int iprofile, jprofile, nprofiles, iblock, n; int profile_found = 0; if ((!(db_ptr)) || first_database_call) { *ierr = DB_IS_NOT_OPEN; return; } if (db_ptr->create_mode) { *ierr = OPEN_FOR_CREATE; return; } if (!(db_ptr->block_is_open)) { *ierr = NO_BLOCK_IS_OPEN; return; } *ierr = 0; n = *steps; iblock = db_ptr->block_dir_index; jprofile = db_ptr->profile_dir_index; nprofiles = db_ptr->block_hdr.dir_nentries; while (!profile_found) { iprofile = jprofile + n; if ((iprofile >= 0) && (iprofile < nprofiles)) profile_found = 1; else { if (iprofile > 0) { iblock++; if (iblock >= (int)db_ptr->block_dir_hdr.dir_nentries) { *ierr = SEARCH_BEYOND_END; iprofile = db_ptr->block_hdr.dir_nentries - 1; profile_found = 1; } else { n = n - (nprofiles - jprofile); if (close_block()) goto error_found; db_ptr->block_dir_index = iblock; if (lock_on_block()) goto error_found; nprofiles = db_ptr->block_hdr.dir_nentries; jprofile = 0; } } else { iblock--; if (iblock < 0) { *ierr = SEARCH_BEFORE_BEGINNING; iprofile = 0; profile_found = 1; } else { n = n + jprofile + 1; if (close_block()) goto error_found; db_ptr->block_dir_index = iblock; if (lock_on_block()) goto error_found; nprofiles = db_ptr->block_hdr.dir_nentries; jprofile = nprofiles - 1; } } } } db_ptr->profile_dir_index = iprofile; if (lock_on_profile()) goto error_found; return; error_found: report_db_error("DBMOVE"); *ierr = db_ptr->error_code * 1000 - db_ptr->error_data; }