Thread: Error in SAC macro command bound within bash script

Started: 2019-04-29 14:20:24
Last activity: 2019-04-29 20:34:01
Topics: SAC Help
riddhi dave
2019-04-29 14:20:24
Hi,

I’m working on SAC macro within the bounds of a bash script.
Following is a portion of my script

#!/bin/bash
tail event_info > temp
year=`awk '{print substr($1,1,4)}' < temp `
jday=`awk '{print substr($1,5,3)}' < temp `
hour=`awk '{print substr($2,1,2)}' < temp`
min=`awk '{print substr($2,3,2)}' < temp`
sec=`awk '{print substr($2,5,2)}' < temp `
msec=`awk '{print $2}' < temp | awk -F. '{print $2}' `
EVLA=`awk '{print $3}' < temp `
EVLO=`awk '{print $4}' < temp `
EVDP=`awk '{print $5}' < temp `

rm -f temp

sac <<EOF

xlim off
cut off

r *BHZ*
synch r on
ch evla $EVLA evlo $EVLO evdp $EVDP
#change O for different event
ch O gmt $year $jday $hour $min $sec $msec
setbb otime &1,O
evaluate to cotime %otime * (-1.0)
ch ALLT %cotime IZTYPE IO
wh
if &1,DELTA NE 1.0
interp d 1.0
w over
endif
#p1
w over
quit
EOF



However, I keep getting this error:
ERROR 1017: Illegal macro command: 'if' can only be used within a macro
ERROR 1017: Illegal macro command: 'endif' can only be used within a macro


I am unable to see how that portion of my script isn’t within the SAC macro. I would really appreciate an insight in this error.
  • George Helffrich
    2019-04-29 20:34:01
    Dear Riddhi Dave -

    Where’s the macro? Thats a file that is invoked with SAC’s “macro” command (abbreviated “m”). What you are showing is command line input to SAC.

    If you want to avoid this message, put your SAC commands into a file and then invoke that as a macro. Try:

    cat << EOF > /tmp/runmacro
    xlim off
    cut off

    r *BHZ*
    synch r on
    ch evla $EVLA evlo $EVLO evdp $EVDP
    #change O for different event
    ch O gmt $year $jday $hour $min $sec $msec
    setbb otime &1,O
    evaluate to cotime %otime * (-1.0)
    ch ALLT %cotime IZTYPE IO
    wh
    if &1,DELTA NE 1.0
    interp d 1.0
    w over
    endif
    #p1
    w over
    quit
    EOF

    and then run SAC like this:
    echo ‘m /tmp/runmacro’ | sac

    or like this:
    sac /tmp/runmacro

    One way gives SAC a single command to run the macro, and the other runs the macro as a startup file.

    On 29 Apr 2019, at 19:33, riddhi dave <riddhidave6<at>gmail.com> wrote:

    Hi,

    I’m working on SAC macro within the bounds of a bash script.
    Following is a portion of my script

    #!/bin/bash
    tail event_info > temp
    year=`awk '{print substr($1,1,4)}' < temp `
    jday=`awk '{print substr($1,5,3)}' < temp `
    hour=`awk '{print substr($2,1,2)}' < temp`
    min=`awk '{print substr($2,3,2)}' < temp`
    sec=`awk '{print substr($2,5,2)}' < temp `
    msec=`awk '{print $2}' < temp | awk -F. '{print $2}' `
    EVLA=`awk '{print $3}' < temp `
    EVLO=`awk '{print $4}' < temp `
    EVDP=`awk '{print $5}' < temp `

    rm -f temp

    sac <<EOF

    xlim off
    cut off

    r *BHZ*
    synch r on
    ch evla $EVLA evlo $EVLO evdp $EVDP
    #change O for different event
    ch O gmt $year $jday $hour $min $sec $msec
    setbb otime &1,O
    evaluate to cotime %otime * (-1.0)
    ch ALLT %cotime IZTYPE IO
    wh
    if &1,DELTA NE 1.0
    interp d 1.0
    w over
    endif
    #p1
    w over
    quit
    EOF



    However, I keep getting this error:
    ERROR 1017: Illegal macro command: 'if' can only be used within a macro
    ERROR 1017: Illegal macro command: 'endif' can only be used within a macro


    I am unable to see how that portion of my script isn’t within the SAC macro. I would really appreciate an insight in this error.

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



    George Helffrich
    george<at>elsi.jp


    • That worked perfectly fine! Thank you for your help.

      On Mon, Apr 29, 2019 at 3:34 PM George Helffrich <george<at>elsi.jp> wrote:

      Dear Riddhi Dave -

      Where’s the macro? Thats a file that is invoked with SAC’s “macro”
      command (abbreviated “m”). What you are showing is command line input to
      SAC.

      If you want to avoid this message, put your SAC commands into a file and
      then invoke that as a macro. Try:

      cat << EOF > /tmp/runmacro

      xlim off
      cut off

      r *BHZ*
      synch r on
      ch evla $EVLA evlo $EVLO evdp $EVDP
      #change O for different event
      ch O gmt $year $jday $hour $min $sec $msec
      setbb otime &1,O
      evaluate to cotime %otime * (-1.0)
      ch ALLT %cotime IZTYPE IO
      wh
      if &1,DELTA NE 1.0
      interp d 1.0
      w over
      endif
      #p1
      w over
      quit
      EOF

      and then run SAC like this:
      echo ‘m /tmp/runmacro’ | sac

      or like this:
      sac /tmp/runmacro

      One way gives SAC a single command to run the macro, and the other runs
      the macro as a startup file.

      On 29 Apr 2019, at 19:33, riddhi dave <riddhidave6<at>gmail.com> wrote:

      Hi,

      I’m working on SAC macro within the bounds of a bash script.
      Following is a portion of my script

      #!/bin/bash
      tail event_info > temp
      year=`awk '{print substr($1,1,4)}' < temp `
      jday=`awk '{print substr($1,5,3)}' < temp `
      hour=`awk '{print substr($2,1,2)}' < temp`
      min=`awk '{print substr($2,3,2)}' < temp`
      sec=`awk '{print substr($2,5,2)}' < temp `
      msec=`awk '{print $2}' < temp | awk -F. '{print $2}' `
      EVLA=`awk '{print $3}' < temp `
      EVLO=`awk '{print $4}' < temp `
      EVDP=`awk '{print $5}' < temp `

      rm -f temp

      sac <<EOF

      xlim off
      cut off

      r *BHZ*
      synch r on
      ch evla $EVLA evlo $EVLO evdp $EVDP
      #change O for different event
      ch O gmt $year $jday $hour $min $sec $msec
      setbb otime &1,O
      evaluate to cotime %otime * (-1.0)
      ch ALLT %cotime IZTYPE IO
      wh
      if &1,DELTA NE 1.0
      interp d 1.0
      w over
      endif
      #p1
      w over
      quit
      EOF



      However, I keep getting this error:
      ERROR 1017: Illegal macro command: 'if' can only be used within a macro
      ERROR 1017: Illegal macro command: 'endif' can only be used within a macro


      I am unable to see how that portion of my script isn’t within the SAC
      macro. I would really appreciate an insight in this error.

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




      George Helffrich
      george<at>elsi.jp



      --







      *Dr. Riddhi DavePostdoctoral ScholarDépartement des sciences de la Terre et
      de l'atmosphèreUniversité du Québec à Montréal201 ave. du
      Président-KennedyMontréal QC H2X 3Y7*

18:19:36 v.22510d55