1,2c1,2
< /*
<    FILE: readtnbp.c
---
> /***************************************************************************
>    FILE: readtran_bbp.c
4c4
<          Routines for READing Transect NarrowBand Processed data files.
---
>          Routines for reading Transect BroadBand Processed data files.
6,7c6,13
< */
< #include <dbinc.h>  /* includes geninc.h */
---
>     Based on readtnbp.c by UH for reading NB processed transect files.
> 
>     Modified by : Dave Senciall    Sept '95
>                   NWAFC,DFO,Gov of Canada
> 
> ***************************************************************************/
> 
> #include <dbinc.h>
10,11c16,17
< /* #include "rawbb.h" */
< #include "tran_nbp.h"
---
> #include "tran_bbp.h"
> #include "tran_dcl.h"
15,21d20
< #define N_DIRECT_CMD 9  /* ?? specific to Teri's data -- need to reduce direct_cmd_size
<                               by this much because of loss of CR character at EOL */
< #if PROTOTYPE_ALLOWED
< void set_depth(DB_ENSEMBLE_TYPE *db_ens, NBP_ENSEMBLE_TYPE *ens);
< #else
< void set_depth();
< #endif
23c22,24
< extern char msg[];
---
> extern char msg[]; /* in loadtbbp.c */
> 
> /***************************************************************************/
26c27
< int read_header(FILE *fp, NBP_HEADER_TYPE *header, long *ens_start)
---
> int read_header(FILE *fp, BBP_HEADER_TYPE *header, long *ens_start)
30c31
<    NBP_HEADER_TYPE *header;
---
>    BBP_HEADER_TYPE *header;
34,35c35,36
<    int n, c, d;
<    static char buff[NBP_HEADER_FIXED_SIZE], *buf_ptr;
---
>    int c, d;
>    static char buff[BBP_HEADER_FIXED_SIZE], *buf_ptr;
39,40c40,42
<    while ( (c = getc(fp)) != EOF && (c != 0x7f  ||
<            (d = getc(fp)) != EOF && d != 0x7e ))
---
>    while ( (c = getc(fp)) != EOF &&
>             (c != 0x7f  ||
>                ( (d = getc(fp)) != EOF && d != 0x7e ) ))
49c51
<    if (fread(buff, NBP_HEADER_FIXED_SIZE, 1, fp) != 1)
---
>    if (fread(buff, BBP_HEADER_FIXED_SIZE, 1, fp) != 1)
52,53c54,60
<    buf_ptr = &buff[0];
<    buf_ptr += convert_array_short((char *)&header->n_bytes_in_data_segment, buf_ptr, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 1);
---
>    buf_ptr = (char *) &buff[0];
>    buf_ptr += convert_array_short((char *)(&header->n_bytes_in_data_segment),
>                                   (char *) buf_ptr,
>                                   PC_COMPATIBLE_HOST,
>                                   HOST_ENVIRONMENT,
>                                   1);
> 
60a68
> 
69,70c77
<       copy_byte((char *) header->offset, (char *) header->offset, 
<                                              2, INVERTED, NULL);
---
>       copy_byte((char *) header->offset, (char *) header->offset, 2, INVERTED, NULL);
76a84,86
> 
> /***************************************************************************/
> 
78c88
< int read_configuration(FILE *fp, NBP_ENSEMBLE_TYPE *ens)
---
> int read_configuration(FILE *fp, BBP_ENSEMBLE_TYPE *ens)
82c92
<    NBP_ENSEMBLE_TYPE *ens;
---
>    BBP_ENSEMBLE_TYPE *ens;
85,86c95,96
<    NBP_CONFIGURATION_TYPE *conf;
<    static char buff[NBP_CONFIGURATION_FIXED_SIZE], *buf_ptr;
---
>    BBP_CONFIGURATION_TYPE *conf;
>    static char buff[BBP_CONFIGURATION_FIXED_SIZE], *buf_ptr;
89c99
<    if (error_found( fread(buff, NBP_CONFIGURATION_FIXED_SIZE, 1, fp) != 1, "Can't read configuration."))
---
>    if (error_found( fread(buff, BBP_CONFIGURATION_FIXED_SIZE, 1, fp) != 1, "Can't read configuration."))
95,96c105,114
<    buf_ptr += convert_array_short((char *) &conf->ADCP_serial_number, buf_ptr, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 2);
<    buf_ptr += copy_byte((char *)&conf->n_beams, buf_ptr, 2, AS_IS, NULL);
---
> 
>    sprintf (msg, "adcp type,ver,rev = %u %u %u\n",
>    conf->adcp_type,conf->transect_version,conf->transect_revision);
>    report_msg(msg);
> 
>    buf_ptr += convert_array_short((char *) &conf->ADCP_firmware_number, buf_ptr, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 1);
> 
> 
>    buf_ptr += copy_byte((char *)&conf->n_beams, buf_ptr, 1, AS_IS, NULL);
>    buf_ptr += convert_array_short((char *) &conf->beam_angle, buf_ptr, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 1);
98c116,118
<    buf_ptr += copy_byte((char *)&conf->range_switch, buf_ptr, 5, AS_IS, NULL);
---
>    buf_ptr += copy_byte((char *)&conf->profile_mode, buf_ptr, 1, AS_IS, NULL);
>    buf_ptr += convert_array_short((char *) &conf->coord_system, buf_ptr, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 3);
>    buf_ptr += copy_byte((char *)&conf->n_bins, buf_ptr, 1, AS_IS, NULL);
101,102c121,122
<    buf_ptr += copy_byte((char *)&conf->bin_length, buf_ptr, 1, AS_IS, NULL);
<    buf_ptr += convert_array_short((char *) &conf->pulse_length, buf_ptr, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 2);
---
>    buf_ptr += convert_array_short((char *) &conf->bin_length, buf_ptr, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 1);
>    buf_ptr += convert_array_short((char *) &conf->blank, buf_ptr, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 1);
112c132,134
<    buf_ptr += convert_array_long((char *) &conf->spare1, buf_ptr, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 2);
---
>    buf_ptr += convert_array_short((char *) &conf->bin_1_dist, buf_ptr, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 1);
>    buf_ptr += convert_array_short((char *) &conf->xmit_pulse_len, buf_ptr, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 1);
>    buf_ptr += convert_array_long((char *) &conf->spare2, buf_ptr, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 1);
115c137,138
<    if ( (conf->name = calloc(conf->dply_name_size + 1, sizeof(char))) == NULL )
---
> 
>    if ( (conf->name = calloc(conf->dply_name_size + 1, 1)) == NULL )
120c143,144
<    if (error_found( fread(&conf->primary_drive, sizeof(BYTE), 3, fp) != 3, "Can't read configuration drives, etc."))
---
> 
>    if (error_found( fread(&conf->primary_drive, sizeof(BYTE), 2, fp) != 2, "Can't read configuration drives, etc."))
123,124c147,155
<    /* ?? This adjustment is specific to Teri's data! direct commands lost CRs */
<    /* conf->direct_cmd_size -= N_DIRECT_CMD; */
---
>    /* Direct commands, possibly in two blocks.  Use calloc to
>    allocate a block 1 byte larger than the expected number of
>    characters and initialize it to zeros.  Then using fread to
>    get the expected number of characters will result in a null-
>    terminated string, which can be manipulated with string
>    handling functions in set_block_comments.
>    */
>    if (error_found( fread(&conf->direct_cmd_size, sizeof(BYTE), 1, fp) != 1, "Can't read configuration direct command 1 size"))
>       return(READ_ERROR);
126c157
<    if ( (conf->direct_cmd = calloc(conf->direct_cmd_size + 1, sizeof(char))) == NULL )
---
>    if ( (conf->direct_cmd = calloc(conf->direct_cmd_size + 1, 1)) == NULL )
128c159,160
<    if (error_found( fread(conf->direct_cmd, conf->direct_cmd_size, 1, fp) != 1, "Can't read configuration direct command set."))
---
> 
>    if (error_found( fread(conf->direct_cmd, conf->direct_cmd_size, 1, fp) != 1, "Can't read configuration direct command 1 set."))
130a163,175
>    if (error_found( fread(&conf->direct_cmd2_size, sizeof(BYTE), 1, fp) != 1, "Can't read configuration direct command 2 size"))
>       return(READ_ERROR);
> 
>    if (conf->direct_cmd2_size > 0)
>    {
> 
>       if ( (conf->direct_cmd2 = calloc(conf->direct_cmd2_size + 1, 1)) == NULL )
>          return(INSUFFICIENT_MEMORY);
> 
>       if (error_found( fread(conf->direct_cmd2, conf->direct_cmd2_size, 1, fp) != 1, "Can't read configuration direct command 2 set."))
>          return(READ_ERROR);
>    }
> 
133a179,180
> /***************************************************************************/
> 
135c182
< int read_leader(FILE *fp, NBP_ENSEMBLE_TYPE *ens)
---
> int read_leader(FILE *fp, BBP_ENSEMBLE_TYPE *ens)
139c186
<    NBP_ENSEMBLE_TYPE *ens;
---
>    BBP_ENSEMBLE_TYPE *ens;
143,144c190,191
<    NBP_LEADER_TYPE *leader;
<    static char buff[NBP_LEADER_SIZE], *buf_ptr;
---
>    BBP_LEADER_TYPE *leader;
>    static char buff[BBP_LEADER_SIZE], *buf_ptr;
147c194
<    if (error_found( fread(buff, NBP_LEADER_SIZE, 1, fp) != 1, "Can't read leader."))
---
>    if (error_found( fread(buff, BBP_LEADER_SIZE, 1, fp) != 1, "Can't read leader."))
152,153c199,200
<    buf_ptr += convert_array_long((char *) &leader->ens_start_seconds, buf_ptr, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 1);
<    buf_ptr += convert_array_short((char *) &leader->ens_number, buf_ptr, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 13);
---
>    buf_ptr += convert_array_long((char *) &leader->ens_start_day, buf_ptr, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 2);
>    buf_ptr += convert_array_short((char *) &leader->ens_number, buf_ptr, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 17);
155c202
<    buf_ptr += copy_byte((char *)&leader->bit_result, buf_ptr, 1, AS_IS, NULL);
---
>    buf_ptr += convert_array_short((char *) &leader->bit_result, buf_ptr, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 1);
157c204,207
<    buf_ptr++;
---
>    /* buf_ptr++; */
>    /* EF 98/01/19: The extra byte seems no longer to be present, so
>       I commented out the line above.
>    */
163a214,215
> /***************************************************************************/
> 
165c217
< int read_velocity(FILE *fp, NBP_ENSEMBLE_TYPE *ens)
---
> int read_velocity(FILE *fp, BBP_ENSEMBLE_TYPE *ens)
169c221
<    NBP_ENSEMBLE_TYPE *ens;
---
>    BBP_ENSEMBLE_TYPE *ens;
184,185c236,238
<    convert_array_short((char *)buff, (char *)buff, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, n_vel);
< 
---
>    convert_array_short((char *)buff,
>                        (char *)buff,
>                        PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, n_vel);
197a251,252
> /***************************************************************************/
> 
199c254
< int read_amp(FILE *fp, NBP_ENSEMBLE_TYPE *ens)
---
> int read_amp(FILE *fp, BBP_ENSEMBLE_TYPE *ens)
203c258
<    NBP_ENSEMBLE_TYPE *ens;
---
>    BBP_ENSEMBLE_TYPE *ens;
223a279,280
> /***************************************************************************/
> 
225c282
< int read_pgood(FILE *fp, NBP_ENSEMBLE_TYPE *ens)
---
> int read_pgood(FILE *fp, BBP_ENSEMBLE_TYPE *ens)
229c286
<    NBP_ENSEMBLE_TYPE *ens;
---
>    BBP_ENSEMBLE_TYPE *ens;
239a297,298
> /***************************************************************************/
> 
241c300
< int read_discharge(FILE *fp, NBP_ENSEMBLE_TYPE *ens)
---
> int read_discharge(FILE *fp, BBP_ENSEMBLE_TYPE *ens)
245c304
<    NBP_ENSEMBLE_TYPE *ens;
---
>    BBP_ENSEMBLE_TYPE *ens;
254c313,316
<    convert_array_long((char *) discharge, (char *) discharge, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, ens->header.n_depth_cells); 
---
>    convert_array_long((char *)discharge,
>                       (char *) discharge,
>                       PC_COMPATIBLE_HOST, HOST_ENVIRONMENT,
>                       ens->header.n_depth_cells);
259a322,323
> /***************************************************************************/
> 
261c325
< int read_navigation(FILE *fp, NBP_ENSEMBLE_TYPE *ens)
---
> int read_navigation(FILE *fp, BBP_ENSEMBLE_TYPE *ens)
265c329
<    NBP_ENSEMBLE_TYPE *ens;
---
>    BBP_ENSEMBLE_TYPE *ens;
268,269c332
<    int n;
<    static char buff[TRANSECT_NAV_SIZE], *buf_ptr;
---
>    char buff[TRANSECT_NAV_SIZE], *buf_ptr;
302a366,367
> /***************************************************************************/
> 
307c372
<               Reads an entire NBP_ENSEMBLE_TYPE from the input file
---
>               Reads an entire BBP_ENSEMBLE_TYPE from the input file
310a376,377
> /***************************************************************************/
> 
312c379
< int read_ensemble(FILE *fp, NBP_ENSEMBLE_TYPE *ens, DB_ENSEMBLE_TYPE *db_ens)
---
> int read_ensemble(FILE *fp, BBP_ENSEMBLE_TYPE *ens, DB_ENSEMBLE_TYPE *db_ens)
316c383
<    NBP_ENSEMBLE_TYPE *ens;
---
>    BBP_ENSEMBLE_TYPE *ens;
330d396
< 
334c400
<       if (fseek(fp, ens_start + ens->header.offset[i] - 1, SEEK_SET))
---
>       if (fseek(fp, ens_start + ens->header.offset[i] - 1 , 0))
344c410,411
<       convert_array_short((char *)&id, (char *) &id, PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 1);
---
>       convert_array_short((char *)&id, (char *) &id,
>                            PC_COMPATIBLE_HOST, HOST_ENVIRONMENT, 1);
382c449,451
<       db_ens->blkvar_has_changed = cmp_byte((char *)&(db_ens->conf1), (char *)&prev_conf, sizeof(CONFIGURATION_1_TYPE));
---
>       db_ens->blkvar_has_changed = cmp_byte((char *)&(db_ens->conf1),
>                                              (char *)&prev_conf,
>                                               sizeof(CONFIGURATION_1_TYPE));
393a463
>       {
400a471
>       }
413a485,486
>       if (ens->leader.ens_number % 10 == 0)
>          report_msg("\n");
419c492
<       report_msg("   BAD");
---
>       report_msg(" READ BAD ");
422a496
>             printf ("SEEK_ERROR\n");
424a499,500
>             printf ("READ_ERROR\n");
>             break;
425a502
>             printf ("ID_NOT_FOUND_ERROR\n");
432a510,511
> /***************************************************************************/
> 
