Thread: Adding SAC headers from .txt file

Started: 2017-10-16 08:31:38
Last activity: 2017-10-17 02:53:26
Topics: SAC Help
joel.lowe.14@ucl.ac.uk
2017-10-16 08:31:38
Hello
I basically want to add the correct SAC header from .txt file to the corresponding .SAC file

I have .SAC file which are named as followed;
N.TROH.U.D.1.SAC
N.TROH.U.D.2.SAC
N.TROH.U.B.3.SAC
N.TROH.U.C.4.SAC
and so on....
I also have a .txt called TROH_T1_T2.txt which is set-out as followed.
N.TROH.U.D.1.SAC 5.5424 6.4533
N.TROH.U.D.2.SAC 3.2432 5.5433
N.TROH.U.B.3.SAC 7.5345 9.5345
N.TROH.U.C.4.SAC 5.3424 3.4234
and so on .....

what i want to do is. If the file name matches $1 (column 1) in TROH_T1_T2.txt input the value from the same row but different column in to a SAC command.


I have been trying with not much success.

#!/bin/bash

for file in /Documents/EarthquakeScaling/Testing/*.SAC;
do


awk '$2 ~ /$file/ {print $1 $2 $3 $4}' /Documents/EarthquakeScaling/KKWH_A_T1_T2.txt > temp_file.txt
handpick_variable=$(awk 'FNR==1 {print $2}' temp_file.txt) ;


SAC <<EOF
read $file
CHNHDR T1 handpick_variable
w $file.new_test
quit

EOF

done

Any help on how to add the SAC header from a .txt to the correct .SAC file will be extremely helpful.

Thanks
  • Milton Plasencia
    2017-10-17 02:53:26
    Joel,

    The script works for me in MAC OSX, it assume sac is in your PATH

    Here, t1_t2.txt is file contains

    N.TROH.U.D.1.SAC 5.5424 6.4533

    N.TROH.U.D.2.SAC 3.2432 5.5433

    N.TROH.U.B.3.SAC 7.5345 9.5345

    N.TROH.U.C.4.SAC 5.3424 3.4234

    --------------------------

    #!/bin/bash


    while read -r LINE

    do

    ROW="$LINE"

    FILE=`echo $ROW | awk '{print $1}'`

    T1=`echo $ROW | awk '{print $2}'`

    T2=`echo $ROW | awk '{print $3}'`

    printf "r $FILE\nch T1 $T1 T2 $T2\nwh\nq\n" | sac

    done < t1_t2.txt
    ----------------------------

    HTH,

    Milton



    ************************************
    Milton P. PLASENCIA LINARES

    Centro di Ricerche Sismologiche (CRS)
    OGS - Istituto Nazionale di Oceanografia e di Geofisica Sperimentale

    Borgo Grotta Gigante 42/C
    (34010) Sgonico - Trieste - Italia
    Tel: +39 040 2140 156 (Udine)
    Tel: +39 040 2140 256 (Trieste)
    Cel.: +39 331 6481 935

    E-mail: mplasencia<at>inogs.it
    GPG key: 22FCFFA8

    ASAIN (Antarctic Seismographic Argentinean Italian Network)
    *********************************

    On 16 October 2017 at 17:15, joel.lowe.14<at>ucl.ac.uk <joel.lowe.14<at>ucl.ac.uk>
    wrote:

    Hello
    I basically want to add the correct SAC header from .txt file to the
    corresponding .SAC file

    I have .SAC file which are named as followed;
    N.TROH.U.D.1.SAC
    N.TROH.U.D.2.SAC
    N.TROH.U.B.3.SAC
    N.TROH.U.C.4.SAC
    and so on....
    I also have a .txt called TROH_T1_T2.txt which is set-out as followed.
    N.TROH.U.D.1.SAC 5.5424 6.4533
    N.TROH.U.D.2.SAC 3.2432 5.5433
    N.TROH.U.B.3.SAC 7.5345 9.5345
    N.TROH.U.C.4.SAC 5.3424 3.4234
    and so on .....

    what i want to do is. If the file name matches $1 (column 1) in
    TROH_T1_T2.txt input the value from the same row but different column in to
    a SAC command.


    I have been trying with not much success.

    #!/bin/bash

    for file in /Documents/EarthquakeScaling/Testing/*.SAC;
    do


    awk '$2 ~ /$file/ {print $1 $2 $3 $4}' /Documents/EarthquakeScaling/KKWH_A_T1_T2.txt
    temp_file.txt
    handpick_variable=$(awk 'FNR==1 {print $2}' temp_file.txt) ;


    SAC <<EOF
    read $file
    CHNHDR T1 handpick_variable
    w $file.new_test
    quit

    EOF

    done

    Any help on how to add the SAC header from a .txt to the correct .SAC file
    will be extremely helpful.

    Thanks

    ----------------------
    SAC Help
    Topic home: http://ds.iris.edu/message-center/topic/sac-help/ |
    Unsubscribe: sac-help-unsubscribe<at>lists.ds.iris.edu

    Sent from the IRIS Message Center (http://ds.iris.edu/message-center/)
    Update subscription preferences at http://ds.iris.edu/account/profile/


14:20:52 v.b3198453