⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mwpick.c

📁 seismic software,very useful
💻 C
📖 第 1 页 / 共 2 页
字号:
char *sdoc = "MWPICK - Mute pick using X WIGgle-trace plot of f(x1,x2) via Bitmap\n""\n""mwpick n1= [optional parameters] <binaryfile\n""itoff=0   output offset-time when itoff=0; output time-offset when \n""          itoff=1 \n""\n""See mutepick \n""\n"" author: Zhiming Li                            9/12/91                 \n""\n";#include "comva.h"#include "par.h"#include "xplot.h"#include <X11/Xatom.h>#include <X11/keysym.h>/* functions defined and used internally */static void zoomBox (int x, int y, int w, int h, 	int xb, int yb, int wb, int hb,	float x1, float x2,	float y1, float y2,	float *x1b, float *x2b,	float *y1b, float *y2b);static XImage *newBitmap (Display *dpy, int width, int height,	int n1, float d1, float f1, int n2, float *x2, float *z,	float x1beg, float x1end, float x2beg, float x2end,	float xcur, float clip, int wt, int va,	float *p2begp, float *p2endp);void xMouseLoc(Display *dpy, Window win, XEvent event, int style, Bool show,	int x, int y, int width, int height,	float x1begb, float x1endb, float x2begb, float x2endb,	float p2beg, float p2end);void xMousePrint(Display *dpy, Window win, XEvent event, int style,        FILE *mpicksfp, int x, int y, int width, int height,        float x1begb, float x1endb, float x2begb, float x2endb,        char *pcard, int ppos, int itoff,         float *xtp, float *tp, int ntp,        float *xbt, float *bt, int nbt, int fex);void xMousePicks(Display *dpy, Window win, XEvent event, int style,	char *topmutecolr, char *bottommutecolr,        FILE *mpicksfp, int x, int y, int width, int height,        float x1begb, float x1endb, float x2begb, float x2endb,        float *xtp, float *tp, int *ntp, float *xbt, float *bt, int *nbt,        int pkey, int tkey, GC gc, int *savebg,	float p2beg, float p2end);static Display *dpy;static Window win;main (argc,argv)int argc; char **argv;{	int n1,n2,n1tic,n2tic,nfloats,wt,va,		i1,i2,grid1,grid2,style,		nz,iz,verbose,		xbox,ybox,wbox,hbox,		xb,yb,wb,hb,		x,y,width,height,		i,j,nx,ny,itoff,		imageOutOfDate,winwidth=-1,winheight=-1,		showloc=0,ppos,ntp=0,nbt=0,tkey=0,pkey,fex, savebg;	float labelsize,titlesize,perc,clip,xcur,bias,		d1,f1,d2,f2,*z,*temp,*x2,		x1beg,x1end,x2beg,x2end,		x1min,x1max,x2min,x2max,		d1num,f1num,d2num,f2num,		x1begb,x1endb,x2begb,x2endb,p2beg,p2end,		*xtp,*tp,*xbt,*bt;	char *label1="time (or depth)",*label2="offset (or cdp)",              title[80],*ttl,		*labelfont="Erg14",*titlefont="Rom22",		*styles="seismic",*grid1s="none",*grid2s="none",		*labelcolor="blue",*titlecolor="red",		*gridcolor="blue",keybuf[256],*mpicks,		*topmutecolor="blue",*bottommutecolor="red",		*pcard="MUTE", strppos[5];	FILE *infp=stdin, *mpicksfp;/*	Display *dpy;	Window win;*/	XEvent event;	KeySym keysym;	XComposeStatus keystat;	XImage *image=NULL;	GC gci;	int scr;	unsigned long black,white;	/* initialize getpar */	initargs(argc,argv);	askdoc(1);	/* get parameters describing 1st dimension sampling */	if (!getparint("n1",&n1))		err("Must specify number of samples in 1st dimension!\n");	d1 = 1.0;  getparfloat("d1",&d1);	f1 = d1;  getparfloat("f1",&f1);	x1min = (d1>0.0)?f1:f1+(n1-1)*d1;	x1max = (d1<0.0)?f1:f1+(n1-1)*d1;	if (!getparint("itoff",&itoff)) itoff = 0;	/* get parameters describing 2nd dimension sampling */	if ((n2=countparval("x2"))==0 && !getparint("n2",&n2)) {			if (fseek(infp,0L,2)!=0)				err("must specify n2 if in a pipe!\n");			nfloats = eftell(infp)/sizeof(float);			efseek(infp,0L,0);			n2 = nfloats/n1;	}	x2 = ealloc1float(n2);	if (!getparfloat("x2",x2)) {		d2 = 1.0;  getparfloat("d2",&d2);		f2 = d2;  getparfloat("f2",&f2);		for (i2=0; i2<n2; i2++)			x2[i2] = f2+i2*d2;	}	for (i2=1,x2min=x2max=x2[0]; i2<n2; i2++) {		x2min = MIN(x2min,x2[i2]);		x2max = MAX(x2max,x2[i2]);	}	/* set up file to save mouse picks */	if (!getparstring("mpicks", &mpicks)) {		mpicksfp = stderr;		fex = 0;	} else {		/* if file exist */                if((mpicksfp = fopen(mpicks,"r"))!=NULL) {                        fclose(mpicksfp);                        mpicksfp = efopen(mpicks,"a");                        fex = 1;                } else {                        mpicksfp = efopen(mpicks,"w");                        fex = 0;                }	}        if (!getparint("ppos", &ppos)) ppos = 1;        /* 256 picks maximum */	xtp = (float*) malloc(256*sizeof(float));        tp = (float*) malloc(256*sizeof(float));        xbt = (float*) malloc(256*sizeof(float));        bt = (float*) malloc(256*sizeof(float));	/* read binary data to be plotted */	nz = n1*n2;	z = ealloc1float(nz);	if (fread(z,sizeof(float),nz,infp)!=nz)		err("error reading input file");	/* if necessary, subtract bias */	if (getparfloat("bias",&bias) && bias!=0.0)		for (iz=0; iz<nz; iz++)			z[iz] -= bias;		/* if necessary, determine clip from percentile */	if (!getparfloat("clip",&clip)) {		perc = 100.0;  getparfloat("perc",&perc);		temp = ealloc1float(nz);		for (iz=0; iz<nz; iz++)			temp[iz] = fabs(z[iz]);		iz = (nz*perc/100.0);		if (iz<0) iz = 0;		if (iz>nz-1) iz = nz-1;		qkfind(iz,nz,temp);		clip = temp[iz];		free1float(temp);	}	verbose = 1;  getparint("verbose",&verbose);	if (verbose) warn("clip=%g\n",clip);	/* get wiggle-trace-variable-area parameters */	wt = 1;  getparint("wt",&wt);	va = 1;  getparint("va",&va);	xcur = 1.0;  getparfloat("xcur",&xcur);	/* get axes parameters */	xbox = 50; getparint("xbox",&xbox);	ybox = 50; getparint("ybox",&ybox);	wbox = 550; getparint("wbox",&wbox);	hbox = 700; getparint("hbox",&hbox);	x1beg = x1min; getparfloat("x1beg",&x1beg);	x1end = x1max; getparfloat("x1end",&x1end);	d1num = 0.0; getparfloat("d1num",&d1num);	f1num = x1min; getparfloat("f1num",&f1num);	n1tic = 1; getparint("n1tic",&n1tic);	getparstring("grid1",&grid1s);	if (STREQ("dot",grid1s)) grid1 = DOT;	else if (STREQ("dash",grid1s)) grid1 = DASH;	else if (STREQ("solid",grid1s)) grid1 = SOLID;	else grid1 = NONE;	getparstring("label1",&label1);	x2beg = x2min; getparfloat("x2beg",&x2beg);	x2end = x2max; getparfloat("x2end",&x2end);	d2num = 0.0; getparfloat("d2num",&d2num);	f2num = 0.0; getparfloat("f2num",&f2num);	n2tic = 1; getparint("n2tic",&n2tic);	getparstring("grid2",&grid2s);	if (STREQ("dot",grid2s)) grid2 = DOT;	else if (STREQ("dash",grid2s)) grid2 = DASH;	else if (STREQ("solid",grid2s)) grid2 = SOLID;	else grid2 = NONE;	getparstring("label2",&label2);	getparstring("labelfont",&labelfont);	labelsize = 18.0; getparfloat("labelsize",&labelsize);	if(!getparstring("title",&ttl)) {                ttl = (char*) malloc(30*sizeof(char));                strcpy(ttl,"Mute Picking ");        }        sprintf(title,"%s at position = %5d \0",ttl,ppos);	getparstring("titlefont",&titlefont);	titlesize = 24.0; getparfloat("titlesize",&titlesize);	getparstring("style",&styles);	if (STREQ("seismic",styles)) style = SEISMIC;	else err("Sorry, only style=seismic is currently available!");	getparstring("titlecolor",&titlecolor);	getparstring("labelcolor",&labelcolor);	getparstring("gridcolor",&gridcolor);	getparstring("topmutecolor",&topmutecolor);	getparstring("bottommutecolor",&bottommutecolor);		/* initialize zoom box parameters */	x1begb = x1beg;  x1endb = x1end;	x2begb = x2beg;  x2endb = x2end;	/* connect to X server */	if ((dpy=XOpenDisplay(NULL))==NULL)		err("Cannot connect to display %s!\n",XDisplayName(NULL));	scr = DefaultScreen(dpy);	black = BlackPixel(dpy,scr);	white = WhitePixel(dpy,scr);		/* create window */	win = xNewWindow(dpy,xbox,ybox,wbox,hbox,black,white,"xwpick");			/* make GC for image */	gci = XCreateGC(dpy,win,0,NULL);	/* set normal event mask */	XSelectInput(dpy,win,		StructureNotifyMask |		ExposureMask |		KeyPressMask |		PointerMotionMask |		ButtonPressMask |		ButtonReleaseMask |		Button1MotionMask |		Button2MotionMask);		/* map window */	XMapWindow(dpy,win);		/* clear the window */	XClearWindow(dpy,win);						/* determine good size for axes box */	xSizeAxesBox(dpy,win,		labelfont,titlefont,style,		&x,&y,&width,&height);		/* note that image is out of date */	imageOutOfDate = 1;	savebg = 1;	/* main event loop */	while(True) {		XNextEvent(dpy,&event);		/* if window was resized */		if (event.type==ConfigureNotify &&			(event.xconfigure.width!=winwidth ||			 event.xconfigure.height!=winheight)) {			winwidth = event.xconfigure.width;			winheight = event.xconfigure.height;										/* determine good size for axes box */			xSizeAxesBox(dpy,win,				labelfont,titlefont,style,				&x,&y,&width,&height);			/* clear background */                        if(savebg) XSetWindowBackground(dpy,win,0L);			/* clear the window */			XClearWindow(dpy,win);						/* note that image is out of date */			imageOutOfDate = 1;		/* else if window exposed */		} else if (event.type==Expose) {						/* clear all expose events from queue */			while (XCheckTypedEvent(dpy,Expose,&event));						/* if necessary, make new image */			if (imageOutOfDate) {				if (image!=NULL) {					free1(image->data);					XDestroyImage(image);				}				image = newBitmap(dpy,width,height,					n1,d1,f1,n2,x2,z,					x1begb,x1endb,x2begb,x2endb,					xcur,clip,wt,va,					&p2beg,&p2end);				imageOutOfDate = 0;			}				/* clear background */                        if(savebg) XSetWindowBackground(dpy,win,0L);			/* draw image (before axes so grid lines visible) */			XPutImage(dpy,win,gci,image,0,0,x,y,				image->width,image->height);						/* draw axes on top of image */			xDrawAxesBox(dpy,win,				x,y,width,height,				x1begb,x1endb,0.0,0.0,				d1num,f1num,n1tic,grid1,label1,				x2begb,x2endb,p2beg,p2end,				d2num,f2num,n2tic,grid2,label2,				labelfont,title,titlefont,				labelcolor,titlecolor,gridcolor,				style);		/* else if key down */		} else if (event.type==KeyPress) {			XLookupString(&event,keybuf,0,&keysym,&keystat);			/* add, delete or insert picks */			pkey =99;                        if (keysym==XK_a) {                                pkey = 0;                                tkey = 0;                        } else if ( keysym==XK_A ) {                                pkey = 0;                                tkey = 1;                        } else if ( keysym==XK_d ) {                                pkey = 1;                                tkey = 0;                        } else if ( keysym==XK_D ) {                                pkey = 1;                                tkey = 1;                        } else if ( keysym==XK_i ) {                                pkey = 2;			        tkey = 0;                        } else if ( keysym==XK_I ) {                                pkey = 2;                                tkey = 1;                        } else if (keysym==XK_p) {                                pkey = 3;                        }                        if (pkey<=3) {                                xMousePicks(dpy,win,event,style,					topmutecolor,bottommutecolor,                                        mpicksfp, x,y,width,height,                                        x1begb,x1endb,x2begb,x2endb,                                        xtp,tp,&ntp,xbt,bt,&nbt,pkey,tkey,gci,					&savebg,p2beg,p2end);			/* output the picks */                        } else if (keysym==XK_s) {                                xMousePrint(dpy,win,event,style,                                        mpicksfp, x,y,width,height,                                        x1begb,x1endb,x2begb,x2endb,                                        pcard,ppos,itoff,										xtp,tp,ntp,xbt,bt,nbt,fex);			} else if (keysym==XK_Q) {			/* This is the exit from the event loop */				break;			} else {				continue;			}		/* else if button down (1 == zoom, 2 == mouse tracking */		} else if (event.type==ButtonPress) {			/* if 1st button: zoom */			if (event.xbutton.button==Button1) {				savebg = 1;				/* track pointer and get new box */				xRubberBox(dpy,win,event,&xb,&yb,&wb,&hb);							/* if new box has tiny width or height */				if (wb<4 || hb<4) {									/* reset box to initial values */					x1begb = x1beg;					x1endb = x1end;					x2begb = x2beg;					x2endb = x2end;							/* else, if new box has non-zero width				/* if new box has zero width or height */				} else {								/* calculate new box parameters */					zoomBox(x,y,width,height,						xb,yb,wb,hb,						x2begb,x2endb,						x1begb,x1endb,						&x2begb,&x2endb,						&x1begb,&x1endb);				}				/* clear background */                                if(savebg) XSetWindowBackground(dpy,win,0L);				/* clear area and force an expose event */				XClearArea(dpy,win,0,0,0,0,True);							/* note that image is out of date */				imageOutOfDate = 1;						/* else if 2nd button down: display mouse coords */			} else if (event.xbutton.button==Button2) {				showloc = 1;				xMouseLoc(dpy,win,event,style,showloc,					  x,y,width,height,x1begb,x1endb,					  x2begb,x2endb,p2beg,p2end);			/* else if 3rd button down: track and pick */	                } else if (event.xbutton.button==Button3) {				pkey = 0;                                xMousePicks(dpy,win,event,style,					topmutecolor,bottommutecolor,                                        mpicksfp, x,y,width,height,                                        x1begb,x1endb,x2begb,x2endb,                                        xtp,tp,&ntp,xbt,bt,&nbt,pkey,tkey,gci,					&savebg,p2beg,p2end);			} else {				continue;			}		/* else if pointer has moved */		} else if (event.type==MotionNotify) {						/* if button2 down, show mouse location */			if (showloc)				xMouseLoc(dpy,win,event,style,True,					x,y,width,height,x1begb,x1endb,					x2begb,x2endb,p2beg,p2end);		/* else if button2 released, stop tracking */		} else if (event.type==ButtonRelease &&			   event.xbutton.button==Button2) {			showloc = 0;		}	} /* end of event loop */	/* close connection to X server */	XCloseDisplay(dpy);	return EXIT_SUCCESS;}			/* update parameters associated with zoom box */static void zoomBox (int x, int y, int w, int h, 	int xb, int yb, int wb, int hb,	float x1, float x2,	float y1, float y2,	float *x1b, float *x2b,	float *y1b, float *y2b){	/* if width and/or height of box are zero, just copy values */	if (wb==0 || hb==0) {		*x1b = x1; *x2b = x2;		*y1b = y1; *y2b = y2;		return;			} 		/* clip box */	if (xb<x) {		wb -= x-xb;		xb = x;	}	if (yb<y) {		hb -= y-yb;		yb = y;	}	if (xb+wb>x+w) wb = x-xb+w;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -