-
Notifications
You must be signed in to change notification settings - Fork 172
/
headerwindow.c
101 lines (80 loc) · 2.52 KB
/
headerwindow.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
/* Window a dataset based on a header mask.
The input data is a collection of traces n1xn2,
mask is an integer array os size n2, windowed is n1xm2,
where m2 is the number of nonzero elements in mask.
*/
/*
Copyright (C) 2004 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
*/
#include <stdio.h>
#include <rsf.h>
int main(int argc, char* argv[])
{
bool inv;
int n1, n2, j2, i2, in2, j, esize, *mask;
off_t pos;
char *trace, *zero, key[3];
sf_file in, head, out;
sf_init (argc,argv);
if (!sf_getbool("inv",&inv)) inv=false;
/* inversion flag */
head = sf_input("mask");
if (SF_INT != sf_gettype(head))
sf_error("Need integer mask");
n2 = sf_filesize(head);
mask = sf_intalloc(n2);
sf_intread(mask,n2,head);
sf_fileclose(head);
in = sf_input ("in");
out = sf_output ("out");
if (!sf_histint(in,"n1",&n1)) n1=1;
in2 = sf_leftsize(in,1);
esize = sf_esize(in);
n1 *= esize;
trace = sf_charalloc(n1);
for (j2=i2=0; i2 < n2; i2++) {
if (mask[i2]) j2++;
}
if (inv) {
if (in2 != j2) sf_error("Wrong input dimensions, need %d traces",j2);
sf_putint(out,"n2",n2);
zero = sf_charalloc(n1);
memset(zero,0,n1);
} else {
if (in2 != n2) sf_error("Wrong input dimensions, need %d traces",n2);
sf_putint(out,"n2",j2);
zero = NULL;
}
for (j=2; j < SF_MAX_DIM; j++) {
(void) snprintf(key,3,"n%d",j+1);
if (!sf_histint(in,key,&j2)) break;
sf_putint(out,key,1);
}
sf_unpipe(in,(off_t) n1*in2);
sf_fileflush(out,in);
sf_setform(in,SF_NATIVE);
sf_setform(out,SF_NATIVE);
pos = sf_tell(in);
for (i2=0; i2<n2; i2++) {
if (mask[i2]) {
if (!inv) sf_seek(in,pos+ (off_t) i2*n1,SEEK_SET);
sf_charread(trace,n1,in);
sf_charwrite(trace,n1,out);
} else if (inv) {
sf_charwrite(zero,n1,out);
}
}
exit(0);
}
/* $Id$ */