Ejemplo n.º 1
0
int
mbbs_xdrpngdata(Ping *png, MemType *data, XDR *xdrs)
/*
   Internal routine.
*/
{
	PingData pd;
	int mbbs_xdrpngpddata(Ping *, PingData *, XDR *);

	if (mbbs_getpngdataptrs(png, data, &pd) != BS_SUCCESS)
		return 0;

	return mbbs_xdrpngpddata(png, &pd, xdrs);
}
Ejemplo n.º 2
0
int
mbbs_setswradius(int version, FILE *fp, long phoffset, int side, unsigned int dtmask, float swradius)
/*
   Flags all samples of the specified datatype on the named side at
   across-track distances greater than swradius with {BTYD,SSD}_SWEDGE for
   the ping whose header is located at an arbitrary file byte offset.
*/
{
	Ping png;
	PingData pngdata;
	XDR xdr;
	int err, i, trimbty, trimss;
	int bsi, nbtyvals, nssvals, ssstart;
	long pdoffset;
	float *bty;
	float sscutoff;
	unsigned int *btyflags;
	unsigned char *ssflags;
	unsigned long datasz;

	switch (version) {
	case MR1_VERSION_1_0:
	case MR1_VERSION_2_0:
		return BS_BADDATA;
	case BS_VERSION_1_0:
	case BS_VERSION_1_1:
	case BS_VERSION_1_2:
	case BS_VERSION_1_3:
	case BS_VERSION_1_4:
		break;
	default:
		return BS_BADDATA;
	}

	if (fp == (FILE *) 0)
		return BS_BADARG;

	switch (side) {
	case ACP_PORT:
	case ACP_STBD:
		break;
	default:
		return BS_BADARG;
	}

	if (!(dtmask & BS_DTM_BATHYMETRY) &&
	    !(dtmask & BS_DTM_SIDESCAN))
		return BS_BADARG;

	if (swradius < 0.)
		return BS_BADARG;

	if (fseek(fp, phoffset, SEEK_SET) != 0)
		return BS_FSEEK;
	xdrstdio_create(&xdr, fp, XDR_DECODE);

	if (!mbbs_xdrpnghdr(&png, &xdr, version)) {
		xdr_destroy(&xdr);
		return BS_READ;
	}
	trimbty= trimss= 0;
	if (dtmask & BS_DTM_BATHYMETRY) {
		if ((nbtyvals= png.png_sides[side].ps_btycount) > 0)
			trimbty= 1;
	}
	if (dtmask & BS_DTM_SIDESCAN) {
		if ((sscutoff= swradius-png.png_sides[side].ps_ssxoffset) < 0.)
			sscutoff= 0.;
		ssstart= sscutoff/png.png_ssincr;
		if ((nssvals= png.png_sides[side].ps_sscount) > ssstart)
			trimss= 1;
	}
	if (!trimbty && !trimss) {
		xdr_destroy(&xdr);
		return BS_SUCCESS;
	}

	/* remember current file offset at end of ping header */
	pdoffset= phoffset+bs_iobytecnt;

	if ((err= mbbs_pngrealloc(&png, &bswsf_databuf, &bswsf_databufsz)) != BS_SUCCESS) {
		xdr_destroy(&xdr);
		return err;
	}
	if ((err= mbbs_rdpngdata(&png, bswsf_databuf, &xdr)) != BS_SUCCESS) {
		xdr_destroy(&xdr);
		return err;
	}
	datasz= bs_iobytecnt;
	xdr_destroy(&xdr);

	if ((err= mbbs_getpngdataptrs(&png, bswsf_databuf, &pngdata)) != BS_SUCCESS)
		return err;

	/* set {BTYD,SSD}_SWEDGE on all desired samples */
	if (dtmask & BS_DTM_BATHYMETRY) {
		if (png.png_flags & PNG_XYZ)
			bsi= 3;
		else
			bsi= 2;
		if ((bty= pngdata.pd_bty[side]) == (float *) 0)
			return BS_BADDATA;
		if ((btyflags= pngdata.pd_btyflags[side]) == (unsigned int *) 0)
			return BS_BADDATA;
		for (i= 0; i < nbtyvals; i++) {
			if (bty[bsi*i] > swradius)
				btyflags[i]|= BTYD_SWEDGE;
		}
	}
	if (dtmask & BS_DTM_SIDESCAN) {
		if ((ssflags= pngdata.pd_ssflags[side]) == (unsigned char *) 0)
			return BS_BADDATA;
		for (i= ssstart; i < nssvals; i++)
			ssflags[i]|= SSD_SWEDGE;
	}

	/* seek to beginning of ping data region and rewrite it */
	if (fseek(fp, pdoffset, SEEK_SET) != 0)
		return BS_FSEEK;
	xdrstdio_create(&xdr, fp, XDR_ENCODE);
	if ((err= mbbs_wrpngdata(&png, bswsf_databuf, &xdr)) != BS_SUCCESS) {
		xdr_destroy(&xdr);
		return err;
	}

	bs_iobytecnt= datasz;
	xdr_destroy(&xdr);
	(void) fflush(fp);

	return BS_SUCCESS;
}
Ejemplo n.º 3
0
int
main(int argc, char **argv)
{
	char *cp;
	Ping png, *pngp;
	int err, i, j, side, npts, bsi;
	PingData pd;
	float *bty, *ss;
	AuxBeamInfo *abi;
	void usage();
	void pr_bsfhdr(BSFile *), pr_pnghdr(Ping *);

	if ((progname= strrchr(*argv, (int) '/')) != (char *) NULL)
		progname++;
	else
		progname= *argv;

	skip= 0;
	count= BS_UNDEFINED;
	iomode= BS_FILEIO;
	fp= stdout;
	output= OUTPUT_ALL;
	ignorecnt= 0;
	showivisping= 1;
	showsns= showbty= showss= 1;
	showbtyd= showbtyfl= showabi= 1;
	showssd= showssfl= 1;
	pngcntonly= 0;
	tmmode= TM_JULIAN;

	databuf= (MemType *) 0;
	databufsz= 0;

	for (argc--, argv++; argc > 0; argc--, argv++) {
		if (!strcmp(*argv, "-s")) {
			if (argc < 2)
				usage();
			argc--, argv++;
			skip= (int) strtol(*argv, &cp, 10);
			if ((cp == *argv) || (*cp != '\0')) {
				(void) fprintf(stderr, "%s: invalid skip value\n", progname);
				exit(BS_BADARG);
			}
			if (skip < 0) {
				(void) fprintf(stderr, "%s: skip value may not be less than 0\n", progname);
				exit(BS_BADARG);
			}
		}
		else if (!strcmp(*argv, "-c")) {
			if (argc < 2)
				usage();
			argc--, argv++;
			count= (int) strtol(*argv, &cp, 10);
			if ((cp == *argv) || (*cp != '\0')) {
				(void) fprintf(stderr, "%s: invalid count value\n", progname);
				exit(BS_BADARG);
			}
			if (count < 0) {
				(void) fprintf(stderr, "%s: count value may not be less than 0\n", progname);
				exit(BS_BADARG);
			}
		}
		else if (!strcmp(*argv, "-sm")) {
			if (argc < 2)
				usage();
			iomode= BS_SHAREDMEM;
			argc--, argv++;
			smcid= (int) strtol(*argv, &cp, 10);
			if ((cp == *argv) || (*cp != '\0')) {
				(void) fprintf(stderr, "%s: invalid shared memory control block ID\n", progname);
				exit(BS_BADARG);
			}
		}
		else if (!strcmp(*argv, "-f")) {
			if (argc < 2)
				usage();
			argc--, argv++;
			if ((fp= fopen(*argv, "w")) == (FILE *) NULL) {
				(void) fprintf(stderr, "%s: cannot open file '%s'\n", progname, *argv);
				exit(BS_OPEN);
			}
		}
		else if (!strcmp(*argv, "-h"))
			output= OUTPUT_HDRSONLY;
		else if (!strcmp(*argv, "-d"))
			output= OUTPUT_DATAONLY;
		else if (!strcmp(*argv, "-nip"))
			showivisping= 0;
		else if (!strcmp(*argv, "-nsns"))
			showsns= 0;
		else if (!strcmp(*argv, "-nb"))
			showbty= 0;
		else if (!strcmp(*argv, "-nbd"))
			showbtyd= 0;
		else if (!strcmp(*argv, "-nbf"))
			showbtyfl= 0;
		else if (!strcmp(*argv, "-nabi"))
			showabi= 0;
		else if (!strcmp(*argv, "-ns"))
			showss= 0;
		else if (!strcmp(*argv, "-nsd"))
			showssd= 0;
		else if (!strcmp(*argv, "-nsf"))
			showssfl= 0;
		else if (!strcmp(*argv, "-i"))
			ignorecnt= 1;
		else if (!strcmp(*argv, "-pco"))
			pngcntonly= 1;
		else if (!strcmp(*argv, "-jt"))
			tmmode= TM_JULIAN;
		else if (!strcmp(*argv, "-ct"))
			tmmode= TM_CALENDAR;
		else if (!strcmp(*argv, "-H"))
			usage();

		/* ignored options */
		else if (!strcmp(*argv, "-tv")) {
			if (argc < 3)
				usage();
			argc-= 2, argv+= 2;
		}
		else if (!strcmp(*argv, "-spm"))
			continue;
		else if (!strcmp(*argv, "-ppm"))
			continue;
		else if (!strncmp(*argv, "-pb", 3))
			continue;
		else if (!strncmp(*argv, "-pp", 3))
			continue;
		else if (!strncmp(*argv, "-ps", 3))
			continue;
	}

	switch (iomode) {
	case BS_FILEIO:
		xdrstdio_create(&xdri, stdin, XDR_DECODE);

		if ((err= mbbs_rdbsfhdr(&bsf, &xdri)) != BS_SUCCESS) {
			(void) fprintf(stderr, "%s: cannot read BS file header\n", progname);
			exit(err);
		}
		if (bsf.bsf_flags & BS_SSSLANTRNG)
			slantrng= 1;
		else
			slantrng= 0;
		if (pngcntonly) {
			(void) fprintf(fp, "%1d\n", bsf.bsf_count);
			(void) fflush(fp);
			exit(BS_SUCCESS);
		}
		if (ignorecnt == 1)
			;
		else if (count == BS_UNDEFINED) {
			if ((count= bsf.bsf_count-skip) < 0) {
				(void) fprintf(stderr, "%s: skip request exceeds number of available pings\n", progname);
				exit(BS_BADARG);
			}
		}
		else {
			if (skip+count > bsf.bsf_count) {
				(void) fprintf(stderr, "%s: skip and count requests exceed number of available pings\n", progname);
				exit(BS_BADARG);
			}
		}
		if ((err= mbbs_seekpng(skip, &xdri, bsf.bsf_version)) != BS_SUCCESS) {
			(void) fprintf(stderr, "%s: ping seek error\n", progname);
			exit(err);
		}
		if (output != OUTPUT_DATAONLY)
			pr_bsfhdr(&bsf);

		break;
	case BS_SHAREDMEM:
		if (pngcntonly) {
			(void) fprintf(fp, "%1d\n", smctl->sm_count);
			(void) fflush(fp);
			exit(BS_SUCCESS);
		}
		if (ignorecnt == 1) {
			(void) fprintf(stderr, "%s: count cannot be ignored in shared memory mode\n", progname);
			exit(BS_BADARG);
		}
		if ((smctl= (SMControl *) shmat(smcid, (MemType *) 0, (int) 0)) == (SMControl *) -1) {
			(void) fprintf(stderr, "%s: shared memory attach failure\n", progname);
			exit(BS_SYSVIPC);
		}
		if (smctl->sm_slantrng)
			slantrng= 1;
		else
			slantrng= 0;
		if (count == BS_UNDEFINED) {
			if ((count= smctl->sm_count-skip) < 0) {
				(void) fprintf(stderr, "%s: skip request exceeds number of available pings\n", progname);
				smctl->sm_status= BS_BADARG;
				exit(BS_BADARG);
			}
		}
		else if (skip+count > smctl->sm_count) {
			(void) fprintf(stderr, "%s: skip and count requests exceed number of available pings\n", progname);
			smctl->sm_status= BS_BADARG;
			exit(BS_BADARG);
		}
		if ((smind= (int *) shmat(smctl->sm_shmiid, (MemType *) 0, (int) 0)) == (int *) -1) {
			(void) fprintf(stderr, "%s: shared memory attach failure\n", progname);
			smctl->sm_status= BS_SYSVIPC;
			exit(BS_SYSVIPC);
		}
		if ((smbuf= (void *) shmat(smctl->sm_shmdid, (MemType *) 0, (int) 0)) == (void *) -1) {
			(void) fprintf(stderr, "%s: shared memory attach failure\n", progname);
			smctl->sm_status= BS_SYSVIPC;
			exit(BS_SYSVIPC);
		}
		(void) strcpy(smctl->sm_msg, "ASCII output");
		smctl->sm_msgtype= SMC_MSGALTPCT;
		cp= (char *) smbuf;
		cp+= smind[skip];
		pngp= (Ping *) cp;
		break;
	}

	for (i= 0; (i < count) || ((count == BS_UNDEFINED) && (ignorecnt == 1)); i++) {
		switch (iomode) {
		case BS_FILEIO:
			if ((err= mbbs_rdpnghdr(&png, &xdri, bsf.bsf_version)) != BS_SUCCESS) {
				(void) fprintf(stderr, "%s: cannot read header from ping %1d\n", progname, (int) (skip+i));
				exit(err);
			}
			if ((err= mbbs_pngrealloc(&png, &databuf, &databufsz)) != BS_SUCCESS) {
				(void) fprintf(stderr, "%s: memory allocation error for ping %1d\n", progname, (int) (skip+i));
				exit(err);
			}
			if ((err= mbbs_rdpngdata(&png, databuf, &xdri)) != BS_SUCCESS) {
				(void) fprintf(stderr, "%s: cannot read data from ping %1d\n", progname, (int) (skip+i));
				exit(err);
			}
			pngp= &png;
			break;
		case BS_SHAREDMEM:
			cp= (char *) pngp;
			cp+= sizeof(Ping);
			databuf= (float *) cp;
			break;
		}
		if ((err= mbbs_getpngdataptrs(pngp, databuf, &pd)) != BS_SUCCESS) {
			(void) fprintf(stderr, "%s: cannot get ping data pointers\n", progname);
			exit(err);
		}

		(void) fprintf(fp, "\n\nPing %1d ****\n\n", (int) (i+skip));
		if (output != OUTPUT_DATAONLY)
			pr_pnghdr(pngp);

		if ((output != OUTPUT_HDRSONLY) &&
		    (showivisping || mbbs_pngvisible(pngp->png_flags))) {
			if (showsns) {
				(void) fprintf(fp, "\nCompass Data:\n");
				for (j= 0; j < pngp->png_compass.sns_nsamps; j++) {
					if (mbbs_isnanf(pd.pd_compass[j]))
						(void) fprintf(fp, "   ?\n");
					else
						(void) fprintf(fp, "%4.2f\n", pd.pd_compass[j]);
				}

				(void) fprintf(fp, "\nDepth Data:\n");
				for (j= 0; j < pngp->png_depth.sns_nsamps; j++) {
					if (mbbs_isnanf(pd.pd_depth[j]))
						(void) fprintf(fp, "   ?\n");
					else
						(void) fprintf(fp, "%4.2f\n", pd.pd_depth[j]);
				}

				(void) fprintf(fp, "\nPitch Data:\n");
				for (j= 0; j < pngp->png_pitch.sns_nsamps; j++) {
					if (mbbs_isnanf(pd.pd_pitch[j]))
						(void) fprintf(fp, "   ?\n");
					else
						(void) fprintf(fp, "%4.2f\n", pd.pd_pitch[j]);
				}

				(void) fprintf(fp, "\nRoll Data:\n");
				for (j= 0; j < pngp->png_roll.sns_nsamps; j++) {
					if (mbbs_isnanf(pd.pd_roll[j]))
						(void) fprintf(fp, "   ?\n");
					else
						(void) fprintf(fp, "%4.2f\n", pd.pd_roll[j]);
				}
			}

			if (showbty) {
				if (pngp->png_flags & PNG_XYZ)
					bsi= 3;
				else
					bsi= 2;
				for (side= ACP_PORT; side < ACP_NSIDES; side++) {
					(void) fprintf(fp, "\n%s Bathymetry Data:\n[Index]        X        ", side == ACP_PORT ? "Port" : "Starboard");
					if (bsi == 3)
						(void) fprintf(fp, "Y        ");
					(void) fprintf(fp, "Z    ");
					if (showbtyfl)
						(void) fprintf(fp, "Flag    ");
					if ((pngp->png_flags & PNG_ABI) && showabi)
						(void) fprintf(fp, "Beam    SSAT0    SSAT1 ABIFlag");
					(void) fprintf(fp, "\n");
					if ((npts= pngp->png_sides[side].ps_btycount) == 0)
						continue;
					bty= pd.pd_bty[side];
					for (j= 0; j < npts; j++) {
						if (!showbtyd && pd.pd_btyflags[side][j])
							continue;
						(void) fprintf(fp, "[%5d]   %8.2f ", j, bty[bsi*j]);
						if (bsi == 3)
							(void) fprintf(fp, "%8.2f %8.2f", bty[(bsi*j)+1], bty[(bsi*j)+2]);
						else
							(void) fprintf(fp, "%8.2f", bty[(bsi*j)+1]);
						if (showbtyfl)
							(void) fprintf(fp, "%#6x  ", pd.pd_btyflags[side][j]);
						if ((pngp->png_flags & PNG_ABI) && showabi) {
							abi= &(pd.pd_abi[side][j]);
							(void) fprintf(fp, "%6d ", abi->abi_id);
							if (mbbs_isnanf(abi->abi_ssat0))
								(void) fprintf(fp, "       ? ");
							else
								(void) fprintf(fp, "%8.2f ", abi->abi_ssat0);
							if (mbbs_isnanf(abi->abi_ssat1))
								(void) fprintf(fp, "       ?  ");
							else
								(void) fprintf(fp, "%8.2f  ", abi->abi_ssat1);
							(void) fprintf(fp, "%#6x", abi->abi_flags);
						}
						(void) fprintf(fp, "\n");
					}
				}
			}

			if (showss) {
				for (side= ACP_PORT; side < ACP_NSIDES; side++) {
					(void) fprintf(fp, "\n%s Sidescan Data:\n[Index]      Intensity", side == ACP_PORT ? "Port" : "Starboard");
					if (showssfl)
						(void) fprintf(fp, "     Flag");
					(void) fprintf(fp, "\n");
					npts= pngp->png_sides[side].ps_sscount;
					ss= pd.pd_ss[side];
					for (j= 0; j < npts; j++) {
						if (!showssd && pd.pd_ssflags[side][j])
							continue;
						(void) fprintf(fp, "[%5d]   %12.2f", j, ss[j]);
						if (showssfl)
							(void) fprintf(fp, "   %#6x", (unsigned int) pd.pd_ssflags[side][j]);
						(void) fprintf(fp, "\n");
					}
				}
			}
		}

		(void) fprintf(fp, "\n");

		switch (iomode) {
		case BS_FILEIO:
			break;
		case BS_SHAREDMEM:
			smctl->sm_ping= skip+i;
			if (i < count-1) {
				cp= (char *) smbuf;
				cp+= smind[skip+i+1];
				pngp= (Ping *) cp;
			}
			break;
		}
	}

	switch (iomode) {
	case BS_FILEIO:
		break;
	case BS_SHAREDMEM:
		smctl->sm_status= BS_SUCCESS;
		smctl->sm_redraw= SMC_RDRNONE;
		break;
	}

	exit(BS_SUCCESS);
}