wavelet.c 3.09 KB
Newer Older
Tilman Steinweg's avatar
Tilman Steinweg committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
/*------------------------------------------------------------------------
 * Copyright (C) 2011 For the list of authors, see file AUTHORS.
 *
 * This file is part of SOFI3D.
 * 
 * SOFI3D is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2.0 of the License only.
 * 
 * SOFI3D is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with SOFI3D. See file COPYING and/or 
  * <http://www.gnu.org/licenses/gpl-2.0.html>.
--------------------------------------------------------------------------*/
/*------------------------------------------------------------------------
*   Calculating source signal at different source positions with different
*   time-shift, centre frequency and amplitude (as specified in SOURCE_FILE).
*   Source signals are written to array signals 
*
*  ----------------------------------------------------------------------*/

#include "fd.h"


float ** wavelet(float ** srcpos_loc, int nsrc){


	/* extern variables */
	extern int SOURCE_SHAPE, NT, MYID;
	extern float  DT;
	extern char SIGNAL_FILE[STRING_SIZE];
	extern FILE *FP;

	/*local variables */
	int nts, nt, k;
	float *psource=NULL, tshift, amp=0.0, a, fc, tau, t, ts;
	float ** signals;
	char errormessage[STRING_SIZE];


	if ((SOURCE_SHAPE==3) && (nsrc>0)) {
		psource=rd_sour(&nts,fopen(SIGNAL_FILE,"r"));
		if (nts != NT) {
			sprintf(errormessage," Number of samples in external source file (nts = %d) does not equal number of time steps (NT = %d)!",nts,NT);
			err(errormessage);
		}
	}
	
	signals=fmatrix(1,nsrc,1,NT);
	
	for (nt=1;nt<=NT;nt++){
56
			t=(float)(nt-1)*DT;
Tilman Steinweg's avatar
Tilman Steinweg committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
			
			for (k=1;k<=nsrc;k++) {
				tshift=srcpos_loc[4][k];
				fc=srcpos_loc[5][k];
				a=srcpos_loc[6][k];
				ts=1.0/fc;

				switch (SOURCE_SHAPE){
					case 1 : /* Ricker */
						tau=PI*(t-1.5*ts-tshift)/(ts);
						amp=(((1.0-2.0*tau*tau)*exp(-tau*tau)));
					break;
					case 2 : /* fumue */
						if ((t<tshift) || (t>(tshift+ts))) amp=0.0;
						else amp=((sin(2.0*PI*(t-tshift)*fc) 
			    				-0.5*sin(4.0*PI*(t-tshift)*fc)));

/*						amp=((sin(2.0*PI*(t+tshift)*fc) 
			    				-0.5*sin(4.0*PI*(t+tshift)*fc)));
*/
					break;
					case 3 :/* source wavelet from file SOURCE_FILE */
						amp=psource[nt];
					break;
					case 4 : /* sinus raised to the power of three */
						if ((t<tshift) || (t>(tshift+ts))) amp=0.0;
83
						else amp=(0.75*PI/ts)*(pow(sin(PI*(t-tshift)/ts),3.0));
Tilman Steinweg's avatar
Tilman Steinweg committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
						break;
					default : 
						err("Which source-wavelet ? ");
						break;
					}
					
					
					signals[k][nt]=amp*a;
		}
	}
	
	fprintf(FP," Message from function wavelet written by PE %d \n",MYID);
	fprintf(FP," %d source positions located in subdomain of PE %d \n",nsrc,MYID);
	fprintf(FP," have been assigned with a source signal. \n");
			
		
	if (SOURCE_SHAPE==3) free_vector(psource,1,NT);
	
	return signals;	

}