-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzerofault_v2.c
More file actions
177 lines (150 loc) · 5.1 KB
/
zerofault_v2.c
File metadata and controls
177 lines (150 loc) · 5.1 KB
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
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "defns.h"
#include "segy.h"
#include "segyIO_class.h"
#include <time.h>
//#include "segyIO_class.h"
int main(int argc, char **argv)
{
FILE *fin; /* Input file */
FILE *fzeros; /* output file */
FILE *fmodel;
//segy thdr; /* holds the full trace header */
char txthdr[3202]; /* The character file header */
//register complex *ct; /* complex transformed trace */
float dt; /* sample spacing */
int ns; /* number of points on input trace */
register int i;
int ierr=0;
int endian = 1;
int format;
unsigned char chdr[3202];
int status=0;
bhed bh;
int fmt, itr;
int idt;
segy thdr;
float *tr; /* Array to hold the trace samples */
int *ptr2hdr;
int count=0;
char trhdr[242];
int delta =0;
int iline=0, xline=0,ilineStart=0,xlineStart=0,xlineEnd=0,horizon=0;
int numXlines=0;
char str[101];
int zero=0;
int window=0;
float fillerBelow=0,fillerAbove=0, fillerAve=0;
int fill=0;
endian = checkEndian();
if (argc == 8) {
fzeros = fopen(argv[1],"r");
fin = fopen(argv[2], "r+b");
//fout = fopen(argv[3],"wb");
if (fzeros == NULL) {
printf("Unable to open the zeros file. Please check the name.\n");
return -1;
}
if (fin == NULL) {
printf("Unable to open the input velocity file. Please check the name.\n");
return -1;
}
if(sscanf(argv[3], "%d", &ilineStart) != 1){
printf("\nStarting Inline entered not valid. Exiting...");
return -1;
}
if(sscanf(argv[4], "%d", &xlineStart) != 1){
printf("\nStarting Xline entered not valid. Exiting...");
return -1;
}
if(sscanf(argv[5], "%d", &xlineEnd) != 1){
printf("\nEnding Xline entered not valid. Exiting...");
return -1;
}
if(sscanf(argv[6], "%d", &window) != 1){
printf("\nStarting window entered not valid. Exiting...");
return -1;
}
if(sscanf(argv[7], "%d", &fill) != 1){
printf("\nStarting fill entered not valid. Exiting...");
return -1;
}
} else {
fprintf(stderr,"\n***************************************************************************\n");
fprintf(stderr, "Program reads horizon data from text file and zeros those horizon values.\n\n");
fprintf(stderr, "Usage: headerDump <horizon data> <input segy file> <starting inline> \n");
fprintf(stderr, " <starting xline> <ending xline> <window> <fill> \n\n");
fprintf(stderr, "window: number samples above and below to be zeroed/filled\n\n");
fprintf(stderr, "fill: 0 = zero values, 1 = fill previously zeroed values \n");
fprintf(stderr,"\n***************************************************************************\n");
return 0;
}
if (fin != NULL ) {
status = segyReadHeader(fin, chdr, &bh, endian);
fmt = bh.format; /*format*/
idt = bh.hdt; /*rate in microseconds*/
ns = bh.hns; /*samples per trace*/
printf("\nSamp rate is: %d Num samps is: %d format: %d \n", idt, ns,fmt);
//New method: Fseek to values!
numXlines=xlineEnd-xlineStart + 1;
while ( fgets(str,100,fzeros)!=NULL){
if(count%5000==0){
printf("Still running...");
}
count++;
if(fill==0){
sscanf(str,"%d %d %d", &iline,&xline,&horizon);
delta = (iline-ilineStart)*(numXlines)*(ns*4 + 240);
delta+= (xline-xlineStart)*(ns*4+240) ;
delta+= 240 + (horizon);
fseek(fin,3600+delta,SEEK_SET);
fwrite(&zero,4,1, fin);
for (i=1;i<=window;++i){
fseek(fin,3600+delta-i*4,SEEK_SET);
fwrite(&zero,4,1, fin);
fseek(fin,3600+delta+i*4,SEEK_SET);
fwrite(&zero,4,1, fin);
}
}else {
sscanf(str,"%d %d %d", &iline,&xline,&horizon);
delta = (iline-ilineStart)*(numXlines)*(ns*4 + 240);
delta+= (xline-xlineStart)*(ns*4+240) ;
delta+= 240 + (horizon);
fseek(fin,3600+delta - (window+1)*4 ,SEEK_SET);
fread(&fillerAbove,4,1,fin);
fseek(fin,3600+delta + (window+1)*4 ,SEEK_SET);
fread(&fillerBelow,4,1,fin);
if(fillerAbove==0 && fillerBelow ==0){
printf("fillerAbove an Below both zero!!");
}else if(fillerAbove==0){
fillerAbove = fillerBelow;
}else if(fillerBelow==0){
fillerBelow = fillerAbove;
}
for(i=1;i<=window;++i){
fseek(fin,3600+delta - i*4 ,SEEK_SET);
fwrite(&fillerAbove,4,1, fin);
fseek(fin,3600+delta + i*4 ,SEEK_SET);
fwrite(&fillerBelow,4,1, fin);
}
fseek(fin,3600+delta ,SEEK_SET);
fwrite(&fillerBelow,4,1, fin);
}
}
}
fclose(fin);
return 0;
}
/*
************************************************************************
*/
void doMessage(char *str)
{
fprintf(stderr, "%s\n", str);
}
/*
***********************************************************************
*/