count_killed_traces.c 3.46 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
 *
Florian Wittkamp's avatar
Florian Wittkamp committed
4
 * This file is part of IFOS.
5
 *
Florian Wittkamp's avatar
Florian Wittkamp committed
6
 * IFOS is free software: you can redistribute it and/or modify
Tilman Steinweg's avatar
Tilman Steinweg committed
7 8
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2.0 of the License only.
9
 *
Florian Wittkamp's avatar
Florian Wittkamp committed
10
 * IFOS is distributed in the hope that it will be useful,
Tilman Steinweg's avatar
Tilman Steinweg committed
11 12 13
 * 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.
14
 *
Tilman Steinweg's avatar
Tilman Steinweg committed
15
 * You should have received a copy of the GNU General Public License
Florian Wittkamp's avatar
Florian Wittkamp committed
16
 * along with IFOS. See file COPYING and/or <http://www.gnu.org/licenses/gpl-2.0.html>.
17
 -----------------------------------------------------------------------------------------*/
Tilman Steinweg's avatar
Tilman Steinweg committed
18 19

/*------------------------------------------------------------------------
20
 *   Calculate number of killed traces
Tilman Steinweg's avatar
Tilman Steinweg committed
21 22 23
 *  ----------------------------------------------------------------------*/
#include "fd.h"

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
void count_killed_traces(int ntr, int swstestshot, int ntr_glob, int **recpos_loc, int nsrc_glob, int ishot, int* ptr_killed_traces, int* ptr_killed_traces_testshots,float ** srcpos, int ** recpos){
    
    /* declaration of variables */
    extern int USE_WORKFLOW, WORKFLOW_STAGE;
    extern char TRKILL_FILE[STRING_SIZE];
    extern int TRKILL_OFFSET;
    extern float TRKILL_OFFSET_LOWER;
    extern float TRKILL_OFFSET_UPPER;
    extern int MYID;
    int i,j,h;
    
    
    /* declaration of variables for trace killing */
    int ** kill_tmp, *kill_vector;
    char trace_kill_file[STRING_SIZE];
    FILE *ftracekill;
    
    
    kill_tmp = imatrix(1,ntr_glob,1,nsrc_glob);
    kill_vector = ivector(1,ntr);
    
    
    if(TRKILL_OFFSET) {
        
        if(MYID==0) {
49 50
            printf("\n\n ----- Offset based Tracekill ------");
            printf("\n Kill offsets between %.1f m and %.1f m",TRKILL_OFFSET_LOWER,TRKILL_OFFSET_UPPER);
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
        }
        
        /* Generate TraceKill file on the fly */
        create_trkill_table(kill_tmp,ntr_glob,recpos,nsrc_glob,srcpos,ishot,TRKILL_OFFSET_LOWER,TRKILL_OFFSET_UPPER);
        
    } else {
        
        /* READ TraceKill file from disk */
        
        if(USE_WORKFLOW){
            sprintf(trace_kill_file,"%s_%i.dat",TRKILL_FILE,WORKFLOW_STAGE);
            ftracekill=fopen(trace_kill_file,"r");
            if (ftracekill==NULL){
                sprintf(trace_kill_file,"%s.dat",TRKILL_FILE);
                ftracekill=fopen(trace_kill_file,"r");
                if (ftracekill==NULL){
                    err(" Trace kill file could not be opened!");
                }
            }
        }else{
71 72 73 74 75 76
            sprintf(trace_kill_file,"%s.dat",TRKILL_FILE);
            ftracekill=fopen(trace_kill_file,"r");
            if (ftracekill==NULL){
                err(" Trace kill file could not be opened!");
            }
        }
77 78 79 80 81
        
        for(i=1;i<=ntr_glob;i++){
            for(j=1;j<=nsrc_glob;j++){
                fscanf(ftracekill,"%d",&kill_tmp[i][j]);
            }
82
        }
83 84 85
        
        fclose(ftracekill);
        
86
    }
87
    
Tilman Steinweg's avatar
Tilman Steinweg committed
88

89 90 91 92 93 94 95 96
    
    h=1;
    for(i=1;i<=ntr;i++){
        kill_vector[h] = kill_tmp[recpos_loc[3][i]][ishot];
        if (kill_vector[h]==1) *ptr_killed_traces=*ptr_killed_traces+1;
        if ((kill_vector[h]==1) && (swstestshot==1)) *ptr_killed_traces_testshots=*ptr_killed_traces_testshots+1;
        h++;
    }
Tilman Steinweg's avatar
Tilman Steinweg committed
97 98
}