#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:  dbdelete.c

              FUNCTIONS FOR DELETING BLOCKS/PROFILES FROM AN EXISTING DATABASE

*/
/*-----------------------------------------------------------------------------

   FUNCTION:  DBDELBLK

      It deletes the current block from the database.

   PARAMETER:
   
      ierr = pointer to error code

   RETURNS:  VOID

*/
#if PROTOTYPE_ALLOWED
void DBDELBLK(int *ierr)
#else
void DBDELBLK(ierr)
int *ierr;
#endif
{
   *ierr = 0;
   if ((!(db)) || first_database_call)
   {
      *ierr = DB_IS_NOT_OPEN;
      return;
   }
   if (!(db->block_is_open))
   {
      *ierr = NO_BLOCK_IS_OPEN;
      return;
   }
   if (db->new_block_is_open)
   {
      *ierr = NEW_BLOCK_IS_OPEN;
      return;
   }
   if (db->block_dir_entry_ptr->file_id > 0)
      db->block_dir_entry_ptr->file_id = -db->block_dir_entry_ptr->file_id;
   if (write_block_dir_entry())
   {
      report_db_error("DBDELBLK");
      *ierr = db->error_code * 1000 - db->error_data;
   }
   db->block_dir_modified = 1;
}

/*-----------------------------------------------------------------------------

   FUNCTION:  DBDELPRF

      It deletes the current profile from the database.

   PARAMETERS: 
   
      ierr = pointer to error code

   RETURNS:  VOID

*/
#if PROTOTYPE_ALLOWED
void DBDELPRF(int *ierr)
#else
void DBDELPRF(ierr)
int *ierr;
#endif
{
   *ierr = 0;
   if ((!(db)) || first_database_call)
   {
      *ierr = DB_IS_NOT_OPEN;
      return;
   }
   if (!(db->block_is_open))
   {
      *ierr = NO_BLOCK_IS_OPEN;
      return;
   }
   if (db->new_block_is_open)
   {
      *ierr = NEW_BLOCK_IS_OPEN;
      return;
   }
   if (!(db->profile_is_open))
   {
      *ierr = NO_PROFILE_IS_OPEN;
      return;
   }
   if (db->profile_dir_entry_ptr->ofs > 0)
      db->profile_dir_entry_ptr->ofs = -db->profile_dir_entry_ptr->ofs;
   if (write_profile_dir_entry())
   {
      report_db_error("DBDELPRF");
      *ierr = db->error_code * 1000 - db->error_data;
   }
   db->block_modified = 1;
}
