コード例 #1
0
/*	function mb_put_binary_short copies a binary short to
 *	a buffer, swapping if necessary
 */
int mb_put_binary_short(int swapped, short value, void *buffer)
{
#ifdef BYTESWAPPED
	if (swapped == MB_NO)
	    value = mb_swap_short(value);
#else
	if (swapped == MB_YES)
	    value = mb_swap_short(value);
#endif
	memcpy(buffer, &value, sizeof(short));
	return(0);
}
コード例 #2
0
/*	function mb_get_binary_short copies a binary short from
 *	a buffer, swapping if necessary
 */
int mb_get_binary_short(int swapped, void *buffer, void *ptr)
{
	short *value;

	value = (short *) ptr;
	memcpy(value, buffer, sizeof(short));
#ifdef BYTESWAPPED
	if (swapped == MB_NO)
	    *value = mb_swap_short(*((short *)value));
#else
	if (swapped == MB_YES)
	    *value = mb_swap_short(*value);
#endif
	return(0);
}
コード例 #3
0
ファイル: mbr_hsurivax.c プロジェクト: joa-quim/MB-system-Win
/*--------------------------------------------------------------------*/
int mbr_wt_hsurivax(int verbose, void *mbio_ptr, void *store_ptr, int *error) {
	char *function_name = "mbr_wt_hsurivax";
	int status = MB_SUCCESS;
	struct mb_io_struct *mb_io_ptr;
	struct mbf_hsuricen_struct *dataplus;
	struct mbf_hsuricen_data_struct *data;
	struct mbsys_hsds_struct *store;
	char *datacomment;
	int time_i[7];
	int time_j[5];
	int i;
	int id;

	/* print input debug statements */
	if (verbose >= 2) {
		fprintf(stderr, "\ndbg2  MBIO function <%s> called\n", function_name);
		fprintf(stderr, "dbg2  Revision id: %s\n", rcs_id);
		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 */
	dataplus = (struct mbf_hsuricen_struct *)mb_io_ptr->raw_data;
	data = &(dataplus->data);
	datacomment = (char *)data;
	store = (struct mbsys_hsds_struct *)store_ptr;

	/* print debug statements */
	if (verbose >= 5) {
		fprintf(stderr, "\ndbg5  Status at beginning of MBIO function <%s>\n", function_name);
		if (store != NULL)
			fprintf(stderr, "dbg5       store->kind:    %d\n", store->kind);
		fprintf(stderr, "dbg5       new_kind:       %d\n", mb_io_ptr->new_kind);
		fprintf(stderr, "dbg5       new_error:      %d\n", mb_io_ptr->new_error);
		fprintf(stderr, "dbg5       error:          %d\n", *error);
		fprintf(stderr, "dbg5       status:         %d\n", status);
	}

	/* first set some plausible amounts for some of the
	    variables in the HSURICEN record */
	data->course = 0;
	data->pitch = 0;
	data->scale = 100;     /* this is a unit scale factor */
	data->speed_ref = 'B'; /* assume speed is over the ground */
	data->quality = 0;

	/* second translate values from hydrosweep data storage structure */
	if (store != NULL) {
		dataplus->kind = store->kind;
		if (store->kind == MB_DATA_DATA) {
			/* position */
			if (store->lon < -180.0)
				store->lon = store->lon + 360.0;
			if (store->lon > 180.0)
				store->lon = store->lon - 360.0;
			data->lon = (int)(0.5 + 10000000.0 * store->lon);
			data->lat = (int)(0.5 + 10000000.0 * store->lat);

			/* time stamp */
			time_i[0] = store->year;
			time_i[1] = store->month;
			time_i[2] = store->day;
			time_i[3] = store->hour;
			time_i[4] = store->minute;
			time_i[5] = store->second;
			time_i[6] = 0;
			mb_get_jtime(verbose, time_i, time_j);
			data->year = time_j[0];
			data->day = time_j[1];
			data->min = time_j[2];
			data->sec = 100 * time_j[3] + 0.0001 * time_j[4];

			/* additional navigation and depths */
			data->hdg = 10.0 * store->course_true;
			data->course = 10.0 * store->course_ground;
			data->speed = 196.36363636363 * store->speed;
			data->speed_ref = store->speed_reference[0];
			data->pitch = 10.0 * store->pitch;
			data->scale = 100 * store->depth_scale;
			id = MBSYS_HSDS_BEAMS - 1;
			for (i = 0; i < MBSYS_HSDS_BEAMS; i++) {
				data->dist[i] = store->distance[i];
				data->deph[i] = store->depth[i];
			}
			/*			for (i=0;i<MBSYS_HSDS_BEAMS;i++)
			                {
			                data->dist[i] = store->distance[id-i];
			                data->deph[i] = store->depth[id-i];
			                }*/
		}

		/* comment */
		else if (store->kind == MB_DATA_COMMENT) {
			strcpy(datacomment, "cc");
			strncat(datacomment, store->comment, MBSYS_HSDS_MAXLINE);
		}
	}

	/* print debug statements */
	if (verbose >= 5) {
		fprintf(stderr, "\ndbg5  Ready to write data in MBIO function <%s>\n", function_name);
		fprintf(stderr, "dbg5       kind:       %d\n", dataplus->kind);
		fprintf(stderr, "dbg5       error:      %d\n", *error);
		fprintf(stderr, "dbg5       status:     %d\n", status);
	}

/* byte swap the data if necessary */
#ifndef BYTESWAPPED
	if (dataplus->kind == MB_DATA_DATA) {
		data->sec = mb_swap_short(data->sec);
		data->min = mb_swap_short(data->min);
		data->day = mb_swap_short(data->day);
		data->year = mb_swap_short(data->year);
		data->lat = mb_swap_int(data->lat);
		data->lon = mb_swap_int(data->lon);
		data->hdg = mb_swap_short(data->hdg);
		data->course = mb_swap_short(data->course);
		data->speed = mb_swap_short(data->speed);
		data->pitch = mb_swap_short(data->pitch);
		data->scale = mb_swap_short(data->scale);
		for (i = 0; i < MBSYS_HSDS_BEAMS; i++) {
			data->dist[i] = mb_swap_short(data->dist[i]);
			data->deph[i] = mb_swap_short(data->deph[i]);
		}
	}
#endif

	/* write next record to file */
	if (dataplus->kind == MB_DATA_DATA || dataplus->kind == MB_DATA_COMMENT) {
		if ((status = fwrite(data, 1, mb_io_ptr->data_structure_size, mb_io_ptr->mbfp)) == mb_io_ptr->data_structure_size) {
			status = MB_SUCCESS;
			*error = MB_ERROR_NO_ERROR;
		}
		else {
			status = MB_FAILURE;
			*error = MB_ERROR_WRITE_FAIL;
		}
	}
	else {
		status = MB_SUCCESS;
		*error = MB_ERROR_NO_ERROR;
		if (verbose >= 5)
			fprintf(stderr, "\ndbg5  No data written in MBIO function <%s>\n", function_name);
	}

	/* 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);
}
コード例 #4
0
ファイル: mbr_hsurivax.c プロジェクト: joa-quim/MB-system-Win
/*--------------------------------------------------------------------*/
int mbr_rt_hsurivax(int verbose, void *mbio_ptr, void *store_ptr, int *error) {
	char *function_name = "mbr_rt_hsurivax";
	int status = MB_SUCCESS;
	struct mb_io_struct *mb_io_ptr;
	struct mbf_hsuricen_struct *dataplus;
	struct mbf_hsuricen_data_struct *data;
	struct mbsys_hsds_struct *store;
	char *datacomment;
	int time_j[5];
	int i;
	int id;

	/* print input debug statements */
	if (verbose >= 2) {
		fprintf(stderr, "\ndbg2  MBIO function <%s> called\n", function_name);
		fprintf(stderr, "dbg2  Revision id: %s\n", rcs_id);
		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 */
	dataplus = (struct mbf_hsuricen_struct *)mb_io_ptr->raw_data;
	data = &(dataplus->data);
	datacomment = (char *)data;
	dataplus->kind = MB_DATA_DATA;
	store = (struct mbsys_hsds_struct *)store_ptr;

	/* set file position */
	mb_io_ptr->file_pos = mb_io_ptr->file_bytes;

	/* read next record from file */
	if ((status = fread(data, 1, mb_io_ptr->data_structure_size, mb_io_ptr->mbfp)) == mb_io_ptr->data_structure_size) {
		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;
	}

/* byte swap the data if necessary */
#ifndef BYTESWAPPED
	if (status == MB_SUCCESS && data->sec != 25443) {
		data->sec = mb_swap_short(data->sec);
		data->min = mb_swap_short(data->min);
		data->day = mb_swap_short(data->day);
		data->year = mb_swap_short(data->year);
		data->lat = mb_swap_int(data->lat);
		data->lon = mb_swap_int(data->lon);
		data->hdg = mb_swap_short(data->hdg);
		data->course = mb_swap_short(data->course);
		data->speed = mb_swap_short(data->speed);
		data->pitch = mb_swap_short(data->pitch);
		data->scale = mb_swap_short(data->scale);
		for (i = 0; i < MBSYS_HSDS_BEAMS; i++) {
			data->dist[i] = mb_swap_short(data->dist[i]);
			data->deph[i] = mb_swap_short(data->deph[i]);
		}
	}
#endif

	/* check for comment or unintelligible records */
	if (status == MB_SUCCESS) {
		if (data->sec == 25443) {
			dataplus->kind = MB_DATA_COMMENT;
		}
		else if (data->year == 0) {
			dataplus->kind = MB_DATA_NONE;
			status = MB_FAILURE;
			*error = MB_ERROR_UNINTELLIGIBLE;
		}
		else {
			dataplus->kind = MB_DATA_DATA;
		}
	}

	/* set kind and error in mb_io_ptr */
	mb_io_ptr->new_kind = dataplus->kind;
	mb_io_ptr->new_error = *error;

	/* translate values to hydrosweep data storage structure */
	if (status == MB_SUCCESS && store != NULL) {
		/* type of data record */
		store->kind = dataplus->kind;

		/* time stamp (all records ) */
		time_j[0] = data->year;
		time_j[1] = data->day;
		time_j[2] = data->min;
		time_j[3] = data->sec / 100;
		time_j[4] = 10000 * (data->sec - 100 * time_j[3]);
		mb_get_itime(verbose, time_j, mb_io_ptr->new_time_i);
		mb_get_time(verbose, mb_io_ptr->new_time_i, &(mb_io_ptr->new_time_d));
		store->year = mb_io_ptr->new_time_i[0];
		store->month = mb_io_ptr->new_time_i[1];
		store->day = mb_io_ptr->new_time_i[2];
		store->hour = mb_io_ptr->new_time_i[3];
		store->minute = mb_io_ptr->new_time_i[4];
		store->second = mb_io_ptr->new_time_i[5];
		store->alt_minute = 0;
		store->alt_second = 0;

		/* position (all records ) */
		store->lon = 0.0000001 * data->lon;
		store->lat = 0.0000001 * data->lat;
		if (store->lon > 180.)
			store->lon = store->lon - 360.;
		else if (store->lon < -180.)
			store->lon = store->lon + 360.;

		/* additional navigation and depths (ERGNMESS and ERGNEICH) */
		store->course_true = 0.1 * data->hdg;
		store->speed_transverse = 0.0;
		store->speed = 0.005092593 * data->speed;
		store->speed_reference[0] = data->speed_ref;
		store->pitch = 0.1 * data->pitch;
		store->track = 0;
		store->depth_scale = 0.01 * data->scale;
		store->depth_center = store->depth_scale * data->deph[MBSYS_HSDS_BEAMS / 2];
		store->spare = 1;
		id = MBSYS_HSDS_BEAMS - 1;
		for (i = 0; i < MBSYS_HSDS_BEAMS; i++) {
			store->distance[i] = data->dist[i];
			store->depth[i] = data->deph[i];
		}
		/*		for (i=0;i<MBSYS_HSDS_BEAMS;i++)
		            {
		            store->distance[id-i] = data->dist[i];
		            store->depth[id-i] = data->deph[i];
		            }*/

		/* travel time data (ERGNSLZT) */
		store->course_ground = 0.1 * data->course;
		store->speed_ground = 0.0;
		store->heave = 0.0;
		store->roll = 0.0;
		store->time_center = 0.0;
		store->time_scale = 0.0;
		for (i = 0; i < MBSYS_HSDS_BEAMS; i++)
			store->time[i] = 0;
		for (i = 0; i < 11; i++)
			store->gyro[i] = 0.0;

		/* amplitude data (ERGNAMPL) */
		store->mode[0] = '\0';
		store->trans_strbd = 0;
		store->trans_vert = 0;
		store->trans_port = 0;
		store->pulse_len_strbd = 0;
		store->pulse_len_vert = 0;
		store->pulse_len_port = 0;
		store->gain_start = 0;
		store->r_compensation_factor = 0;
		store->compensation_start = 0;
		store->increase_start = 0;
		store->tvc_near = 0;
		store->tvc_far = 0;
		store->increase_int_near = 0;
		store->increase_int_far = 0;
		store->gain_center = 0;
		store->filter_gain = 0.0;
		store->amplitude_center = 0;
		store->echo_duration_center = 0;
		store->echo_scale_center = 0;
		for (i = 0; i < MBSYS_HSDS_BEAMS; i++) {
			store->amplitude[i] = 0;
			store->echo_duration[i] = 0;
		}
		for (i = 0; i < 16; i++) {
			store->gain[i] = 0;
			store->echo_scale[i] = 0;
		}

		/* mean velocity (ERGNHYDI) */
		store->draught = 0.0;
		store->vel_mean = 0.0;
		store->vel_keel = 0.0;
		store->tide = 0.0;

		/* water velocity profile (HS_ERGNCTDS) */
		store->num_vel = 0.0;

		/* navigation source (ERGNPOSI) */
		store->pos_corr_x = 0.0;
		store->pos_corr_y = 0.0;
		strncpy(store->sensors, "\0", 8);

		/* comment (LDEOCMNT) */
		strncpy(store->comment, &datacomment[2], MBSYS_HSDS_MAXLINE);

		/* processed backscatter */
		store->back_scale = 0.0;
		for (i = 0; i < MBSYS_HSDS_BEAMS; i++)
			store->back[i] = 0;
	}

	/* 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);
}
コード例 #5
0
/*--------------------------------------------------------------------*/
int mbr_wt_sbsioswb(int verbose, void *mbio_ptr, void *store_ptr, int *error)
{
	char	*function_name = "mbr_wt_sbsioswb";
	int	status = MB_SUCCESS;
	struct mb_io_struct *mb_io_ptr;
	struct mbf_sbsioswb_struct *data;
	struct mbsys_sb_struct *store;
	char	*headerptr;
	char	*sensorptr;
	char	*datarecptr;
	char	*commentptr;
	double	lon, lat;
	int	id;
	int	sensor_size;
	int	data_size;
	int	i;

	/* print input debug statements */
	if (verbose >= 2)
		{
		fprintf(stderr,"\ndbg2  MBIO function <%s> called\n",function_name);
		fprintf(stderr,"dbg2  Revision id: %s\n",rcs_id);
		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_sbsioswb_struct *) mb_io_ptr->raw_data;
	store = (struct mbsys_sb_struct *) store_ptr;

	/* get pointers to records */
	headerptr = (char *) &data->year;
	sensorptr = (char *) &data->eclipse_time;
	datarecptr = (char *) &data->beams_bath;
	commentptr = (char *) &data->comment[0];

	/* print output debug statements */
	if (verbose >= 2 && (store->kind == MB_DATA_DATA || store->kind == MB_DATA_NAV))
		{
		fprintf(stderr,"dbg2   Data to be extracted from storage structure: %p %p\n",
			(void *)store_ptr,(void *)store);
		fprintf(stderr,"dbg2       kind:       %d\n",store->kind);
		fprintf(stderr,"dbg2       lon2u:      %d\n",store->lon2u);
		fprintf(stderr,"dbg2       lon2b:      %d\n",store->lon2b);
		fprintf(stderr,"dbg2       lat2u:      %d\n",store->lat2u);
		fprintf(stderr,"dbg2       lat2b:      %d\n",store->lat2b);
		fprintf(stderr,"dbg2       year:       %d\n",store->year);
		fprintf(stderr,"dbg2       day:        %d\n",store->day);
		fprintf(stderr,"dbg2       min:        %d\n",store->min);
		fprintf(stderr,"dbg2       sec:        %d\n",store->sec);
		}
	if (verbose >= 2 && store->kind == MB_DATA_DATA)
		{
		for (i=0;i<MBSYS_SB_BEAMS;i++)
		  fprintf(stderr,"dbg3       dist[%d]: %d  deph[%d]: %d\n",
			i,store->dist[i],i,store->deph[i]);
		fprintf(stderr,"dbg2       sbtim:        %d\n",store->sbtim);
		fprintf(stderr,"dbg2       sbhdg:        %d\n",store->sbhdg);
		fprintf(stderr,"dbg2       axis:         %d\n",store->axis);
		fprintf(stderr,"dbg2       major:        %d\n",store->major);
		fprintf(stderr,"dbg2       minor:        %d\n",store->minor);
		}
	if (verbose >= 2 && store->kind == MB_DATA_COMMENT)
		{
		fprintf(stderr,"dbg2   Data inserted into storage structure:\n");
		fprintf(stderr,"dbg2       comment:     \ndbg2       %s\n",
			store->comment);
		}

	/* first set some plausible amounts for some of the
		variables in the SBSIOSWB record */
	data->year = 0;
	data->day = 0;
	data->min = 0;
	data->sec = 0;
	data->lat = 0;
	data->lon = 0;
	data->heading = 0;
	data->course = 0;
	data->speed = 0;
	data->speed_ps = 0;
	data->quality = 0;
	data->sensor_size = 0;
	data->data_size = 0;
	data->speed_ref[0] = 0;
	data->speed_ref[1] = 0;
	if (store->kind == MB_DATA_DATA)
		{
		data->sensor_type[0] = 'S';
		data->sensor_type[1] = 'B';
		data->data_type[0] = 'S';
		data->data_type[1] = 'R';
		}
	else
		{
		data->sensor_type[0] = 0;
		data->sensor_type[1] = 0;
		data->data_type[0] = 'T';
		data->data_type[1] = 'R';
		}
	data->eclipse_time = 0;
	data->eclipse_heading = 0;
	data->beams_bath = MB_BEAMS_SBSIOSWB;
	data->sensor_size = 4;
	data->data_size = 4 + 4*data->beams_bath;
	data->scale_factor = 100;
	for (i=0;i<MB_BEAMS_SBSIOSWB;i++)
		{
		data->bath_struct[i].bath = 0;
		data->bath_struct[i].bath_acrosstrack = 0;
		}

	/* translate values from seabeam data storage structure */
	data->kind = store->kind;
	if (store->kind == MB_DATA_DATA)
		{
		data->sensor_type[0] = 'S';
		data->sensor_type[1] = 'B';
		data->data_type[0] = 'S';
		data->data_type[1] = 'R';

		/* position */
		lon = 10000000*(store->lon2u/60.
			+ store->lon2b/600000.);
		if (lon > 1800000000.)
			lon = lon - 3600000000.;
		lat = 10000000*(store->lat2u/60.
			+ store->lat2b/600000. - 90.);
		data->lon = lon;
		data->lat = lat;

		/* time stamp */
		data->year = store->year;
		data->day = store->day;
		data->min = store->min;
		data->sec = 100*store->sec;

		/* heading */
		data->heading =
		    (short) ROUND(((int)store->sbhdg)*0.054931641625);

		/* additional values */
		data->eclipse_time = store->sbtim;
		data->eclipse_heading = store->sbhdg;

		/* put distance and depth values
			into sbsioswb data structure */
		id = data->beams_bath - 1;
		for (i=0;i<MB_BEAMS_SBSIOSWB;i++)
			{
			data->bath_struct[id-i].bath = store->deph[i];;
			data->bath_struct[id-i].bath_acrosstrack =
				store->dist[i];;
			}
		}

	/* comment */
	else if (store->kind == MB_DATA_COMMENT)
		{
		data->sensor_type[0] = 0;
		data->sensor_type[1] = 0;
		data->data_type[0] = 'T';
		data->data_type[1] = 'R';

		data->data_size = strlen(store->comment);
		if (data->data_size > MBSYS_SB_MAXLINE - 1)
			data->data_size = MBSYS_SB_MAXLINE - 1;
		strncpy(commentptr,store->comment,data->data_size);
		commentptr[data->data_size] = 0;
		data->sensor_size = 0;
		}

	/* save sensor_size and data_size before possible byte swapping */
	sensor_size = data->sensor_size;
	data_size = data->data_size;

	/* print debug statements */
	if (verbose >= 5)
		{
		fprintf(stderr,"\ndbg5  Ready to write data in MBIO function <%s>\n",function_name);
		fprintf(stderr,"dbg5       kind:       %d\n",
			data->kind);
		fprintf(stderr,"dbg5       error:      %d\n",*error);
		fprintf(stderr,"dbg5       status:     %d\n",status);
		}

	/* print debug statements */
	if (status == MB_SUCCESS && verbose >= 5)
		{
		fprintf(stderr,"\ndbg5  Header record to be written by MBIO function <%s>\n",function_name);
		fprintf(stderr,"dbg5  Header values:\n");
		fprintf(stderr,"dbg5       year:       %d\n",data->year);
		fprintf(stderr,"dbg5       day:        %d\n",data->day);
		fprintf(stderr,"dbg5       min:        %d\n",data->min);
		fprintf(stderr,"dbg5       sec:        %d\n",data->sec);
		fprintf(stderr,"dbg5       lat:        %d\n",data->lat);
		fprintf(stderr,"dbg5       lon:        %d\n",data->lon);
		fprintf(stderr,"dbg5       heading:    %d\n",data->heading);
		fprintf(stderr,"dbg5       course:     %d\n",data->course);
		fprintf(stderr,"dbg5       speed:      %d\n",data->speed);
		fprintf(stderr,"dbg5       speed_ps:   %d\n",data->speed_ps);
		fprintf(stderr,"dbg5       quality:    %d\n",data->quality);
		fprintf(stderr,"dbg5       sensor size:%d\n",data->sensor_size);
		fprintf(stderr,"dbg5       data size:  %d\n",data->data_size);
		fprintf(stderr,"dbg5       speed_ref:  %c%c\n",
			data->speed_ref[0],data->speed_ref[1]);
		fprintf(stderr,"dbg5       sensor_type:%c%c\n",
			data->sensor_type[0],data->sensor_type[1]);
		fprintf(stderr,"dbg5       data_type:  %c%c\n",
			data->data_type[0],data->data_type[1]);
		}

	/* print debug statements */
	if (status == MB_SUCCESS && verbose >= 5
		&& data->kind == MB_DATA_DATA)
		{
		fprintf(stderr,"\ndbg5  Sensor record to be written by MBIO function <%s>\n",function_name);
		fprintf(stderr,"dbg5  Sensor values:\n");
		fprintf(stderr,"dbg5       eclipse_time:    %d\n",
			data->eclipse_time);
		fprintf(stderr,"dbg5       eclipse_heading: %d\n",
			data->eclipse_heading);
		}

	/* print debug statements */
	if (status == MB_SUCCESS && verbose >= 5
		&& data->kind == MB_DATA_DATA)
		{
		fprintf(stderr,"\ndbg5  Data record to be written by MBIO function <%s>\n",function_name);
		fprintf(stderr,"dbg5  Data values:\n");
		fprintf(stderr,"dbg5       beams_bath:   %d\n",
			data->beams_bath);
		fprintf(stderr,"dbg5       scale_factor: %d\n",
			data->scale_factor);
		for (i=0;i<data->beams_bath;i++)
			fprintf(stderr,"dbg5       beam: %d  bath: %d  across_track: %d\n",
				i,data->bath_struct[i].bath,
				data->bath_struct[i].bath_acrosstrack);
		}

	/* print debug statements */
	if (status == MB_SUCCESS && verbose >= 5
		&& data->kind == MB_DATA_COMMENT)
		{
		fprintf(stderr,"\ndbg5  Comment record to be written by MBIO function <%s>\n",function_name);
		fprintf(stderr,"dbg5  Comment:\n");
		fprintf(stderr,"dbg5       comment:   %s\n",
			data->comment);
		}

	/* byte swap the data if necessary */
#ifdef BYTESWAPPED
	data->year = mb_swap_short(data->year);
	data->day = mb_swap_short(data->day);
	data->min = mb_swap_short(data->min);
	data->sec = mb_swap_short(data->sec);
	data->lat = mb_swap_int(data->lat);
	data->lon = mb_swap_int(data->lon);
	data->heading = mb_swap_short(data->heading);
	data->course = mb_swap_short(data->course);
	data->speed = mb_swap_short(data->speed);
	data->speed_ps = mb_swap_short(data->speed_ps);
	data->quality = mb_swap_short(data->quality);
	data->sensor_size = mb_swap_short(data->sensor_size);
	data->data_size = mb_swap_short(data->data_size);
	data->eclipse_time = mb_swap_short(data->eclipse_time);
	data->eclipse_heading = mb_swap_short(data->eclipse_heading);
	data->beams_bath = mb_swap_short(data->beams_bath);
	data->scale_factor = mb_swap_short(data->scale_factor);
	if (store->kind == MB_DATA_DATA)
		{
		for (i=0;i<MB_BEAMS_SBSIOSWB;i++)
			{
			data->bath_struct[i].bath =
				mb_swap_short(data->bath_struct[i].bath);
			data->bath_struct[i].bath_acrosstrack =
				mb_swap_short(data->bath_struct[i].bath_acrosstrack);
			}
		}
#endif

	/* write header record to file */
	if (status == MB_SUCCESS)
		{
		if ((status = fwrite(headerptr,1,MB_SBSIOSWB_HEADER_SIZE,
			mb_io_ptr->mbfp)) == MB_SBSIOSWB_HEADER_SIZE)
			{
			status = MB_SUCCESS;
			*error = MB_ERROR_NO_ERROR;
			}
		else
			{
			status = MB_FAILURE;
			*error = MB_ERROR_WRITE_FAIL;
			}
		}

	/* write sensor record to file */
	if (status == MB_SUCCESS)
		{
		if ((status = fwrite(sensorptr,1,sensor_size,
			mb_io_ptr->mbfp)) == sensor_size)
			{
			status = MB_SUCCESS;
			*error = MB_ERROR_NO_ERROR;
			}
		else
			{
			status = MB_FAILURE;
			*error = MB_ERROR_WRITE_FAIL;
			}
		}

	/* write data record to file */
	if (status == MB_SUCCESS && data->kind == MB_DATA_DATA)
		{
		if ((status = fwrite(datarecptr,1,data_size,
			mb_io_ptr->mbfp)) == data_size)
			{
			status = MB_SUCCESS;
			*error = MB_ERROR_NO_ERROR;
			}
		else
			{
			status = MB_FAILURE;
			*error = MB_ERROR_WRITE_FAIL;
			}
		}

	/* write comment record to file */
	if (status == MB_SUCCESS && data->kind == MB_DATA_COMMENT)
		{
		if ((status = fwrite(commentptr,1,strlen(data->comment),
			mb_io_ptr->mbfp)) == strlen(data->comment))
			{
			status = MB_SUCCESS;
			*error = MB_ERROR_NO_ERROR;
			}
		else
			{
			status = MB_FAILURE;
			*error = MB_ERROR_WRITE_FAIL;
			}
		}

	/* 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);
}
コード例 #6
0
/*--------------------------------------------------------------------*/
int mbr_rt_sbsioswb(int verbose, void *mbio_ptr, void *store_ptr, int *error)
{
	char	*function_name = "mbr_rt_sbsioswb";
	int	status = MB_SUCCESS;
	struct mb_io_struct *mb_io_ptr;
	struct mbf_sbsioswb_struct *data;
	struct mbsys_sb_struct *store;
	char	*headerptr;
	char	*sensorptr;
	char	*datarecptr;
	char	*commentptr;
	int	read_status;
	char	dummy[2];
	double	lon, lat;
	int	id;
	int	skip;
	int	i, k;

	/* print input debug statements */
	if (verbose >= 2)
		{
		fprintf(stderr,"\ndbg2  MBIO function <%s> called\n",function_name);
		fprintf(stderr,"dbg2  Revision id: %s\n",rcs_id);
		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_sbsioswb_struct *) mb_io_ptr->raw_data;
	store = (struct mbsys_sb_struct *) store_ptr;

	/* get pointers to records */
	headerptr = (char *) &data->year;
	sensorptr = (char *) &data->eclipse_time;
	datarecptr = (char *) &data->beams_bath;
	commentptr = (char *) &data->comment[0];
	skip = 0;

	/* read next header record from file */
	mb_io_ptr->file_pos = mb_io_ptr->file_bytes;
	if ((status = fread(headerptr,1,MB_SBSIOSWB_HEADER_SIZE,
			mb_io_ptr->mbfp)) == MB_SBSIOSWB_HEADER_SIZE)
		{
		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;
		}

	/* byte swap the data if necessary */
#ifdef BYTESWAPPED
	if (status == MB_SUCCESS)
		{
		data->year = mb_swap_short(data->year);
		data->day = mb_swap_short(data->day);
		data->min = mb_swap_short(data->min);
		data->sec = mb_swap_short(data->sec);
		data->lat = mb_swap_int(data->lat);
		data->lon = mb_swap_int(data->lon);
		data->heading = mb_swap_short(data->heading);
		data->course = mb_swap_short(data->course);
		data->speed = mb_swap_short(data->speed);
		data->speed_ps = mb_swap_short(data->speed_ps);
		data->quality = mb_swap_short(data->quality);
		data->sensor_size = mb_swap_short(data->sensor_size);
		data->data_size = mb_swap_short(data->data_size);
		}
#endif

	/* print debug statements */
	if (status == MB_SUCCESS && verbose >= 5)
		{
		fprintf(stderr,"\ndbg5  New header record read by MBIO function <%s>\n",function_name);
		fprintf(stderr,"dbg5  New header values:\n");
		fprintf(stderr,"dbg5       year:       %d\n",data->year);
		fprintf(stderr,"dbg5       day:        %d\n",data->day);
		fprintf(stderr,"dbg5       min:        %d\n",data->min);
		fprintf(stderr,"dbg5       sec:        %d\n",data->sec);
		fprintf(stderr,"dbg5       lat:        %d\n",data->lat);
		fprintf(stderr,"dbg5       lon:        %d\n",data->lon);
		fprintf(stderr,"dbg5       heading:    %d\n",data->heading);
		fprintf(stderr,"dbg5       course:     %d\n",data->course);
		fprintf(stderr,"dbg5       speed:      %d\n",data->speed);
		fprintf(stderr,"dbg5       speed_ps:   %d\n",data->speed_ps);
		fprintf(stderr,"dbg5       quality:    %d\n",data->quality);
		fprintf(stderr,"dbg5       sensor size:%d\n",data->sensor_size);
		fprintf(stderr,"dbg5       data size:  %d\n",data->data_size);
		fprintf(stderr,"dbg5       speed_ref:  %c%c\n",
			data->speed_ref[0],data->speed_ref[1]);
		fprintf(stderr,"dbg5       sensor_type:%c%c\n",
			data->sensor_type[0],data->sensor_type[1]);
		fprintf(stderr,"dbg5       data_type:  %c%c\n",
			data->data_type[0],data->data_type[1]);
		}

	/* if not a good header search through file to find one */
	while (status == MB_SUCCESS &&
		(strncmp(data->data_type,"SR",2) != 0
		&& strncmp(data->data_type,"RS",2) != 0
		&& strncmp(data->data_type,"SP",2) != 0
		&& strncmp(data->data_type,"TR",2) != 0
		&& strncmp(data->data_type,"IR",2) != 0
		&& strncmp(data->data_type,"AT",2) != 0
		&& strncmp(data->data_type,"SC",2) != 0))
		{
		/* unswap data if necessary */
#ifdef BYTESWAPPED
		data->year = mb_swap_short(data->year);
		data->day = mb_swap_short(data->day);
		data->min = mb_swap_short(data->min);
		data->sec = mb_swap_short(data->sec);
		data->lat = mb_swap_int(data->lat);
		data->lon = mb_swap_int(data->lon);
		data->heading = mb_swap_short(data->heading);
		data->course = mb_swap_short(data->course);
		data->speed = mb_swap_short(data->speed);
		data->speed_ps = mb_swap_short(data->speed_ps);
		data->quality = mb_swap_short(data->quality);
		data->sensor_size = mb_swap_short(data->sensor_size);
		data->data_size = mb_swap_short(data->data_size);
#endif

		/* shift bytes by one */
		for (i=0;i<MB_SBSIOSWB_HEADER_SIZE-1;i++)
			headerptr[i] = headerptr[i+1];
		mb_io_ptr->file_pos += 1;

		/* read next byte */
		if ((status = fread(&headerptr[MB_SBSIOSWB_HEADER_SIZE-1],
			1,1,mb_io_ptr->mbfp)) == 1)
			{
			mb_io_ptr->file_bytes += status;
			skip++;
			status = MB_SUCCESS;
			*error = MB_ERROR_NO_ERROR;
			}
		else
			{
			mb_io_ptr->file_bytes += status;
			status = MB_FAILURE;
			*error = MB_ERROR_EOF;
			}

		/* swap data if necessary */
#ifdef BYTESWAPPED
		data->year = mb_swap_short(data->year);
		data->day = mb_swap_short(data->day);
		data->min = mb_swap_short(data->min);
		data->sec = mb_swap_short(data->sec);
		data->lat = mb_swap_int(data->lat);
		data->lon = mb_swap_int(data->lon);
		data->heading = mb_swap_short(data->heading);
		data->course = mb_swap_short(data->course);
		data->speed = mb_swap_short(data->speed);
		data->speed_ps = mb_swap_short(data->speed_ps);
		data->quality = mb_swap_short(data->quality);
		data->sensor_size = mb_swap_short(data->sensor_size);
		data->data_size = mb_swap_short(data->data_size);
#endif

		/* print debug statements */
		if (status == MB_SUCCESS && verbose >= 5)
			{
			fprintf(stderr,"\ndbg5  Header record after byte shift in MBIO function <%s>\n",function_name);
			fprintf(stderr,"dbg5  New header values:\n");
			fprintf(stderr,"dbg5       skip:       %d\n",skip);
			fprintf(stderr,"dbg5       year:       %d\n",data->year);
			fprintf(stderr,"dbg5       day:        %d\n",data->day);
			fprintf(stderr,"dbg5       min:        %d\n",data->min);
			fprintf(stderr,"dbg5       sec:        %d\n",data->sec);
			fprintf(stderr,"dbg5       lat:        %d\n",data->lat);
			fprintf(stderr,"dbg5       lon:        %d\n",data->lon);
			fprintf(stderr,"dbg5       heading:    %d\n",data->heading);
			fprintf(stderr,"dbg5       course:     %d\n",data->course);
			fprintf(stderr,"dbg5       speed:      %d\n",data->speed);
			fprintf(stderr,"dbg5       speed_ps:   %d\n",data->speed_ps);
			fprintf(stderr,"dbg5       quality:    %d\n",data->quality);
			fprintf(stderr,"dbg5       sensor size:%d\n",data->sensor_size);
			fprintf(stderr,"dbg5       data size:  %d\n",data->data_size);
			fprintf(stderr,"dbg5       speed_ref:  %c%c\n",
				data->speed_ref[0],data->speed_ref[1]);
			fprintf(stderr,"dbg5       sensor_type:%c%c\n",
				data->sensor_type[0],data->sensor_type[1]);
			fprintf(stderr,"dbg5       data_type:  %c%c\n",
				data->data_type[0],data->data_type[1]);
			}
		}

	/* check for unintelligible records */
	if (status == MB_SUCCESS)
		{
		if ((strncmp(data->sensor_type,"SB",2) != 0 ||
			strncmp(data->data_type,"SR",2) != 0)
			&& strncmp(data->data_type,"TR",2) != 0)
			{
			status = MB_FAILURE;
			*error = MB_ERROR_UNINTELLIGIBLE;
			data->kind = MB_DATA_NONE;
			}
		else if (strncmp(data->data_type,"SR",2) == 0
			&& data->year == 0)
			{
			status = MB_FAILURE;
			*error = MB_ERROR_UNINTELLIGIBLE;
			data->kind = MB_DATA_NONE;
			}
		else if (strncmp(data->data_type,"SR",2) == 0)
			{
			data->kind = MB_DATA_DATA;
			}
		else
			{
			data->kind = MB_DATA_COMMENT;
			}
		}

	/* deal with unintelligible record */
	if (status == MB_FAILURE
	    && *error == MB_ERROR_UNINTELLIGIBLE)
		{
		/* read rest of record into dummy */
		for (i=0;i<data->sensor_size;i++)
			{
			if ((read_status = fread(dummy,1,1,
				mb_io_ptr->mbfp)) != 1)
				{
				status = MB_FAILURE;
				*error = MB_ERROR_EOF;
				}
			mb_io_ptr->file_bytes
					+= read_status;
			}
		for (i=0;i<data->data_size;i++)
			{
			if ((read_status = fread(dummy,1,1,
				mb_io_ptr->mbfp)) != 1)
				{
				status = MB_FAILURE;
				*error = MB_ERROR_EOF;
				}
			mb_io_ptr->file_bytes
					+= read_status;
			}
		}

	/* read sensor record from file */
	if (status == MB_SUCCESS && data->sensor_size > 0)
		{
		if ((status = fread(sensorptr,1,data->sensor_size,
			mb_io_ptr->mbfp)) == data->sensor_size)
			{
			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;
			}

		/* byte swap the data if necessary */
#ifdef BYTESWAPPED
		if (status == MB_SUCCESS)
			{
			data->eclipse_time = mb_swap_short(data->eclipse_time);
			data->eclipse_heading = mb_swap_short(data->eclipse_heading);
			}
#endif

		/* print debug statements */
		if (status == MB_SUCCESS && verbose >= 5)
			{
			fprintf(stderr,"\ndbg5  New sensor record read by MBIO function <%s>\n",function_name);
			fprintf(stderr,"dbg5  New sensor values:\n");
			fprintf(stderr,"dbg5       eclipse_time:    %d\n",
				data->eclipse_time);
			fprintf(stderr,"dbg5       eclipse_heading: %d\n",
				data->eclipse_heading);
			}
		}

	/* read data record from file */
	if (status == MB_SUCCESS && data->kind == MB_DATA_DATA
		&& data->data_size > 0)
		{
		if ((status = fread(datarecptr,1,data->data_size,
			mb_io_ptr->mbfp)) == data->data_size)
			{
			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;
			}

		/* byte swap the data if necessary */
#ifdef BYTESWAPPED
		if (status == MB_SUCCESS && data->kind == MB_DATA_DATA)
			{
			data->beams_bath = mb_swap_short(data->beams_bath);
			data->scale_factor = mb_swap_short(data->scale_factor);
			}
#endif

		/* check for unintelligible records */
		if (status == MB_SUCCESS)
			{
			if (data->beams_bath < 0
				|| data->beams_bath > MB_BEAMS_SBSIOSWB)
				{
				status = MB_FAILURE;
				*error = MB_ERROR_UNINTELLIGIBLE;
				data->kind = MB_DATA_NONE;
				}
			}

		/* byte swap the data if necessary */
#ifdef BYTESWAPPED
		if (status == MB_SUCCESS && data->kind == MB_DATA_DATA)
			{
			for (i=0;i<data->beams_bath;i++)
				{
				data->bath_struct[i].bath =
					mb_swap_short(data->bath_struct[i].bath);
				data->bath_struct[i].bath_acrosstrack =
					mb_swap_short(data->bath_struct[i].bath_acrosstrack);
				}
			}
#endif

		/* check for fewer than expected beams */
		if (status == MB_SUCCESS
			&& (data->data_size / 4) - 1 < data->beams_bath)
			{
			k = (data->data_size / 4) - 2;
			for (i=k;i<data->beams_bath;i++)
			    {
			    data->bath_struct[i].bath = 0;
			    data->bath_struct[i].bath_acrosstrack = 0;
			    }
			}

		/* zero ridiculous soundings */
		if (status == MB_SUCCESS && data->kind == MB_DATA_DATA)
			{
			for (i=0;i<data->beams_bath;i++)
			    {
			    if (data->bath_struct[i].bath > 11000
				|| data->bath_struct[i].bath_acrosstrack > 11000
				    || data->bath_struct[i].bath_acrosstrack < -11000)
				{
				data->bath_struct[i].bath = 0;
				data->bath_struct[i].bath_acrosstrack = 0;
				}
			    }
			}

		/* print debug statements */
		if (status == MB_SUCCESS && verbose >= 5
			&& data->kind == MB_DATA_DATA)
			{
			fprintf(stderr,"\ndbg5  New data record read by MBIO function <%s>\n",function_name);
			fprintf(stderr,"dbg5  New data values:\n");
			fprintf(stderr,"dbg5       beams_bath:   %d\n",
				data->beams_bath);
			fprintf(stderr,"dbg5       scale_factor: %d\n",
				data->scale_factor);
			for (i=0;i<data->beams_bath;i++)
				fprintf(stderr,"dbg5       beam: %d  bath: %d  across_track: %d\n",
					i,data->bath_struct[i].bath,
					data->bath_struct[i].bath_acrosstrack);
			}
		}

	/* read comment record from file */
	if (status == MB_SUCCESS && data->kind == MB_DATA_COMMENT)
		{
		if ((status = fread(commentptr,1,data->data_size,
			mb_io_ptr->mbfp)) == data->data_size)
			{
			mb_io_ptr->file_bytes += status;
			status = MB_SUCCESS;
			*error = MB_ERROR_NO_ERROR;
			for (i=data->data_size;i<MBSYS_SB_MAXLINE;i++)
				commentptr[i] = '\0';
			}
		else
			{
			mb_io_ptr->file_bytes += status;
			status = MB_FAILURE;
			*error = MB_ERROR_EOF;
			}

		/* print debug statements */
		if (status == MB_SUCCESS && verbose >= 5)
			{
			fprintf(stderr,"\ndbg5  New comment record read by MBIO function <%s>\n",function_name);
			fprintf(stderr,"dbg5  New comment:\n");
			fprintf(stderr,"dbg5       comment:   %s\n",
				data->comment);
			}
		}

	/* set kind and error in mb_io_ptr */
	mb_io_ptr->new_kind = data->kind;
	mb_io_ptr->new_error = *error;

	/* translate values to seabeam data storage structure */
	if (status == MB_SUCCESS)
		{
		/* type of data record */
		store->kind = data->kind;

		if (store->kind == MB_DATA_DATA)
			{
			/* position */
			lon = 0.0000001*data->lon;
			if (lon < 0.0) lon = lon + 360.0;
			store->lon2u = (short) 60.0*lon;
			store->lon2b = (short) ROUND(600000.0*
				(lon - store->lon2u/60.0));
			lat = 0.0000001*data->lat + 90.0;
			store->lat2u = (short) 60.0*lat;
			store->lat2b = (short) ROUND(600000.0*
				(lat - store->lat2u/60.0));

			/* time stamp */
			store->year = data->year;
			store->day = data->day;
			store->min = data->min;
			store->sec = 0.01*data->sec;

			/* heading */
			store->sbhdg = (data->heading < (short) 0)
			    ? (unsigned short) ROUND(((int)data->heading + 3600)*18.204444444)
			    : (unsigned short) ROUND(data->heading*18.204444444);

			/* depths and distances */
			id = data->beams_bath - 1;
			for (i=0;i<data->beams_bath;i++)
				{
				store->deph[id-i] = data->bath_struct[i].bath;
				store->dist[id-i] =
					data->bath_struct[i].bath_acrosstrack;
				}

			/* additional values */
			store->sbtim = data->eclipse_time;
			store->axis = 0;
			store->major = 0;
			store->minor = 0;
			}

		else if (store->kind == MB_DATA_COMMENT)
			{
			/* comment */
			strncpy(store->comment,data->comment,
				MBSYS_SB_MAXLINE);
			}
		}

	/* 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);
}
コード例 #7
0
ファイル: mbr_sbsiolsi.c プロジェクト: dwcaress/MB-System
/*--------------------------------------------------------------------*/
int mbr_wt_sbsiolsi(int verbose, void *mbio_ptr, void *store_ptr, int *error)
{
	char	*function_name = "mbr_wt_sbsiolsi";
	int	status = MB_SUCCESS;
	struct mb_io_struct *mb_io_ptr;
	struct mbf_sbsiolsi_struct *dataplus;
	struct mbf_sbsiolsi_data_struct *data;
	struct mbsys_sb_struct *store;
	char	*datacomment;
	int	i;

	/* print input debug statements */
	if (verbose >= 2)
		{
		fprintf(stderr,"\ndbg2  MBIO function <%s> called\n",function_name);
		fprintf(stderr,"dbg2  Revision id: %s\n",rcs_id);
		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 */
	dataplus = (struct mbf_sbsiolsi_struct *) mb_io_ptr->raw_data;
	data = &(dataplus->data);
	datacomment = (char *) data;
	store = (struct mbsys_sb_struct *) store_ptr;

	/* first set some plausible amounts for some of the
		variables in the MBURICEN record */
	data->axis = 0;
	data->major = 0;
	data->minor = 0;

	/* second translate values from seabeam data storage structure */
	if (store != NULL)
		{
		dataplus->kind = store->kind;
		if (store->kind == MB_DATA_DATA)
			{
			/* position */
			data->lon2u = store->lon2u;
			data->lon2b = store->lon2b;
			data->lat2u = store->lat2u;
			data->lat2b = store->lat2b;

			/* time stamp */
			data->year = store->year;
			data->day = store->day;
			data->min = store->min;
			data->sec = store->sec;

			/* depths and distances */
			for (i=0;i<MBSYS_SB_BEAMS;i++)
				{
				data->dist[i] = store->dist[i];
				data->deph[i] = store->deph[i];
				}

			/* additional values */
			data->sbhdg = store->sbhdg;
			data->axis = store->axis;
			data->major = store->major;
			data->minor = store->minor;
			}

		/* comment */
		else if (store->kind == MB_DATA_COMMENT)
			{
			strcpy(datacomment,"cc");
			strncat(datacomment,store->comment,MBSYS_SB_MAXLINE-1);
			}
		}

	/* print debug statements */
	if (verbose >= 5)
		{
		fprintf(stderr,"\ndbg5  Ready to write data in MBIO function <%s>\n",function_name);
		fprintf(stderr,"dbg5       kind:       %d\n",
			dataplus->kind);
		fprintf(stderr,"dbg5       error:      %d\n",*error);
		fprintf(stderr,"dbg5       status:     %d\n",status);
		}

	/* byte swap the data if necessary */
#ifdef BYTESWAPPED
	if (dataplus->kind == MB_DATA_DATA)
		{
		for (i=0;i<MBSYS_SB_BEAMS;i++)
			{
			data->dist[i] = mb_swap_short(data->dist[i]);
			data->deph[i] = mb_swap_short(data->deph[i]);
			}
		data->axis = mb_swap_short(data->axis);
		data->major = mb_swap_short(data->major);
		data->minor = mb_swap_short(data->minor);
		data->sbhdg = mb_swap_short(data->sbhdg);
		data->lat2b = mb_swap_short(data->lat2b);
		data->lat2u = mb_swap_short(data->lat2u);
		data->lon2b = mb_swap_short(data->lon2b);
		data->lon2u = mb_swap_short(data->lon2u);
		data->sec = mb_swap_short(data->sec);
		data->min = mb_swap_short(data->min);
		data->day = mb_swap_short(data->day);
		data->year = mb_swap_short(data->year);
		}
#endif

	/* write next record to file */
	if (dataplus->kind == MB_DATA_DATA
		|| dataplus->kind == MB_DATA_COMMENT)
		{
		if ((status = fwrite(data,1,mb_io_ptr->data_structure_size,
			mb_io_ptr->mbfp)) == mb_io_ptr->data_structure_size)
			{
			status = MB_SUCCESS;
			*error = MB_ERROR_NO_ERROR;
			}
		else
			{
			status = MB_FAILURE;
			*error = MB_ERROR_WRITE_FAIL;
			}
		}
	else
		{
		status = MB_SUCCESS;
		*error = MB_ERROR_NO_ERROR;
		if (verbose >= 5)
			fprintf(stderr,"\ndbg5  No data written in MBIO function <%s>\n",function_name);
		}

	/* 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);
}
コード例 #8
0
ファイル: mbr_sbsiolsi.c プロジェクト: dwcaress/MB-System
/*--------------------------------------------------------------------*/
int mbr_rt_sbsiolsi(int verbose, void *mbio_ptr, void *store_ptr, int *error)
{
	char	*function_name = "mbr_rt_sbsiolsi";
	int	status = MB_SUCCESS;
	struct mb_io_struct *mb_io_ptr;
	struct mbf_sbsiolsi_struct *dataplus;
	struct mbf_sbsiolsi_data_struct *data;
	struct mbsys_sb_struct *store;
	char	*datacomment;
	int	i;

	/* print input debug statements */
	if (verbose >= 2)
		{
		fprintf(stderr,"\ndbg2  MBIO function <%s> called\n",function_name);
		fprintf(stderr,"dbg2  Revision id: %s\n",rcs_id);
		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 */
	dataplus = (struct mbf_sbsiolsi_struct *) mb_io_ptr->raw_data;
	data = &(dataplus->data);
	datacomment = (char *) data;
	dataplus->kind = MB_DATA_DATA;
	store = (struct mbsys_sb_struct *) store_ptr;

	/* read next record from file */
	mb_io_ptr->file_pos = mb_io_ptr->file_bytes;
	if ((status = fread(data,1,mb_io_ptr->data_structure_size,
			mb_io_ptr->mbfp)) == mb_io_ptr->data_structure_size)
		{
		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;
		}

	/* byte swap the data if necessary */
#ifdef BYTESWAPPED
	if (status == MB_SUCCESS)
		{
		for (i=0;i<MBSYS_SB_BEAMS;i++)
			{
			data->dist[i] = mb_swap_short(data->dist[i]);
			data->deph[i] = mb_swap_short(data->deph[i]);
			}
		data->axis = mb_swap_short(data->axis);
		data->major = mb_swap_short(data->major);
		data->minor = mb_swap_short(data->minor);
		data->sbhdg = mb_swap_short(data->sbhdg);
		data->lat2b = mb_swap_short(data->lat2b);
		data->lat2u = mb_swap_short(data->lat2u);
		data->lon2b = mb_swap_short(data->lon2b);
		data->lon2u = mb_swap_short(data->lon2u);
		data->sec = mb_swap_short(data->sec);
		data->min = mb_swap_short(data->min);
		data->day = mb_swap_short(data->day);
		data->year = mb_swap_short(data->year);
		}
#endif

	/* check for comment or unintelligible records */
	if (status == MB_SUCCESS)
		{
		if (data->deph[0] > 15000)
			{
			dataplus->kind = MB_DATA_COMMENT;
			}
		else if (data->year == 0)
			{
			status = MB_FAILURE;
			*error = MB_ERROR_UNINTELLIGIBLE;
			}
		else
			{
			dataplus->kind = MB_DATA_DATA;
			}
		}

	/* set kind and error in mb_io_ptr */
	mb_io_ptr->new_kind = dataplus->kind;
	mb_io_ptr->new_error = *error;

	/* translate values to seabeam data storage structure */
	if (status == MB_SUCCESS
		&& store != NULL)
		{
		/* type of data record */
		store->kind = dataplus->kind;

		if (store->kind == MB_DATA_DATA)
			{
			/* position */
			store->lon2u = data->lon2u;
			store->lon2b = data->lon2b;
			store->lat2u = data->lat2u;
			store->lat2b = data->lat2b;

			/* time stamp */
			store->year = data->year;
			store->day = data->day;
			store->min = data->min;
			store->sec = data->sec;

			/* depths and distances */
			for (i=0;i<MBSYS_SB_BEAMS;i++)
				{
				store->dist[i] = data->dist[i];
				store->deph[i] = data->deph[i];
				}

			/* additional values */
			store->sbtim = 0;
			store->sbhdg = data->sbhdg;
			store->axis = data->axis;
			store->major = data->major;
			store->minor = data->minor;
			}

		else if (store->kind == MB_DATA_COMMENT)
			{
			/* comment */
			strncpy(store->comment,&datacomment[2],
				MBSYS_SB_MAXLINE);
			}
		}

	/* 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);
}