Thread: change ray paramter

Started: 2020-05-30 01:56:19
Last activity: 2020-05-31 20:07:59
Topics: SAC Help
Waddah Mahmoud
2020-05-30 01:56:19
Dear All
I need a script or macro; its function is to change the unit of ray parameter in USER7 header from s/deg to s/km for many files; I can do this for each separately but it is very tedious work.
I mean to loop over all files and change the unit.
I cannot construct such script or macro and need help please.

Regards
Wadah
  • Milton Plasencia
    2020-05-30 11:32:33
    Hi,

    Perhaps you like to try it:
    But, the script run smooth if you set the SAC variable

    SAC_DISPLAY_COPYRIGHT=0
    in your sac configuration file, eg. sacinit.sh
    It is tested in OSX and CentOS

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

    #!/bin/bash


    # Begin loop for all *.sac files in actual dir

    for SACFILE in $(ls *.sac); do


    # Using saclst program including in sac distibution, so it must be in the
    PATH

    SDEG=`saclst USER7 f $SACFILE | awk '{print $2}'`


    # Using eval (evaluate) SAC command to calculate s/km, here s/deg times
    1/111.11=0.009 (1 deg = 111.111 km)

    SKM=`printf "eval $SDEG*0.009\nq\n" | sac`


    # Using printf bash command to write the new header variable

    printf "r *.sac\nch user7 $SKM\nwh\nq\n" | sac


    # To verify if all is OK

    saclst USER7 f $SACFILE


    done


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



    I attach the script he7.sh to avoid typo after copy and paste.

    milton

    ************************************
    Milton P. PLASENCIA LINARES
    Istituto Nazionale di Oceanografia e di Geofisica Sperimentale - OGS
    Borgo Grotta Gigante 42/C
    (34010) Sgonico - Trieste - Italia
    Tel: +39 040 2140 156 (Udine)
    Tel: +39 040 2140 256 (Trieste)
    Cell.: +39 331 6481 935

    E-mail: mplasencia<at>inogs.it

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


    On Sat, 30 May 2020 at 04:02, Waddah Mahmoud (via IRIS) <
    sac-help<at>lists.ds.iris.edu> wrote:

    Dear All
    I need a script or macro; its function is to change the unit of ray
    parameter in USER7 header from s/deg to s/km for many files; I can do this
    for each separately but it is very tedious work.
    I mean to loop over all files and change the unit.
    I cannot construct such script or macro and need help please.

    Regards
    Wadah

    ----------------------
    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/


    Attachments
    • Waddah Mahmoud
      2020-05-30 19:24:16
      Thank you Milton
      I tried your script and it is working, but the result is very small in the order of e-26, when following it carefully I found that each value in USER7 will be multiplied by 0.009 "n" times, where n is the number of files, in my case i have 13 sac file and an example ray parameter of one of them is 4.88763 s/deg and after running the script this value became 1.24236e-26.
      This issue triggered me to make a script taking advantage of your script and others.
      I tried it and it is working very well, here is the script to be in use for anyone need it, also I attached it :

      #!/bin/bash
      for filename in `ls *.sac`
      do
      sac << END
      READ $filename
      SETBB rayd &$filename,USER7&
      # conv 1/111.195= 0.008992806 – convert from deg to km
      setbb conft 0.00899321
      # multiply by the factor
      setbb rayk (MULTIPLY %rayd% %conft%)
      ch USER7 %rayk%
      w over
      dc
      unsetbb
      quit
      END
      done
      • Milton Plasencia
        2020-05-30 21:47:36
        Nothing, important is you solved the problem.

        Yes, i tested the script with one only file..

        m.

        ************************************
        Milton P. PLASENCIA LINARES
        Istituto Nazionale di Oceanografia e di Geofisica Sperimentale - OGS
        Borgo Grotta Gigante 42/C
        (34010) Sgonico - Trieste - Italia
        Tel: +39 040 2140 156 (Udine)
        Tel: +39 040 2140 256 (Trieste)
        Cell.: +39 331 6481 935

        E-mail: mplasencia<at>inogs.it

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


        On Sat, 30 May 2020 at 21:30, Waddah Mahmoud (via IRIS) <
        sac-help<at>lists.ds.iris.edu> wrote:

        Thank you Milton
        I tried your script and it is working, but the result is very small in the
        order of e-26, when following it carefully I found that each value in USER7
        will be multiplied by 0.009 "n" times, where n is the number of files, in
        my case i have 13 sac file and an example ray parameter of one of them is
        4.88763 s/deg and after running the script this value became 1.24236e-26.
        This issue triggered me to make a script taking advantage of your script
        and others.
        I tried it and it is working very well, here is the script to be in use
        for anyone need it, also I attached it :

        #!/bin/bash
        for filename in `ls *.sac`
        do
        sac << END
        READ $filename
        SETBB rayd &$filename,USER7&
        # conv 1/111.195= 0.008992806 – convert from deg to km
        setbb conft 0.00899321
        # multiply by the factor
        setbb rayk (MULTIPLY %rayd% %conft%)
        ch USER7 %rayk%
        w over
        dc
        unsetbb
        quit
        END
        done

        ----------------------
        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/


      • Milton Plasencia
        2020-05-31 07:37:24
        Yes, if you change line 13 for it:

        printf "r $SACFILE\nch user7 $SKM\nwh\nq\n"|sac


        all is OK.


        m.

        ************************************
        Milton P. PLASENCIA LINARES
        Istituto Nazionale di Oceanografia e di Geofisica Sperimentale - OGS
        Borgo Grotta Gigante 42/C
        (34010) Sgonico - Trieste - Italia
        Tel: +39 040 2140 156 (Udine)
        Tel: +39 040 2140 256 (Trieste)
        Cell.: +39 331 6481 935

        E-mail: mplasencia<at>inogs.it

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


        On Sat, 30 May 2020 at 21:30, Waddah Mahmoud (via IRIS) <
        sac-help<at>lists.ds.iris.edu> wrote:

        Thank you Milton
        I tried your script and it is working, but the result is very small in the
        order of e-26, when following it carefully I found that each value in USER7
        will be multiplied by 0.009 "n" times, where n is the number of files, in
        my case i have 13 sac file and an example ray parameter of one of them is
        4.88763 s/deg and after running the script this value became 1.24236e-26.
        This issue triggered me to make a script taking advantage of your script
        and others.
        I tried it and it is working very well, here is the script to be in use
        for anyone need it, also I attached it :

        #!/bin/bash
        for filename in `ls *.sac`
        do
        sac << END
        READ $filename
        SETBB rayd &$filename,USER7&
        # conv 1/111.195= 0.008992806 – convert from deg to km
        setbb conft 0.00899321
        # multiply by the factor
        setbb rayk (MULTIPLY %rayd% %conft%)
        ch USER7 %rayk%
        w over
        dc
        unsetbb
        quit
        END
        done

        ----------------------
        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/


    • Waddah Mahmoud
      2020-05-30 19:30:02
      sorry but I don't know how to attach file with meaasge.

      Regards
      Wadah
  • Geo .
    2020-05-30 17:00:40
    Hi Wadah,

    This is straight forward. Go here to see how you can construct a simple for
    loop in shell to read in a set of files:
    https://www.cyberciti.biz/faq/bash-loop-over-file/
    Once you do this, you just include the SAC commands you already have within
    the for loop. Just make sure you have your data backed up, once the files
    are over written, they are changed irreversibly.

    e.g.

    #!/bin/sh
    for filename in `ls my_path/*.SAC`
    do

    SAC << END
    READ $filename
    CHNHDR USER7 s/km
    WRITE OVER
    QUIT
    END

    done


    Januka


    Januka Attanayake
    Research Fellow | Earthquake Seismology
    Homepage: *https://sites.google.com/site/janukaattanayake
    https://sites.google.com/site/janukaattanayake*

    School of Earth Sciences | McCoy Bldg. 200
    University of Melbourne | Parkville 3010 VIC
    Australia




    On Sat, 30 May 2020 at 12:00, Waddah Mahmoud (via IRIS) <
    sac-help<at>lists.ds.iris.edu> wrote:

    Dear All
    I need a script or macro; its function is to change the unit of ray
    parameter in USER7 header from s/deg to s/km for many files; I can do this
    for each separately but it is very tedious work.
    I mean to loop over all files and change the unit.
    I cannot construct such script or macro and need help please.

    Regards
    Wadah

    ----------------------
    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/


16:09:45 v.22510d55