Example #1
0
int
mbbs_mr1_xdrpnghdrv1(Ping *png, XDR *xdrs)
/*
   Internal routine.
   Does XDR decoding of an MR1 version 1 ping header.
   Returns 1 if successful, 0 otherwise.
*/
{
	int tvsec, tvusec;
	unsigned long sidebc;
	int mr1_xdrsidev1(PingSide *, XDR *, unsigned long *);

	bs_iobytecnt= 0;

	/* output in obsolete format not allowed! */
	if (xdrs->x_op == XDR_ENCODE)
		return 0;

	if (!bs_ionaninit) {
		bs_ionanf= mbbs_nanf();
		bs_ionand= mbbs_nand();
		bs_ionaninit= 1;
	}

	png->png_flags= PNG_BTYSSFLAGSABSENT;

	/* depending upon the platform, the size of the timeval
	   struct's fields may be 4 or 8 bytes; for backward
	   compatibility with old files that use 4-byte fields,
	   we use 4-byte primitives */
	if (!xdr_int(xdrs, &tvsec))
		return 0;
	bs_iobytecnt+= 4;
	png->png_tm.tv_sec= tvsec;
	if (!xdr_int(xdrs, &tvusec))
		return 0;
	bs_iobytecnt+= 4;
	png->png_tm.tv_usec= tvusec;

	png->png_period= bs_ionanf;
	png->png_slon= bs_ionand;
	png->png_slat= bs_ionand;
	png->png_scourse= bs_ionanf;
	png->png_laybackrng= bs_ionanf;
	png->png_laybackbrg= bs_ionanf;

	if (!xdr_double(xdrs, &(png->png_tlon)))
		return 0;
	bs_iobytecnt+= 8;
	if (!xdr_double(xdrs, &(png->png_tlat)))
		return 0;
	bs_iobytecnt+= 8;
	if (!xdr_float(xdrs, &(png->png_tcourse)))
		return 0;
	bs_iobytecnt+= 4;

	png->png_compass.sns_int= bs_ionanf;
	png->png_compass.sns_nsamps= 0;
	if (!xdr_float(xdrs, &(png->png_compass.sns_repval)))
		return 0;
	bs_iobytecnt+= 4;

	png->png_depth.sns_int= bs_ionanf;
	png->png_depth.sns_nsamps= 0;
	if (!xdr_float(xdrs, &(png->png_depth.sns_repval)))
		return 0;
	bs_iobytecnt+= 4;

	if (!xdr_float(xdrs, &(png->png_alt)))
		return 0;
	bs_iobytecnt+= 4;

	png->png_pitch.sns_int= bs_ionanf;
	png->png_pitch.sns_nsamps= 0;
	if (!xdr_float(xdrs, &(png->png_pitch.sns_repval)))
		return 0;
	bs_iobytecnt+= 4;

	png->png_roll.sns_int= bs_ionanf;
	png->png_roll.sns_nsamps= 0;
	if (!xdr_float(xdrs, &(png->png_roll.sns_repval)))
		return 0;
	bs_iobytecnt+= 4;

	png->png_snspad= 0;

	if (!xdr_float(xdrs, &(png->png_temp)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_float(xdrs, &(png->png_ssincr)))
		return 0;
	bs_iobytecnt+= 4;

	png->png_ssyoffsetmode= PNG_SSYOM_UNKNOWN;
	png->png_magcorr= bs_ionanf;
	png->png_sndvel= bs_ionanf;
	png->png_cond= bs_ionanf;
	png->png_magx= bs_ionanf;
	png->png_magy= bs_ionanf;
	png->png_magz= bs_ionanf;

	if (!mr1_xdrsidev1(&(png->png_sides[ACP_PORT]), xdrs, &sidebc))
		return 0;
	bs_iobytecnt+= sidebc;
	png->png_sides[ACP_PORT].ps_bdrange= png->png_alt;
	png->png_sides[ACP_PORT].ps_ssndrmask= 0.;
	png->png_sides[ACP_PORT].ps_ssyoffset= bs_ionanf;

	if (!mr1_xdrsidev1(&(png->png_sides[ACP_STBD]), xdrs, &sidebc))
		return 0;
	bs_iobytecnt+= sidebc;
	png->png_sides[ACP_STBD].ps_bdrange= png->png_alt;
	png->png_sides[ACP_STBD].ps_ssndrmask= 0.;
	png->png_sides[ACP_STBD].ps_ssyoffset= bs_ionanf;

	return 1;
}
Example #2
0
int
mbbs_xdrpnghdr(Ping *png, XDR *xdrs, int version)
/*
   Internal routine.
   Does XDR encoding and decoding of a BS ping header.
   Returns 1 if successful, 0 otherwise.
*/
{
	unsigned int flags;
	int tvsec, tvusec;
	unsigned long sidebc;
	int mbbs_xdrside(PingSide *, XDR *, int, unsigned long *);

	switch (version) {
	case BS_VERSION_1_0:
	case BS_VERSION_1_1:
	case BS_VERSION_1_2:
	case BS_VERSION_1_3:

		/* output in obsolete format not allowed! */
		if (xdrs->x_op == XDR_ENCODE)
			return 0;

		break;
	case BS_VERSION_1_4:
		break;
	default:
		return 0;
	}

	bs_iobytecnt= 0;

	if (!bs_ionaninit) {
		bs_ionanf= mbbs_nanf();
		bs_ionand= mbbs_nand();
		bs_ionaninit= 1;
	}

	/* always clear the PNG_BTYSSFLAGSABSENT bit when writing
	   since all current format output files are guaranteed to
	   include bathymetry and sidescan flags -- this bit should
	   normally be set only by I/O functions from this library
	   when reading flagless older format version files */	
	if (xdrs->x_op == XDR_ENCODE) {
		flags= png->png_flags;
		flags&= ~PNG_BTYSSFLAGSABSENT;
	}
	if (!xdr_u_int(xdrs, &flags))
		return 0;
	bs_iobytecnt+= 4;
	if (xdrs->x_op == XDR_DECODE)
		png->png_flags= flags;

	/* depending upon the platform, the size of the timeval
	   struct's fields may be 4 or 8 bytes; for backward
	   compatibility with old files that use 4-byte fields,
	   we force these quantities into 4-byte primitives when
	   doing output, returning an error when overflow would result */
	if (xdrs->x_op == XDR_ENCODE) {
		if (((long) png->png_tm.tv_sec < INT32_MIN) ||
		    ((long) png->png_tm.tv_sec > INT32_MAX))
			return 0;

		/* on some platforms where tv_usec is 4 bytes (e.g., mac_x8664
		   under MacOS 10.7) the following may generate a compiler
		   warning about an invalid comparison -- it's probably best to
		   leave this as is rather than code around this unusual size
		   and risk failure in the future if it's ever increased */
		if ((sizeof png->png_tm.tv_usec > 4) &&
		    (((long) png->png_tm.tv_usec < INT32_MIN) ||
		     ((long) png->png_tm.tv_usec > INT32_MAX)))
			return 0;

		tvsec= (int) png->png_tm.tv_sec;
		tvusec= (int) png->png_tm.tv_usec;
	}
	if (!xdr_int(xdrs, &tvsec))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_int(xdrs, &tvusec))
		return 0;
	bs_iobytecnt+= 4;
	if (xdrs->x_op == XDR_DECODE) {
		png->png_tm.tv_sec= tvsec;
		png->png_tm.tv_usec= tvusec;
	}

	if (!xdr_float(xdrs, &(png->png_period)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_double(xdrs, &(png->png_slon)))
		return 0;
	bs_iobytecnt+= 8;
	if (!xdr_double(xdrs, &(png->png_slat)))
		return 0;
	bs_iobytecnt+= 8;
	if (!xdr_float(xdrs, &(png->png_scourse)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_float(xdrs, &(png->png_laybackrng)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_float(xdrs, &(png->png_laybackbrg)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_double(xdrs, &(png->png_tlon)))
		return 0;
	bs_iobytecnt+= 8;
	if (!xdr_double(xdrs, &(png->png_tlat)))
		return 0;
	bs_iobytecnt+= 8;
	if (!xdr_float(xdrs, &(png->png_tcourse)))
		return 0;
	bs_iobytecnt+= 4;

	if (!xdr_float(xdrs, &(png->png_compass.sns_int)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_int(xdrs, &(png->png_compass.sns_nsamps)))
		return 0;
	bs_iobytecnt+= 4;
	if (png->png_compass.sns_nsamps < 0)
		return 0;
	if (!xdr_float(xdrs, &(png->png_compass.sns_repval)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_float(xdrs, &(png->png_depth.sns_int)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_int(xdrs, &(png->png_depth.sns_nsamps)))
		return 0;
	bs_iobytecnt+= 4;
	if (png->png_depth.sns_nsamps < 0)
		return 0;
	if (!xdr_float(xdrs, &(png->png_depth.sns_repval)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_float(xdrs, &(png->png_pitch.sns_int)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_int(xdrs, &(png->png_pitch.sns_nsamps)))
		return 0;
	bs_iobytecnt+= 4;
	if (png->png_pitch.sns_nsamps < 0)
		return 0;
	if (!xdr_float(xdrs, &(png->png_pitch.sns_repval)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_float(xdrs, &(png->png_roll.sns_int)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_int(xdrs, &(png->png_roll.sns_nsamps)))
		return 0;
	bs_iobytecnt+= 4;
	if (png->png_roll.sns_nsamps < 0)
		return 0;
	if (!xdr_float(xdrs, &(png->png_roll.sns_repval)))
		return 0;
	bs_iobytecnt+= 4;
	if (xdrs->x_op == XDR_DECODE)
		png->png_snspad= 0;

	if (!xdr_float(xdrs, &(png->png_temp)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_float(xdrs, &(png->png_ssincr)))
		return 0;
	bs_iobytecnt+= 4;
	if (version >= BS_VERSION_1_4) {
		if (!xdr_int(xdrs, &(png->png_ssyoffsetmode)))
			return 0;
		bs_iobytecnt+= 4;
	}
	else {
		if (xdrs->x_op == XDR_DECODE)
			png->png_ssyoffsetmode= PNG_SSYOM_UNKNOWN;
	}
	if (!xdr_float(xdrs, &(png->png_alt)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_float(xdrs, &(png->png_magcorr)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_float(xdrs, &(png->png_sndvel)))
		return 0;
	bs_iobytecnt+= 4;
	if (version >= BS_VERSION_1_1) {
		if (!xdr_float(xdrs, &(png->png_cond)))
			return 0;
		bs_iobytecnt+= 4;
		if (!xdr_float(xdrs, &(png->png_magx)))
			return 0;
		bs_iobytecnt+= 4;
		if (!xdr_float(xdrs, &(png->png_magy)))
			return 0;
		bs_iobytecnt+= 4;
		if (!xdr_float(xdrs, &(png->png_magz)))
			return 0;
		bs_iobytecnt+= 4;
	}
	else {
		if (xdrs->x_op == XDR_DECODE) {
			png->png_cond= bs_ionanf;
			png->png_magx= bs_ionanf;
			png->png_magy= bs_ionanf;
			png->png_magz= bs_ionanf;
		}
	}

	if (!mbbs_xdrside(&(png->png_sides[ACP_PORT]), xdrs, version, &sidebc))
		return 0;
	bs_iobytecnt+= sidebc;
	if (!mbbs_xdrside(&(png->png_sides[ACP_STBD]), xdrs, version, &sidebc))
		return 0;
	bs_iobytecnt+= sidebc;

	return 1;
}
Example #3
0
int
mr1_xdrsidev1(PingSide *ps, XDR *xdrs, unsigned long *bytecnt)
/*
   Internal routine.
   Does XDR decoding of an obsolete MR1 version 1 PingSide header.
   Records the total number of bytes transferred into *bytecnt.
   Returns 1 if successful, 0 otherwise.
*/
{
	*bytecnt= 0;

	/* output in obsolete format not allowed! */
	if (xdrs->x_op == XDR_ENCODE)
		return 0;

	if (!bs_ionaninit) {
		bs_ionanf= mbbs_nanf();
		bs_ionand= mbbs_nand();
		bs_ionaninit= 1;
	}

	/* HMRG code never archived anything to the old ps_trans[]
	   fields, so their contents are meaningless -- this code
	   reads those meaningless values and then stores a NaN
	   to the new ps_xmitpwr field */
	if (!xdr_float(xdrs, &(ps->ps_xmitpwr)))
		return 0;
	*bytecnt+= 4;
	if (!xdr_float(xdrs, &(ps->ps_xmitpwr)))
		return 0;
	*bytecnt+= 4;
	ps->ps_xmitpwr= bs_ionanf;

	/* HMRG code never archived anything to the ps_gain field
	   prior to the format MR1 version 2 changeover -- this code
	   reads that meaningless value and then stores a NaN
	   to the ps_gain field */
	if (!xdr_float(xdrs, &(ps->ps_gain)))
		return 0;
	*bytecnt+= 4;
	ps->ps_gain= bs_ionanf;

	/* HMRG code never archived anything to the ps_pulse field
	   prior to the format MR1 version 2 changeover with the exception
	   of one format conversion program (sb4b2mr) -- this code
	   reads that value and then replaces it with a NaN unless
	   it is non-zero */
	if (!xdr_float(xdrs, &(ps->ps_pulse)))
		return 0;
	*bytecnt+= 4;
	if (ps->ps_pulse == 0.)
		ps->ps_pulse= bs_ionanf;

	if (!xdr_int(xdrs, &(ps->ps_btycount)))
		return 0;
	*bytecnt+= 4;
	if (xdrs->x_op == XDR_DECODE)
		ps->ps_btypad= 0;
	if (!xdr_float(xdrs, &(ps->ps_ssxoffset)))
		return 0;
	*bytecnt+= 4;
	if (!xdr_int(xdrs, &(ps->ps_sscount)))
		return 0;
	*bytecnt+= 4;
	if (xdrs->x_op == XDR_DECODE)
		ps->ps_sspad= 0;

	return 1;
}