Thread: Nested Variables in IF statement

Started: 2016-09-20 21:38:47
Last activity: 2016-09-21 18:03:23
Topics: SAC Help
James Neely
2016-09-20 21:38:47
Hi,
I'm running into a problem with nested variables in an IF statement. I want to check the sampling rate of the many SAC files and then perform an action based on whether that rate is above or below a reference value. I'm trying to use a DO loop to cycle through the files. However, when I call the macro variable $i inside the header variable, I get an error that it $i is an illegal file name. It looks like SAC is not reading the macro variable correctly. Any ideas on how I can get it to read the macro variable? Here is my script.

read $File
DO i list $File
IF &$i$,DELTA& < 0.05
MESSAGE "This needs to be resampled"
ELSE
MESSAGE "This one is ok"
ENDIF
ENDDO
  • Milton Plasencia
    2016-09-21 12:19:20
    Hi James,

    Instead if you do:

    do i list %list%
    readhdr $i
    if &1,delta& LT 0.05
    message "$i$ is OK"
    else
    message "$i$ not OK"
    endif
    enddo

    I works for me, and readhdr is appropriate to load only header in memory.

    Cheers,

    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 Sep 20, 2016, at 23:43, James Neely <neelyj<at>umich.edu> wrote:

    Hi,
    I'm running into a problem with nested variables in an IF statement. I want to check the sampling rate of the many SAC files and then perform an action based on whether that rate is above or below a reference value. I'm trying to use a DO loop to cycle through the files. However, when I call the macro variable $i inside the header variable, I get an error that it $i is an illegal file name. It looks like SAC is not reading the macro variable correctly. Any ideas on how I can get it to read the macro variable? Here is my script.

    read $File
    DO i list $File
    IF &$i$,DELTA& < 0.05
    MESSAGE "This needs to be resampled"
    ELSE
    MESSAGE "This one is ok"
    ENDIF
    ENDDO

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

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


    • James Neely
      2016-09-21 16:31:07
      Hi Milton,

      That works great. Thank you.

      Thanks,
      James

      On Tue, Sep 20, 2016 at 11:19 PM, Milton Percy Plasencia Linares <
      mplasencia<at>inogs.it> wrote:

      Hi James,

      Instead if you do:

      do i list %list%
      readhdr $i
      if &1,delta& LT 0.05
      message "$i$ is OK"
      else
      message "$i$ not OK"
      endif
      enddo

      I works for me, and readhdr is appropriate to load only header in memory.

      Cheers,

      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 Sep 20, 2016, at 23:43, James Neely <neelyj<at>umich.edu> wrote:

      Hi,
      I'm running into a problem with nested variables in an IF statement. I
      want to check the sampling rate of the many SAC files and then perform an
      action based on whether that rate is above or below a reference value. I'm
      trying to use a DO loop to cycle through the files. However, when I call
      the macro variable $i inside the header variable, I get an error that it $i
      is an illegal file name. It looks like SAC is not reading the macro
      variable correctly. Any ideas on how I can get it to read the macro
      variable? Here is my script.

      read $File
      DO i list $File
      IF &$i$,DELTA& < 0.05
      MESSAGE "This needs to be resampled"
      ELSE
      MESSAGE "This one is ok"
      ENDIF
      ENDDO

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

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




  • George Helffrich
    2016-09-21 18:03:23
    Dear James -

    I suspect that you are using the IRIS version of SAC, which lacks some of the features described in the SAC book, in particular, the syntax embedding macro variables in file or blackboard variables. Here’s demonstration of the features using SAC/BRIS (terminology of section 1.5 in the SAC book):

    #cat /tmp/mactest
    fg seismogram
    setbb list "/tmp/filea /tmp/fileb"
    do i list %list%
    w $i$
    enddo

    read %list%

    do i list %list%
    if &$i$,delta& LT 0.05
    message "$i$ is OK"
    else
    message "$i$ isn't OK"
    endif
    enddo

    #sac
    SEISMIC ANALYSIS CODE [June 25 1991 (Version 10.6d-grh111/242)]
    Copyright 1991 Regents of the University of California

    SAC> echo on
    SAC> m /tmp/mactest
    m /tmp/mactest
    fg seismogram
    setbb list "/tmp/filea /tmp/fileb"
    do i list %list%
    ==> do i list /tmp/filea /tmp/fileb
    w $i$
    ==> w /tmp/filea
    enddo
    w $i$
    ==> w /tmp/fileb
    enddo

    read %list%
    ==> read /tmp/filea /tmp/fileb

    do i list %list%
    ==> do i list /tmp/filea /tmp/fileb
    if &$i$,delta& LT 0.05
    ==> if 0.10E-01 LT 0.05
    message "$i$ is OK"
    ==> message "/tmp/filea is OK"
    /tmp/filea is OK
    else
    endif
    enddo
    if &$i$,delta& LT 0.05
    ==> if 0.10E-01 LT 0.05
    message "$i$ is OK"
    ==> message "/tmp/fileb is OK"
    /tmp/fileb is OK
    else
    endif
    enddo
    SAC> quit
    quit
    #

    On 21 Sep 2016, at 06:43, James Neely <neelyj<at>umich.edu> wrote:

    Hi,
    I'm running into a problem with nested variables in an IF statement. I want to check the sampling rate of the many SAC files and then perform an action based on whether that rate is above or below a reference value. I'm trying to use a DO loop to cycle through the files. However, when I call the macro variable $i inside the header variable, I get an error that it $i is an illegal file name. It looks like SAC is not reading the macro variable correctly. Any ideas on how I can get it to read the macro variable? Here is my script.

    read $File
    DO i list $File
    IF &$i$,DELTA& < 0.05
    MESSAGE "This needs to be resampled"
    ELSE
    MESSAGE "This one is ok"
    ENDIF
    ENDDO

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

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


    George Helffrich
    george<at>elsi.jp


00:48:52 v.22510d55