saveseis_glob.c 13.1 KB
Newer Older
Tilman Steinweg's avatar
Tilman Steinweg committed
1
/*-----------------------------------------------------------------------------------------
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
 *   write seismograms to files
Tilman Steinweg's avatar
Tilman Steinweg committed
21 22 23 24
 *  ----------------------------------------------------------------------*/

#include "fd.h"

25 26
void saveseis_glob(FILE *fp, float **sectionvx, float **sectionvy,float **sectionvz,float **sectionp,float **sectioncurl, float **sectiondiv, int  **recpos, int  **recpos_loc,int ntr, float ** srcpos, int ishot, int ns, int iter, int type_switch){
    
27
    /* type_switch:
28 29 30 31
     *  1== synthetic data
     *  2== measured - synthetic data (residuals)
     *  3== filtered measured data
     */
32
    
33
    extern int SEISMO, SEIS_FORMAT, RUN_MULTIPLE_SHOTS, WAVETYPE, VERBOSE,FORWARD_ONLY;
34
    extern char SEIS_FILE[STRING_SIZE];
35
    extern int VELOCITY, WRITE_FILTERED_DATA, ADJOINT_TYPE;;
36 37 38
    
    char vxf[STRING_SIZE], vyf[STRING_SIZE],vzf[STRING_SIZE], curlf[STRING_SIZE], divf[STRING_SIZE], pf[STRING_SIZE];
    int nsrc=1;
39
    
40 41
    switch (type_switch) {
        case 1:
42 43 44 45 46 47 48 49 50 51 52
            if(ADJOINT_TYPE==1) {
                sprintf(vxf,"%s_vx.su.syn.shot%d.it%d",SEIS_FILE,ishot,iter);
                sprintf(vyf,"%s_vy.su.syn.shot%d.it%d",SEIS_FILE,ishot,iter);
            }
            if(ADJOINT_TYPE==2){
                sprintf(vyf,"%s_vy.su.syn.shot%d.it%d",SEIS_FILE,ishot,iter);
            }
            if(ADJOINT_TYPE==3){
                sprintf(vxf,"%s_vx.su.syn.shot%d.it%d",SEIS_FILE,ishot,iter);
            }

53
            if(WAVETYPE==2 || WAVETYPE==3) {
54
                sprintf(vzf,"%s_vz.su.syn.shot%d.it%d",SEIS_FILE,ishot,iter);
55
            }
56 57 58
            sprintf(pf,"%s_p.su.syn.shot%d.it%d",SEIS_FILE,ishot,iter);
            sprintf(divf,"%s_div.su.syn.shot%d.it%d",SEIS_FILE,ishot,iter);
            sprintf(curlf,"%s_curl.su.syn.shot%d.it%d",SEIS_FILE,ishot,iter);
59 60 61
            break;
            
        case 2:
62 63 64 65 66 67 68 69 70 71
            if(ADJOINT_TYPE==1) {
                sprintf(vxf,"%s_vx.su.shot%d_adjoint_src",SEIS_FILE,ishot);
                sprintf(vyf,"%s_vy.su.shot%d_adjoint_src",SEIS_FILE,ishot);
            }
            if(ADJOINT_TYPE==2){
                sprintf(vyf,"%s_vy.su.shot%d_adjoint_src",SEIS_FILE,ishot);
            }
            if(ADJOINT_TYPE==3){
                sprintf(vxf,"%s_vx.su.shot%d_adjoint_src",SEIS_FILE,ishot);
            }
72 73 74 75 76 77 78 79 80
            if(WAVETYPE==2 || WAVETYPE==3) {
                sprintf(vzf,"%s_vz.su.shot%d_adjoint_src",SEIS_FILE,ishot);
            }
            sprintf(pf,"%s_p.su.shot%d_adjoint_src",SEIS_FILE,ishot);
            sprintf(divf,"%s_div.su.shot%d_adjoint_src",SEIS_FILE,ishot);
            sprintf(curlf,"%s_curl.su.shot%d_adjoint_src",SEIS_FILE,ishot);
            break;
            
        case 3:
81
            if(WRITE_FILTERED_DATA==1){
82 83 84 85 86 87 88 89 90 91 92
                if(ADJOINT_TYPE==1) {
                    sprintf(vxf,"%s_vx.su.obs.shot%d.it%d",SEIS_FILE,ishot,iter);
                    sprintf(vyf,"%s_vy.su.obs.shot%d.it%d",SEIS_FILE,ishot,iter);
                }
                if(ADJOINT_TYPE==2){
                    sprintf(vyf,"%s_vy.su.obs.shot%d.it%d",SEIS_FILE,ishot,iter);
                }
                if(ADJOINT_TYPE==3){
                    sprintf(vxf,"%s_vx.su.obs.shot%d.it%d",SEIS_FILE,ishot,iter);
                }

93
                if(WAVETYPE==2 || WAVETYPE==3) {
94
                    sprintf(vzf,"%s_vz.su.obs.shot%d.it%d",SEIS_FILE,ishot,iter);
95
                }
96 97 98 99
                sprintf(pf,"%s_p.su.obs.shot%d.it%d",SEIS_FILE,ishot,iter);
                sprintf(divf,"%s_div.su.obs.shot%d.it%d",SEIS_FILE,ishot,iter);
                sprintf(curlf,"%s_curl.su.obs.shot%d.it%d",SEIS_FILE,ishot,iter);
            }else if(WRITE_FILTERED_DATA==2){
100 101 102 103 104 105 106 107 108 109 110
                if(ADJOINT_TYPE==1) {
                    sprintf(vxf,"%s_vx.su.obs.adj.shot%d.it%d",SEIS_FILE,ishot,iter);
                    sprintf(vyf,"%s_vy.su.obs.adj.shot%d.it%d",SEIS_FILE,ishot,iter);
                }
                if(ADJOINT_TYPE==2){
                    sprintf(vyf,"%s_vy.su.obs.adj.shot%d.it%d",SEIS_FILE,ishot,iter);
                }
                if(ADJOINT_TYPE==3){
                    sprintf(vxf,"%s_vx.su.obs.adj.shot%d.it%d",SEIS_FILE,ishot,iter);
                }

111
                if(WAVETYPE==2 || WAVETYPE==3) {
112
                    sprintf(vzf,"%s_vz.su.obs.adj.shot%d.it%d",SEIS_FILE,ishot,iter);
113
                }
114 115 116
                sprintf(pf,"%s_p.su.obs.adj.shot%d.it%d",SEIS_FILE,ishot,iter);
                sprintf(divf,"%s_div.su.obs.adj.shot%d.it%d",SEIS_FILE,ishot,iter);
                sprintf(curlf,"%s_curl.su.obs.adj.shot%d.it%d",SEIS_FILE,ishot,iter);
117 118 119
            }
            break;
            
120
        case 4:
121 122 123 124 125 126 127 128 129 130 131
            if(ADJOINT_TYPE==1) {
                sprintf(vxf,"%s_vx.su.syn.adj.shot%d.it%d",SEIS_FILE,ishot,iter);
                sprintf(vyf,"%s_vy.su.syn.adj.shot%d.it%d",SEIS_FILE,ishot,iter);
            }
            if(ADJOINT_TYPE==2){
                sprintf(vyf,"%s_vy.su.syn.adj.shot%d.it%d",SEIS_FILE,ishot,iter);
            }
            if(ADJOINT_TYPE==3){
                sprintf(vxf,"%s_vx.su.syn.adj.shot%d.it%d",SEIS_FILE,ishot,iter);
            }

132 133
            if(WAVETYPE==2 || WAVETYPE==3) {
                sprintf(vzf,"%s_vz.su.syn.adj.shot%d.it%d",SEIS_FILE,ishot,iter);
134
            }
135 136 137
            sprintf(pf,"%s_p.su.syn.adj.shot%d.it%d",SEIS_FILE,ishot,iter);
            sprintf(divf,"%s_div.su.syn.adj.shot%d.it%d",SEIS_FILE,ishot,iter);
            sprintf(curlf,"%s_curl.su.syn.adj.shot%d.it%d",SEIS_FILE,ishot,iter);
138 139
            break;
            
140
        default:
141
            declare_error("saveseis_glob: Unkown type_switch");
142
            break;
143 144
    }
    
145
    if(FORWARD_ONLY==1){
146 147
        sprintf(vxf,"%s_vx.su.shot%d",SEIS_FILE,ishot);
        sprintf(vyf,"%s_vy.su.shot%d",SEIS_FILE,ishot);
148
        if(WAVETYPE==2 || WAVETYPE==3) {
149
            sprintf(vzf,"%s_vz.su.shot%d",SEIS_FILE,ishot);
150
        }
151 152 153
        sprintf(pf,"%s_p.su.shot%d",SEIS_FILE,ishot);
        sprintf(divf,"%s_div.su.shot%d",SEIS_FILE,ishot);
        sprintf(curlf,"%s_curl.su.shot%d",SEIS_FILE,ishot);
154
    }
155 156 157 158
    
    switch (SEISMO){
        case 1 : /* particle velocities only */
            if (WAVETYPE==1 || WAVETYPE==3) {
159
                if(ADJOINT_TYPE==1 || ADJOINT_TYPE==0) {
160 161 162 163 164 165 166 167 168 169 170 171 172 173
                    
                    if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms (vx) to\n\t %s \n",0,ntr,vxf);
                    outseis_glob(fp,fopen(vxf,"w"),1,sectionvx,recpos,recpos_loc,ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
                    if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms (vy) to\n\t %s \n",0,ntr,vyf);
                    outseis_glob(fp,fopen(vyf,"w"),2,sectionvy,recpos,recpos_loc, ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
                }
                if(ADJOINT_TYPE==2){
                    if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms (vy) to\n\t %s \n",0,ntr,vyf);
                    outseis_glob(fp,fopen(vyf,"w"),2,sectionvy,recpos,recpos_loc, ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
                }
                if(ADJOINT_TYPE==3){
                    if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms (vx) to\n\t %s \n",0,ntr,vxf);
                    outseis_glob(fp,fopen(vxf,"w"),1,sectionvx,recpos,recpos_loc,ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
                }
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
            }
            if(WAVETYPE==2 || WAVETYPE==3) {
                if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms (vz) to\n\t %s \n",0,ntr,vzf);
                outseis_glob(fp,fopen(vzf,"w"),2,sectionvz,recpos,recpos_loc, ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
            }
            break;
            
        case 2 : /* pressure only */
            if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms of pressure to\n\t %s \n",0,ntr,pf);
            outseis_glob(fp,fopen(pf,"w"), 0, sectionp,recpos,recpos_loc,ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
            break;
            
        case 3 : /* curl and div only */
            if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms of divergence to\n\t %s \n",0,ntr,divf);
            outseis_glob(fp,fopen(divf,"w"), 0, sectiondiv,recpos,recpos_loc,ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
            if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms of curl to\n\t %s \n",0,ntr,curlf);
            outseis_glob(fp,fopen(curlf,"w"), 0, sectioncurl,recpos,recpos_loc,ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
            break;
            
        case 4 : /* everything */
            if (WAVETYPE==1 || WAVETYPE==3) {
195
                if(ADJOINT_TYPE==1 || ADJOINT_TYPE==0) {
196 197 198 199 200 201 202 203 204 205 206 207 208 209
                    if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms (vx) to\n\t %s \n",0,ntr,vxf);
                    outseis_glob(fp,fopen(vxf,"w"),1,sectionvx,recpos,recpos_loc,ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
                    if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms (vy) to\n\t %s \n",0,ntr,vyf);
                    outseis_glob(fp,fopen(vyf,"w"),2,sectionvy,recpos,recpos_loc, ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
                }
                if(ADJOINT_TYPE==2){
                    if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms (vy) to\n\t %s \n",0,ntr,vyf);
                    outseis_glob(fp,fopen(vyf,"w"),2,sectionvy,recpos,recpos_loc, ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
                }
                if(ADJOINT_TYPE==3){
                    if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms (vx) to\n\t %s \n",0,ntr,vxf);
                    outseis_glob(fp,fopen(vxf,"w"),1,sectionvx,recpos,recpos_loc,ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
                }

210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
                if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms of pressure to\n\t %s \n",0,ntr,pf);
                outseis_glob(fp,fopen(pf,"w"), 0, sectionp,recpos,recpos_loc,ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
                
                if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms of divergence to\n\t %s \n",0,ntr,divf);
                outseis_glob(fp,fopen(divf,"w"),0, sectiondiv,recpos,recpos_loc,ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
                if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms of curl to\n\t %s \n",0,ntr,curlf);
                outseis_glob(fp,fopen(curlf,"w"),0, sectioncurl,recpos,recpos_loc,ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
            }
            if(WAVETYPE==2 || WAVETYPE==3) {
                if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms (vz) to\n\t %s \n",0,ntr,vzf);
                outseis_glob(fp,fopen(vzf,"w"),2,sectionvz,recpos,recpos_loc, ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
            }
            break;
            
        case 5 : /* everything except curl and div */
            if (WAVETYPE==1 || WAVETYPE==3) {
226
                if(ADJOINT_TYPE==1 || ADJOINT_TYPE==0) {
227 228 229 230 231 232 233 234 235 236 237 238 239 240
                    if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms (vx) to\n\t %s \n",0,ntr,vxf);
                    outseis_glob(fp,fopen(vxf,"w"),1,sectionvx,recpos,recpos_loc,ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
                    if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms (vy) to\n\t %s \n",0,ntr,vyf);
                    outseis_glob(fp,fopen(vyf,"w"),2,sectionvy,recpos,recpos_loc, ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
                }
                if(ADJOINT_TYPE==2){
                    if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms (vy) to\n\t %s \n",0,ntr,vyf);
                    outseis_glob(fp,fopen(vyf,"w"),2,sectionvy,recpos,recpos_loc, ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
                }
                if(ADJOINT_TYPE==3){
                    if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms (vx) to\n\t %s \n",0,ntr,vxf);
                    outseis_glob(fp,fopen(vxf,"w"),1,sectionvx,recpos,recpos_loc,ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
                }

241 242 243 244 245 246 247 248 249
                if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms of pressure to\n\t %s \n",0,ntr,pf);
                outseis_glob(fp,fopen(pf,"w"), 0, sectionp,recpos,recpos_loc,ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
            }
            if(WAVETYPE==2 || WAVETYPE==3) {
                if(VERBOSE==1) fprintf(fp," PE %d is writing %d seismograms (vz) to\n\t %s \n",0,ntr,vzf);
                outseis_glob(fp,fopen(vzf,"w"),2,sectionvz,recpos,recpos_loc, ntr,srcpos,nsrc,ns,SEIS_FORMAT,ishot,1);
            }
            break;
            
250
    }
Tilman Steinweg's avatar
Tilman Steinweg committed
251
}