Example #1
0
void ps_ctext(t_psdata ps, real x1, real y1, const char *str, int expos)
{
    if (expos == eXLeft)
    {
        ps_text(ps, x1, y1, str);
        return;
    }
    ps_moveto(ps, x1, y1);
    fprintf(ps->fp, "(%s) stringwidth\n", str);
    switch (expos)
    {
        case eXLeft:
            fprintf(ps->fp, "exch 0 exch pop exch\n");
            break;
        case eXCenter:
            fprintf(ps->fp, "exch 2 div neg exch\n");
            break;
        case eXRight:
            fprintf(ps->fp, "exch neg exch\n");
            break;
        default:
            gmx_fatal(FARGS, "invalid position index (expos=%d)", expos);
    }
    fprintf(ps->fp, "rmoveto (%s) show\n", str);
}
Example #2
0
int main (int argc, char **argv)
{
	char program_name[] = "MBPS";
	char help_message[] =  "MBPS reads a swath bathymetry data file and creates a postscript 3-d mesh plot";
	char usage_message[] = "mbps [-Iinfile -Fformat -Nnpings -Ppings\n\t-Byr/mo/da/hr/mn/sc -Eyr/mo/da/hr/mn/sc  \n\t-Aalpha -Keta -Dviewdir -Xvertexag \n\t-T\"title\" -Wmetersperinch \n\t-Sspeedmin -Ggap -Ydisplay_stats \n\t-Zdisplay_scales -V -H]";
	extern char *optarg;
	int	errflg = 0;
	int	c;
	int	help = 0;
	int	flag = 0;

	/*ALBERTO definitions */
	int	gap=1;
	double	*xp, *yp;
	double	xl[4], yl[4];
	double	alpha =		ALPHA_DEF;
	double	eta =		ETA_DEF;
	double	ve =		VE_DEF;
	char	viewdir =	VIEWDIR_DEF;
	int	display_stats = MB_YES;
	int	display_scales = MB_YES;
	double	sin_eta, cos_eta;
	double	sin_alpha, cos_alpha;
	double	track_length, xscale, zscale, zscale_inch;
	double	mean_xp=0.0, mean_yp=0.0, min_xp, max_xp, min_yp, max_yp;
	double	scaling, x_off, y_off;
	double	min_z, max_z, range_z, meters_per_inch=(-1.0);
	double	mean_lat=0.0;
	double	mean_lon=0.0;
	double	mean_latmin;
	double	mean_lonmin;
	double	mean_hdg=0.0;
	int	done, mean_knt=0;
	int	orient;
	char	label[100];
	int	a, b, rotate;
	double	x, y, z;

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

	/* MBIO read control parameters */
	int	format;
	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	pings = 1;
	int	beams_bath;
	int	beams_amp;
	int	pixels_ss;
	int	num_pings_max = MBPS_MAXPINGS;

	/* MBIO read values */
	void	*mbio_ptr = NULL;
	int	kind;
	struct ping data[MBPS_MAXPINGS+3];
	int	time_i[7];
	double	time_d;
	double	navlon;
	double	navlat;
	double	speed;
	double	heading;
	double	distance;
	double	altitude;
	double	sonardepth;
	char	*beamflag;
	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];
	int	timbeg_i[7];
	int	timend_i[7];
	double	distot = 0.0;
	int	nread;

	char	title[MB_COMMENT_MAXLINE];
	int	forward;
	double	xx, yy, zz;
	double	heading_start, dheading, dheadingx, dheadingy;
	int	i, j, jj, k;
	
	void Polygon_Fill();
	void Good_Polygon();

	/* initialize some time variables */
	for (i=0;i<7;i++)
		{
		timbeg_i[i] = 0;
		timend_i[i] = 0;
		}

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

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

	/* process argument list */
	while ((c = getopt(argc, argv, "VvHhF:f:B:b:E:e:S:s:T:t:I:i:A:a:X:x:K:k:D:d:N:n:P:p:W:w:G:g:YyZz")) != -1)
	    switch (c) 
		{
		case 'H':
		case 'h':
			help++;
			break;
		case 'V':
		case 'v':
			verbose++;
			break;
		case 'A':
		case 'a':
			sscanf (optarg, "%lf", &alpha);
			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, "%c", &viewdir);
			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':
			sscanf (optarg, "%d", &gap);
			flag++;
			break;
		case 'I':
		case 'i':
			sscanf (optarg,"%s", file);
			flag++;
			break;
		case 'K':
		case 'k':
			sscanf (optarg, "%lf", &eta);
			flag++;
			break;
		case 'N':
		case 'n':
			sscanf (optarg, "%d", &num_pings_max);
			if (num_pings_max < 2
			    || num_pings_max > MBPS_MAXPINGS) 
			num_pings_max = MBPS_MAXPINGS;
			flag++;
			break;
		case 'P':
		case 'p':
			sscanf (optarg, "%d", &pings);
			flag++;
			break;
		case 'S':
		case 's':
			sscanf (optarg,"%lf", &speedmin);
			flag++;
			break;
		case 'T':
		case 't':
			sscanf (optarg,"%s", title);
			flag++;
			break;
		case 'X':
		case 'x':
			sscanf (optarg, "%lf", &ve);
			flag++;
			break;
		case 'W':
		case 'w':
			sscanf (optarg, "%lf", &meters_per_inch);
			flag++;
			break;
		case 'Y':
		case 'y':
			display_stats = MB_NO;
			flag++;
			break;
		case 'Z':
		case 'z':
			display_scales = MB_NO;
			flag++;
			break;
		case '?':
			errflg++;
			break;
		} /* switch */

		
	/* Process the title of the plot */
	for (i = 1; i < argc; i++) 
		{
		if (argv[i][0] == '-'&& ((argv[i][1]=='T')||(argv[i][1]=='t')) ) {
			strcpy(title,argv[i]);
			title[0]=' ';
			title[1]=' ';
			}
		}

	/* check that otions are allowed */
	if ((viewdir!='P') && (viewdir!='S') && (viewdir!='B') && 
            (viewdir!='p') && (viewdir!='s') && (viewdir!='b'))
		{
		fprintf(stderr,"viewdir must be either P/p (port) S/s (stbd) or B/b (back)\n");
		errflg++;
		}

	/* if error flagged then print it and exit */
	if (errflg) 
		{
		fprintf(stderr,"usage: %s\n", usage_message);
		fprintf(stderr,"\nProgram <%s> Terminated\n",
			program_name);
		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);
		fprintf(stderr,"dbg2       format:     %d\n",format);
		fprintf(stderr,"dbg2       btime_i[0]: %d\n",btime_i[0]);
		fprintf(stderr,"dbg2       btime_i[1]: %d\n",btime_i[1]);
		fprintf(stderr,"dbg2       btime_i[2]: %d\n",btime_i[2]);
		fprintf(stderr,"dbg2       btime_i[3]: %d\n",btime_i[3]);
		fprintf(stderr,"dbg2       btime_i[4]: %d\n",btime_i[4]);
		fprintf(stderr,"dbg2       btime_i[5]: %d\n",btime_i[5]);
		fprintf(stderr,"dbg2       btime_i[6]: %d\n",btime_i[6]);
		fprintf(stderr,"dbg2       etime_i[0]: %d\n",etime_i[0]);
		fprintf(stderr,"dbg2       etime_i[1]: %d\n",etime_i[1]);
		fprintf(stderr,"dbg2       etime_i[2]: %d\n",etime_i[2]);
		fprintf(stderr,"dbg2       etime_i[3]: %d\n",etime_i[3]);
		fprintf(stderr,"dbg2       etime_i[4]: %d\n",etime_i[4]);
		fprintf(stderr,"dbg2       etime_i[5]: %d\n",etime_i[5]);
		fprintf(stderr,"dbg2       etime_i[6]: %d\n",etime_i[6]);
		fprintf(stderr,"dbg2       speedmin:   %f\n",speedmin);
		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);
		}

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

	/* initialize reading the swath 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(stderr,"\nMBIO Error returned from function <mb_read_init>:\n%s\n",message);
		fprintf(stderr,"\nMultibeam File <%s> not initialized for reading\n",file);
		fprintf(stderr,"\nProgram <%s> Terminated\n",
			program_name);
		exit(error);
		}

	/* initialize values */
	sin_alpha = sin(alpha*DTR);
	cos_alpha = cos(alpha*DTR);
	sin_eta = sin(eta*DTR);
	cos_eta = cos(eta*DTR);
	min_z = 0.0;
	max_z = -9999.0;

	/* allocate memory for data arrays */
	beamflag = NULL;
	bath = NULL;
	bathacrosstrack = NULL;
	bathalongtrack = NULL;
	amp = NULL;
	ss = NULL;
	ssacrosstrack = NULL;
	ssalongtrack = NULL;
	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_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_AMPLITUDE,
						sizeof(double), (void **)&amp, &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);
	for (i=0;i<num_pings_max+3;i++) 
		{
		data[i].beams_bath = 0;
		data[i].beamflag = NULL;
		data[i].bath = NULL;
		data[i].bathacrosstrack = NULL;
		data[i].bathalongtrack = NULL;
		data[i].xp = NULL;
		data[i].yp = NULL;
		}  


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

	/* read and process data */
	nread = 0;
	done = MB_NO;
	error = MB_ERROR_NO_ERROR;
	while (done == MB_NO && 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);
			
		/* only work with survey data */
		if (error == MB_ERROR_NO_ERROR && kind == MB_DATA_DATA)
			{

			/* allocate arrays */
			data[nread].beams_bath = beams_bath;
			status = mb_mallocd(verbose, __FILE__, __LINE__, beams_bath*sizeof(char), (void **)&(data[nread].beamflag), &error);
			status = mb_mallocd(verbose, __FILE__, __LINE__, beams_bath*sizeof(double), (void **)&(data[nread].bath), &error);
			status = mb_mallocd(verbose, __FILE__, __LINE__, beams_bath*sizeof(double), (void **)&(data[nread].bathacrosstrack), &error);
			status = mb_mallocd(verbose, __FILE__, __LINE__, beams_bath*sizeof(double), (void **)&(data[nread].bathalongtrack), &error);
			status = mb_mallocd(verbose, __FILE__, __LINE__, beams_bath*sizeof(double), (void **)&(data[nread].xp), &error);
			status = mb_mallocd(verbose, __FILE__, __LINE__, beams_bath*sizeof(double), (void **)&(data[nread].yp), &error);

			/* copy data to storage arrays */
			for (i=0;i<beams_bath;i++)
				{
				data[nread].beamflag[i] = beamflag[i];
				data[nread].bath[i] = bath[i];
				data[nread].bathacrosstrack[i] = bathacrosstrack[i];
				data[nread].bathalongtrack[i] = bathalongtrack[i];
				data[nread].xp[i] = BAD;
				data[nread].yp[i] = BAD;
				}

			/* ignore time gaps */
			if (error == MB_ERROR_TIME_GAP)
				{
				error = MB_ERROR_NO_ERROR;
				status = MB_SUCCESS;
				}

			/* output error messages */
			if (error == MB_ERROR_COMMENT)
				{
				/* do nothing */
				}
			else if (verbose >= 1 && error < MB_ERROR_NO_ERROR
				&& error >= MB_ERROR_OTHER)
				{
				mb_error(verbose,error,&message);
				fprintf(stderr,"\nNonfatal MBIO Error:\n%s\n",
					message);
				fprintf(stderr,"Time: %d %d %d %d %d %d %d\n",
					time_i[0],time_i[1],time_i[2],
					time_i[3],time_i[4],time_i[5],
					time_i[6]);
				}
			else if (verbose >= 1 && error < MB_ERROR_NO_ERROR)
				{
				mb_error(verbose,error,&message);
				fprintf(stderr,"\nNonfatal MBIO Error:\n%s\n",
					message);
				fprintf(stderr,"Number of good records so far: %d\n",nread);
				}
			else if (verbose >= 1 && error > MB_ERROR_NO_ERROR 
				&& error != MB_ERROR_EOF)
				{
				mb_error(verbose,error,&message);
				fprintf(stderr,"\nFatal MBIO Error:\n%s\n",
					message);
				fprintf(stderr,"Last Good Time: %d %d %d %d %d %d %d\n",
					time_i[0],time_i[1],time_i[2],
					time_i[3],time_i[4],time_i[5],
					time_i[6]);
				}

			/* calculate raw x,y locations for each beam */
			if (status == MB_SUCCESS) 
				{
				/* set initial heading */
				if (nread == 0)
					heading_start = heading;

				/* get heading x and y components */
				dheading = heading - heading_start;
				if (dheading > 360.0)
				    dheading -= 360.0;
				else if (dheading < 0.0)
				    dheading += 360.0;
				dheadingx = sin(DTR * dheading);
				dheadingy = cos(DTR * dheading);

				/* get alongtrack distance in nav */
				distot += distance * 1000.0;	/* distance in meters */

				/* loop over the beams */
				for (j=0; j<beams_bath; j++) 
					{
					if (j >= data[nread].beams_bath)
						{
						data[nread].beamflag[j] = MB_FLAG_NULL;
						data[nread].xp[j] = BAD;
						data[nread].yp[j] = BAD;
						}
					else if (mb_beam_ok(beamflag[j])) 
						{
						xx = dheadingy * bathacrosstrack[j]
						    + dheadingx * bathalongtrack[j];
						yy = distot
						    - dheadingx * bathacrosstrack[j]
						    + dheadingy * bathalongtrack[j];
						zz = -bath[j];
						if (viewdir=='S' || viewdir=='s') 
							{
							data[nread].xp[j] = yy 
							    + xx * sin_eta * cos_alpha;
							data[nread].yp[j] = zz * cos_eta * ve
							    - xx * sin_eta * sin_alpha;
							}
						else if (viewdir=='P' || viewdir=='p') 
							{
							data[nread].xp[j]= -yy 
							    - xx * sin_eta * cos_alpha;
							data[nread].yp[j]= zz * cos_eta * ve
							    + xx * sin_eta * sin_alpha;
							}
						else if (viewdir=='B' || viewdir=='b') 
							{
							data[nread].xp[j] = xx
							    + yy * sin_eta * cos_alpha;
							data[nread].yp[j]= zz * cos_eta * ve
							    + yy * sin_eta * sin_alpha;
							}
						mean_lat += navlat;
						mean_lon += navlon;
						mean_hdg += heading;
						mean_xp += data[nread].xp[j];
						mean_yp += data[nread].yp[j];
						mean_knt++;

						if (-data[nread].bath[j] < min_z) 
						    min_z= -data[nread].bath[j];
						if (-data[nread].bath[j] > max_z) 
						    max_z= -data[nread].bath[j];
						}
					else 
						{
						data[nread].xp[j] = BAD;
						data[nread].yp[j] = BAD;
						}
					} /* for j=0 ... */

				if (nread == 0)
					{
					for (k=0; k<7; k++)
						timbeg_i[k] = time_i[k];
					}
				else
					{
					for (k=0; k<7; k++)
						timend_i[k]=time_i[k];
					}
				}	/* if status==MB_SUCCESS */

			/* increment counters */
			if (error == MB_ERROR_NO_ERROR)
				{
				nread++;
				}
			}

		/* print debug statements */
		if (verbose >= 2) 
			{
			fprintf(stderr,"\ndbg2  Reading loop finished in program <%s>\n",
			program_name);
			fprintf(stderr,"dbg2       status:     %d\n",status);
			fprintf(stderr,"dbg2       error:      %d\n",error);
			fprintf(stderr,"dbg2       nread:      %d\n",nread);
			fprintf(stderr,"dbg2       pings:      %d\n",pings);
			}

		/* test if done */
		if (nread >= num_pings_max
			&& verbose >= 1) 
			{
			fprintf(stderr, "%s: Maximum number of pings [%d] read before end of file reached...\n",
			    program_name, num_pings_max);
			done = MB_YES;
			}
		if (nread >= num_pings_max || error > MB_ERROR_NO_ERROR) 
			{
			done = MB_YES;
			}

		}  /* end of processing data, 1'st while under read/process data */

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

	/* print debug statements */
	if (verbose >= 2) 
		{
		fprintf(stderr,"\ndbg2  Reading loop finished in program <%s>\n",
				program_name);
		fprintf(stderr,"dbg2       status:     %d\n",status);
		fprintf(stderr,"dbg2       error:      %d\n",error);
		fprintf(stderr,"dbg2       nread:      %d\n",nread);
		fprintf(stderr,"dbg2       pings: %d\n",pings);
		}

	/* total track length in m */
	track_length = distot;	
	mean_lat /= mean_knt;
	mean_latmin = fabs(mean_lat - (int) mean_lat) * 60.0;
	mean_lon /= mean_knt;
	mean_lonmin = fabs(mean_lon - (int) mean_lon) * 60.0;
	mean_hdg /= mean_knt;
	mean_xp /= mean_knt;
	mean_yp /= mean_knt;

	/* rescale xp[],yp[] to zero mean; get min and max */
	max_yp = min_yp = max_xp = min_xp = 0.0;
	for (i=0; i<nread; i++) 
		{
		beamflag = data[i].beamflag;
		xp = data[i].xp;
		yp = data[i].yp;
		for (j=0; j<data[i].beams_bath; j++) 
			{
			if (mb_beam_ok(beamflag[j])) 
				{
				yp[j] -= mean_yp;
				xp[j] -= mean_xp;
				min_xp = MIN(min_xp, xp[j]);
				max_xp = MAX(max_xp, xp[j]);
				min_yp = MIN(min_yp, yp[j]);
				max_yp = MAX(max_yp, yp[j]);
				} /* if yp[][] */
			} 	  /* for j */
		} 		  /* for i */

	/* get page orientation, scaling(in/m) factor and startup plot */
	if ((viewdir=='P') || (viewdir=='S') || (viewdir=='p') || (viewdir=='s')) 
		{
		/* Landscape */		
		orient = 0;
		if (meters_per_inch > 0.0) 
			{
			scaling = 1.0 / meters_per_inch;
			x_off = 11. / 2;
			y_off = 8.5 / 2.;
			} 
		else 
			{
			if ( (5.2 / (max_yp - min_yp)) < (8.5 / (max_xp - min_xp)) )
				scaling = (5.2 / (max_yp - min_yp));
			else
				scaling = (8.5 / (max_xp - min_xp));			
			x_off=(-(max_xp + min_xp) * scaling / 2.0) + (11. / 2);
			y_off=(-(max_yp + min_yp) * scaling / 2.0) + (8.5 / 2) - .2;
			}
		} 
	else 
		{
		/* Portrait */		
		orient = 1;
		if (meters_per_inch > 0.0) 
			{
			scaling = 1.0 / meters_per_inch;
			x_off = 8.5 / 2.0;
			y_off = 11. / 2.0;
			} 
		else 
			{
			if ( (8./(max_yp-min_yp))<(6.5/(max_xp-min_xp)) )
				scaling = (8./(max_yp-min_yp));
			else
				scaling = (6.5/(max_xp-min_xp));
			x_off=(-(max_xp+min_xp)*scaling/2.0)+(8.5/2);
			y_off=(-(max_yp+min_yp)*scaling/2.0)+(11./2)-.2;
			}
		}

       /* initialize the Postscript plotting */
#ifdef GMT_MINOR_VERSION
       ps_plotinit_hires(NULL,0,orient,x_off,y_off,1.0,1.0,1,300,1,
               gmtdefs.paper_width, gmtdefs.page_rgb, 
               gmtdefs.encoding.name, 
               GMT_epsinfo (argv[0]));
#else
       ps_plotinit(NULL,0,orient,x_off,y_off,1.0,1.0,1,300,1,
               gmtdefs.paper_width, gmtdefs.page_rgb, 
               gmtdefs.encoding.name, 
               GMT_epsinfo (argv[0]));
#endif
       GMT_echo_command (argc, argv);

	/* now loop over the data in the appropriate order
	    laying down white filled boxes with black outlines
	    wherever the data is good */
	
	if ((viewdir=='S') || (viewdir=='s')) 
		forward = MB_YES;
	else if ((viewdir=='P') || (viewdir=='p')) 
		forward = MB_NO;
	else if ((viewdir=='B') || (viewdir=='b')) 
		{
		if (alpha < 90.0) 
			forward = MB_YES;
		else 
			forward = MB_NO;
		}
	for (j=0;j<beams_bath-1;j++)
		{
		for (i=0;i<nread-1;i++)
			{
			if (forward == MB_YES)
				jj = j;
			else
				jj = beams_bath - 2 - j;
				
			/* make box */
			if (mb_beam_ok(data[i].beamflag[jj])
			    && mb_beam_ok(data[i+1].beamflag[jj])
			    && mb_beam_ok(data[i].beamflag[jj+1])
			    && mb_beam_ok(data[i+1].beamflag[jj+1]))
				{
				xl[0] = scaling * data[i].xp[jj];
				yl[0] = scaling * data[i].yp[jj];
				xl[1] = scaling * data[i+1].xp[jj];
				yl[1] = scaling * data[i+1].yp[jj];
				xl[2] = scaling * data[i+1].xp[jj+1];
				yl[2] = scaling * data[i+1].yp[jj+1];
				xl[3] = scaling * data[i].xp[jj+1];
				yl[3] = scaling * data[i].yp[jj+1];
				ps_polygon(xl,yl,4,rgb_white,1);
				}
			}
		}

	/* titles and such */
	ps_setline(2);	/* set line width */

	if (display_stats == MB_NO) 
		{
		/* plot a title */
		xl[0]=0;
		yl[0]=max_yp*scaling+.6;
		sprintf(label,"%s",title);
		ps_text(xl[0],yl[0],20.,label,0.,6,0);
		} 
	else 
		{
		/* plot a title */
		xl[0]=0;
		yl[0]=max_yp*scaling+1.3;
		sprintf(label,"%s",title);
		ps_text(xl[0],yl[0],20.,label,0.,6,0);

		/*xl[0]-=3.25;*/
		yl[0]-=0.3;
		sprintf(label,"Mean Lat.: %3d@+o@+ %4.1f'   Mean Lon.: %4d@+o @+%4.1f'   Heading: %.1lf@+o @+",(int)mean_lat, mean_latmin, (int)mean_lon, mean_lonmin, mean_hdg);
		ps_text(xl[0],yl[0],15.,label,0.,6,0);

		yl[0]-=0.3;
		sprintf(label,"View Angle: %.1lf@+o @+  V.E.: %.1lfX   Scale: %.0lf m/inch   Track Length: %.1lf km",eta,ve,1.0/scaling,track_length/1000.0);
		ps_text(xl[0],yl[0],15.,label,0.,6,0);

		yl[0]-=0.3;
		sprintf(label,
		"From %.4d/%.2d/%.2d %.2d:%.2d:%.2d   to  %.4d/%.2d/%.2d %.2d:%.2d:%.2d",
		timbeg_i[0],timbeg_i[1],timbeg_i[2],timbeg_i[3],
		timbeg_i[4],timbeg_i[5],timend_i[0],timend_i[1],
		timend_i[2],timend_i[3],timend_i[4],timend_i[5]);
		ps_text(xl[0],yl[0],15.,label,0.,6,0);
		} /* else after if display_stats */


	if (display_scales == MB_YES) 
		{
		/* plot the x-scale */
		xscale=10000;		/* x scale in m */
		if (track_length < 50000) xscale=5000;
		if (track_length < 20000) xscale=2000;
		if (track_length < 10000) xscale=1000;
		xl[0]=xl[1]= (-xscale*scaling/2.0);
		xl[2]=xl[3]= (-xl[0]);
		xl[0]+=2.;xl[1]+=2.;xl[2]+=2.;xl[3]+=2.;
		yl[1]=yl[2]= min_yp*scaling-1.;
		yl[0]=yl[3]= yl[1]+0.1;
	
#ifdef GMT_MINOR_VERSION
		ps_line(xl,yl,4,3,0);
#else
		ps_line(xl,yl,4,3,0,0);
#endif
		sprintf(label,"%.0f km",xscale/1000.0);
		ps_text(xl[0]+.5,yl[0]+.05,15.,label,0.,6,0);

	
		/* plot the z-scale */
		range_z=(max_z-min_z);
		zscale=2000;		/* z scale in m */
		if (range_z < 3000) zscale=1000;
		if (range_z < 1000) zscale=500;
		if (range_z < 500) zscale=200;
		if (range_z < 250) zscale=100;
		zscale_inch= zscale*scaling*cos_eta*ve;
		xl[1]=xl[2]+0.5;
		xl[2]=xl[1];
		xl[0]=xl[3]= xl[1]+.1;
		yl[0]=yl[1]= min_yp*scaling-1.;
		yl[2]=yl[3]= yl[0]+zscale_inch;

#ifdef GMT_MINOR_VERSION
		ps_line(xl,yl,4,3,0);
#else
		ps_line(xl,yl,4,3,0,0);
#endif
		sprintf(label,"%.0f m",zscale);
		ps_text(xl[0]+0.3,yl[0]+zscale_inch/2.0,15.,label,0.,6,0);


		/* plot an arrow in the ship's direction */
		a=0;
		b=beams_bath/2;
		while (!mb_beam_ok(data[a++].beamflag[b])) {}
		xl[0] = data[--a].xp[b];
		yl[0] = data[a].yp[b];
		a = nread - 1;
		while (!mb_beam_ok(data[a--].beamflag[b])) {}
		xl[1] = data[++a].xp[b];
		yl[1] = data[a].yp[b];
		xl[1] = ((xl[1]-xl[0])/distot/2)+.6;
		yl[1] = ((yl[1]-yl[0])/distot/2) + min_yp*scaling-1.;
		xl[0] = 0.+.6; 
		yl[0] = 0.+min_yp*scaling-0.85;
		ps_vector(xl[0],yl[0],xl[1],yl[1],
		    0.01,0.25,0.1,1.0,rgb_black,0);
		ps_text(xl[0]-1.7,yl[0]+.2,15.,"ship heading",0.,1,0);
		ps_text(xl[0]-1.7,yl[0],15.,"direction",0.,1,0);


		/* plot the three axes */
		for (i=0;i<3;i++) 
			{
			xl[0]=0.;	/* point in center of page */
			yl[0]=0.;
			rotate=0;	/* set to 1 if arrow is rotated below */
			if (i==0) 
				{	
				/* x-axis */
				x=1.;
				y=0;	
				z=0;
				} 
			else if (i==1) 
				{
				/* y-axis */
				x=0;	
				y=1.;	
				z=0;
				} 
			else if (i==2) 
				{	
				/* z-axis */
				x=0;
				y=0;	
				z=-1.;
				}

			if (viewdir=='P' || viewdir=='p') 
				{
				xl[1]=-y-x*sin_eta*cos_alpha+xl[0];
				yl[1]= -z*cos_eta+x*sin_eta*sin_alpha+yl[0];
				} 
			else if (viewdir=='B' || viewdir=='b') 
				{
				xl[1]=(x+y*sin_eta*cos_alpha)+xl[0];
				yl[1]=-z*cos_eta+y*sin_eta*sin_alpha+yl[0];
				} 
			else if (viewdir=='S' || viewdir=='s') 
				{
				xl[1]=y+x*sin_eta*cos_alpha+xl[0];
				yl[1]=z*cos_eta-x*sin_eta*sin_alpha+yl[0];
				}

			if (yl[1]<yl[0]) 
				{	
				/* rotate arrows 180 if facing downward */
				xl[1]=-xl[1];
				yl[1]=-yl[1];
				rotate=1;
				}

			xl[0]=(-3.);		/* move arrows from center to lower left corner */
			yl[0]=(min_yp*scaling-1.);
			xl[1]=xl[0]+xl[1];
			yl[1]=yl[0]+yl[1];

			ps_vector(xl[0],yl[0],xl[1],yl[1],
				0.01,0.25,0.1,1.0,rgb_black,0);

			if (i==0&&rotate==0)
				ps_text(xl[1],yl[1]+.15,15.,"x",0.,6,0);
			else if (i==1&&rotate==0)
				ps_text(xl[1],yl[1]+.15,15.,"y",0.,6,0);
			else if (i==2&&rotate==0)
				ps_text(xl[1],yl[1]+.15,15.,"z",0.,6,0);
			else if (i==0&&rotate==1)
				ps_text(xl[1],yl[1]+.15,15.,"-x",0.,6,0);
			else if (i==1&&rotate==1)
				ps_text(xl[1],yl[1]+.15,15.,"-y",0.,6,0);
			else if (i==2&&rotate==1)
				ps_text(xl[1],yl[1]+.15,15.,"z",0.,6,0);

			} /* (i=0;i<3;i++) */
		} /* if display_scales */

	/* end the postscript file */
	ps_plotend(1);
	
	/* deallocate arrays */
	for (i=0;i<nread;i++)
		{
		mb_freed(verbose,__FILE__, __LINE__, (void **)&(data[i].beams_bath), &error);
		mb_freed(verbose,__FILE__, __LINE__, (void **)&(data[i].bath), &error);
		mb_freed(verbose,__FILE__, __LINE__, (void **)&(data[i].bathacrosstrack), &error);
		mb_freed(verbose,__FILE__, __LINE__, (void **)&(data[i].bathalongtrack), &error);
		mb_freed(verbose,__FILE__, __LINE__, (void **)&(data[i].xp), &error);
		mb_freed(verbose,__FILE__, __LINE__, (void **)&(data[i].yp), &error);
		}

	/* check memory */
	if (verbose >= 4)
		status = mb_memory_list(verbose,&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);

}	/* main */
Example #3
0
int main (int argc, char **argv)
{
    GMT_LONG     i, symbol = 0, n, n_files = 0, fno;
    GMT_LONG     n_args;
    GMT_LONG     form_s = 0, justify_s = 5;
    
    GMT_LONG error = FALSE, nofile = TRUE;
    GMT_LONG done, greenwich, label_s = FALSE;
    GMT_LONG change_position = FALSE;
    GMT_LONG get_position = FALSE, get_size = FALSE, get_symbol = FALSE;
    GMT_LONG outline_E = FALSE, outline_G = FALSE, outline_F = FALSE;
    GMT_LONG old_GMT_world_map, skip_if_outside = TRUE;
    GMT_LONG plot_polS = FALSE, vecS = FALSE, scolor = FALSE, outline_s = FALSE;
    GMT_LONG def_cpen = FALSE, def_fpen = FALSE, def_tpen = FALSE;
    GMT_LONG def_gpen = FALSE, def_epen = FALSE, def_spen = FALSE;
    GMT_LONG hypo = FALSE;
    
    double west = 0.0, east = 0.0, south = 0.0, north = 0.0;
    double plot_x, plot_y, symbol_size = 0.0, symbol_size2;
    double lon, lat, plot_x0, plot_y0;
    double new_lon, new_lat, new_plot_x0, new_plot_y0;
    double radius, ech = 0., azimut, ih, plongement;
    double c_pointsize = 0.015, fontsize_s = 12.0;
    double angle_s = 0.0;
    double azS, sizeS = GMT_d_NaN;
    double v_width = GMT_d_NaN, h_length = GMT_d_NaN, h_width = GMT_d_NaN, shape;
    double si, co;

    char line[BUFSIZ], symbol_type, col[4][GMT_TEXT_LEN];
    char pol, *not_used = NULL;
    char txt_a[GMT_TEXT_LEN],txt_b[GMT_TEXT_LEN],txt_c[GMT_TEXT_LEN], txt_d[GMT_TEXT_LEN];
    char stacode[GMT_TEXT_LEN];
    
    FILE *fp = NULL;
    
    struct GMT_PEN pen, cpen, fpen, gpen, epen, spen, tpen;
    struct GMT_FILL fill, ffill, gfill, efill, sfill;
    struct GMT_FILL black, nofill;
    
    argc = (int)GMT_begin (argc, argv);
    
    GMT_init_pen (&pen, GMT_PENWIDTH);
    GMT_init_fill (&nofill, -1, -1, -1); 
    GMT_init_fill (&black, 0, 0, 0);     
    GMT_init_fill (&efill, 250, 250, 250);
    
    fill = nofill;
    ffill = nofill;
    sfill = nofill;
    gfill = black;

    /* Check and interpret the command line arguments */
    
    for (i = 1; !error && i < argc; i++) {
        if (argv[i][0] == '-') {
            switch(argv[i][1]) {
        
                /* Common parameters */
            
                case 'B':
                case 'H':
                case 'J':
                case 'K':
                case 'O':
                case 'P':
                case 'R':
                case 'U':
                case 'V':
                case 'X':
                case 'x':
                case 'Y':
                case 'y':
                case 'c':
                case '\0':
                    error += GMT_parse_common_options (argv[i], &west, &east, &south, &north);
                    break;
                
                /* Supplemental parameters */
            
                case 'C':       /* New coordinates */
                         change_position = TRUE;
                         sscanf(&argv[i][2], "%lf/%lf", &new_lon, &new_lat);
                         if(strchr(argv[i], 'W')) {
                             GMT_getpen (strchr(argv[i]+1, 'W')+1, &cpen);
                             def_cpen = TRUE;
                         }
                         if(strchr(argv[i], 'P')) {
                             sscanf(strchr(argv[i]+1, 'P')+1, "%lf", &c_pointsize);
                         }
                         break;
                case 'D':       /* Coordinates */
                         get_position = TRUE;
                         sscanf(&argv[i][2], "%lf/%lf", &lon, &lat);
                         break;
                case 'E':        /* Set color for station in extensive part */
                         GMT_getfill (&argv[i][2], &efill);
                         break;
                case 'e':        /* Outline station symbol in extensive part */
                         outline_E = TRUE;
                         if(strlen(argv[i]) > 2) {
                             GMT_getpen (&argv[i][2], &epen);
                             def_epen = TRUE;
                         }
                         break;
                case 'F':        /* Set background color of beach ball */
                         GMT_getfill (&argv[i][2], &ffill);
                         break;
                case 'f':        /* Outline beach ball */
                         outline_F = TRUE;
                         if(strlen(argv[i]) > 2) {
                             GMT_getpen (&argv[i][2], &fpen);
                             def_fpen = TRUE;
                         }
                         break;
                case 'G':        /* Set color for station in compressive part */
                         GMT_getfill (&argv[i][2], &gfill);
                         break;
                case 'g':        /* Outline station symbol in compressive part */
                         outline_G = TRUE;
                         if(strlen(argv[i]) > 2) {
                             GMT_getpen (&argv[i][2], &gpen);
                             def_gpen = TRUE;
                         }
                         break;
                case 'h':    /* Use HYPO71 format */
                         hypo = TRUE;
                         break;
                case 'M':    /* Focal sphere size */
                         get_size = TRUE;
                         sscanf(&argv[i][2], "%s", txt_a);
                         ech = GMT_convert_units (txt_a, GMT_INCH);
                         break;
                case 'N':        /* Do not skip points outside border */
                         skip_if_outside = FALSE;
                         break;
                case 'S':        /* Get symbol [and size] */
                         symbol_type = argv[i][2];
                         symbol_size = GMT_convert_units (&argv[i][3], GMT_INCH);
                         get_symbol = TRUE;
                         switch (symbol_type) {
                             case 'a':
                                 symbol = STAR;
                                 break;
                             case 'c':
                                 symbol = CIRCLE;
                                 break;
                             case 'd':
                                 symbol = DIAMOND;
                                 break;
                             case 'h':
                                 symbol = HEXAGON;
                                 break;
                             case 'i':
                                 symbol = ITRIANGLE;
                                 break;
                             case 'p':
                                 symbol = POINT;
                                 break;
                             case 's':
                                 symbol = SQUARE;
                                 break;
                             case 't':
                                 symbol = TRIANGLE;
                                 break;
                             case 'x':
                                 symbol = CROSS;
                                 break;
                             default:
                                 error = TRUE;
                                 fprintf (stderr, "%s: GMT SYNTAX ERROR -S option:  Unrecognized symbol type %c\n", argv[0], symbol_type);
                                 break;
                         }
                         break;
                case 's':        /* Get S polarity */
                         plot_polS = TRUE;
                         strcpy(txt_a, &argv[i][3]);
                         n=0; while (txt_a[n] && txt_a[n] != '/' && txt_a[n] != 'V' && txt_a[n] != 'G' && txt_a[n] != 'L') n++; txt_a[n]=0;
                         sizeS = GMT_convert_units (txt_a, GMT_INCH);

                         if(strchr(argv[i], 'V')) {
                             vecS = TRUE;
                             strcpy(txt_a,strchr(argv[i], 'V'));
                             if(strncmp(txt_a,"VG",(size_t)2) == 0 || strncmp(txt_a,"VL",(size_t)2) == 0 || strlen(txt_a) == 1) {
                                 v_width = 0.03; h_length = 0.12; h_width = 0.1; shape = gmtdefs.vector_shape;
                                 if (!gmtdefs.measure_unit) {
                                     v_width = 0.075; h_length = 0.3; h_width = 0.25; shape = gmtdefs.vector_shape;
                                 }
                             }
                             else {
                                strcpy(txt_a, strchr(argv[i], 'V')+1);
                                strcpy(txt_b, strchr(txt_a+1, '/')+1);
                                strcpy(txt_c, strchr(txt_b+1, '/')+1);
                                strcpy(txt_d, strchr(txt_c+1, '/')+1);
                                n=0; while (txt_a[n] && txt_a[n] != '/') n++; txt_a[n]=0;
                                n=0; while (txt_b[n] && txt_b[n] != '/') n++; txt_b[n]=0;
                                n=0; while (txt_c[n] && txt_c[n] != '/') n++; txt_c[n]=0;
                                n=0; while (txt_d[n] && txt_d[n] != '/' && txt_d[n] != 'L' && txt_d[n] != 'G') n++; txt_d[n]=0;
                                v_width = GMT_convert_units (txt_a, GMT_INCH);
                                h_length = GMT_convert_units (txt_b, GMT_INCH);
                                h_width = GMT_convert_units (txt_c, GMT_INCH);
                                shape = atof(txt_d);
                             }
                         }
                         if(strchr(argv[i], 'G')) {
                             sscanf (strchr(argv[i]+1,'G')+1,"%d/%d/%d",&sfill.rgb[0],&sfill.rgb[1],&sfill.rgb[2]);
                             sprintf(txt_a, "%d/%d/%d",sfill.rgb[0],sfill.rgb[1],sfill.rgb[2]);
                             GMT_getfill (txt_a, &sfill);
                             scolor = TRUE;
                         }
                         if(strchr(argv[i], 'L')) outline_s = TRUE;
                         break;
                case 'T':       /* Information about label printing */
                        label_s = TRUE;
                        if (strlen(argv[i]) > 2) {
                             sscanf (&argv[i][2], "%lf/%" GMT_LL "d/%" GMT_LL "d/%lf/", &angle_s,
                                     &form_s, &justify_s, &fontsize_s);
                        }
                        break;
                case 't':       /* Set color for station label */
                         GMT_getpen (&argv[i][2], &tpen);
                         def_tpen = TRUE;
                         break;

                case 'W':        /* Set line attributes */
                         GMT_getpen (&argv[i][2], &pen);
                         break;
                    
                /* Illegal options */
            
                default:        /* Options not recognized */
                         error = TRUE;
                         GMT_default_error (argv[i][1]);
                         break;
            }
        }
        else
            n_files++;
    }

    /* Check that the options selected are consistent */
    
    if (!project_info.region_supplied) {
        error++;
    }
    if(ech <= 0.) {
        error++;
    }
    if(get_position + get_size + get_symbol < 3) {
        error++;
    }
    
    if (argc == 1 || GMT_give_synopsis_and_exit || error) {    /* Display usage */
        fprintf (stderr,"%s %s - Plot polarities on the inferior focal half-sphere on maps\n\n",argv[0], GMT_VERSION);
        fprintf (stderr,"usage: argv[0] <infiles> %s %s\n", GMT_J_OPT, GMT_Rgeo_OPT);
        fprintf (stderr, " -Dlongitude/latitude -Msize[i/c] -S<symbol><size>[i/c]\n");
        fprintf (stderr, " [-A] [%s] [-Clongitude/latitude[W<pen>][Ppointsize]] [-E<fill>]\n", GMT_B_OPT);
        fprintf (stderr, " [-e[<pen>]] [-F<fill>] [-f[<pen>]] [-G<fill>] [-g[<pen>]] [%s] [-K] [-N] [-O] [-P]\n", GMT_Ho_OPT);
        fprintf (stderr, " [-s<half-size>/[V[<v_width/h_length/h_width/shape]][G<r/g/b>][L]\n");
        fprintf (stderr, " [-T[<labelinfo>]] [-t<pen>] [%s] [-V] [-W<pen>]\n", GMT_U_OPT);
        fprintf (stderr, " [%s] [%s] [%s]\n", GMT_X_OPT, GMT_Y_OPT, GMT_c_OPT);
        
        if (GMT_give_synopsis_and_exit) exit (EXIT_FAILURE);
        
        fprintf (stderr, "    <infiles> is one or more files.  If no, read standard input\n");
        GMT_explain_option ('j');
        GMT_explain_option ('R');
        fprintf (stderr, "        -D Set longitude/latitude\n");
        fprintf (stderr, "        -M Set size of beach ball in %s\n", GMT_unit_names[gmtdefs.measure_unit]);
        fprintf (stderr, "        -S to select symbol type and symbol size (in %s).  Choose between\n", GMT_unit_names[gmtdefs.measure_unit]);
        fprintf (stderr, "           st(a)r, (c)ircle, (d)iamond, (h)exagon, (i)nvtriangle\n");
        fprintf (stderr, "           (p)oint, (s)quare, (t)riangle, (x)cross\n");
        fprintf (stderr, "\n\tOPTIONS:\n");
        GMT_explain_option ('B');
        GMT_explain_option ('b');
        fprintf (stderr, "        -C Set new_longitude/new_latitude[W<pen>][Ppointsize]\n");
        fprintf (stderr, "           A line will be plotted between both positions\n");
        fprintf (stderr, "           Default is width = 3, color = current pen and pointsize = 0.015\n");
        fprintf (stderr, "        -E Specify color symbol for station in extensive part.\n");
        fprintf (stderr, "           Fill can be either <r/g/b> (each 0-255) for color \n");
        fprintf (stderr, "           or <gray> (0-255) for gray-shade [0].\n");
        fprintf (stderr, "           Default is light gray.\n");
        fprintf (stderr, "        -e Outline of station symbol in extensive part.\n");
        fprintf (stderr, "           Default is current pen.\n");
        fprintf (stderr, "        -F Specify background color of beach ball. It can be\n");
        fprintf (stderr, "           <r/g/b> (each 0-255) for color or <gray> (0-255) for gray-shade [0].\n");
        fprintf (stderr, "           Default is no fill\n");
        fprintf (stderr, "        -f Outline beach ball\n");
        fprintf (stderr, "           Add <pen attributes> if not current pen.\n");
        fprintf (stderr, "        -G Specify color symbol for station in compressive part. Fill can be either\n");
        fprintf (stderr, "           Fill can be either <r/g/b> (each 0-255) for color\n");
        fprintf (stderr, "           or <gray> (0-255) for gray-shade [0].\n");
        fprintf (stderr, "           Add L[<pen>] to outline\n");
        fprintf (stderr, "           Default is black.\n");
        fprintf (stderr, "        -g Outline of station symbol in compressive part.\n");
        fprintf (stderr, "           Add <pen attributes> if not current pen.\n");
        fprintf (stderr, "        -h Use special format derived from HYPO71 output.\n");
        GMT_explain_option ('H');
        GMT_explain_option ('K');
        fprintf (stderr, "        -N Do Not skip/clip symbols that fall outside map border\n");
        fprintf (stderr, "           [Default will ignore those outside]\n");
        GMT_explain_option ('O');
        GMT_explain_option ('P');
        fprintf (stderr, "        -s to plot S polarity azimuth.\n");
        fprintf (stderr, "           Azimuth of S polarity is in last column.\n");
        fprintf (stderr, "           It may be a vector (V option) or a segment. Give half-size in cm.\n");
        fprintf (stderr, "           L option is for outline\n");
        fprintf (stderr, "           -s<half-size>/[V[<v_width/h_length/h_width/shape>]][G<r/g/b>][L]\n");
        fprintf (stderr, "           Default definition of v is 0.075/0.3/0.25/1\n");
        fprintf (stderr, "           Outline is current pen\n");
        fprintf (stderr, "        -T[<info about labal printing>] to write station code.\n");
        fprintf (stderr, "           <angle/form/justify/fontsize in points>\n");
        fprintf (stderr, "           Default is 0.0/0/5/12\n");
        fprintf (stderr, "        -t sets pen attributes to write station codes [default is current pen]\n");
        GMT_explain_option ('U');
        GMT_explain_option ('V');
        fprintf (stderr, "        -W sets current pen attributes [width = %gp, color = (%d/%d/%d), texture = solid line].\n", pen.width, pen.rgb[0], pen.rgb[1], pen.rgb[2]);
        GMT_explain_option ('X');
        GMT_explain_option ('c');
        GMT_explain_option ('.');
        exit (EXIT_FAILURE);
    }
    
    if(!def_cpen) {
        cpen = pen; cpen.width = 3;
    }                                         /* pen for change position */
    if(!def_fpen) fpen = pen;                 /* outline beach ball */
    if(!def_gpen) gpen = pen;                 /* outline compressive stations */
    if(!def_epen) epen = pen;                 /* outline extensive stations */
    if(!def_spen) spen = pen;                 /* outline S_pol segment */
    if(!def_tpen) tpen = pen;                 /* pen to print station name */

    if (n_files > 0)
        nofile = FALSE;
    else
        n_files = 1;
    n_args = (argc > 1) ? argc : 2;
    
    greenwich = (west < 0.0 || east <= 0.0);
    
    GMT_err_fail (GMT_map_setup (west, east, south, north), "");

    GMT_plotinit (argc, argv);
    
    if (label_s) ps_setfont (gmtdefs.annot_font[0]);

    if (symbol > 0 && skip_if_outside) GMT_map_clip_on (GMT_no_rgb, 3);
    
    old_GMT_world_map = GMT_world_map;
    
    done = FALSE;


    for (fno = 1; !done && fno < n_args; fno++) {    /* Loop over all input files */
        if (!nofile && argv[fno][0] == '-') continue;
        if (nofile) {
            fp = GMT_stdin;
            done = TRUE;
        }
        else if ((fp = GMT_fopen (argv[fno], "r")) == NULL) {
            fprintf (stderr, "%s: Cannot open file %s\n", argv[0], argv[fno]);
            continue;
        }

        if (!nofile && gmtdefs.verbose) {
            fprintf (stderr, "%s: Working on file %s\n", argv[0], argv[fno]);
            sprintf (line, "File: %s", argv[fno]);
            ps_comment (line);
        }
        if (GMT_io.io_header[GMT_IN]) for (i = 0; i < GMT_io.n_header_recs; i++) not_used = GMT_fgets (line, 512, fp);
        
        GMT_world_map = TRUE;
        
        GMT_geo_to_xy(lon, lat, &plot_x0, &plot_y0);
        if(change_position) {
            GMT_setpen (&cpen);
            GMT_geo_to_xy(new_lon, new_lat, &new_plot_x0, &new_plot_y0);
            ps_circle(plot_x0, plot_y0, c_pointsize, cpen.rgb, 1);
            ps_plot(plot_x0, plot_y0, PSL_PEN_MOVE);
            ps_plot(new_plot_x0, new_plot_y0, PSL_PEN_DRAW_AND_STROKE);
            plot_x0 = new_plot_x0;
            plot_y0 = new_plot_y0;
        }
        if (skip_if_outside) {
            GMT_map_outside (lon, lat);
            if (GMT_abs (GMT_x_status_new) > 1 || GMT_abs (GMT_y_status_new) > 1) continue;
        }

        GMT_setpen (&fpen);
        ps_circle (plot_x0, plot_y0, ech, ffill.rgb, outline_F);

        while (GMT_fgets (line, BUFSIZ, fp)) {
            switch (hypo) {
                case 0 :
                    if(!plot_polS) {
                        sscanf (line, "%s %lf %lf %c", stacode, &azimut, &ih, &pol);
                    }
                    else {
                        n = sscanf (line, "%s %lf %lf %c %lf", stacode, &azimut, &ih, &pol, &azS);
                        if(n == 4) azS = -1.;
                    }
                    break;
                case 1 :
 	    	    memset ((void *)col, 0, 4 * GMT_TEXT_LEN * sizeof (char));
                   if(!plot_polS) {
                        sscanf (line, "%s %s %s %s %lf %lf %c", col[0], col[1], col[2], stacode, &azimut, &ih, col[3]);
                        pol = col[3][2];
                    }
                    else {
                        n = sscanf (line, "%s %s %s %s %lf %lf %c %lf", col[0], col[1], col[2], stacode, &azimut, &ih, col[3], &azS);
                        pol = col[3][2];
                        if(n == 7) azS = -1.;
                    }
                    break;
            }
        
            if(strcmp(col[0],"000000")!=0) {
                plongement = (ih - 90.) * M_PI / 180.;
                if(plongement  < 0.) {
                    plongement = -plongement;
                    azimut += 180 ;
                    symbol_size2 = symbol_size * 0.8;
                }
                else symbol_size2 = symbol_size;
                radius = sqrt(1. - sin(plongement));
                if(radius >= 0.97) radius = 0.97;
                azimut += 180;
                azimut *= M_PI / 180.;
                sincos (azimut, &si, &co);
                plot_x = radius * si * ech / 2. + plot_x0;
                plot_y = radius * co * ech / 2. + plot_y0;
                if (symbol == CROSS || symbol == POINT) ps_setpaint (fill.rgb);
            
                if(label_s) {
                    GMT_setpen (&tpen);
                    switch (justify_s) {
                        case 11 :
                            ps_text(plot_x-symbol_size2-0.1, plot_y-symbol_size2-0.1, fontsize_s, stacode, angle_s, 11, form_s);
                            break;
                        case 10 :
                            ps_text(plot_x, plot_y-symbol_size2-0.1, fontsize_s, stacode, angle_s, 10, form_s);
                            break;
                        case 9 :
                            ps_text(plot_x+symbol_size2+0.1, plot_y-symbol_size2-0.1, fontsize_s, stacode, angle_s, 9, form_s);
                            break;
                        case 7:
                            ps_text(plot_x-symbol_size2-0.1, plot_y, fontsize_s, stacode, angle_s, 7, form_s);
                            break;
                        case 6:
                            ps_text(plot_x, plot_y, fontsize_s, stacode, angle_s, 6, form_s);
                            break;
                        case 5:
                            ps_text(plot_x+symbol_size2+0.1, plot_y, fontsize_s, stacode, angle_s, 5, form_s);
                            break;
                        case 3:
                            ps_text(plot_x-symbol_size2-0.1, plot_y+symbol_size2+0.1, fontsize_s, stacode, angle_s, 3, form_s);
                            break;
                        case 2:
                            ps_text(plot_x, plot_y+symbol_size2+0.1, fontsize_s, col[3], angle_s, 2, form_s);
                            break;
                        case 1:
                            ps_text(plot_x+symbol_size2+0.1, plot_y+symbol_size2+0.1, fontsize_s, stacode, angle_s, 1, form_s);
                            break;
                    }
                }
    
                switch (symbol) {
                    case STAR:
                              if(pol == 'u' || pol == 'U' || pol == 'c' || pol == 'C' || pol == '+') {
                                  GMT_setpen (&gpen);
                                  ps_star (plot_x, plot_y, symbol_size2, gfill.rgb, outline_G);
                              }
                              else if(pol == 'r' || pol == 'R' || pol == 'd' || pol == 'D' || pol == '-') {
                                  GMT_setpen (&epen);
                                  ps_star (plot_x, plot_y, symbol_size2, efill.rgb, outline_E);
                              }
                              else {
                                  GMT_setpen (&pen);
                                  ps_cross (plot_x, plot_y, symbol_size2);
                              }
                              break;
                    case CROSS:
                              GMT_setpen (&pen);
                              ps_cross (plot_x, plot_y, symbol_size2);
                              break;
                    case POINT:
                              GMT_setpen (&pen);
                              ps_cross (plot_x, plot_y, POINTSIZE);
                              break;
                    case CIRCLE:
                              if(pol == 'u' || pol == 'U' || pol == 'c' || pol == 'C' || pol == '+') {
                                  GMT_setpen (&gpen);
                                  ps_circle (plot_x, plot_y, symbol_size2, gfill.rgb, outline_G);
                              }
                              else if(pol == 'r' || pol == 'R' || pol == 'd' || pol == 'D' || pol == '-') {
                                  GMT_setpen (&epen);
                                  ps_circle (plot_x, plot_y, symbol_size2, efill.rgb, outline_E);
                              }
                              else {
                                  GMT_setpen (&pen);
                                  ps_cross (plot_x, plot_y, symbol_size2);
                              }
                              break;
                    case SQUARE:
                              if(pol == 'u' || pol == 'U' || pol == 'c' || pol == 'C' || pol == '+') {
                                  GMT_setpen (&gpen);
                                  ps_square (plot_x, plot_y, symbol_size2, gfill.rgb, outline_G);
                              }
                              else if(pol == 'r' || pol == 'R' || pol == 'd' || pol == 'D' || pol == '-') {
                                  GMT_setpen (&epen);
                                  ps_square (plot_x, plot_y, symbol_size2, efill.rgb, outline_E);
                              }
                              else {
                                  GMT_setpen (&pen);
                                  ps_cross (plot_x, plot_y, symbol_size2);
                              }
                              break;
                    case HEXAGON:
                              if(pol == 'u' || pol == 'U' || pol == 'c' || pol == 'C' || pol == '+') {
                                  GMT_setpen (&gpen);
                                  ps_hexagon (plot_x, plot_y, symbol_size2, gfill.rgb, outline_G);
                              }
                              else if(pol == 'r' || pol == 'R' || pol == 'd' || pol == 'D' || pol == '-') {
                                  GMT_setpen (&epen);
                                  ps_hexagon (plot_x, plot_y, symbol_size2, efill.rgb, outline_E);
                              }
                              else {
                                  GMT_setpen (&pen);
                                  ps_cross (plot_x, plot_y, symbol_size2);
                              }
                              break;
                    case TRIANGLE:
                              if(pol == 'u' || pol == 'U' || pol == 'c' || pol == 'C' || pol == '+') {
                                  GMT_setpen (&gpen);
                                  ps_triangle (plot_x, plot_y, symbol_size2, gfill.rgb, outline_G);
                              }
                              else if(pol == 'r' || pol == 'R' || pol == 'd' || pol == 'D' || pol == '-') {
                                  GMT_setpen (&epen);
                                  ps_triangle (plot_x, plot_y, symbol_size2, efill.rgb, outline_E);
                              }
                              else {
                                  GMT_setpen (&pen);
                                  ps_cross (plot_x, plot_y, symbol_size2);
                              }
                              break;
                    case ITRIANGLE:
                              if(pol == 'u' || pol == 'U' || pol == 'c' || pol == 'C' || pol == '+') {
                                  GMT_setpen (&gpen);
                                  ps_itriangle (plot_x, plot_y, symbol_size2, gfill.rgb, outline_G);
                              }
                              else if(pol == 'r' || pol == 'R' || pol == 'd' || pol == 'D' || pol == '-') {
                                  GMT_setpen (&epen);
                                  ps_itriangle (plot_x, plot_y, symbol_size2, efill.rgb, outline_E);
                              }
                              else {
                                  GMT_setpen (&pen);
                                  ps_cross (plot_x, plot_y, symbol_size2);
                              }
                              break;
                    case DIAMOND:
                              if(pol == 'u' || pol == 'U' || pol == 'c' || pol == 'C' || pol == '+') {
                                  GMT_setpen (&gpen);
                                  ps_diamond (plot_x, plot_y, symbol_size2, gfill.rgb, outline_G);
                              }
                              else if(pol == 'r' || pol == 'R' || pol == 'd' || pol == 'D' || pol == '-') {
                                  GMT_setpen (&epen);
                                  ps_diamond (plot_x, plot_y, symbol_size2, efill.rgb, outline_E);
                              }
                              else {
                                  GMT_setpen (&pen);
                                  ps_cross (plot_x, plot_y, symbol_size2);
                              }
                              break;
                }
                if(plot_polS && azS >= 0.) {
                    GMT_setpen (&spen);
                    sincos (azS*M_PI/180., &si, &co);
                    if(vecS) {
                        ps_vector(plot_x - sizeS*si, plot_y - sizeS*co, 
                            plot_x + sizeS*si, plot_y + sizeS*co, v_width, 
                            h_length, h_width, gmtdefs.vector_shape, sfill.rgb, outline_s);
                    }
                    else { 
                        if(scolor) ps_setpaint (sfill.rgb);
                        else ps_setpaint (pen.rgb);
                        ps_plot(plot_x - sizeS*si, plot_y - sizeS*co, PSL_PEN_MOVE);
                        ps_plot(plot_x + sizeS*si, plot_y + sizeS*co, PSL_PEN_DRAW_AND_STROKE); 
                    }
                }
            }
        }
        if (fp != stdin) GMT_fclose (fp);
    }
    
    if (skip_if_outside) GMT_map_clip_off ();

    GMT_world_map = old_GMT_world_map;
    
    if (pen.texture[0]) ps_setdash (CNULL, 0);

    GMT_map_basemap ();

    GMT_plotend ();
    
    GMT_end (argc, argv);

    exit (EXIT_SUCCESS);
}