/**************************************************************************
 transub_bbp.c 

        BASED on transub.c of NB proccessed transect files by UH.

        Modified Sept '95
                Dave Senciall
                NWAFC,DFO,Gov of Canada

The main change here is to handle the 2 paragraphs of direct commands that the
BB format supports.

NOTE the 2nd parargraph code has not been tested . Its ok for 1 paragraph.
                                                        ~Davsen
**************************************************************************/

#include <common.h>
#include <ioserv.h>    /* error_found */
#include "tran_bbp.h"  /* BBP_ENSEMBLE_TYPE */
#include "tran_dcl.h"

/**************************************************************************/
void set_depth(db_ens,ens)
DB_ENSEMBLE_TYPE *db_ens;
BBP_ENSEMBLE_TYPE *ens;
{
   int i;
/* BB encode middle of first bin depth as cm  ~davsen */
    db_ens->depth[0] = db_ens->conf1.tr_depth + (ens->conf.bin_1_dist)/100.0 ;

   for (i = 1; i < db_ens->conf1.num_bins; i++)
      db_ens->depth[i] = db_ens->depth[0] + i * db_ens->conf1.bin_length;
   db_ens->depth_range.min_depth = db_ens->depth[0];
   db_ens->depth_range.max_depth = db_ens->depth[db_ens->conf1.num_bins-1];
}
/**************************************************************************/
int set_block_comments(db_ens, ens)

 DB_ENSEMBLE_TYPE *db_ens;
 BBP_ENSEMBLE_TYPE *ens;
{
   db_ens->bc_nbytes = 32 + ens->conf.direct_cmd_size+ens->conf.direct_cmd2_size;

   if (error_found( db_ens->bc == NULL ?
        (db_ens->bc = malloc(db_ens->bc_nbytes)) == NULL :
        (db_ens->bc = realloc(db_ens->bc, db_ens->bc_nbytes)) == NULL, 
        "Can't allocate memory for block comments."))
      return(INSUFFICIENT_MEMORY);

   /* ens->conf.direct_cmd etc. are null-terminated strings.
   The Name label line adds 11 characters and "DirectCommands:\n"
   adds 16.  Null termination adds one, for a total of 28; hence
   adding 32 to bc_nbytes above should be more than adequate. */
   sprintf(db_ens->bc, "Name: %-4s\nDirectCommands:\n%s",
      (ens->conf.dply_name_size > 0 ? ens->conf.name : "none"),
      (ens->conf.direct_cmd_size > 0 ? ens->conf.direct_cmd : "none"));

/* IF A 2nd PARARGRAPH IS PRESENT */

   if (ens->conf.direct_cmd2_size)
   {
      strcat (db_ens->bc,ens->conf.direct_cmd2);
   }

   return(OK);
}
/**************************************************************************/
