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

📄 sufdmod2.c

📁 seismic software,very useful
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) Colorado School of Mines, 1997.*//* All rights reserved.                       *//* sufdmod2 - finite difference modeling by simple 2nd order explict method */#include "par.h"#include "su.h"#include "segy.h"/*********************** self documentation **********************/char *sdoc[] = {" 									"," SUFDMOD2 - Finite-Difference MODeling (2nd order) for acoustic wave equation"," 									"," sufdmod2 <vfile >wfile nx= nz= tmax= xs= zs= [optional parameters]	"," 									"," Required Parameters:							"," <vfile		file containing velocity[nx][nz]		"," >wfile		file containing waves[nx][nz] for time steps	"," nx=			number of x samples (2nd dimension)		"," nz=			number of z samples (1st dimension)		"," xs=			x coordinates of source				"," zs=			z coordinates of source				"," tmax=			maximum time					"," 									"," Optional Parameters:							"," nt=1+tmax/dt		number of time samples (dt determined for stability)"," mt=1			number of time steps (dt) per output time step	"," 									"," dx=1.0		x sampling interval				"," fx=0.0		first x sample					"," dz=1.0		z sampling interval				"," fz=0.0		first z sample					"," 									"," fmax = vmin/(10.0*h)	maximum frequency in source wavelet		"," fpeak=0.5*fmax	peak frequency in ricker wavelet		"," 									"," dfile=		input file containing density[nx][nz]		"," vsx=			x coordinate of vertical line of seismograms	"," hsz=			z coordinate of horizontal line of seismograms	"," vsfile=		output file for vertical line of seismograms[nz][nt]"," hsfile=		output file for horizontal line of seismograms[nx][nt]"," ssfile=		output file for source point seismograms[nt]	"," verbose=0		=1 for diagnostic messages, =2 for more		"," 									"," abs=1,1,1,1		Absorbing boundary conditions on top,left,bottom,right"," 			sides of the model. 				"," 		=0,1,1,1 for free surface condition on the top		"," 									"," Notes:								"," 									"," This program uses the traditional explicit second order differencing	"," method. 								"," 									",NULL};/* * Authors:  CWP:Dave Hale *           CWP:modified for SU by John Stockwell, 1993. * * * Trace header fields set: ns, delrt, tracl, tracr, offset, d1, d2, *                          sdepth, trid *//**************** end self doc ********************************/#define	ABS0	1#define	ABS1	1#define	ABS2	1#define	ABS3	1void ptsrc (float xs, float zs,	int nx, float dx, float fx,	int nz, float dz, float fz,	float dt, float t, float fmax, float fpeak, float tdelay, float **s);void exsrc (int ns, float *xs, float *zs,	int nx, float dx, float fx,	int nz, float dz, float fz,	float dt, float t, float fmax, float **s);void tstep2 (int nx, float dx, int nz, float dz, float dt,	float **dvv, float **od, float **s,	float **pm, float **p, float **pp, int *abs);segy cubetr; 	/* data cube traces */segy srctr;	/* source seismogram traces */segy horiztr;	/* horizontal line seismogram traces */segy verttr;	/* vertical line seismogram traces */intmain(int argc, char **argv){	int ix,iz,it,is;	/* counters */	int nx,nz,nt,mt;	/* x,z,t,tsizes */	int verbose;		/* is verbose? */	int nxs;		/* number of source x coordinates */	int nzs;		/* number of source y coordinates */	int ns;			/* total number of sources ns=nxs=nxz */	int vs2;		/* depth in samples of horiz rec line */	int hs1;		/* horiz sample of vert rec line */	float fx;		/* first x value */	float dx;		/* x sample interval */	float fz;		/* first z value */	float dz;		/* z sample interval */	float h;		/* minumum spatial sample interval */	float hsz;		/* z position of horiz receiver line */	float vsx;		/* x position of vertical receiver line */	float dt;		/* time sample interval */	float fmax;		/* maximum temporal frequency allowable */	float fpeak;		/* peak frequency of ricker wavelet */	float tdelay=0.;	/* time delay of source beginning */	float vmin;		/* minimum wavespeed in vfile */	float vmax;		/* maximum wavespeed in vfile */	float dmin;		/* minimum density in dfile */	float dmax;		/* maximum density in dfile */	float tmax;		/* maximum time to compute */	float t;		/* time */	float *xs;		/* array of source x coordinates */	float *zs;		/* array of source z coordinates */	int *ixs;		/* array of source x sample locations */	int *izs;		/* array of source z sample locations */	float **s;		/* array of source pressure values */	float **dvv;		/* array of velocity values from vfile */	float **od;		/* array of density values from dfile */	/* pressure field arrays */	float **pm;		/* pressure field at t-dt */	float **p;		/* pressure field at t */	float **pp;		/* pressure field at t+dt */	float **ptemp;		/* temp pressure array */	/* output data arrays */	float **ss;		/* source point seismogram array */	float **hs;		/* seismograms from horiz receiver line */	float **vs;		/* seismograms from vert receiver line */	/* file names */	char *dfile="";		/* density file name */	char *vsfile="";	/* vert receiver seismogram line file  name */	char *hsfile="";	/* horiz receiver seismogram line file name */	char *ssfile="";	/* source point seismogram file name */	/* input file pointers */	FILE *velocityfp=stdin; /* pointer to input velocity data */	FILE *densityfp;	/* pointer to input density data file */	/* output file pointers */	FILE *hseisfp=NULL;	/* pointer to output horiz rec line file  */	FILE *vseisfp=NULL;	/* pointer to output vert rec line file  */		FILE *sseisfp=NULL;	/* pointer to source point seis output file */	/* SEGY fields */	long tracl=0;		/* trace number within a line */	long tracr=0;		/* trace number within a reel */	/* Absorbing boundary conditions related stuff*/	int abs[4];		/* absorbing boundary cond. flags */	int nabs;		/* number of values given */	/* hook up getpar to handle the parameters */	initargs(argc,argv);	requestdoc(0);		/* get required parameters */	if (!getparint("nx",&nx)) err("must specify nx!\n");	if (!getparint("nz",&nz)) err("must specify nz!\n");	if (!getparfloat("tmax",&tmax)) err("must specify tmax!\n");	nxs = countparval("xs");	nzs = countparval("zs");	if (nxs!=nzs)		err("number of xs = %d must equal number of zs = %d\n",			nxs,nzs);	ns = nxs;	if (ns==0) err("must specify xs and zs!\n");	xs = alloc1float(ns);	zs = alloc1float(ns);	ixs = alloc1int(ns);	izs = alloc1int(ns);	getparfloat("xs",xs);	getparfloat("zs",zs);		nabs = countparval("abs");	if (nabs==4) {		getparint("abs", abs);		} else {		abs[0] = ABS0;		abs[1] = ABS1;		abs[2] = ABS2;		abs[3] = ABS3;		if (!((nabs==4) || (nabs==0)) ) 			warn("Number of abs %d, using abs=1,1,1,1",nabs);	}		/* get optional parameters */	if (!getparint("nt",&nt)) nt = 0;	if (!getparint("mt",&mt)) mt = 1;	if (!getparfloat("dx",&dx)) dx = 1.0;	if (!getparfloat("fx",&fx)) fx = 0.0;	if (!getparfloat("dz",&dz)) dz = 1.0;	if (!getparfloat("fz",&fz)) fz = 0.0;	/* source coordinates in samples */	for (is=0 ; is < ns ; ++is) {		ixs[is] = NINT( ( xs[is] - fx )/dx );		izs[is] = NINT( ( zs[is] - fz )/dx );	}	if (!getparfloat("hsz",&hsz)) hsz = 0.0;	hs1 = NINT( (hsz - fz)/dz );	if (!getparfloat("vsx",&vsx)) vsx = 0.0;	vs2 = NINT((vsx - fx)/dx );		if (!getparint("verbose",&verbose)) verbose = 0;	getparstring("dfile",&dfile);	getparstring("hsfile",&hsfile);	getparstring("vsfile",&vsfile);	getparstring("ssfile",&ssfile);		/* allocate space */	s = alloc2float(nz,nx);	dvv = alloc2float(nz,nx);	od = alloc2float(nz,nx);	pm = alloc2float(nz,nx);	p = alloc2float(nz,nx);	pp = alloc2float(nz,nx);		/* read velocities */	fread(dvv[0],sizeof(float),nx*nz,velocityfp);		/* determine minimum and maximum velocities */	vmin = vmax = dvv[0][0];	for (ix=0; ix<nx; ++ix) {		for (iz=0; iz<nz; ++iz) {			vmin = MIN(vmin,dvv[ix][iz]);			vmax = MAX(vmax,dvv[ix][iz]);		}	}		/* determine mininum spatial sampling interval */	h = MIN(ABS(dx),ABS(dz));		/* determine time sampling interval to ensure stability */	dt = h/(2.0*vmax);		/* determine maximum temporal frequency to avoid dispersion */	if (!getparfloat("fmax", &fmax))	fmax = vmin/(10.0*h);	/* compute or set peak frequency for ricker wavelet */	if (!getparfloat("fpeak", &fpeak))	fpeak = 0.5*fmax;	/* determine number of time steps required to reach maximum time */	if (nt==0) nt = 1+tmax/dt;	/* if requested, open file and allocate space for seismograms */	if (*hsfile!='\0') {		if((hseisfp=fopen(hsfile,"w"))==NULL)			err("cannot open hsfile=%s\n",hsfile);		hs = alloc2float(nt,nx);	} else {		hs = NULL;	}	if (*vsfile!='\0') {		if((vseisfp=fopen(vsfile,"w"))==NULL)			err("cannot open vsfile=%s\n",vsfile);		vs = alloc2float(nt,nz);	} else {		vs = NULL;	}	if (*ssfile!='\0') {		if((sseisfp=fopen(ssfile,"w"))==NULL)			err("cannot open ssfile=%s\n",ssfile);		ss = alloc2float(nt,ns);	} else {		ss = NULL;	}		/* if specified, read densities */	if (*dfile!='\0') {		if((densityfp=fopen(dfile,"r"))==NULL)			err("cannot open dfile=%s\n",dfile);		if (fread(od[0],sizeof(float),nx*nz,densityfp)!=nx*nz)			err("error reading dfile=%s\n",dfile);		fclose(densityfp);		dmin = dmax = od[0][0];		for (ix=0; ix<nx; ++ix) {			for (iz=0; iz<nz; ++iz) {				dmin = MIN(dmin,od[ix][iz]);				dmax = MAX(dmax,od[ix][iz]);			}		}	}		/* if densities not specified or constant, make densities = 1 */	if (*dfile=='\0' || dmin==dmax ) {		for (ix=0; ix<nx; ++ix)			for (iz=0; iz<nz; ++iz)				od[ix][iz] = 1.0;		dmin = dmax = 1.0;	}		/* compute density*velocity^2 and 1/density and zero time slices */		for (ix=0; ix<nx; ++ix) {		for (iz=0; iz<nz; ++iz) {			dvv[ix][iz] = od[ix][iz]*dvv[ix][iz]*dvv[ix][iz];			od[ix][iz] = 1.0/od[ix][iz];			pp[ix][iz] = p[ix][iz] = pm[ix][iz] = 0.0;		}	}		/* if densities constant, free space and set NULL pointer */	if (dmin==dmax) {		free2float(od);		od = NULL;	}		/* if verbose, print parameters */	if (verbose) {		fprintf(stderr,"nx = %d\n",nx);		fprintf(stderr,"dx = %g\n",dx);		fprintf(stderr,"nz = %d\n",nz);		fprintf(stderr,"dz = %g\n",dz);		fprintf(stderr,"nt = %d\n",nt);		fprintf(stderr,"dt = %g\n",dt);		fprintf(stderr,"tmax = %g\n",tmax);		fprintf(stderr,"fmax = %g\n",fmax);		fprintf(stderr,"fpeak = %g\n",fpeak);		fprintf(stderr,"vmin = %g\n",vmin);		fprintf(stderr,"vmax = %g\n",vmax);		fprintf(stderr,"mt = %d\n",mt);		if (dmin==dmax) {			fprintf(stderr,"constant density\n");		} else {			fprintf(stderr,"dfile=%s\n",dfile);			fprintf(stderr,"dmin = %g\n",dmin);			fprintf(stderr,"dmax = %g\n",dmax);		}	}		/* loop over time steps */	for (it=0,t=0.0; it<nt; ++it,t+=dt) {			/* if verbose, print time step */		if (verbose>1) fprintf(stderr,"it=%d  t=%g\n",it,t);			/* update source function */		if (ns==1)			ptsrc(xs[0],zs[0],nx,dx,fx,nz,dz,fz,dt,t,			      fmax,fpeak,tdelay,s);		else			exsrc(ns,xs,zs,nx,dx,fx,nz,dz,fz,dt,t,fmax,s);				/* do one time step */		tstep2(nx,dx,nz,dz,dt,dvv,od,s,pm,p,pp,abs);				/* write waves */	/* if (it%mt==0) fwrite(pp[0],sizeof(float),nx*nz,stdout); */		if (it%mt==0) {			cubetr.sx = xs[0];			cubetr.sdepth = zs[0];			cubetr.trid = 30 ;			cubetr.ns = nz ;			cubetr.d1 = dz ;			cubetr.d2 = dx ;			/* account for delay in source starting time */			cubetr.delrt = - 1000.0 * tdelay;			tracl = 0 ;			for (ix=0 ; ix < nx ; ++ix) {				++tracl;				++tracr;				cubetr.offset = ix * dx - xs[0];				cubetr.tracl = tracl;				cubetr.tracr = tracr;				for (iz=0 ; iz < nz ; ++iz) {						cubetr.data[iz] = pp[ix][iz];				}				fputtr(stdout, &cubetr);			}		}		/* if requested, save horizontal line of seismograms */		if (hs!=NULL) {			for (ix=0; ix<nx; ++ix)				hs[ix][it] = pp[ix][hs1];		}		/* if requested, save vertical line of seismograms */		if (vs!=NULL) {			for (iz=0; iz<nz; ++iz)				vs[iz][it] = pp[vs2][iz];		}		/* if requested, save seismograms at source locations */		if (ss!=NULL) {			for (is=0; is<ns; ++is)				ss[is][it] = pp[ixs[is]][izs[is]];		}		/* roll time slice pointers */		ptemp = pm;		pm = p;		p = pp;		pp = ptemp;	}	/* if requested, write horizontal line of seismograms */	if (hs!=NULL) {		horiztr.sx = xs[0];		horiztr.sdepth = zs[0];		horiztr.trid = 1;		horiztr.ns = nt ;		horiztr.dt = 1000000 * dt ;		horiztr.d2 = dx ;		/* account for delay in source starting time */		horiztr.delrt = -1000.0 * tdelay ; 		tracl = tracr = 0;		for (ix=0 ; ix < nx ; ++ix){			++tracl;			++tracr;			/* offset from first source location */			horiztr.offset = ix * dx - xs[0];			horiztr.tracl = tracl;			horiztr.tracr = tracr;			for (it = 0 ; it < nt ; ++it){				horiztr.data[it] = hs[ix][it];			}						fputtr(hseisfp , &horiztr);		}					fclose(hseisfp);	}	/* if requested, write vertical line of seismograms */	if (vs!=NULL) {		verttr.trid = 1;		verttr.ns = nt ;		verttr.sx = xs[0];		verttr.sdepth = zs[0];		verttr.dt = 1000000 * dt ;		verttr.d2 = dx ;		/* account for delay source starting time */		verttr.delrt = -1000.0 * tdelay ;		tracl = tracr = 0;		for (iz=0 ; iz < nz ; ++iz){			++tracl;			++tracr;			/* vertical line implies offset in z */			verttr.offset = iz * dz - zs[0];			verttr.tracl = tracl;			verttr.tracr = tracr;			for (it = 0 ; it < nt ; ++it){				verttr.data[it] = vs[iz][it];			}						fputtr(vseisfp , &verttr);		}		fclose(vseisfp);	}	/* if requested, write seismogram at source position */	if (ss!=NULL) {		srctr.trid = 1;		srctr.ns = nt ;		srctr.dt = 1000000 * dt ;		srctr.d2 = dx ;		srctr.delrt = -1000.0 * tdelay ;		tracl = tracr = 0;		for (is=0 ; is < ns ; ++is){			++tracl;			++tracr;			srctr.sx = xs[is];			srctr.sdepth = zs[is];			srctr.tracl = tracl;			srctr.tracr = tracr;			for (it = 0 ; it < nt ; ++it){				srctr.data[it] = ss[is][it];			}						fputtr(sseisfp , &srctr);		}		fclose(sseisfp);	}		/* free space before returning */	free2float(s);	free2float(dvv);	free2float(pm);	free2float(p);	free2float(pp);		if (od!=NULL) free2float(od);	if (hs!=NULL) free2float(hs);	if (vs!=NULL) free2float(vs);	if (ss!=NULL) free2float(ss);		return EXIT_SUCCESS;}

⌨️ 快捷键说明

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