Thread: SAC header

Started: 2016-05-03 08:27:27
Last activity: 2016-05-03 23:47:19
Topics: SAC Help
Abhash Kumar
2016-05-03 08:27:27
Hi,
I have several SAC files and I want to output the value of a particular
header variable of each SAC file to a text file. Is it possible (or any SAC
command) to print out the value of a header variable in the SAC terminal
and save it to a text file. I would be grateful for any suggestion in this
regard.

Best regards
Abhash Kumar

  • Rob Porritt
    2016-05-03 12:36:40
    Hi Abhash,

    Have you tried saclst? It comes with sac and is very useful for getting sac
    header variables to a shell.

    Cheers,
    Rob
    On Mon, May 2, 2016 at 22:30 Abhash Kumar <abhash.kumar84<at>gmail.com> wrote:

    Hi,
    I have several SAC files and I want to output the value of a
    particular header variable of each SAC file to a text file. Is it possible
    (or any SAC command) to print out the value of a header variable in the SAC
    terminal and save it to a text file. I would be grateful for any suggestion
    in this regard.

    Best regards
    Abhash Kumar

    ----------------------
    SAC Help (http://ds.iris.edu/message-center/topic/sac-help/)

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


  • Lukas Janku
    2016-05-03 13:38:20
    Hi Abhash

    I am not aware of any SAC function that would help you, but you can access the Sac header variables via a Bash utility Saclst and save it wherever you want from Bash. More info on Saclst are for instance here:
    http://geophysics.eas.gatech.edu/classes/SAC/

    Cheers

    Lukas Janku


    ________________________________
    From: sac-help<at>iris.washington.edu [sac-help<at>iris.washington.edu] on behalf of Abhash Kumar [abhash.kumar84<at>gmail.com]
    Sent: 03 May 2016 17:28
    To: SAC Help
    Subject: [sac-help] SAC header

    Hi,
    I have several SAC files and I want to output the value of a particular header variable of each SAC file to a text file. Is it possible (or any SAC command) to print out the value of a header variable in the SAC terminal and save it to a text file. I would be grateful for any suggestion in this regard.

    Best regards
    Abhash Kumar

    This email may be confidential and subject to legal privilege, it may
    not reflect the views of the University of Canterbury, and it is not
    guaranteed to be virus free. If you are not an intended recipient,
    please notify the sender immediately and erase all copies of the message
    and any attachments.

    Please refer to http://www.canterbury.ac.nz/emaildisclaimer for more
    information.

  • Geo .
    2016-05-03 16:01:37
    Hi,
    saclst STLO STLO EVDP f filename.SAC > textfile.txt

    Note that saclst is a utility that comes with the SAC bundle.

    Januka

    Januka Attanayake
    Postdoctoral Research Associate

    Institut für Geophysik
    Westfälische Wilhelms - Universität Münster
    CorrensstraBe 24
    48149 Münster
    Germany

    University email: jattanayake<at>uni-muenster.de
    Homepage: http://sites.google.com/site/janukaattanayake/

    On 3 May 2016 at 07:28, Abhash Kumar <abhash.kumar84<at>gmail.com> wrote:

    Hi,
    I have several SAC files and I want to output the value of a
    particular header variable of each SAC file to a text file. Is it possible
    (or any SAC command) to print out the value of a header variable in the SAC
    terminal and save it to a text file. I would be grateful for any suggestion
    in this regard.

    Best regards
    Abhash Kumar


    ----------------------
    SAC Help (http://ds.iris.edu/message-center/topic/sac-help/)

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



  • Peter Schmidt
    2016-05-03 16:14:15
    HI Abhash

    Not of hand, but you could always create a little script to do the task.
    E.g. if running bash a starting point could be (if your using bash) a
    script with the following lines:

    #! /bin/sh
    export SAC_DISPLAY_COPYRIGHT=0
    sac << EOF
    read $1
    listhdr $2
    quit
    EOF

    which would take as input the name of the sac file and the header
    variable to output and write the result to stdout, hence you could
    redirect stdout into a fileobject.

    You will find more info about scripting SAC in the user manual


    regP



    On 03/05/16 07:28, Abhash Kumar wrote:
    Hi,
    I have several SAC files and I want to output the value of a
    particular header variable of each SAC file to a text file. Is it
    possible (or any SAC command) to print out the value of a header
    variable in the SAC terminal and save it to a text file. I would be
    grateful for any suggestion in this regard.

    Best regards
    Abhash Kumar


    ----------------------
    SAC Help (http://ds.iris.edu/message-center/topic/sac-help/)

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

    --
    ********************************************************************************
    Peter Schmidt Tel: +46-18-4712259
    Swedish National Seismological Network (SNSN) Mobile: +46-73-3190975
    Dept. of Earth Sciences:geophysics e-mail: peter.schmidt<at>geo.uu.se
    Uppsala University
    Villavagen 16
    SE-75236 Uppsala
    ********************************************************************************


    • Andy Nowacki
      2016-05-03 17:21:02
      Dear Abhash Kumar,

      A couple of other options:

      1) Use SAC's variable substitution alongside the `systemcommand` (`sc`) command:

      SAC> * Generate some data; yours will come from `rh`, I guess
      SAC> fg seis
      SAC> sc echo &1,kstnm > /tmp/headers
      SAC> sc cat /tmp/headers
      CDV

      Note that substitution is also allowed within quotes, which must be escaped using SAC's `@` escape character:

      SAC> sc echo @"(conc "Station name is: '" &1,kstnm& "'")@"
      Station name is: 'CDV'

      The SAC Book is probably the most comprehensive guide to macros, expressions and substitution rules (ISBN: 9781107613195), but of course the IRIS online help is also useful.


      2) Use the `to` option to the `getbb` command.

      A minimal working example to do this:

      SAC> setbb evtlon &1,evlo&
      SAC> getbb to /tmp/headers evtlon
      SAC> sc cat /tmp/headers
      CDV
      evtlon = -125

      It's somewhat convoluted, since you need to set a blackboard variable first, but I've made use of this in macros many times. Note that the file is appended to rather than overwritten. See the help (`help getbb`) for the options.

      Yours,

      Andy



      On 3 May 2016, at 08:16, peter.schmidt<at>geo.uu.se wrote:

      HI Abhash

      Not of hand, but you could always create a little script to do the task. E.g. if running bash a starting point could be (if your using bash) a script with the following lines:

      #! /bin/sh
      export SAC_DISPLAY_COPYRIGHT=0
      sac << EOF
      read $1
      listhdr $2
      quit
      EOF

      which would take as input the name of the sac file and the header variable to output and write the result to stdout, hence you could redirect stdout into a fileobject.

      You will find more info about scripting SAC in the user manual


      regP



      On 03/05/16 07:28, Abhash Kumar wrote:
      Hi,
      I have several SAC files and I want to output the value of a particular header variable of each SAC file to a text file. Is it possible (or any SAC command) to print out the value of a header variable in the SAC terminal and save it to a text file. I would be grateful for any suggestion in this regard.

      Best regards
      Abhash Kumar


      ----------------------
      SAC Help (
      http://ds.iris.edu/message-center/topic/sac-help/
      )

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

      --
      ********************************************************************************
      Peter Schmidt Tel: +46-18-4712259
      Swedish National Seismological Network (SNSN) Mobile: +46-73-3190975
      Dept. of Earth Sciences:geophysics e-mail:
      peter.schmidt<at>geo.uu.se

      Uppsala University
      Villavagen 16
      SE-75236 Uppsala
      ********************************************************************************


      ----------------------
      SAC Help (http://ds.iris.edu/message-center/topic/sac-help/)

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


  • George Helffrich
    2016-05-03 23:47:19
    This need has arisen many times and there are many implementations of command line tools to display header variables in SAC files. One, called “sachdrinfo," is documented in the SAC book and distributed with that version of SAC (SAC/BRIS).

    On 3 May 2016, at 14:28, Abhash Kumar <abhash.kumar84<at>gmail.com> wrote:

    Hi,
    I have several SAC files and I want to output the value of a particular header variable of each SAC file to a text file. Is it possible (or any SAC command) to print out the value of a header variable in the SAC terminal and save it to a text file. I would be grateful for any suggestion in this regard.

    Best regards
    Abhash Kumar

    ----------------------
    SAC Help (http://ds.iris.edu/message-center/topic/sac-help/)

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

    George Helffrich
    george.helffrich<at>bris.ac.uk


06:13:17 v.22510d55