📄 xwigb.c
字号:
/* Copyright (c) Colorado School of Mines, 2006.*//* All rights reserved. *//* XWIGB: $Revision: 1.43 $ ; $Date: 2006/05/31 18:06:55 $ */#include "xplot.h"#include <X11/Xatom.h>#include <X11/keysym.h>/*********************** self documentation **********************/char *sdoc[] = {" "," XWIGB - X WIGgle-trace plot of f(x1,x2) via Bitmap "," "," xwigb n1= [optional parameters] <binaryfile "," "," X Functionality: "," Button 1 Zoom with rubberband box "," Button 2 Show mouse (x1,x2) coordinates while pressed "," q or Q key Quit "," s key Save current mouse (x1,x2) location to file "," p or P key Plot current window with pswigb (only from disk files) "," a or page up keys enhance clipping by 10% "," c or page down keys reduce clipping by 10% "," up,down,left,right keys move zoom window by half width/height "," i or +(keypad) zoom in by factor 2 "," o or -(keypad) zoom out by factor 2 "," l lock the zoom while moving the coursor "," u unlock the zoom "," 1,2,...,9 Zoom/Move factor of the window size "," "," Notes: "," Reaching the window limits while moving within changes the zoom "," factor in this direction. The use of zoom locking(l) disables it"," "," Required Parameters: "," n1 number of samples in 1st (fast) dimension "," "," Optional Parameters: "," d1=1.0 sampling interval in 1st dimension "," f1=0.0 first sample in 1st dimension "," n2=all number of samples in 2nd (slow) dimension "," d2=1.0 sampling interval in 2nd dimension "," f2=0.0 first sample in 2nd dimension "," x2=f2,f2+d2,... array of sampled values in 2nd dimension "," mpicks=/dev/tty file to save mouse picks in "," bias=0.0 data value corresponding to location along axis 2"," perc=100.0 percentile for determining clip "," clip=(perc percentile) data values < bias+clip and > bias-clip are clipped"," xcur=1.0 wiggle excursion in traces corresponding to clip"," wt=1 =0 for no wiggle-trace; =1 for wiggle-trace "," va=1 =0 for no variable-area; =1 for variable-area fill"," =2 for variable area, solid/grey fill "," SHADING: 2<=va<=5 va=2 light grey, va=5 black "," verbose=1 =1 for info printed on stderr (0 for no info) "," xbox=50 x in pixels of upper left corner of window "," ybox=50 y in pixels of upper left corner of window "," wbox=550 width in pixels of window "," hbox=700 height in pixels of window "," x1beg=x1min value at which axis 1 begins "," x1end=x1max value at which axis 1 ends "," d1num=0.0 numbered tic interval on axis 1 (0.0 for automatic)"," f1num=x1min first numbered tic on axis 1 (used if d1num not 0.0)"," n1tic=1 number of tics per numbered tic on axis 1 "," grid1=none grid lines on axis 1 - none, dot, dash, or solid"," x2beg=x2min value at which axis 2 begins "," x2end=x2max value at which axis 2 ends "," d2num=0.0 numbered tic interval on axis 2 (0.0 for automatic)"," f2num=x2min first numbered tic on axis 2 (used if d2num not 0.0)"," n2tic=1 number of tics per numbered tic on axis 2 "," grid2=none grid lines on axis 2 - none, dot, dash, or solid"," label2= label on axis 2 "," labelfont=Erg14 font name for axes labels "," title= title of plot "," titlefont=Rom22 font name for title "," windowtitle=xwigb title on window "," labelcolor=blue color for axes labels "," titlecolor=red color for title "," gridcolor=blue color for grid lines "," style=seismic normal (axis 1 horizontal, axis 2 vertical) or "," seismic (axis 1 vertical, axis 2 horizontal) "," endian= =0 little endian =1 big endian "," interp=0 no interpolation in display "," =1 use 8 point sinc interpolation "," wigclip=0 If 0, the plot box is expanded to accommodate "," the larger wiggles created by xcur>1. If this "," flag is non-zero, the extra-large wiggles are "," are clipped at the boundary of the plot box. "," plotfile=plotfile.ps filename for interactive ploting (P) "," curve=curve1,curve2,... file(s) containing points to draw curve(s) "," npair=n1,n2,n2,... number(s) of pairs in each file "," curvecolor=color1,color2,... color(s) for curve(s) "," "," Notes: "," Xwigb will try to detect the endian value of the X-display and will "," set it to the right value. If it gets obviously wrong information the "," endian value will be set to the endian value of the machine that is "," given at compile time as the value of CWPENDIAN defined in cwp.h "," and set via the compile time flag ENDIANFLAG in Makefile.config. "," "," The only time that you might want to change the value of the endian "," variable is if you are viewing traces on a machine with a different "," byte order than the machine you are creating the traces on AND if for "," some reason the automaic detection of the display byte order fails. "," Set endian to that of the machine you are viewing the traces on. "," "," The interp flag is useful for making better quality wiggle trace for "," making plots from screen dumps. However, this flag assumes that the "," data are purely oscillatory. This option may not be appropriate for all"," data sets. "," "," The curve file is an ascii file with the points specified as x1 x2 "," pairs, separated by a space, one pair to a line. A \"vector\" of curve"," files and curve colors may be specified as curvefile=file1,file2,etc. "," and curvecolor=color1,color2,etc, and the number of pairs of values "," in each file as npair=npair1,npair2,... . "," ",NULL};/* * AUTHOR: Dave Hale, Colorado School of Mines, 08/09/90 * * Endian stuff by: * Morten Wendell Pedersen, Aarhus University (visiting CSM, June 1995) * & John Stockwell, Colorado School of Mines, 5 June 1995 * * Stewart A. Levin, Mobil - Added ps print option * John Stockwell - Added optional sinc interpolation * Stewart A. Levin, Mobil - protect title, labels in pswigb call * * Brian J. Zook, SwRI - Added style=normal and wigclip flag * * Brian K. Macy, Phillips Petroleum, 11/27/98, added curve plotting option * Curve plotting notes: * MODIFIED: P. Michaels, Boise State Univeristy 29 December 2000 * Added solid/grey color scheme for peaks/troughs * * G.Klein, IFG Kiel University, 2002-09-29, added cursor scrolling and * interactive change of zoom and clipping. * IFM-GEOMAR Kiel, 2004-03-12, added zoom locking * IFM-GEOMAR Kiel, 2004-03-25, interactive plotting fixed *//************************ end self doc ********************************//* 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, int style);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, int endian, int interp, int wigclip, int style);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(XEvent event, int style, FILE *mpicksfp, int x, int y, int width, int height, float x1begb, float x1endb, float x2begb, float x2endb, float p2beg, float p2end);static XImage *RotImage90(Display *dpy, XImage *oldImage);intmain (int argc, char **argv){ int n1,n2,n1tic,n2tic,wt,va, i2,grid1,grid2,style=0, nz,iz,verbose, xbox,ybox,wbox,hbox, xb,yb,wb,hb, x,y,width,height, imageOutOfDate,winwidth=-1,winheight=-1, showloc=0,endian,interp,wigclip; unsigned long nfloats; 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=0,p2end=0; char *label1="",*label2="",*title="",*windowtitle="xwigb", *labelfont="Erg14",*titlefont="Rom22", *styles="seismic",*grid1s="none",*grid2s="none", *labelcolor="blue",*titlecolor="red", *gridcolor="blue",keybuf[256],*mpicks; 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; float **x1curve=NULL,**x2curve=NULL; int i,j,curve,*npair=NULL,ncurvecolor=0; char **curvefile=NULL,**curvecolor=NULL; FILE *curvefp=NULL; cwp_Bool is_curve=cwp_false; /* added by Gerald Klein */ char *plotfile; /* filename of plotfile GK */ int lock=0; /* lock/unlock zoom while scrolling */ float mve; /* distance for scrolling */ float mvefac=8.; /* window factor for scrolldistance * 2=half window size; * 8=one eighths of the window size */ char *msg=""; /* message on screen */ /* initialize getpar */ initargs(argc,argv); requestdoc(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 = 0.0; getparfloat("f1",&f1); x1min = (d1>0.0)?f1:f1+(n1-1)*d1; x1max = (d1<0.0)?f1:f1+(n1-1)*d1; /* get parameters describing 2nd dimension sampling */ if ((n2=countparval("x2"))==0 && !getparint("n2",&n2)) { if (efseeko(infp,(off_t) 0,SEEK_END)!=0) err("must specify n2 if in a pipe!\n"); nfloats =(int) (eftell(infp)/((off_t) sizeof(float))); efseeko(infp,(off_t) 0,SEEK_SET); n2 = (int) (nfloats/n1); } x2 = ealloc1float(n2); if (!getparfloat("x2",x2)) { d2 = 1.0; getparfloat("d2",&d2); f2 = 0.0; 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]); } if (!getparstring("plotfile", &plotfile)) plotfile = "plotfile.ps" ; /* set up file to save mouse picks */ if (!getparstring("mpicks", &mpicks)) mpicks = "/dev/tty"; mpicksfp = efopen(mpicks, "w"); /* set up curve plotting */ if ((curve=countparval("curve"))!=0) { curvefile=(char**)ealloc1(curve,sizeof(void*)); getparstringarray("curve",curvefile); if ((x1curve=(float**)malloc(curve*sizeof(void*)))==NULL) err("Could not allocate x1curve pointers\n"); if ((x2curve=(float**)malloc(curve*sizeof(void*)))==NULL) err("Could not allocate x2curve pointers\n"); npair=ealloc1int(curve); getparint("npair",npair); is_curve = cwp_true; } else { npair=(int *)NULL; curvefile=(char **)NULL; x1curve=(float **)NULL; x2curve=(float **)NULL; is_curve = cwp_false; } if (is_curve) { if ((ncurvecolor=countparval("curvecolor"))<curve) { curvecolor=(char**)ealloc1(curve,sizeof(void*)); if (!getparstringarray("curvecolor",curvecolor)) { curvecolor[0]=(char *)cwp_strdup("blue\0"); ncurvecolor=1; } for (i=ncurvecolor; i<curve; i++) curvecolor[i]=(char *)cwp_strdup(curvecolor[ncurvecolor-1]); } else if( ncurvecolor ){ curvecolor=(char**)ealloc1(ncurvecolor,sizeof(void*)); getparstringarray("curvecolor",curvecolor); } for (j=0; j<curve; j++) { curvefp=efopen(curvefile[j],"r"); x1curve[j]=ealloc1float(npair[j]); x2curve[j]=ealloc1float(npair[j]); for (i=0; i<npair[j]; i++) { fscanf(curvefp,"%f",&x1curve[j][i]); fscanf(curvefp,"%f",&x2curve[j][i]); } efclose(curvefp); } } /* 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); /* set wt=va for va with solid/grey coloring */ if (va>=2) { wt=va; va=1; } xcur = 1.0; getparfloat("xcur",&xcur); wigclip = 0; getparint("wigclip",&wigclip); /* 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); getparstring("title",&title); getparstring("titlefont",&titlefont); titlesize = 24.0; getparfloat("titlesize",&titlesize); getparstring("style",&styles); if (STREQ("seismic",styles)) style = SEISMIC; else if (STREQ("normal",styles)) style = NORMAL; else err("Unknown style='%s'\n",styles); getparstring("titlecolor",&titlecolor); getparstring("labelcolor",&labelcolor); getparstring("gridcolor",&gridcolor); getparstring("windowtitle",&windowtitle); /* initialize zoom box parameters */ x1begb = x1beg; x1endb = x1end; x2begb = x2beg; x2endb = x2end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -