outseis_glob.c 9.14 KB
Newer Older
Tilman Steinweg's avatar
Tilman Steinweg committed
1
/*-----------------------------------------------------------------------------------------
Florian Wittkamp's avatar
Florian Wittkamp committed
2
 * Copyright (C) 2016  For the list of authors, see file AUTHORS.
Tilman Steinweg's avatar
Tilman Steinweg committed
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
56
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
 *
 * This file is part of DENISE.
 * 
 * DENISE 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.
 * 
 * DENISE 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 DENISE. See file COPYING and/or <http://www.gnu.org/licenses/gpl-2.0.html>.
-----------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------
 *   Write seismograms to disk                                  
 *   last update 19/01/02, T. Bohlen
 *  ----------------------------------------------------------------------*/
#include "fd.h"
#include "segy.h"

void  outseis_glob(FILE *fp, FILE *fpdata, int comp, float **section,
int **recpos, int **recpos_loc, int ntr, float ** srcpos,
int nsrc, int ns, int seis_form, int ishot, int sws){

	/* declaration of extern variables */
	extern int NDT;
	extern float  TIME, DH, DT, REFREC[4];

	const float xshift=800.0, yshift=800.0;


	/* declaration of local variables */
	int i,j,ndt,ns2,nt,lsamp;
	segy tr;
	int tracl1 ;
	float xr, yr, x, y;
	float XS=0.0, YS=0.0;
	
	
	nt=iround(TIME/DT);
	if (sws==1){	/* parameter NDT is used */
		ndt=NDT;
		ns2=iround(nt/NDT);}
	else{ 
		ndt=1;
		ns2=ns;}

	
	
	
	
	/* source coordinates are written into trace header fields */
	XS=srcpos[1][ishot];	
	YS=srcpos[2][ishot];	
		
	
	switch(seis_form){
	case 1 :
		for(tracl1=1;tracl1<=ntr;tracl1++){        /*SEGY (without file-header)*/
         		xr=recpos[1][tracl1]*DH;
         		yr=recpos[2][tracl1]*DH;
         		x=xr-REFREC[1];
         		y=yr-REFREC[2];
			/*tr.tracl=(int)recpos[3][tracl1];*/
			tr.tracl=(int)tracl1;
			tr.ep=comp;     
			tr.cdp=(int)recpos[3][tracl1];
			tr.trid=(short)1;           /* trace identification code: 1=seismic*/
			tr.offset=(signed int)iround(sqrt((XS-xr)*(XS-xr)
                                  +(YS-yr)*(YS-yr))*1000.0);
			tr.gelev=(signed int)iround(yr*1000.0);
			tr.sdepth=(signed int)iround(YS*1000.0);   /* source depth (positive) */
                        /* angle between receiver position and reference point
                           (sperical coordinate system: swdep=theta, gwdep=phi) */
			tr.swdep=iround(((360.0/(2.0*PI))*atan2(x-xshift,y-yshift))*1000.0);
			/*tr.scalel=(signed short)-3;*/
			tr.scalel=(signed short)-1000;
			/*tr.scalco=(signed short)-3;*/
			tr.scalco=(signed short)-1000;
			tr.sx=(signed int)iround(XS*1000.0);  /* X source coordinate */

			        /* group coordinates */
			tr.gx=(signed int)iround(xr*1000.0);

			tr.ns=(unsigned short)ns2; /* number of samples in this trace */
			tr.dt=(unsigned short)iround(((float)ndt*DT)*1.0e6); /* sample interval in micro-seconds */
			/*tr.d1=(float)(TIME/ns2);*/        /* sample spacing for non-seismic data */
			tr.d1=(float)tr.dt*1.0e-6;
			
			tr.tracr=0	;	/* trace sequence number within reel */

			tr.fldr=0       ;	/* field record number */

			tr.tracf=0      ;	/* trace number within field record */

			tr.ep=0         ;	/* energy source point number */

			tr.cdpt=0       ;	/* trace number within CDP ensemble */

	
			tr.nvs=0       	;   /* number of vertically summed traces (see vscode
			   			in bhed structure) */

			tr.nhs=0       	;   /* number of horizontally summed traces (see vscode
			  			in bhed structure) */

			tr.duse=0     	;   /* data use:
						1 = production
						2 = test */

			tr.selev=0     	; /* source elevation from sea level
			   			(above sea level is positive) */

			tr.gdel=0      	; /* datum elevation at receiver group */

			tr.sdel=0      	; /* datum elevation at source */

			tr.gwdep=0     	; /* water depth at receiver group */

			
			tr.sy= (signed int)iround(YS*1000.0)    ;   /* Y source coordinate */

	
			tr.gy= (signed int)iround(yr*1000.0)    ;   /* Y group coordinate */

			tr.counit=0    	;   /* coordinate units code:
						for previous four entries
						1 = length (meters or feet)
						2 = seconds of arc (in this case, the
						X values are longitude and the Y values
						are latitude, a positive value designates
						the number of seconds east of Greenwich
						or north of the equator */

			tr.wevel=0     ;	/* weathering velocity */

			tr.swevel=0    ;	/* subweathering velocity */

			tr.sut=0       ;	/* uphole time at source */

			tr.gut=0       ;	/* uphole time at receiver group */

			tr.sstat=0     ;	/* source static correction */

			tr.gstat=0     ;	/* group static correction */

			tr.tstat=0     ;	/* total static applied */

			tr.laga=0      ; /* lag time A, time in ms between end of 240-
			   			byte trace identification header and time
			   			break, positive if time break occurs after
			   			end of header, time break is defined as
			   			the initiation pulse which maybe recorded
			   			on an auxiliary trace or as otherwise
			   			specified by the recording system */

			tr.lagb=0     	; /* lag time B, time in ms between the time break
			   			and the initiation time of the energy source,
			   			may be positive or negative */

			tr.delrt=0     	; /* delay recording time, time in ms between
			   			initiation time of energy source and time
			   			when recording of data samples begins
			   			(for deep water work if recording does not
			   			start at zero time) */

			tr.muts=0      ; /* mute time--start */

			tr.mute=0      ; /* mute time--end */

	
			tr.gain=0      ; /* gain type of field instruments code:
						1 = fixed
						2 = binary
						3 = floating point
						4 ---- N = optional use */

			tr.igc=0       ; /* instrument gain constant */

			tr.igi=0       ; /* instrument early or initial gain */

			tr.corr=0      ; /* correlated:
						1 = no
						2 = yes */

			tr.sfs=0       ; /* sweep frequency at start */

			tr.sfe=0       ; /* sweep frequency at end */

			tr.slen=0      ; /* sweep length in ms */

			tr.styp=0      ; /* sweep type code:
						1 = linear
						2 = cos-squared
						3 = other */

			tr.stas=0      	; /* sweep trace length at start in ms */

			tr.stae=0      	; /* sweep trace length at end in ms */

			tr.tatyp=0     	; /* taper type: 1=linear, 2=cos^2, 3=other */

			tr.afilf=0     	; /* alias filter frequency if used */

			tr.afils=0     	; /* alias filter slope */

			tr.nofilf=0    	; /* notch filter frequency if used */

			tr.nofils=0   	; /* notch filter slope */

			tr.lcf=0      	; /* low cut frequency if used */

			tr.hcf=0      	; /* high cut frequncy if used */

			tr.lcs=0       	; /* low cut slope */

			tr.hcs=0       	; /* high cut slope */

			tr.year=0      	; /* year data recorded */

			tr.day=0       	; /* day of year */

			tr.hour=0     	; /* hour of day (24 hour clock) */

			tr.minute=0    	; /* minute of hour */

			tr.sec=0       	; /* second of minute */

			tr.timbas=0    	; /* time basis code:
						1 = local
						2 = GMT
						3 = other */

			tr.trwf=0      	; /* trace weighting factor, defined as 1/2^N
			   			volts for the least sigificant bit */

			tr.grnors=0   	; /* geophone group number of roll switch
			   			position one */

			tr.grnofr=0    	; /* geophone group number of trace one within
			   			original field record */

			tr.grnlof=0    	; /* geophone group number of last trace within
			   			original field record */

			tr.gaps=0      	;  /* gap size (total number of groups dropped) */

			tr.otrav=0     	;  /* overtravel taper code:
						1 = down (or behind)
						2 = up (or ahead) */

			/* local assignments */

			tr.f1=0.0;	/* first sample location for non-seismic data */

			tr.d2=0.0;	/* sample spacing between traces */

			tr.f2=0.0;	/* first trace location */

			tr.ungpow=0.0;	/* negative of power used for dynamic
			   			range compression */

			tr.unscale=0.0;	/* reciprocal of scaling factor to normalize
			   			range */
			tr.ntr=0      ;   /* number of traces */

			tr.mark=0     ;
			
			if (sws==0){		
				for(j=1;j<=ns;j++) tr.data[j]=section[tracl1][j];}
			else{
				lsamp=0;
				for(j=1;j<=ns2;j++){
					lsamp +=NDT;
					tr.data[j]=section[tracl1][lsamp];}
			}

			fwrite(&tr,240,1,fpdata);
			fwrite(&tr.data[1],4,ns2,fpdata);
		}
		break;


	case 2 :
		for(i=1;i<=ntr;i++){         /*ASCII ONE COLUMN*/
			if (sws==0){
				for(j=1;j<=ns;j++) fprintf(fpdata,"%e\n", section[i][j]);}
			else{
				lsamp=0;
				for(j=1;j<=ns2;j++){
					lsamp+=NDT;
					fprintf(fpdata,"%e\n", section[i][lsamp]);}
			}
		}
		break;

	case 3 :                             /*BINARY */

		for(i=1;i<=ntr;i++){
			if(sws==0){
				for(j=1;j<=ns;j++){
					fwrite(&section[i][j],sizeof(float),1,fpdata); }}
			else{
				lsamp=0;
				for(j=1;j<=ns2;j++){
					lsamp+=NDT;
					fwrite(&section[i][lsamp],sizeof(float),1,fpdata); }}}
		break;

	default :
		fprintf(fp," Don't know data format for seismograms !\n");
		fprintf(fp," No output written. ");
	}

	fclose(fpdata);
}