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

📄 sumigps.c

📁 su 的源代码库
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) Colorado School of Mines, 2006.*//* All rights reserved.                       *//* SUMIGPS: $Revision: 1.13 $ ; $Date: 2003/06/09 16:17:07 $		*/#include "su.h"#include "segy.h"#include "header.h"#include <signal.h>/*********************** self documentation ******************************/char *sdoc[] = {"									"," SUMIGPS - MIGration by Phase Shift with turning rays			","									"," sumigps <stdin >stdout [optional parms]				","									"," Required Parameters:							"," 	None								","									"," Optional Parameters:							"," dt=from header(dt) or .004	time sampling interval			"," dx=from header(d2) or 1.0	distance between sucessive cdp's	"," ffil=0,0,0.5/dt,0.5/dt  trapezoidal window of frequencies to migrate	"," tmig=0.0		times corresponding to interval velocities in vmig"," vmig=1500.0		interval velocities corresponding to times in tmig"," vfile=		binary (non-ascii) file containing velocities v(t)"," nxpad=0		number of cdps to pad with zeros before FFT	"," ltaper=0		length of linear taper for left and right edges", " verbose=0		=1 for diagnostic print				","									","									"," tmpdir= 	 if non-empty, use the value as a directory path	","		 prefix for storing temporary files; else if the	","	         the CWP_TMPDIR environment variable is set use		","	         its value for the path; else use tmpfile()		"," 									"," Notes:								"," Input traces must be sorted by either increasing or decreasing cdp.	","									"," The tmig and vmig arrays specify an interval velocity function of time."," Linear interpolation and constant extrapolation is used to determine	"," interval velocities at times not specified.  Values specified in tmig	"," must increase monotonically.						","									"," Alternatively, interval velocities may be stored in a binary file	"," containing one velocity for every time sample.  If vfile is specified,"," then the tmig and vmig arrays are ignored.				","									"," The time of first sample is assumed to be zero, regardless of the value"," of the trace header field delrt.					",NULL};/* Credits: *	CWP: Dave Hale (originally called supsmig.c) * *  Trace header fields accessed:  ns, dt, d2 *//**************** end self doc *******************************************/typedef struct TATableStruct {	int np;	float *p;	float *taumax;	float *taumin;	float *tturn;	float **t;	float **a;} TATable;void mig1k (TATable *table, float k, float ffil[4], int ntflag,	int nt, float dt, complex *cp,	int ntau, float dtau, complex *cq);TATable *tableta (int np, int ntau, float dtau, float vtau[],	int nt, float dt, int verbose);static void closefiles(void);/* Globals (so can trap signal) defining temporary disk files */char tracefile[BUFSIZ];	/* filename for the file of traces	*/char headerfile[BUFSIZ];/* filename for the file of headers	*/FILE *tracefp;		/* fp for trace storage file		*/FILE *headerfp;		/* fp for header storage file		*/segy tr;intmain(int argc, char **argv){	int nt,nx,nxfft,nxpad,ix,it,nk,ik,nfil,ntflag,		ltaper,ntmig,nvmig,itmig,verbose,np;	float dt,dx,dk,taper,t,k,fftscl,ffil[4],		*tmig,*vmig,*vt,**gtx;	complex **gtk;	char *vfile="";	TATable *table;	char *tmpdir;	/* directory path for tmp files			*/	cwp_Bool istmpdir=cwp_false;/* true for user-given path		*/	/* hook up getpar */	initargs(argc, argv);	requestdoc(1);	/* get information from the first header */	if (!gettr(&tr)) err("can't get first trace");	nt = tr.ns;	/* let user give dt and/or dx from command line */	if (!getparfloat("dt", &dt)) {		if (tr.dt) { /* is dt field set? */			dt = ((double) tr.dt)/1000000.0;		} else { /* dt not set, assume 4 ms */			dt = 0.004;			warn("tr.dt not set, assuming dt=0.004");		}	}	if (!getparfloat("dx",&dx)) {		if (tr.d2) { /* is d2 field set? */			dx = tr.d2;		} else {			dx = 1.0;			warn("tr.d2 not set, assuming d2=1.0");		}	}	/* get parameters */	if (!(nfil=getparfloat("ffil",ffil))) {		ffil[0] = ffil[1] = 0.0;		ffil[2] = ffil[3] = 0.5/dt;	} else if (nfil!=4) {		err("if ffil specified, exactly 4 values must be provided");	}	if (!getparint("nxpad",&nxpad)) nxpad=0;	if (!getparint("ltaper",&ltaper)) ltaper=0;	if (!getparint("verbose",&verbose)) verbose=0;	if (!getparint("np",&np)) np=200;	if (!getparint("ntflag",&ntflag)) ntflag=1;		/* look for user-supplied tmpdir */	if (!getparstring("tmpdir",&tmpdir) &&	    !(tmpdir = getenv("CWP_TMPDIR"))) tmpdir="";	if (!STREQ(tmpdir, "") && access(tmpdir, WRITE_OK))		err("you can't write in %s (or it doesn't exist)", tmpdir);	/* determine velocity function v(t) */	vt = ealloc1float(nt);	if (!getparstring("vfile",&vfile)) {		ntmig = countparval("tmig");		if (ntmig==0) ntmig = 1;		tmig = ealloc1float(ntmig);		if (!getparfloat("tmig",tmig)) tmig[0] = 0.0;		nvmig = countparval("vmig");		if (nvmig==0) nvmig = 1;		if (nvmig!=ntmig) err("number of tmig and vmig must be equal");		vmig = ealloc1float(nvmig);		if (!getparfloat("vmig",vmig)) vmig[0] = 1500.0;		for (itmig=1; itmig<ntmig; ++itmig)			if (tmig[itmig]<=tmig[itmig-1])				err("tmig must increase monotonically");		for (it=0,t=0.0; it<nt; ++it,t+=dt)			intlin(ntmig,tmig,vmig,vmig[0],vmig[ntmig-1],				1,&t,&vt[it]);	} else {		if (efread(vt,sizeof(float),nt,fopen(vfile,"r"))!=nt)			err("cannot read %d velocities from file %s",nt,vfile);	}		/* copy traces and headers to temporary files */	if (STREQ(tmpdir,"")) {		tracefp = etmpfile();		headerfp = etmpfile();		if (verbose) warn("using tmpfile() call");	} else { /* user-supplied tmpdir */		char directory[BUFSIZ];		strcpy(directory, tmpdir);		strcpy(tracefile, temporary_filename(directory));		strcpy(headerfile, temporary_filename(directory));		/* Trap signals so can remove temp files */		signal(SIGINT,  (void (*) (int)) closefiles);		signal(SIGQUIT, (void (*) (int)) closefiles);		signal(SIGHUP,  (void (*) (int)) closefiles);		signal(SIGTERM, (void (*) (int)) closefiles);		tracefp = efopen(tracefile, "w+");		headerfp = efopen(headerfile, "w+");      		istmpdir=cwp_true;				if (verbose) warn("putting temporary files in %s", directory);	}	/* count the traces */	nx = 0;	do {		nx++;		efwrite(&tr,HDRBYTES,1,headerfp);		efwrite(tr.data,sizeof(float),nt,tracefp);	} while(gettr(&tr));	erewind(headerfp);	erewind(tracefp);	if (verbose) fprintf(stderr,"\t%d traces input\n",nx);		/* determine wavenumber sampling */	nxfft = npfaro(nx+nxpad,2*(nx+nxpad));	nk = nxfft/2+1;	dk = 2.0*PI/(nxfft*dx);	/* allocate space for Fourier transform */	gtk = ealloc2complex(nt,nk);	gtx = ealloc1(nxfft,sizeof(float*));	for (ix=0; ix<nxfft; ++ix)		gtx[ix] = (float*)gtk[0]+ix*nt;	/* read and apply fft scaling to traces and pad with zeros */	fftscl = 1.0/nxfft;	for (ix=0; ix<nx; ++ix) {		efread(gtx[ix],sizeof(float),nt,tracefp);		for (it=0; it<nt; ++it)			gtx[ix][it] *= fftscl;		if (ix<ltaper) {			taper = (float)(ix+1)/(float)(ltaper+1);			for (it=0; it<nt; ++it)				gtx[ix][it] *= taper;		} else if (ix>=nx-ltaper) {			taper = (float)(nx-ix)/(float)(ltaper+1);			for (it=0; it<nt; ++it)				gtx[ix][it] *= taper;		}	}	for (ix=nx; ix<nxfft; ++ix)		for (it=0; it<nt; ++it)			gtx[ix][it] = 0.0;		/* Fourier transform g(t,x) to g(t,k) */	pfa2rc(-1,2,nt,nxfft,gtx[0],gtk[0]);	if (verbose) fprintf(stderr,"\tFourier transform done\n");		/* build time/amplitude table */	table = tableta(np,nt,dt,vt,nt,dt,verbose);	if (verbose) fprintf(stderr,"\tTime/amplitude table built\n");		/* loop over wavenumbers */	for (ik=0,k=0.0; ik<nk; ++ik,k+=dk) {			/* report */		if (verbose && ik%(nk/10>0?nk/10:1)==0)			fprintf(stderr,"\t%d of %d wavenumbers done\n",				ik,nk);				/* migrate */		mig1k(table,k,ffil,ntflag,nt,dt,gtk[ik],nt,dt,gtk[ik]);	}		/* Fourier transform g(t,k) to g(t,x) */	pfa2cr(1,2,nt,nxfft,gtk[0],gtx[0]);	if (verbose) fprintf(stderr,"\tinverse Fourier transform done\n");		/* output migrated traces with headers */	for (ix=0; ix<nx; ++ix) {		efread(&tr,HDRBYTES,1,headerfp);		memcpy((void *) tr.data,				(const void *) gtx[ix], nt*sizeof(float));		puttr(&tr);	}	/* clean up */	efclose(headerfp);	if (istmpdir) eremove(headerfile);	efclose(tracefp);	if (istmpdir) eremove(tracefile);	return(CWP_Exit());}void mig1k (TATable *table, float k, float ffil[4], int ntflag,	int nt, float dt, complex *cp,	int ntau, float dtau, complex *cq)/*****************************************************************************phase shift migration for one wavenumber k via tabulated times and amps******************************************************************************Input:table	 	pointer to the TATablek		wavenumberffil[4]		four frequencies (in Hz) defining trapezoidal filterntflag		=1 for normal, 2 for turned, 3 for normal+turnednt		number of time samplesdt		time sampling intervalcp		array[nt] of data to be migratedntau		number of vertical two-way times taudtau		vertical time sampling intervalOutput:cq		array[ntau] of migrated data******************************************************************************/{	int ntfft,nw,iwnyq,iwmin,iwmax,iw,itau,it,np,		ip1,ip2,iwfil0,iwfil1,iwfil2,iwfil3,		itaumax,itaumin,itab;	float dw,wnyq,wmin,wmax,w,ampf,p1,p2,a1,a2,wa1,wa2,		taumaxi,taumini,kow,phst,pwsr,pwsi,pwdr,pwdi,		ampi,phsi,phsn,		*p,*taumax,*taumin,*tturn,**t,**a;

⌨️ 快捷键说明

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