/*--------------------------------------------------------------------*/ int mbr_rt_em12darw(int verbose, void *mbio_ptr, void *store_ptr, int *error) { char *function_name = "mbr_rt_em12darw"; int status = MB_SUCCESS; struct mb_io_struct *mb_io_ptr; struct mbf_em12darw_struct *data; struct mbsys_simrad_struct *store; struct mbsys_simrad_survey_struct *ping; char line[MBF_EM12DARW_RECORD_LENGTH]; int index; char *datacomment; int time_j[5]; int time_i[7]; int kind; int i; /* print input debug statements */ if (verbose >= 2) { fprintf(stderr, "\ndbg2 MBIO function <%s> called\n", function_name); fprintf(stderr, "dbg2 Input arguments:\n"); fprintf(stderr, "dbg2 verbose: %d\n", verbose); fprintf(stderr, "dbg2 mbio_ptr: %p\n", (void *)mbio_ptr); fprintf(stderr, "dbg2 store_ptr: %p\n", (void *)store_ptr); } /* get pointer to mbio descriptor */ mb_io_ptr = (struct mb_io_struct *)mbio_ptr; /* get pointer to raw data structure */ data = (struct mbf_em12darw_struct *)mb_io_ptr->raw_data; datacomment = (char *)&line[80]; store = (struct mbsys_simrad_struct *)store_ptr; /* set file position */ mb_io_ptr->file_pos = mb_io_ptr->file_bytes; /* read next record from file */ if ((status = fread(line, 1, MBF_EM12DARW_RECORD_LENGTH, mb_io_ptr->mbfp)) == MBF_EM12DARW_RECORD_LENGTH) { mb_io_ptr->file_bytes += status; status = MB_SUCCESS; *error = MB_ERROR_NO_ERROR; } else { mb_io_ptr->file_bytes += status; status = MB_FAILURE; *error = MB_ERROR_EOF; } /* get data type */ kind = MB_DATA_NONE; if (status == MB_SUCCESS) { mb_get_binary_short(MB_NO, &line[0], &(data->func)); } /* deal with comment */ if (status == MB_SUCCESS && data->func == 100) { kind = MB_DATA_COMMENT; strncpy(store->comment, datacomment, MBSYS_SIMRAD_COMMENT_LENGTH); } /* deal with data */ else if (status == MB_SUCCESS && data->func == 150) { kind = MB_DATA_DATA; index = 2; mb_get_binary_short(MB_NO, &line[index], &(data->year)); index += 2; mb_get_binary_short(MB_NO, &line[index], &(data->jday)); index += 2; mb_get_binary_short(MB_NO, &line[index], &(data->minute)); index += 2; mb_get_binary_short(MB_NO, &line[index], &(data->secs)); index += 8; mb_get_binary_double(MB_NO, &line[index], &(data->latitude)); index += 8; mb_get_binary_double(MB_NO, &line[index], &(data->longitude)); index += 8; mb_get_binary_short(MB_NO, &line[index], &(data->corflag)); index += 4; mb_get_binary_float(MB_NO, &line[index], &(data->utm_merd)); index += 4; mb_get_binary_short(MB_NO, &line[index], &(data->utm_zone)); index += 2; mb_get_binary_short(MB_NO, &line[index], &(data->posq)); index += 2; mb_get_binary_int(MB_NO, &line[index], &(data->pingno)); index += 4; mb_get_binary_short(MB_NO, &line[index], &(data->mode)); index += 4; mb_get_binary_float(MB_NO, &line[index], &(data->depthl)); index += 4; mb_get_binary_float(MB_NO, &line[index], &(data->speed)); index += 4; mb_get_binary_float(MB_NO, &line[index], &(data->gyro)); index += 4; mb_get_binary_float(MB_NO, &line[index], &(data->roll)); index += 4; mb_get_binary_float(MB_NO, &line[index], &(data->pitch)); index += 4; mb_get_binary_float(MB_NO, &line[index], &(data->heave)); index += 4; mb_get_binary_float(MB_NO, &line[index], &(data->sndval)); index += 4; for (i = 0; i < MBF_EM12DARW_BEAMS; i++) { mb_get_binary_short(MB_NO, &line[index], &(data->depth[i])); index += 2; } for (i = 0; i < MBF_EM12DARW_BEAMS; i++) { mb_get_binary_short(MB_NO, &line[index], &(data->distacr[i])); index += 2; } for (i = 0; i < MBF_EM12DARW_BEAMS; i++) { mb_get_binary_short(MB_NO, &line[index], &(data->distalo[i])); index += 2; } for (i = 0; i < MBF_EM12DARW_BEAMS; i++) { mb_get_binary_short(MB_NO, &line[index], &(data->range[i])); index += 2; } for (i = 0; i < MBF_EM12DARW_BEAMS; i++) { mb_get_binary_short(MB_NO, &line[index], &(data->refl[i])); index += 2; } for (i = 0; i < MBF_EM12DARW_BEAMS; i++) { mb_get_binary_short(MB_NO, &line[index], &(data->beamq[i])); index += 2; } /* print debug statements */ if (verbose >= 4) { fprintf(stderr, "\ndbg4 Data read by MBIO function <%s>\n", function_name); fprintf(stderr, "dbg4 Read values:\n"); fprintf(stderr, "dbg4 kind: %d\n", kind); fprintf(stderr, "dbg4 error: %d\n", *error); fprintf(stderr, "dbg4 year: %d\n", data->year); fprintf(stderr, "dbg4 jday: %d\n", data->jday); fprintf(stderr, "dbg4 minute: %d\n", data->minute); fprintf(stderr, "dbg4 secs: %d\n", data->secs); fprintf(stderr, "dbg4 latitude: %f\n", data->latitude); fprintf(stderr, "dbg4 longitude: %f\n", data->longitude); fprintf(stderr, "dbg4 corflag: %d\n", data->corflag); fprintf(stderr, "dbg4 utm_merd: %f\n", data->utm_merd); fprintf(stderr, "dbg4 utm_zone: %d\n", data->utm_zone); fprintf(stderr, "dbg4 posq: %d\n", data->posq); fprintf(stderr, "dbg4 pingno: %d\n", data->pingno); fprintf(stderr, "dbg4 mode: %d\n", data->mode); fprintf(stderr, "dbg4 depthl: %f\n", data->depthl); fprintf(stderr, "dbg4 speed: %f\n", data->speed); fprintf(stderr, "dbg4 gyro: %f\n", data->gyro); fprintf(stderr, "dbg4 roll: %f\n", data->roll); fprintf(stderr, "dbg4 pitch: %f\n", data->pitch); fprintf(stderr, "dbg4 heave: %f\n", data->heave); fprintf(stderr, "dbg4 sndval: %f\n", data->sndval); for (i = 0; i < MBF_EM12DARW_BEAMS; i++) fprintf(stderr, "dbg4 beam:%d depth:%d distacr:%d distalo:%d range:%d refl:%d beamq:%d\n", i, data->depth[i], data->distacr[i], data->distalo[i], data->range[i], data->refl[i], data->beamq[i]); } } /* else unintelligible */ else if (status == MB_SUCCESS) { kind = MB_DATA_NONE; status = MB_FAILURE; *error = MB_ERROR_UNINTELLIGIBLE; } /* set kind and error in mb_io_ptr */ mb_io_ptr->new_kind = kind; mb_io_ptr->new_error = *error; /* translate values to em12 data storage structure */ if (status == MB_SUCCESS && store != NULL) { /* type of data record */ store->kind = kind; store->sonar = MBSYS_SIMRAD_EM12S; /* time */ mb_fix_y2k(verbose, (int)data->year, &time_j[0]); time_j[1] = data->jday; time_j[2] = data->minute; time_j[3] = data->secs / 100; time_j[4] = 0.0001 * (100 * time_j[3] - data->secs); mb_get_itime(verbose, time_j, time_i); store->year = data->year; store->month = time_i[1]; store->day = time_i[2]; store->hour = time_i[3]; store->minute = time_i[4]; store->second = time_i[5]; store->centisecond = 0.0001 * time_i[6]; store->pos_year = store->year; store->pos_month = store->month; store->pos_day = store->day; store->pos_hour = store->hour; store->pos_minute = store->minute; store->pos_second = store->second; store->pos_centisecond = store->centisecond; /* navigation */ if (data->corflag == 0) { store->pos_latitude = data->latitude; store->pos_longitude = data->longitude; store->utm_northing = 0.0; store->utm_easting = 0.0; } else { store->pos_latitude = 0.0; store->pos_longitude = 0.0; store->utm_northing = data->latitude; store->utm_easting = data->longitude; } store->utm_zone = data->utm_zone; store->utm_zone_lon = data->utm_merd; store->utm_system = data->corflag; store->pos_quality = data->posq; store->speed = data->speed; store->line_heading = 10 * data->gyro; /* allocate secondary data structure for survey data if needed */ if (kind == MB_DATA_DATA && store->ping == NULL) { status = mbsys_simrad_survey_alloc(verbose, mbio_ptr, store_ptr, error); } /* deal with putting survey data into secondary data structure */ if (status == MB_SUCCESS && kind == MB_DATA_DATA) { /* get data structure pointer */ ping = (struct mbsys_simrad_survey_struct *)store->ping; /* copy data */ ping->longitude = data->longitude; ping->latitude = data->latitude; ping->swath_id = EM_SWATH_CENTER; ping->ping_number = data->pingno; ping->beams_bath = MBF_EM12DARW_BEAMS; ping->bath_mode = 0; ping->bath_res = data->mode; ping->bath_quality = 0; ping->keel_depth = data->depthl; ping->heading = (int)10 * data->gyro; ping->roll = (int)100 * data->roll; ping->pitch = (int)100 * data->pitch; ping->xducer_pitch = (int)100 * data->pitch; ping->ping_heave = (int)100 * data->heave; ping->sound_vel = (int)10 * data->sndval; ping->pixels_ss = 0; ping->ss_mode = 0; for (i = 0; i < ping->beams_bath; i++) { if (data->depth[i] > 0) { ping->bath[i] = data->depth[i]; ping->beamflag[i] = MB_FLAG_NONE; } else if (data->depth[i] < 0) { ping->bath[i] = -data->depth[i]; ping->beamflag[i] = MB_FLAG_FLAG + MB_FLAG_MANUAL; } else { ping->bath[i] = data->depth[i]; ping->beamflag[i] = MB_FLAG_NULL; } ping->bath_acrosstrack[i] = data->distacr[i]; ping->bath_alongtrack[i] = data->distalo[i]; ping->tt[i] = data->range[i]; ping->amp[i] = (mb_s_char)data->refl[i]; ping->quality[i] = (mb_u_char)data->beamq[i]; ping->heave[i] = (mb_s_char)0; ping->beam_frequency[i] = 0; ping->beam_samples[i] = 0; ping->beam_center_sample[i] = 0; } } else if (status == MB_SUCCESS && kind == MB_DATA_COMMENT) { /* comment */ strncpy(store->comment, datacomment, MBSYS_SIMRAD_COMMENT_LENGTH); } } /* print output debug statements */ if (verbose >= 2) { fprintf(stderr, "\ndbg2 MBIO function <%s> completed\n", function_name); fprintf(stderr, "dbg2 Return values:\n"); fprintf(stderr, "dbg2 error: %d\n", *error); fprintf(stderr, "dbg2 Return status:\n"); fprintf(stderr, "dbg2 status: %d\n", status); } return (status); }
/*--------------------------------------------------------------------*/ int mbr_rt_hydrob93(int verbose, void *mbio_ptr, void *store_ptr, int *error) { char *function_name = "mbr_rt_hydrob93"; int status = MB_SUCCESS; struct mb_io_struct *mb_io_ptr; struct mbsys_singlebeam_struct *store; char line[MBF_HYDROB93_RECORD_LENGTH]; int ilongitude, ilatitude, idepth; short itype; /* print input debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 MBIO function <%s> called\n",function_name); fprintf(stderr,"dbg2 Input arguments:\n"); fprintf(stderr,"dbg2 verbose: %d\n",verbose); fprintf(stderr,"dbg2 mbio_ptr: %lu\n",(size_t)mbio_ptr); fprintf(stderr,"dbg2 store_ptr: %lu\n",(size_t)store_ptr); } /* get pointers to mbio descriptor and data structures */ mb_io_ptr = (struct mb_io_struct *) mbio_ptr; store = (struct mbsys_singlebeam_struct *) store_ptr; /* set file position */ mb_io_ptr->file_bytes = ftell(mb_io_ptr->mbfp); mb_io_ptr->file_pos = mb_io_ptr->file_bytes; /* read next record from file */ mb_io_ptr->file_pos = mb_io_ptr->file_bytes; if ((status = fread(line,1,MBF_HYDROB93_RECORD_LENGTH, mb_io_ptr->mbfp)) == MBF_HYDROB93_RECORD_LENGTH) { mb_io_ptr->file_bytes += status; status = MB_SUCCESS; *error = MB_ERROR_NO_ERROR; } else { mb_io_ptr->file_bytes += status; status = MB_FAILURE; *error = MB_ERROR_EOF; } /* handle the data */ if (status == MB_SUCCESS) { /* parse data */ mb_get_binary_int(MB_YES, &line[0], (int *) &ilatitude); mb_get_binary_int(MB_YES, &line[4], (int *) &ilongitude); mb_get_binary_int(MB_YES, &line[8], (int *) &idepth); mb_get_binary_short(MB_YES, &line[12], (short *) &itype); store->longitude = (ilongitude) * 0.000001; store->latitude = (ilatitude) * 0.000001; store->bath = (idepth) * 0.1; if (itype == 711) store->flag = MB_FLAG_NONE; else if (itype == 10711) store->flag = MB_FLAG_FLAG + MB_FLAG_MANUAL; else store->flag = MB_FLAG_NULL; store->time_d = MB_TIME_D_UNKNOWN; mb_get_date(verbose, store->time_d, store->time_i); store->heading = 0.0; store->speed = 0.0; store->roll = 0.0; store->pitch = 0.0; store->heave = 0.0; /* set kind */ if (itype == 711 || itype == 10711) store->kind = MB_DATA_DATA; else store->kind = MB_DATA_RAW_LINE; if (status == MB_SUCCESS) { /* print output debug statements */ if (verbose >= 4) { fprintf(stderr,"\ndbg4 Data read in MBIO function <%s>\n",function_name); fprintf(stderr,"dbg4 Values read:\n"); fprintf(stderr,"dbg4 time_i[0]: %d\n",store->time_i[0]); fprintf(stderr,"dbg4 time_i[1]: %d\n",store->time_i[1]); fprintf(stderr,"dbg4 time_i[2]: %d\n",store->time_i[2]); fprintf(stderr,"dbg4 time_i[3]: %d\n",store->time_i[3]); fprintf(stderr,"dbg4 time_i[4]: %d\n",store->time_i[4]); fprintf(stderr,"dbg4 time_i[5]: %d\n",store->time_i[5]); fprintf(stderr,"dbg4 time_i[6]: %d\n",store->time_i[6]); fprintf(stderr,"dbg4 time_d: %f\n",store->time_d); fprintf(stderr,"dbg4 latitude: %f\n",store->latitude); fprintf(stderr,"dbg4 longitude: %f\n",store->longitude); fprintf(stderr,"dbg4 bath: %f\n",store->bath); fprintf(stderr,"dbg4 flag: %d\n",store->flag); fprintf(stderr,"dbg4 heading: %f\n",store->heading); fprintf(stderr,"dbg4 speed: %f\n",store->speed); fprintf(stderr,"dbg4 roll: %f\n",store->roll); fprintf(stderr,"dbg4 pitch: %f\n",store->pitch); fprintf(stderr,"dbg4 heave: %f\n",store->heave); fprintf(stderr,"dbg4 error: %d\n",*error); fprintf(stderr,"dbg4 status: %d\n",status); } } else { status = MB_FAILURE; *error = MB_ERROR_UNINTELLIGIBLE; } } /* set error and kind in mb_io_ptr */ mb_io_ptr->new_error = *error; mb_io_ptr->new_kind = store->kind; /* print output debug statements */ if (verbose >= 2) { fprintf(stderr,"\ndbg2 MBIO function <%s> completed\n",function_name); fprintf(stderr,"dbg2 Return values:\n"); fprintf(stderr,"dbg2 error: %d\n",*error); fprintf(stderr,"dbg2 Return status:\n"); fprintf(stderr,"dbg2 status: %d\n",status); } /* return status */ return(status); }