コード例 #1
0
TEST(StringTest, FormatString)
{
    char *str = mb_format("Hello, %s!", "World");
    ASSERT_NE(str, nullptr);
    ASSERT_STREQ(str, "Hello, World!");
    free(str);
}
コード例 #2
0
TEST(StringTest, FormatEmptyString)
{
    char *str = mb_format("");
    ASSERT_NE(str, nullptr);
    ASSERT_STREQ(str, "");
    free(str);
}
コード例 #3
0
TEST(StringTest, FormatSizeT)
{
    ptrdiff_t signed_val = 0x7FFFFFFF;
    size_t unsigned_val = 0xFFFFFFFFu;

    char *signed_d_str = mb_format("%" MB_PRIzd, signed_val);
    ASSERT_NE(signed_d_str, nullptr);
    ASSERT_STREQ(signed_d_str, "2147483647");
    free(signed_d_str);

    char *signed_i_str = mb_format("%" MB_PRIzi, signed_val);
    ASSERT_NE(signed_i_str, nullptr);
    ASSERT_STREQ(signed_i_str, "2147483647");
    free(signed_i_str);

    char *unsigned_o_str = mb_format("%" MB_PRIzo, unsigned_val);
    ASSERT_NE(unsigned_o_str, nullptr);
    ASSERT_STREQ(unsigned_o_str, "37777777777");
    free(unsigned_o_str);

    char *unsigned_u_str = mb_format("%" MB_PRIzu, unsigned_val);
    ASSERT_NE(unsigned_u_str, nullptr);
    ASSERT_STREQ(unsigned_u_str, "4294967295");
    free(unsigned_u_str);

    char *unsigned_x_str = mb_format("%" MB_PRIzx, unsigned_val);
    ASSERT_NE(unsigned_x_str, nullptr);
    ASSERT_STREQ(unsigned_x_str, "ffffffff");
    free(unsigned_x_str);

    char *unsigned_X_str = mb_format("%" MB_PRIzX, unsigned_val);
    ASSERT_NE(unsigned_X_str, nullptr);
    ASSERT_STREQ(unsigned_X_str, "FFFFFFFF");
    free(unsigned_X_str);
}
コード例 #4
0
ファイル: delete.cpp プロジェクト: Caio99BR/DualBootPatcher
 bool delete_path()
 {
     if (remove(_curr->fts_accpath) < 0) {
         char *msg = mb_format("%s: Failed to remove: %s",
                               _curr->fts_path, strerror(errno));
         if (msg) {
             _error_msg = msg;
             free(msg);
         }
         LOGE("%s", _error_msg.c_str());
         return false;
     }
     return true;
 }
コード例 #5
0
ファイル: chmod.cpp プロジェクト: Caio99BR/DualBootPatcher
 bool chmod_path()
 {
     if (::chmod(_curr->fts_accpath, _perms) < 0) {
         char *msg = mb_format("%s: Failed to chmod: %s",
                               _curr->fts_path, strerror(errno));
         if (msg) {
             _error_msg = msg;
             free(msg);
         }
         LOGW("%s", _error_msg.c_str());
         return false;
     }
     return true;
 }
コード例 #6
0
 bool copy_path()
 {
     if (!util::copy_file(_curr->fts_accpath, _curtgtpath,
                          util::COPY_ATTRIBUTES | util::COPY_XATTRS)) {
         char *msg = mb_format("%s: Failed to copy file: %s",
                               _curr->fts_path, strerror(errno));
         if (msg) {
             _error_msg = msg;
             free(msg);
         }
         LOGW("%s", _error_msg.c_str());
         return false;
     }
     return true;
 }
コード例 #7
0
    virtual int on_reached_directory_pre() override
    {
        if (_curr->fts_level == 0) {
            return Action::FTS_OK;
        }

        // _target is the correct parameter here (or pathbuf and
        // COPY_EXCLUDE_TOP_LEVEL flag)
        if (!util::copy_dir(_curr->fts_accpath, _target,
                            util::COPY_ATTRIBUTES | util::COPY_XATTRS)) {
            char *msg = mb_format("%s: Failed to copy directory: %s",
                                  _curr->fts_path, strerror(errno));
            if (msg) {
                _error_msg = msg;
                free(msg);
            }
            LOGW("%s", _error_msg.c_str());
            return Action::FTS_Skip | Action::FTS_Fail;
        }
        return Action::FTS_Skip;
    }
コード例 #8
0
ファイル: mbhistogram.c プロジェクト: dwcaress/MB-System
int main (int argc, char **argv)
{
	char program_name[] = "MBHISTOGRAM";
	char help_message[] =  "MBHISTOGRAM reads a swath sonar data file and generates a histogram\n\tof the bathymetry,  amplitude,  or sidescan values. Alternatively, \n\tmbhistogram can output a list of values which break up the\n\tdistribution into equal sized regions.\n\tThe results are dumped to stdout.";
	char usage_message[] = "mbhistogram [-Akind -Byr/mo/da/hr/mn/sc -Dmin/max -Eyr/mo/da/hr/mn/sc -Fformat -G -Ifile -Llonflip -Mnintervals -Nnbins -Ppings -Rw/e/s/n -Sspeed -V -H]";
	extern char *optarg;
	int	errflg = 0;
	int	c;
	int	help = 0;
	int	flag = 0;

	/* MBIO status variables */
	int	status = MB_SUCCESS;
	int	verbose = 0;
	int	error = MB_ERROR_NO_ERROR;
	char	*message;

	/* MBIO read control parameters */
	int	read_datalist = MB_NO;
	char	read_file[MB_PATH_MAXLINE];
	void	*datalist;
	int	look_processed = MB_DATALIST_LOOK_UNSET;
	double	file_weight;
	int	format;
	int	pings;
	int	lonflip;
	double	bounds[4];
	int	btime_i[7];
	int	etime_i[7];
	double	btime_d;
	double	etime_d;
	double	speedmin;
	double	timegap;
	char	file[MB_PATH_MAXLINE];
	int	beams_bath;
	int	beams_amp;
	int	pixels_ss;

	/* MBIO read values */
	void	*mbio_ptr = NULL;
	int	kind;
	int	time_i[7];
	double	time_d;
	double	navlon;
	double	navlat;
	double	speed;
	double	heading;
	double	distance;
	double	altitude;
	double	sonardepth;
	char	*beamflag = NULL;
	double	*bath = NULL;
	double	*bathacrosstrack = NULL;
	double	*bathalongtrack = NULL;
	double	*amp = NULL;
	double	*ss = NULL;
	double	*ssacrosstrack = NULL;
	double	*ssalongtrack = NULL;
	char	comment[MB_COMMENT_MAXLINE];

	/* histogram variables */
	int	mode = MBHISTOGRAM_SS;
	int	gaussian = MB_NO;
	int	nbins = 0;
	int	nintervals = 0;
	double	value_min = 0.0;
	double	value_max = 128.0;
	double	dvalue_bin;
	double	value_bin_min;
	double	value_bin_max;
	double	data_min;
	double	data_max;
	int	data_first = MB_YES;
	double	target_min;
	double	target_max;
	double	*histogram = NULL;
	double	*intervals = NULL;
	double	total;
	double	sum;
	double	p;
	double	target;
	double	dinterval;
	double	bin_fraction;
	int	ibin;

	/* output stream for basic stuff (stdout if verbose <= 1,
		stderr if verbose > 1) */
	FILE	*output;

	int	read_data;
	int	nrec, nvalue;
	int	nrectot = 0;
	int	nvaluetot = 0;
	int	i, j;

	/* get current default values */
	status = mb_defaults(verbose,&format,&pings,&lonflip,bounds,
		btime_i,etime_i,&speedmin,&timegap);

	/* set default input to stdin */
	strcpy (read_file, "stdin");

	/* process argument list */
	while ((c = getopt(argc, argv, "A:a:B:b:D:d:E:e:F:f:GgHhI:i:L:l:M:m:N:n:P:p:R:r:S:s:T:t:Vv")) != -1)
	  switch (c)
		{
		case 'A':
		case 'a':
			sscanf (optarg,"%d", &mode);
			flag++;
			break;
		case 'B':
		case 'b':
			sscanf (optarg,"%d/%d/%d/%d/%d/%d",
				&btime_i[0],&btime_i[1],&btime_i[2],
				&btime_i[3],&btime_i[4],&btime_i[5]);
			btime_i[6] = 0;
			flag++;
			break;
		case 'D':
		case 'd':
			sscanf (optarg,"%lf/%lf", &value_min,&value_max);
			flag++;
			break;
		case 'E':
		case 'e':
			sscanf (optarg,"%d/%d/%d/%d/%d/%d",
				&etime_i[0],&etime_i[1],&etime_i[2],
				&etime_i[3],&etime_i[4],&etime_i[5]);
			etime_i[6] = 0;
			flag++;
			break;
		case 'F':
		case 'f':
			sscanf (optarg,"%d", &format);
			flag++;
			break;
		case 'G':
		case 'g':
			gaussian = MB_YES;
			break;
		case 'H':
		case 'h':
			help++;
			break;
		case 'I':
		case 'i':
			sscanf (optarg,"%s", read_file);
			flag++;
			break;
		case 'L':
		case 'l':
			sscanf (optarg,"%d", &lonflip);
			flag++;
			break;
		case 'M':
		case 'm':
			sscanf (optarg,"%d", &nintervals);
			flag++;
			break;
		case 'N':
		case 'n':
			sscanf (optarg,"%d", &nbins);
			flag++;
			break;
		case 'P':
		case 'p':
			sscanf (optarg,"%d", &pings);
			flag++;
			break;
		case 'R':
		case 'r':
			mb_get_bounds(optarg, bounds);
			flag++;
			break;
		case 'S':
		case 's':
			sscanf (optarg,"%lf", &speedmin);
			flag++;
			break;
		case 'T':
		case 't':
			sscanf (optarg,"%lf", &timegap);
			flag++;
			break;
		case 'V':
		case 'v':
			verbose++;
			break;
		case '?':
			errflg++;
		}

	/* set output stream */
	if (verbose <= 1)
		output = stdout;
	else
		output = stderr;

	/* if error flagged then print it and exit */
	if (errflg)
		{
		fprintf(output,"usage: %s\n", usage_message);
		fprintf(output,"\nProgram <%s> Terminated\n",
			program_name);
		error = MB_ERROR_BAD_USAGE;
		exit(error);
		}

	/* print starting message */
	if (verbose == 1 || help)
		{
		fprintf(output,"\nProgram %s\n",program_name);
		fprintf(output,"Version %s\n",rcs_id);
		fprintf(output,"MB-system Version %s\n",MB_VERSION);
		}

	/* get format if required */
	if (format == 0)
		mb_get_format(verbose,read_file,NULL,&format,&error);

	/* figure out histogram dimensions */
	if (nintervals > 0 && nbins <= 0)
		nbins = 50*nintervals;
	if (nbins <= 0)
		nbins = 16;

	/* print starting debug statements */
	if (verbose >= 2)
		{
		fprintf(output,"\ndbg2  Program <%s>\n",program_name);
		fprintf(output,"dbg2  Version %s\n",rcs_id);
		fprintf(output,"dbg2  MB-system Version %s\n",MB_VERSION);
		fprintf(output,"dbg2  Control Parameters:\n");
		fprintf(output,"dbg2       verbose:    %d\n",verbose);
		fprintf(output,"dbg2       help:       %d\n",help);
		fprintf(output,"dbg2       format:     %d\n",format);
		fprintf(output,"dbg2       pings:      %d\n",pings);
		fprintf(output,"dbg2       lonflip:    %d\n",lonflip);
		fprintf(output,"dbg2       bounds[0]:  %f\n",bounds[0]);
		fprintf(output,"dbg2       bounds[1]:  %f\n",bounds[1]);
		fprintf(output,"dbg2       bounds[2]:  %f\n",bounds[2]);
		fprintf(output,"dbg2       bounds[3]:  %f\n",bounds[3]);
		fprintf(output,"dbg2       btime_i[0]: %d\n",btime_i[0]);
		fprintf(output,"dbg2       btime_i[1]: %d\n",btime_i[1]);
		fprintf(output,"dbg2       btime_i[2]: %d\n",btime_i[2]);
		fprintf(output,"dbg2       btime_i[3]: %d\n",btime_i[3]);
		fprintf(output,"dbg2       btime_i[4]: %d\n",btime_i[4]);
		fprintf(output,"dbg2       btime_i[5]: %d\n",btime_i[5]);
		fprintf(output,"dbg2       btime_i[6]: %d\n",btime_i[6]);
		fprintf(output,"dbg2       etime_i[0]: %d\n",etime_i[0]);
		fprintf(output,"dbg2       etime_i[1]: %d\n",etime_i[1]);
		fprintf(output,"dbg2       etime_i[2]: %d\n",etime_i[2]);
		fprintf(output,"dbg2       etime_i[3]: %d\n",etime_i[3]);
		fprintf(output,"dbg2       etime_i[4]: %d\n",etime_i[4]);
		fprintf(output,"dbg2       etime_i[5]: %d\n",etime_i[5]);
		fprintf(output,"dbg2       etime_i[6]: %d\n",etime_i[6]);
		fprintf(output,"dbg2       speedmin:   %f\n",speedmin);
		fprintf(output,"dbg2       timegap:    %f\n",timegap);
		fprintf(output,"dbg2       file:       %s\n",read_file);
		fprintf(output,"dbg2       mode:       %d\n",mode);
		fprintf(output,"dbg2       gaussian:   %d\n",gaussian);
		fprintf(output,"dbg2       nbins:      %d\n",nbins);
		fprintf(output,"dbg2       nintervals: %d\n",nintervals);
		fprintf(output,"dbg2       value_min:  %f\n",value_min);
		fprintf(output,"dbg2       value_max:  %f\n",value_max);
		}

	/* if help desired then print it and exit */
	if (help)
		{
		fprintf(output,"\n%s\n",help_message);
		fprintf(output,"\nusage: %s\n", usage_message);
		exit(error);
		}

	/* allocate memory for histogram arrays */
	if (error == MB_ERROR_NO_ERROR)
		status = mb_mallocd(verbose,__FILE__,__LINE__,nbins*sizeof(double),
				(void **)&histogram,&error);
	if (error == MB_ERROR_NO_ERROR)
		status = mb_mallocd(verbose,__FILE__,__LINE__,nintervals*sizeof(double),
				(void **)&intervals,&error);

	/* if error initializing memory then quit */
	if (error != MB_ERROR_NO_ERROR)
		{
		mb_error(verbose,error,&message);
		fprintf(output,"\nMBIO Error allocating histogram arrays:\n%s\n",message);
		fprintf(output,"\nProgram <%s> Terminated\n",
			program_name);
		exit(error);
		}

	/* output some information */
	if (verbose > 0)
		{
		fprintf(stderr, "\nNumber of data bins: %d\n", nbins);
		fprintf(stderr, "Minimum value:         %f\n", value_min);
		fprintf(stderr, "Maximum value:         %f\n", value_max);
		if (mode == MBHISTOGRAM_BATH)
			fprintf(stderr, "Working on bathymetry data...\n");
		else if (mode == MBHISTOGRAM_AMP)
			fprintf(stderr, "Working on beam amplitude data...\n");
		else
			fprintf(stderr, "Working on sidescan data...\n");
		}

	/* get size of bins */
	dvalue_bin = (value_max - value_min)/(nbins-1);
	value_bin_min = value_min - 0.5*dvalue_bin;
	value_bin_max = value_max + 0.5*dvalue_bin;

	/* initialize histogram */
	for (i=0;i<nbins;i++)
		histogram[i] = 0;

	/* determine whether to read one file or a list of files */
	if (format < 0)
		read_datalist = MB_YES;

	/* open file list */
	if (read_datalist == MB_YES)
	    {
	    if ((status = mb_datalist_open(verbose,&datalist,
					    read_file,look_processed,&error)) != MB_SUCCESS)
		{
		error = MB_ERROR_OPEN_FAIL;
		fprintf(stderr,"\nUnable to open data list file: %s\n",
			read_file);
		fprintf(stderr,"\nProgram <%s> Terminated\n",
			program_name);
		exit(error);
		}
	    if ((status = mb_datalist_read(verbose,datalist,
			    file,&format,&file_weight,&error))
			    == MB_SUCCESS)
		read_data = MB_YES;
	    else
		read_data = MB_NO;
	    }
	/* else copy single filename to be read */
	else
	    {
	    strcpy(file, read_file);
	    read_data = MB_YES;
	    }

	/* loop over all files to be read */
	while (read_data == MB_YES)
	{

	/* obtain format array location - format id will
		be aliased to current id if old format id given */
	status = mb_format(verbose,&format,&error);

	/* initialize reading the swath sonar data file */
	if ((status = mb_read_init(
		verbose,file,format,pings,lonflip,bounds,
		btime_i,etime_i,speedmin,timegap,
		&mbio_ptr,&btime_d,&etime_d,
		&beams_bath,&beams_amp,&pixels_ss,&error)) != MB_SUCCESS)
		{
		mb_error(verbose,error,&message);
		fprintf(output,"\nMBIO Error returned from function <mb_read_init>:\n%s\n",message);
		fprintf(output,"\nMultibeam File <%s> not initialized for reading\n",file);
		fprintf(output,"\nProgram <%s> Terminated\n",
			program_name);
		exit(error);
		}

	/* allocate memory for data arrays */
	if (error == MB_ERROR_NO_ERROR)
		status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY,
						sizeof(char), (void **)&beamflag, &error);
	if (error == MB_ERROR_NO_ERROR)
		status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY,
						sizeof(double), (void **)&bath, &error);
	if (error == MB_ERROR_NO_ERROR)
		status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_AMPLITUDE,
						sizeof(double), (void **)&amp, &error);
	if (error == MB_ERROR_NO_ERROR)
		status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY,
						sizeof(double), (void **)&bathacrosstrack, &error);
	if (error == MB_ERROR_NO_ERROR)
		status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_BATHYMETRY,
						sizeof(double), (void **)&bathalongtrack, &error);
	if (error == MB_ERROR_NO_ERROR)
		status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_SIDESCAN,
						sizeof(double), (void **)&ss, &error);
	if (error == MB_ERROR_NO_ERROR)
		status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_SIDESCAN,
						sizeof(double), (void **)&ssacrosstrack, &error);
	if (error == MB_ERROR_NO_ERROR)
		status = mb_register_array(verbose, mbio_ptr, MB_MEM_TYPE_SIDESCAN,
						sizeof(double), (void **)&ssalongtrack, &error);

	/* if error initializing memory then quit */
	if (error != MB_ERROR_NO_ERROR)
		{
		mb_error(verbose,error,&message);
		fprintf(output,"\nMBIO Error allocating data arrays:\n%s\n",message);
		fprintf(output,"\nProgram <%s> Terminated\n",
			program_name);
		exit(error);
		}

	/* output information */
	if (error == MB_ERROR_NO_ERROR && verbose > 0)
	    {
	    fprintf(stderr, "\nprocessing file: %s %d\n", file, format);
	    }

	/* initialize counting variables */
	nrec = 0;
	nvalue = 0;

	/* read and process data */
	while (error <= MB_ERROR_NO_ERROR)
		{

		/* read a ping of data */
		status = mb_get(verbose,mbio_ptr,&kind,&pings,
				time_i,&time_d,
				&navlon,&navlat,
				&speed,&heading,
				&distance,&altitude,&sonardepth,
				&beams_bath,&beams_amp,&pixels_ss,
				beamflag,bath,amp,bathacrosstrack,bathalongtrack,
				ss,ssacrosstrack,ssalongtrack,
				comment,&error);

		/* process the pings */
		if (error == MB_ERROR_NO_ERROR
			|| error == MB_ERROR_TIME_GAP)
			{
			/* increment record counter */
			nrec++;

			/* do the bathymetry */
			if (mode == MBHISTOGRAM_BATH)
			for (i=0;i<beams_bath;i++)
				{
				if (mb_beam_ok(beamflag[i]))
					{
					nvalue++;
					j = (bath[i] - value_bin_min)
						/dvalue_bin;
					if (j >= 0 && j < nbins)
						histogram[j]++;
					if (data_first == MB_YES)
						{
						data_min = bath[i];
						data_max = bath[i];
						data_first = MB_NO;
						}
					else
						{
						data_min = MIN(bath[i], data_min);
						data_max = MAX(bath[i], data_max);
						}
					}
				}

			/* do the amplitude */
			if (mode == MBHISTOGRAM_AMP)
			for (i=0;i<beams_amp;i++)
				{
				if (mb_beam_ok(beamflag[i]))
					{
					nvalue++;
					j = (amp[i] - value_bin_min)
						/dvalue_bin;
					if (j >= 0 && j < nbins)
						histogram[j]++;
					if (data_first == MB_YES)
						{
						data_min = amp[i];
						data_max = amp[i];
						data_first = MB_NO;
						}
					else
						{
						data_min = MIN(amp[i], data_min);
						data_max = MAX(amp[i], data_max);
						}
					}
				}

			/* do the sidescan */
			if (mode == MBHISTOGRAM_SS)
			for (i=0;i<pixels_ss;i++)
				{
				if (ss[i] > MB_SIDESCAN_NULL)
					{
					nvalue++;
					j = (ss[i] - value_bin_min)
						/dvalue_bin;
					if (j >= 0 && j < nbins)
						histogram[j]++;
					if (data_first == MB_YES)
						{
						data_min = ss[i];
						data_max = ss[i];
						data_first = MB_NO;
						}
					else
						{
						data_min = MIN(ss[i], data_min);
						data_max = MAX(ss[i], data_max);
						}
					}
				}

			}
		}

	/* close the swath sonar data file */
	status = mb_close(verbose,&mbio_ptr,&error);
	nrectot += nrec;
	nvaluetot += nvalue;

	/* output information */
	if (error == MB_ERROR_NO_ERROR && verbose > 0)
	    {
	    fprintf(stderr, "%d records processed\n%d data processed\n",
		    nrec, nvalue);
	    }

	/* figure out whether and what to read next */
        if (read_datalist == MB_YES)
                {
		if ((status = mb_datalist_read(verbose,datalist,
			    file,&format,&file_weight,&error))
			    == MB_SUCCESS)
                        read_data = MB_YES;
                else
                        read_data = MB_NO;
                }
        else
                {
                read_data = MB_NO;
                }

	/* end loop over files in list */
	}
	if (read_datalist == MB_YES)
		mb_datalist_close(verbose,&datalist,&error);

	/* output information */
	if (error == MB_ERROR_NO_ERROR && verbose > 0)
	    {
	    fprintf(stderr, "\n%d total records processed\n", nrectot);
	    fprintf(stderr, "%d total data processed\n\n", nvaluetot);
	    }

	/* recast histogram as gaussian */
	if (gaussian == MB_YES)
		{
		/* get total number of good values */
		total = 0.0;
		for (i=0;i<nbins;i++)
			total = total + histogram[i];

		/* recast histogram */
		sum = 0.0;
		for (i=0;i<nbins;i++)
			{
			p = (histogram[i]/2 + sum)/(total + 1);
			sum = sum + histogram[i];
			histogram[i] = qsnorm(p);
			}
		}

	/* calculate gaussian intervals if required */
	if (nintervals > 0 && gaussian == MB_YES)
		{
		/* get interval spacing */
		target_min = -2.0;
		target_max = 2.0;
		dinterval = (target_max - target_min)/(nintervals-1);

		/* get intervals */
		intervals[0] = MAX(data_min, value_min);
		intervals[nintervals-1] = MIN(data_max, value_max);
		ibin = 0;
		for (j=1;j<nintervals-1;j++)
			{
			target = target_min + j*dinterval;
			while (histogram[ibin] < target && ibin < nbins-1)
				ibin++;
			if (ibin > 0)
				bin_fraction = 1.0 - (histogram[ibin] - target)
					/(histogram[ibin] - histogram[ibin-1]);
			else
				bin_fraction = 0.0;
			intervals[j] = value_bin_min
					+ dvalue_bin*ibin
					+ bin_fraction*dvalue_bin;
			}
		}

	/* calculate linear intervals if required */
	else if (nintervals > 0)
		{
		/* get total number of good values */
		total = 0.0;
		for (i=0;i<nbins;i++)
			total = total + histogram[i];

		/* get interval spacing */
		dinterval = total/(nintervals-1);

		/* get intervals */
		intervals[0] = value_bin_min;
		total = 0.0;
		ibin = -1;
		for (j=1;j<nintervals;j++)
			{
			target = j*dinterval;
			while (total < target && ibin < nbins-1)
				{
				ibin++;
				total = total + histogram[ibin];
				if (total <= 0.0)
					intervals[0] = value_bin_min
						+ dvalue_bin*ibin;
				}
			bin_fraction = 1.0 - (total - target)/histogram[ibin];
			intervals[j] = value_bin_min
					+ dvalue_bin*ibin
					+ bin_fraction*dvalue_bin;
			}
		}

	/* print out the results */
	if (nintervals <= 0 && gaussian == MB_YES)
		{
		for (i=0;i<nbins;i++)
			{
			fprintf(output,"%f %f\n",
				value_min+i*dvalue_bin,histogram[i]);
			}
		}
	else if (nintervals <= 0)
		{
		for (i=0;i<nbins;i++)
			{
			fprintf(output,"%f %d\n",
				value_min+i*dvalue_bin,(int)histogram[i]);
			}
		}
	else
		{
		for (i=0;i<nintervals;i++)
			fprintf(output,"%f\n",intervals[i]);
		}

	/* deallocate memory used for data arrays */
	mb_freed(verbose,__FILE__,__LINE__,(void **)&histogram,&error);
	mb_freed(verbose,__FILE__,__LINE__,(void **)&intervals,&error);

	/* set program status */
	status = MB_SUCCESS;

	/* check memory */
	if (verbose >= 4)
		status = mb_memory_list(verbose,&error);

	/* print output debug statements */
	if (verbose >= 2)
		{
		fprintf(output,"\ndbg2  Program <%s> completed\n",
			program_name);
		fprintf(output,"dbg2  Ending status:\n");
		fprintf(output,"dbg2       status:  %d\n",status);
		}

	/* end it all */
	fprintf(output,"\n");
	exit(error);
}
コード例 #9
0
ファイル: mbformat.c プロジェクト: jbrahy/mb-system
int main (int argc, char **argv)
{
	/* id variables */
	char program_name[] = "MBFORMAT";
	char help_message[] = "MBFORMAT is an utility which identifies the swath data formats \nassociated with MBIO format id's.  If no format id is specified, \nMBFORMAT lists all of the currently supported formats.";
	char usage_message[] = "mbformat [-Fformat -Ifile -L -W -V -H]";

	/* parsing variables */
	extern char *optarg;
	int	errflg = 0;
	int	c;
	int	error = MB_ERROR_NO_ERROR;
	int	status;
	int	help;
	int	html;
	int	verbose;
	char	file[MB_PATH_MAXLINE];
	char	root[MB_PATH_MAXLINE];
	int	file_specified;
	int	format;
	int	format_save;
	int	format_specified;
	char	format_description[MB_DESCRIPTION_LENGTH];
	char	*format_informal_ptr;
	char	*format_attributes_ptr;
	char	format_name[MB_DESCRIPTION_LENGTH];
	char	format_informal[MB_DESCRIPTION_LENGTH];
	char	format_attributes[MB_DESCRIPTION_LENGTH];
	int	list_mode;
	int	i;

	help = 0;
	verbose = 0;
	file_specified = MB_NO;
	format = 0;
	format_specified = MB_NO;
	html = MB_NO;
	list_mode = MBFORMAT_LIST_LONG;

	/* process argument list */
	while ((c = getopt(argc, argv, "F:f:HhI:i:LlKkVvWw")) != -1)
	  switch (c) 
		{
		case 'F':
		case 'f':
			sscanf (optarg,"%d", &format);
			format_specified = MB_YES;
			break;
		case 'L':
		case 'l':
			list_mode = MBFORMAT_LIST_SIMPLE;
			break;
		case 'K':
		case 'k':
			list_mode = MBFORMAT_LIST_ROOT;
			break;
		case 'H':
		case 'h':
			help++;
			break;
		case 'I':
		case 'i':
			sscanf (optarg,"%s", file);
			file_specified = MB_YES;
			break;
		case 'V':
		case 'v':
			verbose++;
			break;
		case 'W':
		case 'w':
			html = MB_YES;
			break;
		case '?':
			errflg++;
		}

	/* if error flagged then print it and exit */
	if (errflg)
		{
		fprintf(stderr,"usage: %s\n", usage_message);
		error = MB_ERROR_BAD_USAGE;
		exit(error);
		}

	/* print starting message */
	if (verbose == 1 || help)
		{
		fprintf(stderr,"\nProgram %s\n",program_name);
		fprintf(stderr,"MB-system Version %s\n",MB_VERSION);
		}

	/* print starting debug statements */
	if (verbose >= 2)
		{
		fprintf(stderr,"\ndbg2  Program <%s>\n",program_name);
		fprintf(stderr,"dbg2  MB-system Version %s\n",MB_VERSION);
		fprintf(stderr,"dbg2  Control Parameters:\n");
		fprintf(stderr,"dbg2       verbose: %d\n",verbose);
		fprintf(stderr,"dbg2       help:    %d\n",help);
		if (format_specified == MB_YES)
		    fprintf(stderr,"dbg2       format:  %d\n",format);
		if (file_specified == MB_YES)
		    fprintf(stderr,"dbg2       file:    %s\n",file);
		}

	/* if help desired then print it and exit */
	if (help)
		{
		fprintf(stderr,"\n%s\n",help_message);
		fprintf(stderr,"\nusage: %s\n", usage_message);
		exit(error);
		}
		
	/* print out the info */
	if (file_specified == MB_YES)
		{
		format_save = format;
		status = mb_get_format(verbose,file,root,&format,&error);
		}
	else if (format_specified == MB_YES)
		{
		format_save = format;
		status = mb_format(verbose,&format,&error);
		}
	if (file_specified == MB_YES
		&& format == 0)
		{
		if (list_mode == MBFORMAT_LIST_SIMPLE)
			printf("%d\n",format);
		else if (list_mode == MBFORMAT_LIST_ROOT)
			printf("%s %d\n", root, format);
		else
			printf("Program %s unable to infer format from filename %s\n",program_name,file);
		}
	else if (format_specified == MB_YES
		&& format == 0)
		{
		if (list_mode == MBFORMAT_LIST_SIMPLE)
			printf("%d\n",format);
		else if (list_mode == MBFORMAT_LIST_ROOT)
			printf("%s %d\n", root, format);
		else
			printf("Specified format %d invalid for MB-System\n",format_save);
		}
	else if (format != 0)
		{
		if (list_mode == MBFORMAT_LIST_SIMPLE)
			{
			printf("%d\n",format);
			}
		else if (list_mode == MBFORMAT_LIST_ROOT)
			{
			printf("%s %d\n", root, format);
			}
		else
			{
			status = mb_format_description(verbose,&format,format_description,&error);
			if (status == MB_SUCCESS)
				{
				printf("\nMBIO data format id: %d\n",format);
				printf("%s",format_description);
				}
			else if (file_specified == MB_YES)
				{
				printf("Program %s unable to infer format from filename %s\n",program_name,file);
				}
			else if (format_specified == MB_YES)
				{
				printf("Specified format %d invalid for MB-System\n",format_save);
				}
			}
		}
	else if (html == MB_YES)
		{
		printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
		printf("<HTML>\n<HEAD>\n   <TITLE>MB-System Supported Data Formats</TITLE>\n");
		printf("</HEAD>\n<BODY TEXT=\"#000000\" BGCOLOR=\"#FFFFFF\" LINK=\"#336699\" VLINK=\"#997040\" ALINK=\"#CC9900\">\n\n");
		printf("<CENTER><P><B><FONT SIZE=+2>MB-System Supported Swath Data Formats</FONT></B></P></CENTER>\n\n");
		printf("<P>Each swath mapping sonar system outputs a data stream which includes\n");
		printf("some values or parameters unique to that system. In general, a number of\n");
		printf("different data formats have come into use for data from each of the sonar\n");
		printf("systems; many of these formats include only a subset of the original data\n");
		printf("stream. Internally, MBIO recognizes which sonar system each data format\n");
		printf("is associated with and uses a data structure including the complete data\n");
		printf("stream for that sonar. At present, formats associated with the following\n");
		printf("sonars are supported: </P>\n\n");
		printf("<UL>\n<LI>Sea Beam &quot;classic&quot; multibeam sonar </LI>\n\n");
		printf("<LI>Hydrosweep DS multibeam sonar </LI>\n\n");
		printf("<LI>Hydrosweep DS2 multibeam sonar </LI>\n\n");
		printf("<LI>Hydrosweep MD multibeam sonar </LI>\n\n");
		printf("<LI>Sea Beam 2000 multibeam sonar </LI>\n\n");
		printf("<LI>Sea Beam 2112 and 2136 multibeam sonars </LI>\n\n");
		printf("<LI>Sea Beam 2120 multibeam sonars </LI>\n\n");
		printf("<LI>Simrad EM12, EM121, EM950, and EM1000 multibeam sonars </LI>\n\n");
		printf("<LI>Simrad EM120, EM300, and EM3000 multibeam sonars</LI>\n\n");
		printf("<LI>Simrad EM122, EM302, EM710, and EM3002 multibeam sonars</LI>\n\n");
		printf("<LI>Simrad Mesotech SM2000 multibeam sonar</LI>\n\n");
		printf("<LI>Hawaii MR-1 shallow tow interferometric sonar </LI>\n\n");
		printf("<LI>ELAC Bottomchart and Bottomchart MkII shallow water multibeam sonars</LI>\n\n");
		printf("<LI>Reson Seabat multibeam sonars (e.g. 9001, 8081, 7125)</LI>\n\n");
		printf("<LI>WHOI DSL AMS-120 deep tow interferometric sonar </LI>\n\n");
		printf("<LI>Sea Scan sidescan sonar</LI>\n\n");
		printf("<LI>Furuno HS-1 multibeam sonar</LI>\n\n");
		printf("<LI>Edgetech sidescan and subbottom profiler sonars</LI>\n\n");
		printf("<LI>Imagenex DeltaT multibeam sonars</LI>\n\n");
		printf("<LI>Odom ES3 multibeam sonar</LI>\n\n");
		printf("</UL>\n\n");
		printf("<P>The following swath mapping sonar data formats are currently supported by MB-System:</P>\n\n");

		for (i=0;i<=1000;i++)
			{
			format = i;
			if ((status = mb_format_description(verbose,&format,format_description,&error)) == MB_SUCCESS
				&& format == i)
				{
				format_informal_ptr = (char *) 
				    strstr(format_description, "Informal Description:");
				format_attributes_ptr = (char *) 
				    strstr(format_description, "Attributes:");
				strncpy(format_name, format_description, 
					strlen(format_description) 
					    - strlen(format_informal_ptr));
				format_name[strlen(format_description) 
					    - strlen(format_informal_ptr) - 1] = '\0';
				strncpy(format_informal, format_informal_ptr, 
					strlen(format_informal_ptr) 
					    - strlen(format_attributes_ptr));
				format_informal[strlen(format_informal_ptr) 
					    - strlen(format_attributes_ptr) - 1] = '\0';
				strcpy(format_attributes, format_attributes_ptr);
				format_attributes[strlen(format_attributes_ptr)-1] = '\0';
				printf("\n<UL>\n<LI>MBIO Data Format ID:  %d </LI>\n",format);
				printf("\n<UL>\n<LI>%s</LI>\n",format_name);
				printf("\n<LI>%s</LI>\n",format_informal);
				printf("\n<LI>%s</LI>\n",format_attributes);
				printf("</UL>\n</UL>\n");
				}
			}

		printf("\n<CENTER><P><BR>\n");
		printf("Last Updated: %s</P></CENTER>\n", MB_FORMAT_UPDATEDATE);
		printf("\n<P>\n<HR WIDTH=\"100%%\"></P>\n\n");
		printf("<P><IMG SRC=\"mbsystem_logo_small.gif\" HEIGHT=55 WIDTH=158><A HREF=\"mbsystem_home.html\">Back\n");
		printf("to MB-System Home Page...</A></P>\n");
		printf("\n</BODY>\n</HTML>\n");

		status = MB_SUCCESS;
		error = MB_ERROR_NO_ERROR;
		}
	else if (list_mode == MB_YES)
		{
		for (i=0;i<=1000;i++)
			{
			format = i;
			if ((status = mb_format(verbose,&format,&error)) == MB_SUCCESS
				&& format == i)
				{
				printf("%d\n",format);
				}
			}
		status = MB_SUCCESS;
		error = MB_ERROR_NO_ERROR;
		}
	else
		{
		printf("\nSupported MBIO Formats:\n");
		for (i=0;i<=1000;i++)
			{
			format = i;
			if ((status = mb_format_description(verbose,&format,format_description,&error)) == MB_SUCCESS
				&& format == i)
				{
				printf("\nMBIO Data Format ID:  %d\n",format);
				printf("%s",format_description);
				}
			}
		status = MB_SUCCESS;
		error = MB_ERROR_NO_ERROR;
		}

	/* print output debug statements */
	if (verbose >= 2)
		{
		fprintf(stderr,"\ndbg2  Program <%s> completed\n",
			program_name);
		fprintf(stderr,"dbg2  Ending status:\n");
		fprintf(stderr,"dbg2       status:  %d\n",status);
		}

	/* end it all */
	exit(error);
}
コード例 #10
0
ファイル: hsdump.c プロジェクト: jbrahy/mb-system
int main (int argc, char **argv)
{
	/* id variables */
	char program_name[] = "HSDUMP";
	char help_message[] =  "HSDUMP lists the information contained in data records on\n\tHydrosweep DS data files, including survey, calibrate, water \n\tvelocity and comment records. The default input stream is stdin.";
	char usage_message[] = "hsdump [-Fformat -V -H -Iinfile -Okind]";

	/* parsing variables */
	extern char *optarg;
	int	errflg = 0;
	int	c;
	int	help = 0;
	int	flag = 0;

	/* MBIO status variables */
	int	status = MB_SUCCESS;
	int	verbose = 0;
	int	error = MB_ERROR_NO_ERROR;
	char	format_description[MB_DESCRIPTION_LENGTH];
	char	*message = NULL;

	/* MBIO read and write control parameters */
	int	format = 0;
	int	pings;
	int	lonflip;
	double	bounds[4];
	int	btime_i[7];
	int	etime_i[7];
	double	btime_d;
	double	etime_d;
	double	speedmin;
	double	timegap;
	int	beams_bath;
	int	beams_amp;
	int	pixels_ss;
	char	file[MB_PATH_MAXLINE];
	void	*mbio_ptr = NULL;

	/* mbio read and write values */
	void	*store_ptr;
	struct mbsys_hsds_struct *store;
	int	kind;
	int	time_i[7];
	double	time_d;
	double	navlon;
	double	navlat;
	double	speed;
	double	heading;
	double	distance;
	double	altitude;
	double	sonardepth;
	int	nbath;
	int	namp;
	int	nss;
	char	*beamflag = NULL;
	double	*bath = NULL;
	double	*bathacrosstrack = NULL;
	double	*bathalongtrack = NULL;
	double	*amp = NULL;
	double	*ss = NULL;
	double	*ssacrosstrack = NULL;
	double	*ssalongtrack = NULL;
	char	comment[MB_COMMENT_MAXLINE];

	/* dump control parameters */
	int	mb_data_data_list = MB_NO;
	int	mb_data_comment_list = MB_NO;
	int	mb_data_calibrate_list = MB_NO;
	int	mb_data_mean_velocity_list = MB_NO;
	int	mb_data_velocity_profile_list = MB_NO;
	int	mb_data_standby_list = MB_NO;
	int	mb_data_nav_source_list = MB_NO;
	int	mb_data_data_count = 0;
	int	mb_data_comment_count = 0;
	int	mb_data_calibrate_count = 0;
	int	mb_data_mean_velocity_count = 0;
	int	mb_data_velocity_profile_count = 0;
	int	mb_data_standby_count = 0;
	int	mb_data_nav_source_count = 0;

	/* output stream for basic stuff (stdout if verbose <= 1,
		stderr if verbose > 1) */
	FILE	*output;

	int	i;

	/* get current default values */
	status = mb_defaults(verbose,&format,&pings,&lonflip,bounds,
		btime_i,etime_i,&speedmin,&timegap);

	/* reset all defaults */
	format = MBF_HSATLRAW;
	pings = 1;
	lonflip = 0;
	bounds[0] = -360.;
	bounds[1] = 360.;
	bounds[2] = -90.;
	bounds[3] = 90.;
	btime_i[0] = 1962;
	btime_i[1] = 2;
	btime_i[2] = 21;
	btime_i[3] = 10;
	btime_i[4] = 30;
	btime_i[5] = 0;
	btime_i[6] = 0;
	etime_i[0] = 2062;
	etime_i[1] = 2;
	etime_i[2] = 21;
	etime_i[3] = 10;
	etime_i[4] = 30;
	etime_i[5] = 0;
	etime_i[6] = 0;
	speedmin = 0.0;
	timegap = 1000000000.0;

	/* set default input and output */
	strcpy (file, "stdin");

	/* process argument list */
	while ((c = getopt(argc, argv, "VvHhF:f:I:i:O:o:")) != -1)
	  switch (c) 
		{
		case 'H':
		case 'h':
			help++;
			break;
		case 'V':
		case 'v':
			verbose++;
			break;
		case 'F':
		case 'f':
			sscanf (optarg,"%d", &format);
			flag++;
			break;
		case 'I':
		case 'i':
			sscanf (optarg,"%s", file);
			flag++;
			break;
		case 'O':
		case 'o':
			sscanf (optarg,"%d", &kind);
			if (kind == MB_DATA_DATA)
				mb_data_data_list = MB_YES;
			if (kind == MB_DATA_COMMENT)
				mb_data_comment_list = MB_YES;
			if (kind == MB_DATA_CALIBRATE)
				mb_data_calibrate_list = MB_YES;
			if (kind == MB_DATA_MEAN_VELOCITY)
				mb_data_mean_velocity_list = MB_YES;
			if (kind == MB_DATA_VELOCITY_PROFILE)
				mb_data_velocity_profile_list = MB_YES;
			if (kind == MB_DATA_STANDBY)
				mb_data_standby_list = MB_YES;
			if (kind == MB_DATA_NAV_SOURCE)
				mb_data_nav_source_list = MB_YES;
			flag++;
			break;
		case '?':
			errflg++;
		}

	/* set output stream */
	if (verbose <= 1)
		output = stdout;
	else
		output = stderr;

	/* if error flagged then print it and exit */
	if (errflg)
		{
		fprintf(output,"usage: %s\n", usage_message);
		fprintf(output,"\nProgram <%s> Terminated\n",
			program_name);
		error = MB_ERROR_BAD_USAGE;
		exit(error);
		}

	/* print starting message */
	if (verbose == 1 || help)
		{
		fprintf(output,"\nProgram %s\n",program_name);
		fprintf(output,"MB-system Version %s\n",MB_VERSION);
		}

	/* print starting debug statements */
	if (verbose >= 2)
		{
		fprintf(output,"\ndbg2  Program <%s>\n",program_name);
		fprintf(output,"dbg2  MB-system Version %s\n",MB_VERSION);
		fprintf(output,"dbg2  Control Parameters:\n");
		fprintf(output,"dbg2       verbose:         %d\n",verbose);
		fprintf(output,"dbg2       help:            %d\n",help);
		fprintf(output,"dbg2       format:          %d\n",format);
		fprintf(output,"dbg2       pings:           %d\n",pings);
		fprintf(output,"dbg2       lonflip:         %d\n",lonflip);
		fprintf(output,"dbg2       bounds[0]:       %f\n",bounds[0]);
		fprintf(output,"dbg2       bounds[1]:       %f\n",bounds[1]);
		fprintf(output,"dbg2       bounds[2]:       %f\n",bounds[2]);
		fprintf(output,"dbg2       bounds[3]:       %f\n",bounds[3]);
		fprintf(output,"dbg2       btime_i[0]:      %d\n",btime_i[0]);
		fprintf(output,"dbg2       btime_i[1]:      %d\n",btime_i[1]);
		fprintf(output,"dbg2       btime_i[2]:      %d\n",btime_i[2]);
		fprintf(output,"dbg2       btime_i[3]:      %d\n",btime_i[3]);
		fprintf(output,"dbg2       btime_i[4]:      %d\n",btime_i[4]);
		fprintf(output,"dbg2       btime_i[5]:      %d\n",btime_i[5]);
		fprintf(output,"dbg2       btime_i[6]:      %d\n",btime_i[6]);
		fprintf(output,"dbg2       etime_i[0]:      %d\n",etime_i[0]);
		fprintf(output,"dbg2       etime_i[1]:      %d\n",etime_i[1]);
		fprintf(output,"dbg2       etime_i[2]:      %d\n",etime_i[2]);
		fprintf(output,"dbg2       etime_i[3]:      %d\n",etime_i[3]);
		fprintf(output,"dbg2       etime_i[4]:      %d\n",etime_i[4]);
		fprintf(output,"dbg2       etime_i[5]:      %d\n",etime_i[5]);
		fprintf(output,"dbg2       etime_i[6]:      %d\n",etime_i[6]);
		fprintf(output,"dbg2       speedmin:        %f\n",speedmin);
		fprintf(output,"dbg2       timegap:         %f\n",timegap);
		fprintf(output,"dbg2       input file:      %s\n",file);
		fprintf(output,"dbg2       mb_data_data_list:             %d\n",
			mb_data_data_list);
		fprintf(output,"dbg2       mb_data_comment_list:          %d\n",
			mb_data_comment_list);
		fprintf(output,"dbg2       mb_data_calibrate_list:        %d\n",
			mb_data_calibrate_list);
		fprintf(output,"dbg2       mb_data_mean_velocity_list:    %d\n",
			mb_data_mean_velocity_list);
		fprintf(output,"dbg2       mb_data_velocity_profile_list: %d\n",
			mb_data_velocity_profile_list);
		fprintf(output,"dbg2       mb_data_standby_list:          %d\n",
			mb_data_standby_list);
		fprintf(output,"dbg2       mb_data_nav_source_list:       %d\n",
			mb_data_nav_source_list);
		}

	/* if help desired then print it and exit */
	if (help)
		{
		fprintf(output,"\n%s\n",help_message);
		fprintf(output,"\nusage: %s\n", usage_message);
		exit(error);
		}

	/* if bad format specified then print it and exit */
	status = mb_format(verbose,&format,&error);
	if (format != MBF_HSATLRAW && format != MBF_HSLDEOIH)
		{
		fprintf(output,"\nProgram <%s> requires complete Hydrosweep DS data stream\n",program_name);
		fprintf(output,"!!Format %d is unacceptable, only formats %d and %d can be used\n",format,MBF_HSATLRAW,MBF_HSLDEOIH);
		fprintf(output,"\nProgram <%s> Terminated\n",
			program_name);
		error = MB_ERROR_BAD_FORMAT;
		exit(error);
		}

	/* initialize reading the input multibeam file */
	if ((status = mb_read_init(
		verbose,file,format,pings,lonflip,bounds,
		btime_i,etime_i,speedmin,timegap,
		&mbio_ptr,&btime_d,&etime_d,
		&beams_bath,&beams_amp,&pixels_ss,&error)) != MB_SUCCESS)
		{
		mb_error(verbose,error,&message);
		fprintf(output,"\nMBIO Error returned from function <mb_read_init>:\n%s\n",message);
		fprintf(output,"\nMultibeam File <%s> not initialized for reading\n",file);
		fprintf(output,"\nProgram <%s> Terminated\n",
			program_name);
		exit(error);
		}

	/* allocate memory for data arrays */
	status = mb_mallocd(verbose,__FILE__,__LINE__,beams_bath*sizeof(char),(void **)&beamflag,&error);
	status = mb_mallocd(verbose,__FILE__,__LINE__,beams_bath*sizeof(double),(void **)&bath,&error);
	status = mb_mallocd(verbose,__FILE__,__LINE__,beams_bath*sizeof(double),
				(void **)&bathacrosstrack,&error);
	status = mb_mallocd(verbose,__FILE__,__LINE__,beams_bath*sizeof(double),
				(void **)&bathalongtrack,&error);
	status = mb_mallocd(verbose,__FILE__,__LINE__,beams_amp*sizeof(double),(void **)&amp,&error);
	status = mb_mallocd(verbose,__FILE__,__LINE__,pixels_ss*sizeof(double),(void **)&ss,&error);
	status = mb_mallocd(verbose,__FILE__,__LINE__,pixels_ss*sizeof(double),
			(void **)&ssacrosstrack,&error);
	status = mb_mallocd(verbose,__FILE__,__LINE__,pixels_ss*sizeof(double),
			(void **)&ssalongtrack,&error);

	/* if error initializing memory then quit */
	if (error != MB_ERROR_NO_ERROR)
		{
		mb_error(verbose,error,&message);
		fprintf(output,"\nMBIO Error allocating data arrays:\n%s\n",message);
		fprintf(output,"\nProgram <%s> Terminated\n",
			program_name);
		exit(error);
		}

	/* printf out file and format */
	mb_format_description(verbose, &format, format_description, &error);
	fprintf(output,"\nHydrosweep DS Data File:  %s\n",file);
	fprintf(output,"MBIO Data Format ID:  %d\n",format);
	fprintf(output,"%s",format_description);

	/* read and list */
	while (error <= MB_ERROR_NO_ERROR)
		{
		/* read some data */
		error = MB_ERROR_NO_ERROR;
		status = MB_SUCCESS;
		status = mb_get_all(verbose,mbio_ptr,&store_ptr,&kind,
				time_i,&time_d,&navlon,&navlat,
				&speed,&heading,
				&distance,&altitude,&sonardepth,
				&nbath,&namp,&nss,
				beamflag,bath,amp,bathacrosstrack,bathalongtrack,
				ss,ssacrosstrack,ssalongtrack,
				comment,&error);

		/* get data structure pointer */
		store = (struct mbsys_hsds_struct *) store_ptr;

		/* non-survey data do not matter to hsdump */
		if (error >= MB_ERROR_OTHER && error < MB_ERROR_NO_ERROR)
			{
			status = MB_SUCCESS;
			error = MB_ERROR_NO_ERROR;
			}

		/* output error messages */
		if (verbose >= 1 && error <= MB_ERROR_OTHER)
			{
			mb_error(verbose,error,&message);
			fprintf(output,"\nNonfatal MBIO Error:\n%s\n",message);
			}
		else if (verbose >= 1 && error > MB_ERROR_NO_ERROR 
			&& error != MB_ERROR_EOF)
			{
			mb_error(verbose,error,&message);
			fprintf(output,"\nFatal MBIO Error:\n%s\n",message);
			}

		/* deal with survey data record */
		if (kind == MB_DATA_DATA && mb_data_data_list == MB_YES)
			{
			mb_data_data_count++;
			fprintf(output,"\n");
			fprintf(output,"Survey Data Record (ERGNMESS + ERGNSLZT +ERGNAMPL):\n");
			fprintf(output,"  Time:            %2d/%2d/%4d %2.2d:%2.2d:%2.2d\n",
				store->month,store->day,store->year,
				store->hour,store->minute,store->second);
			fprintf(output,"  Alternate Time:   %4d  %4d\n",
				store->alt_minute,store->alt_second);
			fprintf(output,"  Longitude:        %f\n",store->lon);
			fprintf(output,"  Latitude:         %f\n",store->lat);
			fprintf(output,"  Course:           %f\n",
				store->course_true);
			fprintf(output,"  Course On Ground: %f\n",
				store->course_ground);
			fprintf(output,"  Speed:            %f\n",
				store->speed);
			fprintf(output,"  Speed On Ground:  %f\n",
				store->speed_ground);
			fprintf(output,"  Transverse Speed: %f\n",
				store->speed_transverse);
			fprintf(output,"  Speed Reference:  %c%c\n",
				store->speed_reference[0],
				store->speed_reference[1]);
			fprintf(output,"  Roll:             %f\n",
				store->roll);
			fprintf(output,"  Pitch:            %f\n",
				store->pitch);
			fprintf(output,"  Heave:            %f\n",
				store->heave);
			fprintf(output,"  Track:            %d\n",
				store->track);
			fprintf(output,"  Center Depth:     %f\n",
				store->depth_center);
			fprintf(output,"  Depth Scale:      %f\n",
				store->depth_scale);
			fprintf(output,"  Spare:            %d\n",
				store->spare);
			fprintf(output,"  Crosstrack Distances and Depths:\n");
			for (i=0;i<MBSYS_HSDS_BEAMS;i++)
				fprintf(output,"                    %5d %5d\n",
					store->distance[i],store->depth[i]);
			fprintf(output,"  Center Travel Time: %f\n",
				store->time_center);
			fprintf(output,"  Time Scale:       %f\n",
				store->time_scale);
			fprintf(output,"  Travel Times:\n");
			for (i=0;i<MBSYS_HSDS_BEAMS;i++)
				fprintf(output,"            %5d\n",
					store->time[i]);
			fprintf(output,"  Gyro Headings:\n");
			for (i=0;i<11;i++)
				fprintf(output,"            %f\n",
					store->gyro[i]);
			fprintf(output,"  Mode:             %c%c\n",
				store->mode[0],store->mode[1]);
			fprintf(output,"  Transmit Starboard: %d\n",
				store->trans_strbd);
			fprintf(output,"  Transmit Vertical:  %d\n",
				store->trans_vert);
			fprintf(output,"  Transmit Port:      %d\n",
				store->trans_port);
			fprintf(output,"  Pulse Starboard:    %d\n",
				store->pulse_len_strbd);
			fprintf(output,"  Pulse Vertical:     %d\n",
				store->pulse_len_vert);
			fprintf(output,"  Pulse Port:         %d\n",
				store->pulse_len_port);
			fprintf(output,"  Gain Start:         %d\n",
				store->gain_start);
			fprintf(output,"  Compensation Factor:%d\n",
				store->r_compensation_factor);
			fprintf(output,"  Compensation Start: %d\n",
				store->compensation_start);
			fprintf(output,"  Increase Start:     %d\n",
				store->increase_start);
			fprintf(output,"  Near TVC:           %d\n",
				store->tvc_near);
			fprintf(output,"  Far TVC:            %d\n",
				store->tvc_far);
			fprintf(output,"  Near Increase:      %d\n",
				store->increase_int_near);
			fprintf(output,"  Far Increase:       %d\n",
				store->increase_int_far);
			fprintf(output,"  Center Gain:        %d\n",
				store->gain_center);
			fprintf(output,"  Filter Gain:        %f\n",
				store->filter_gain);
			fprintf(output,"  Center Amplitude:   %d\n",
				store->amplitude_center);
			fprintf(output,"  Center Echo Time:   %d\n",
				store->echo_duration_center);
			fprintf(output,"  Echo Scale:         %d\n",
				store->echo_scale_center);

			fprintf(output,"  Amplitudes and Durations:\n");
			for (i=0;i<MBSYS_HSDS_BEAMS;i++)
				fprintf(output,"            %5d %5d\n",
					store->amplitude[i],
					store->echo_duration[i]);
			fprintf(output,"  Echo Gains and Scales:\n");
			for (i=0;i<16;i++)
				fprintf(output,"            %5d %5d\n",
					store->gain[i],
					store->echo_scale[i]);
			}

		/* deal with comment record */
		if (kind == MB_DATA_COMMENT && mb_data_comment_list == MB_YES)
			{
			mb_data_comment_count++;
			fprintf(output,"\n");
			fprintf(output,"Comment Record (LDEOCMNT):\n");
			fprintf(output,"  %s\n",store->comment);
			}

		/* deal with calibrate data record */
		if (kind == MB_DATA_CALIBRATE 
			&& mb_data_calibrate_list == MB_YES)
			{
			mb_data_calibrate_count++;
			fprintf(output,"\n");
			fprintf(output,"Calibrate Data Record (ERGNEICH + ERGNSLZT +ERGNAMPL):\n");
			fprintf(output,"  Time:            %2d/%2d/%4d %2.2d:%2.2d:%2.2d\n",
				store->month,store->day,store->year,
				store->hour,store->minute,store->second);
			fprintf(output,"  Alternate Time:   %4d  %4d\n",
				store->alt_minute,store->alt_second);
			fprintf(output,"  Longitude:        %f\n",store->lon);
			fprintf(output,"  Latitude:         %f\n",store->lat);
			fprintf(output,"  Course:           %f\n",
				store->course_true);
			fprintf(output,"  Course On Ground: %f\n",
				store->course_ground);
			fprintf(output,"  Speed:            %f\n",
				store->speed);
			fprintf(output,"  Speed On Ground:  %f\n",
				store->speed_ground);
			fprintf(output,"  Transverse Speed: %f\n",
				store->speed_transverse);
			fprintf(output,"  Speed Reference:  %c%c\n",
				store->speed_reference[0],
				store->speed_reference[1]);
			fprintf(output,"  Roll:             %f\n",
				store->roll);
			fprintf(output,"  Pitch:            %f\n",
				store->pitch);
			fprintf(output,"  Heave:            %f\n",
				store->heave);
			fprintf(output,"  Track:            %d\n",
				store->track);
			fprintf(output,"  Center Depth:     %f\n",
				store->depth_center);
			fprintf(output,"  Depth Scale:      %f\n",
				store->depth_scale);
			fprintf(output,"  Spare:            %d\n",
				store->spare);
			fprintf(output,"  Crosstrack Distances and Depths:\n");
			for (i=0;i<MBSYS_HSDS_BEAMS;i++)
				fprintf(output,"                    %5d %5d\n",
					store->distance[i],store->depth[i]);
			fprintf(output,"  Center Travel Time: %f\n",
				store->time_center);
			fprintf(output,"  Time Scale:       %f\n",
				store->time_scale);
			fprintf(output,"  Travel Times:\n");
			for (i=0;i<MBSYS_HSDS_BEAMS;i++)
				fprintf(output,"            %5d\n",
					store->time[i]);
			fprintf(output,"  Gyro Headings:\n");
			for (i=0;i<11;i++)
				fprintf(output,"            %f\n",
					store->gyro[i]);
			fprintf(output,"  Mode:             %c%c\n",
				store->mode[0],store->mode[1]);
			fprintf(output,"  Transmit Starboard: %d\n",
				store->trans_strbd);
			fprintf(output,"  Transmit Vertical:  %d\n",
				store->trans_vert);
			fprintf(output,"  Transmit Port:      %d\n",
				store->trans_port);
			fprintf(output,"  Pulse Starboard:    %d\n",
				store->pulse_len_strbd);
			fprintf(output,"  Pulse Vertical:     %d\n",
				store->pulse_len_vert);
			fprintf(output,"  Pulse Port:         %d\n",
				store->pulse_len_port);
			fprintf(output,"  Gain Start:         %d\n",
				store->gain_start);
			fprintf(output,"  Compensation Factor:%d\n",
				store->r_compensation_factor);
			fprintf(output,"  Compensation Start: %d\n",
				store->compensation_start);
			fprintf(output,"  Increase Start:     %d\n",
				store->increase_start);
			fprintf(output,"  Near TVC:           %d\n",
				store->tvc_near);
			fprintf(output,"  Far TVC:            %d\n",
				store->tvc_far);
			fprintf(output,"  Near Increase:      %d\n",
				store->increase_int_near);
			fprintf(output,"  Far Increase:       %d\n",
				store->increase_int_far);
			fprintf(output,"  Center Gain:        %d\n",
				store->gain_center);
			fprintf(output,"  Filter Gain:        %f\n",
				store->filter_gain);
			fprintf(output,"  Center Amplitude:   %d\n",
				store->amplitude_center);
			fprintf(output,"  Center Echo Time:   %d\n",
				store->echo_duration_center);
			fprintf(output,"  Echo Scale:         %d\n",
				store->echo_scale_center);

			fprintf(output,"  Amplitudes and Durations:\n");
			for (i=0;i<MBSYS_HSDS_BEAMS;i++)
				fprintf(output,"            %5d %5d\n",
					store->amplitude[i],
					store->echo_duration[i]);
			fprintf(output,"  Echo Gains and Scales:\n");
			for (i=0;i<16;i++)
				fprintf(output,"            %5d %5d\n",
					store->gain[i],
					store->echo_scale[i]);
			}

		/* deal with mean velocity data record */
		if (kind == MB_DATA_MEAN_VELOCITY 
			&& mb_data_mean_velocity_list == MB_YES)
			{
			mb_data_mean_velocity_count++;
			fprintf(output,"\n");
			fprintf(output,"Mean Water Velocity Record (ERGNHYDI):\n");
			fprintf(output,"  Time:            %2d/%2d/%4d %2.2d:%2.2d:%2.2d\n",
				store->month,store->day,store->year,
				store->hour,store->minute,store->second);
			fprintf(output,"  Alternate Time:   %4d  %4d\n",
				store->alt_minute,store->alt_second);
			fprintf(output,"  Longitude:        %f\n",store->lon);
			fprintf(output,"  Latitude:         %f\n",store->lat);
			fprintf(output,"  Draught:          %f\n",
				store->draught);
			fprintf(output,"  Mean velocity:    %f\n",
				store->vel_mean);
			fprintf(output,"  Keel velocity:    %f\n",
				store->vel_keel);
			fprintf(output,"  Tide:             %f\n",store->tide);
			}

		/* deal with velocity profile data record */
		if (kind == MB_DATA_VELOCITY_PROFILE
			&& mb_data_velocity_profile_list == MB_YES)
			{
			mb_data_velocity_profile_count++;
			fprintf(output,"\n");
			fprintf(output,"Water Velocity Profile Record (ERGNCTDS):\n");
			fprintf(output,"  Time:             %2d/%2d/%4d %2.2d:%2.2d:%2.2d\n",
				store->month,store->day,store->year,
				store->hour,store->minute,store->second);
			fprintf(output,"  Longitude:        %f\n",store->lon);
			fprintf(output,"  Latitude:         %f\n",store->lat);
			fprintf(output,"  Number of points: %d\n",
				store->num_vel);
			fprintf(output,"  Water Velocity Profile:\n");
			for (i=0;i<store->num_vel;i++)
				fprintf(output,"    %f %f\n",
					store->vdepth[i],store->velocity[i]);
			}

		/* deal with standby data record */
		if (kind == MB_DATA_STANDBY
			&& mb_data_standby_list == MB_YES)
			{
			mb_data_standby_count++;
			fprintf(output,"\n");
			fprintf(output,"Standby Data Record (ERGNPARA):\n");
			fprintf(output,"  Time:            %2d/%2d/%4d %2.2d:%2.2d:%2.2d\n",
				store->month,store->day,store->year,
				store->hour,store->minute,store->second);
			fprintf(output,"  Alternate Time:   %4d  %4d\n",
				store->alt_minute,store->alt_second);
			fprintf(output,"  Longitude:        %f\n",store->lon);
			fprintf(output,"  Latitude:         %f\n",store->lat);
			}

		/* deal with navigation source data record */
		if (kind == MB_DATA_NAV_SOURCE
			&& mb_data_nav_source_list == MB_YES)
			{
			mb_data_nav_source_count++;
			fprintf(output,"\n");
			fprintf(output,"Standby Data Record (ERGNPARA):\n");
			fprintf(output,"  Time:            %2d/%2d/%4d %2.2d:%2.2d:%2.2d\n",
				store->month,store->day,store->year,
				store->hour,store->minute,store->second);
			fprintf(output,"  Alternate Time:   %4d  %4d\n",
				store->alt_minute,store->alt_second);
			fprintf(output,"  Longitude:        %f\n",store->lon);
			fprintf(output,"  Latitude:         %f\n",store->lat);
			fprintf(output,"  X Correction:     %f\n",
				store->pos_corr_x);
			fprintf(output,"  Y Correction:     %f\n",
				store->pos_corr_y);
			fprintf(output,"  Sensors:          ");
			for (i=0;i<10;i++)
				fprintf(output,"%c",store->sensors[i]);
			fprintf(output,"\n");
			}

		}

	/* close the file */
	status = mb_close(verbose,&mbio_ptr,&error);

	/* deallocate memory for data arrays */
	mb_freed(verbose,__FILE__,__LINE__,(void **)&beamflag,&error); 
	mb_freed(verbose,__FILE__,__LINE__,(void **)&bath,&error); 
	mb_freed(verbose,__FILE__,__LINE__,(void **)&bathacrosstrack,&error); 
	mb_freed(verbose,__FILE__,__LINE__,(void **)&bathalongtrack,&error); 
	mb_freed(verbose,__FILE__,__LINE__,(void **)&amp,&error); 
	mb_freed(verbose,__FILE__,__LINE__,(void **)&ss,&error); 
	mb_freed(verbose,__FILE__,__LINE__,(void **)&ssacrosstrack,&error); 
	mb_freed(verbose,__FILE__,__LINE__,(void **)&ssalongtrack,&error); 

	/* check memory */
	if (verbose >= 4)
		status = mb_memory_list(verbose,&error);

	/* give the statistics */
	fprintf(output,"\n");
	if (mb_data_data_list == MB_YES)
		fprintf(output,"%d survey data records listed\n",
			mb_data_data_count);
	if (mb_data_comment_list == MB_YES)
		fprintf(output,"%d comment records listed\n",
			mb_data_comment_count);
	if (mb_data_calibrate_list == MB_YES)
		fprintf(output,"%d calibrate data records listed\n",
			mb_data_calibrate_count);
	if (mb_data_mean_velocity_list == MB_YES)
		fprintf(output,"%d mean velocity data records listed\n",
			mb_data_mean_velocity_count);
	if (mb_data_velocity_profile_list == MB_YES)
		fprintf(output,"%d velocity profile data records listed\n",
			mb_data_velocity_profile_count);
	if (mb_data_standby_list == MB_YES)
		fprintf(output,"%d standby data records listed\n",
			mb_data_standby_count);
	if (mb_data_nav_source_list == MB_YES)
		fprintf(output,"%d navigation source data records listed\n",
			mb_data_nav_source_count);

	/* end it all */
	exit(error);
}