time_window.c 5.13 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
 *
 * 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>.
-----------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------
 *   Apply time damping (after Brossier (2009))                                 
 *   last update 31/08/11, D.Koehn
 *   modified    02/02/12, S.Heider
 *  ----------------------------------------------------------------------*/
#include "fd.h"

26
void time_window(float **sectiondata, int iter, int ntr_glob, int **recpos_loc, int ntr, int ns, int ishot){
Tilman Steinweg's avatar
Tilman Steinweg committed
27

28
29
30
    /* declaration of variables */
    extern float DT;
    extern float GAMMA, TWLENGTH_PLUS, TWLENGTH_MINUS;
31
    extern int TW_IND, USE_WORKFLOW, WORKFLOW_STAGE;
32
33
34
35
36
    extern char PICKS_FILE[STRING_SIZE];
    char pickfile_char[STRING_SIZE];
    float time, dump, dump1, dump2, dump3, taper, taper1;
    float *pick_tmp, **pick_tmp_m;
    int i, j, h;
37

38
39
40
    float *picked_times=NULL, **picked_times_m=NULL;
    
    FILE *fptime;
41

42
43
44
45
46
47
48
49
    if(TW_IND){
        picked_times_m = matrix(1,3,1,ntr_glob);
        pick_tmp_m = matrix(1,3,1,ntr_glob);
    }else{
        picked_times = vector(1,ntr_glob);
        pick_tmp = vector(1,ntr_glob);
    }
    
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
    /* read picked first arrival times */
    if(USE_WORKFLOW){
        sprintf(pickfile_char,"%s_%i_%i.dat",PICKS_FILE,ishot,WORKFLOW_STAGE);
        fptime=fopen(pickfile_char,"r");
        if (fptime == NULL) {
            sprintf(pickfile_char,"%s_%i.dat",PICKS_FILE,ishot);
            fptime=fopen(pickfile_char,"r");
            if (fptime == NULL) {
                err(" picks_?.dat could not be opened !");
            }
        }
    }else{
        sprintf(pickfile_char,"%s_%i.dat",PICKS_FILE,ishot);
        fptime=fopen(pickfile_char,"r");
        if (fptime == NULL) {
            err(" picks_?.dat could not be opened !");
        }
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
    }
    
    if(TW_IND){
        for(i=1;i<=ntr_glob;i++){
            fscanf(fptime,"%f%f%f",&dump,&dump2,&dump3);
            pick_tmp_m[1][i] = dump;
            pick_tmp_m[2][i] = dump2;
            pick_tmp_m[3][i] = dump3;
        }
    }else{
        for(i=1;i<=ntr_glob;i++){
            fscanf(fptime,"%f",&dump);
            pick_tmp[i] = dump;
        }
    }
    
    fclose(fptime);
    
    /* distribute picks on CPUs */
    h=1;
    if(TW_IND){
        for(i=1;i<=ntr;i++){
            picked_times_m[1][h] = pick_tmp_m[1][recpos_loc[3][i]];
            picked_times_m[2][h] = pick_tmp_m[2][recpos_loc[3][i]];
            picked_times_m[3][h] = pick_tmp_m[3][recpos_loc[3][i]];
            
            h++;
        }
    }else{
        for(i=1;i<=ntr;i++){
            picked_times[h] = pick_tmp[recpos_loc[3][i]];
            
            h++;
        }
    }
    
    if(TW_IND)
        free_matrix(pick_tmp_m,1,3,1,ntr_glob);
    else
        free_vector(pick_tmp,1,ntr_glob);
    
    if(TW_IND){
        for(i=1;i<=ntr;i++){
        for(j=2;j<=ns;j++){
        
            time = (float)(j * DT);
            
            dump = (time-picked_times_m[1][i]-picked_times_m[2][i]);
            taper = exp(-GAMMA*dump*dump);
            
            dump1 = (time-picked_times_m[1][i]+picked_times_m[3][i]); 
            taper1 = exp(-GAMMA*dump1*dump1);
            
            if(time>=picked_times_m[1][i]+picked_times_m[2][i]){
            sectiondata[i][j] = sectiondata[i][j] * taper;}
            
            if(time<=picked_times_m[1][i]-picked_times_m[3][i]){
            sectiondata[i][j] = sectiondata[i][j] * taper1;}
            
            sectiondata[i][j] = sectiondata[i][j];
            
        }
        }
    }else{
        for(i=1;i<=ntr;i++){
        for(j=2;j<=ns;j++){
        
            time = (float)(j * DT);
            
            dump = (time-picked_times[i]-TWLENGTH_PLUS);
            taper = exp(-GAMMA*dump*dump);
            
            dump1 = (time-picked_times[i]+TWLENGTH_MINUS); 
            taper1 = exp(-GAMMA*dump1*dump1);
            
            if(time>=picked_times[i]+TWLENGTH_PLUS){
            sectiondata[i][j] = sectiondata[i][j] * taper;}
            
            if(time<=picked_times[i]-TWLENGTH_MINUS){
            sectiondata[i][j] = sectiondata[i][j] * taper1;}
            
            sectiondata[i][j] = sectiondata[i][j];
            
        }     
        }
    }
    
    if(TW_IND)
        free_matrix(picked_times_m,1,3,1,ntr_glob);
    else
        free_vector(picked_times,1,ntr_glob);
    
} /* end of function time_window.c */