snap_ssg_SH.c 3.54 KB
Newer Older
1
/*-----------------------------------------------------------------------------------------
2
 * Copyright (C) 2016  For the list of authors, see file AUTHORS.
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
7 8 9
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2.0 of the License only.
 *
Florian Wittkamp's avatar
Florian Wittkamp committed
10
 * IFOS is distributed in the hope that it will be useful,
11 12 13 14 15
 * 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
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 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
 -----------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------
 *   Write 2D snapshot for current timestep  to file
 *
 *  See COPYING file for copying and redistribution conditions.
 *  ----------------------------------------------------------------------*/

#include "fd.h"


void snap_SH(FILE *fp,int nt, int nsnap, float ** vz, float **u, float **pi, float *hc, int ishot){
    
    /*
     different data formats of output:
     SNAP_FORMAT=1  :  SU (IEEE)
     SNAP_FORMAT=2  :  ASCII
     SNAP_FORMAT=3  :  BINARY (IEEE)
     
     different types:
     SNAP=1 : values in vx and vy
     SNAP=2 : -(vx+vy) (pressure field)
     SNAP=3 : divergence of vx and vy (energy of compressional waves)
     and curl of vx and vy (energy of shear waves)
     SNAP=4 : both particle velocities (type=1) and energy (type=3)
     */
    
    
    int i,j, fdoh;
    float  dhi;
    char snapfile_z[STRING_SIZE];
    char  ext[8], wm[2];
    FILE *fpx1;
    
    extern float DH, DT;
    extern char SNAP_FILE[STRING_SIZE];
    extern int NX, NY,  SNAP_FORMAT, SNAP, FDORDER, ACOUSTIC;
    extern int MYID, POS[3], IDX, IDY,VERBOSE;
    
    /* Check if snapshots should be writen for this shot*/
    extern int SNAPSHOT_START, SNAPSHOT_END, SNAPSHOT_INCR;
    int check=0;
    for(i=SNAPSHOT_START;i<=SNAPSHOT_END;i+=SNAPSHOT_INCR) {
        if(ishot==i) check=1;
    }
    if(check==0) return;
    
    
    dhi = 1.0/DH;
    fdoh = FDORDER/2;
    
    switch(SNAP_FORMAT){
        case 1:
            sprintf(ext,".su");
            break;
        case 2:
            sprintf(ext,".asc");
            break;
        case 3:
            sprintf(ext,".bin");
            break;
    }
    
    sprintf(snapfile_z,"%s%s.z.shot%i.%i.%i",SNAP_FILE,ext,ishot,POS[1],POS[2]);

    
    if(VERBOSE) fprintf(fp,"\n\n PE %d is writing snapshot-data SH at T=%fs to \n",MYID,nt*DT);
    
    if (nsnap==1)
        sprintf(wm,"w");
    else
        sprintf(wm,"a");
    
    switch(SNAP){
        case 1 :
            if(VERBOSE) fprintf(fp,"%s\n", snapfile_z);
            fpx1=fopen(snapfile_z,wm);
            for (i=1;i<=NX;i+=IDX)
                for (j=1;j<=NY;j+=IDY){
                    writedsk(fpx1,vz[j][i],SNAP_FORMAT);
                }
            fclose(fpx1);
            break;
            
            
        case 2 :
            break;
            
        case 4 :
           if(VERBOSE)  fprintf(fp,"%s\n", snapfile_z);
            fpx1=fopen(snapfile_z,wm);
            for (i=1;i<=NX;i+=IDX)
                for (j=1;j<=NY;j+=IDY){
                    writedsk(fpx1,vz[j][i],SNAP_FORMAT);
                }
            fclose(fpx1);
            break;
        case 3 :
            break;
    }
    
    
}