/
Mtahgethw.c
209 lines (171 loc) · 6.87 KB
/
Mtahgethw.c
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
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
/* Trace And Header GET Header Word prints trace headers.
tah is the abbreviation of Trace And Header. Madagascar programs
that begin with sftah are a designed to:
1- read trace and headers from separate rsf files and write them to
standard output (ie sftahread)
2- filter programs that read and write standard input/output and
process the tah data (eg sftahnmo, sftahstack)
3- read tah data from standard input and write separate rsf files for
the trace and headers data (ie sftahwrite)
These programs allow Seismic Unix (su) like processing in Madagascar.
Some programs have su like names.
Some programs in this suite are sftahread, sftahgethw, ftahhdrmath,
and sftahwrite.
The sftahgethw program prints headers. List the headers you want to
print in the key parameter.
EXAMPLE:
sftahread \\
verbose=1 \\
input=npr3_gathers.rsf \\
| sftahgethw \\
verbose=0 \\
key=sx,sy,gx,gy,offset \\
>/dev/null
The headers are in the file npr3_gathers_hdr.rsf,
the headers parameter default. The headers are merged with the trace
amplitudes and the tah data sent down the pipe for sftahgethw. The
source and group coordinates and offset (sx,sy,gx,gy,offset) are
printed to STDERR. Traces are sent to STDOUT, which is directed to
/dev/null (the bit bucket).
PARAMETERS
string key= no default
list of header keys print. Look at the sfsegyread for a list
of header names.
*/
/*
Copyright (C) 2013 University of Texas at Austin
This program 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; either version 2 of the License, or
(at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
Program change history:
date Who What
04/26/2013 Karl Schleicher Original program
10/22/2013 Karl Schleicher Factor reused functions into tahsub.c
*/
#include <string.h>
#include <rsf.h>
#include <rsfsegy.h>
#include "tahsub.h"
int main(int argc, char* argv[])
{
int verbose;
sf_file in=NULL, out=NULL;
int n1_traces;
int n1_headers;
char* header_format=NULL;
sf_datatype typehead;
/* kls do I need to add this? sf_datatype typein; */
float* fheader=NULL;
float* intrace=NULL;
int numkeys;
int ikey;
char** list_of_keys;
int *indx_of_keys;
/*****************************/
/* initialize verbose switch */
/*****************************/
sf_init (argc,argv);
if(!sf_getint("verbose",&verbose))verbose=1;
/* \n
flag to control amount of print
0 terse, 1 informative, 2 chatty, 3 debug
*/
sf_warning("verbose=%d",verbose);
/******************************************/
/* input and output data are stdin/stdout */
/******************************************/
if(verbose>0)fprintf(stderr,"read in file name\n");
in = sf_input ("in");
if(verbose>0)fprintf(stderr,"read out file name\n");
out = sf_output ("out");
if (!sf_histint(in,"n1_traces",&n1_traces))
sf_error("input data not define n1_traces");
if (!sf_histint(in,"n1_headers",&n1_headers))
sf_error("input data does not define n1_headers");
header_format=sf_histstring(in,"header_format");
if(strcmp (header_format,"native_int")==0) typehead=SF_INT;
else typehead=SF_FLOAT;
if(verbose>0)fprintf(stderr,"allocate headers. n1_headers=%d\n",n1_headers);
fheader = sf_floatalloc(n1_headers);
if(verbose>0)fprintf(stderr,"allocate intrace. n1_traces=%d\n",n1_traces);
intrace= sf_floatalloc(n1_traces);
if(verbose>0)fprintf(stderr,"call list of keys\n");
list_of_keys=sf_getnstring("key",&numkeys);
if(list_of_keys==NULL)
sf_error("The required parameter \"key\" was not found.");
/* I wanted to use sf_getstrings, but it seems to want a colon seperated
list of keys (eg key=offset:ep:fldr:cdp) and I wanted a comma seperated
list of keys (eg key=offset:ep:fldr:cdp).
numkeys=sf_getnumpars("key");
if(numkeys==0)
sf_error("The required parameter \"key\" was not found.");
fprintf(stderr,"alloc list_of_keys numkeys=%d\n",numkeys);
list_of_keys=(char**)sf_alloc(numkeys,sizeof(char*));
sf_getstrings("key",list_of_keys,numkeys);
*/
/* print the list of keys */
if(verbose>1){
fprintf(stderr,"numkeys=%d\n",numkeys);
for(ikey=0; ikey<numkeys; ikey++){
fprintf(stderr,"list_of_keys[%d]=%s\n",ikey,list_of_keys[ikey]);
}
}
/* maybe I should add some validation that n1== n1_traces+n1_headers+2
and the record length read in the second word is consistent with
n1. */
/**********************************************************/
/* end code block for standard tah Trace And Header setup */
/* continue with any sf_puthist this tah program calls to */
/* add to the history file */
/**********************************************************/
/* put the history from the input file to the output */
sf_fileflush(out,in);
/********************************************************/
/* continue initialization specific to this tah program */
/********************************************************/
/* segy_init gets the list header keys required by segykey function */
segy_init(n1_headers,in);
indx_of_keys=sf_intalloc(numkeys);
for (ikey=0; ikey<numkeys; ikey++){
/* kls need to check each of these key names are in the segy header and
make error message for invalid keys. Of does segykey do this? NO, just
segmentation fault. */
indx_of_keys[ikey]=segykey(list_of_keys[ikey]);
}
/***************************/
/* start trace loop */
/***************************/
if(verbose>0)fprintf(stderr,"start trace loop\n");
while (0==get_tah(intrace, fheader, n1_traces, n1_headers, in)){
if(verbose>1)fprintf(stderr,"process the tah in sftahgethw\n");
/********************/
/* process the tah. */
/********************/
/* this program prints selected header keys */
for(ikey=0; ikey<numkeys; ikey++){
fprintf(stderr," %s=",list_of_keys[ikey]);
if(typehead == SF_INT){
/* just cast the header to int so the print works */
fprintf(stderr,"%d",((int*)fheader)[indx_of_keys[ikey]]);
} else {
fprintf(stderr,"%f",fheader[indx_of_keys[ikey]]);
}
} /* end of the for(ikey..) loop */
fprintf(stderr,"\n");
/***************************/
/* write trace and headers */
/***************************/
put_tah(intrace, fheader, n1_traces, n1_headers, out);
}
exit(0);
}