Thread: Unexpected character open bracket

Started: 2021-07-02 15:37:01
Last activity: 2021-07-09 12:27:11
Topics: SAC Help
David Schlaphorst
2021-07-02 15:37:01
Hello,

I have a problem running a SAC macro (“mtrf”) on a Linux machine. It has the following lines:

77 * Read files to determine component orientations
78 rh %files%
79 do fn list %files%
80 if &1,filename& eq $fn$
81 setbb temp &1,cmpinc&
82 elseif &2,filename& eq $fn$
83 setbb temp &2,cmpinc&
84 else
85 setbb temp &3,cmpinc&
86 endif
87 if (abs (90 - %temp%)) lt 1
88 setbb hfiles APPEND " $fn$"
89 setbb rt APPEND (substring end end $fn$)
90 else
91 setbb zfile $fn$
92 endif
93 enddo

Trying to run this macro in SAC (version 102.0) it gives an error in line 87 not being able to understand the brackets (the error is “Unexpected character”, pointing to the first open bracket). This problem I could solve by introducing a line right before that and doing something like this:

setbb tmp_var (abs (90 - %temp%))
if tmp_var lt 1

Then it seemed to have a problem with the word “end” in line 89 and at the moment I’m not quite sure how to change this line to make it work. Also, in general, is there something fundamentally different in terms of syntax on this machine that I just missed so far, since it does not seem to be very happy with curved brackets?

Thank you very much!
David Schlaphorst


  • Fiona Darbyshire
    2021-07-05 09:57:59
    Dear David Schlaphorst,

    I am a regular MTRF user on a Linux machine, so I had a look at the
    version that works for me on my system.The two differences from your
    version are (i) the use of the blackboard variable as you'd mentioned,
    (ii) the line with the "end end" is commented out. In fact, apart from
    the initial definition setbb rt "" at the very beginning of the macro,
    all references to this blackboard variable are commented out. Here is
    the entire macro. I don't know if it's the latest version, but I've
    been using it successfully for a few years now.

    Best regards,

    Fiona Darbyshire
    Université du Québec à Montréal

    * mtrf calculates receiver functions by multitaper cross-correlation in the
    * frequency domain.
    *
    * It builds input and runs the receiver function program.
    *
    * Assumes A variable in file header set to begin of measurement interval, F
    * variable set to end. If variables not set, then you are prompted.
    * Other parameters:
    * file xxxx - prefix to file names
    * comps ce cn cz - three component suffixes, east north vertical components.
    * File names are thus xxxx.ce xxxx.cn xxxx.cz, OK?
    * plot yes - make SGF plot file and plot to screen
    * plot no - plot only to screen (default)
    * phase xxx - name of phase to measure, just a comment saved in file hdr.
    * fmax xxx - max frequency to deal with in frequency domain.
    * pick [ yes | maybe ] - If yes, force re-picking of seismogram even if
    * A and F are set.
    * window xxx - window length around arrival for display purposes.
    *
    * G. Helffrich/U. Bristol Jan-Oct. 2005
    * Updated 8 Aug. 2013
    *
    * Assumes two programs are available in your search path:
    * mtdecon, sacsetomarker.
    * Assumes macros available in macro search path:
    * prompt, ttimes
    *
    * There is a pause between panels of the results. If you are viewing them
    * and wish to abort, respond by typing a nonblank response.
    **** NOTE before opening any windows type the following command to get
    * proper windowing
    * window 1 x 0.05 0.80 y 0.05 0.74
    * then type 'bd xwindow' or 'bd sunwindow' or 'bd macwindow'
    ****
    * Copyright (c) 2013 by G. Helffrich.
    * All rights reserved.
    *
    * Redistribution and use in source form, with or without
    * modification, is permitted provided that the following conditions are met:
    * * Redistributions of source code must retain the above copyright
    * notice, this list of conditions and the following disclaimer:
    * THERE IS NO WARRANTY EXPRESSED OR IMPLIED, NOR LIABILITY FOR DAMAGES ASSUMED,
    * IN PROVIDING THIS SOFTWARE.
    *
    $keys file comps phase plot fmax pick window tables debug
    $default phase default
    $default plot no
    $default fmax 3.0
    $default pick maybe
    $default window 120
    $default tables ak135
    $default debug no
    setbb sta (CONCAT (BEFORE "." "$file$") ".dpar")
    setbb pick $pick
    setbb args ""
    setbb files ""
    setbb hfiles ""
    setbb rfiles ""
    setbb rt ""
    setbb ok no

    *echo on errors warnings output commands macros processed


    * Build file names from prefix and suffix list
    do sfx list $comps
    setbb files APPEND " $file$.$sfx$"
    enddo

    * Check for upper/lower case suffixes
    setbb case (change z Z "$sfx$")
    if "$sfx$" eq "%case%"
    setbb rfcns "$file$.NRFR $file$.NRFT $file$.NRFZ"
    setbb rad (change Z R "$sfx$")
    setbb tan (change Z T "$sfx$")
    setbb radfile "$file$.%rad%"
    setbb tanfile "$file$.%tan%"
    setbb rfiles "%radfile% %tanfile%
    else
    setbb rfcns "$file$.nrfr $file$.nrft $file$.nrfz"
    setbb rad (change z r "$sfx$")
    setbb tan (change z t "$sfx$")
    setbb radfile "$file$.%rad%"
    setbb tanfile "$file$.%tan%"
    setbb rfiles "%radfile% %tanfile%
    endif

    * Read files to determine component orientations
    rh %files%
    do fn list %files%
    if &1,filename& eq $fn$
    setbb temp &1,cmpinc&
    elseif &2,filename& eq $fn$
    setbb temp &2,cmpinc&
    else
    setbb temp &3,cmpinc&
    endif
    setbb incdiff (abs (90 - %temp%))
    if %incdiff% lt 1
    setbb hfiles APPEND " $fn$"
    * setbb rt APPEND (substring end end $fn$)
    else
    setbb zfile $fn$
    endif
    enddo

    * Horizontal component suffixes to lower case for rt checking later
    *setbb rt "(change R r (change T t %rt%))"
    *if %rt% eq tr
    * setbb rt rt
    *endif

    * Phase being measured is taken from KA marker in the file, if present.
    if $phase eq default
    if UNDEFINED ne &1,ka
    setbb phase "&1,ka "
    else
    setbb phase P
    endif
    else
    setbb phase $phase
    endif

    * Pass debug flags to program
    if _no ne "_$debug$"
    setbb args append " -debug $debug$"
    endif

    do loopo list once
    * if &1,a eq UNDEFINED
    setbb pick yes
    * endif
    * Invite user to pick measurement window if not yet set. If no pick made,
    * or picking declined, escape DO loop and don't measure.
    if %pick% eq yes
    r %files% ; rmean
    setbb prompt (REPLY "Hit return, then pick window - A begins
    window, F ends it ")
    * Escape loop if no picking wanted after seismogram examined
    if "%prompt%_" ne "_"
    break
    endif
    plotpk zero markall on bell off
    * Escape loop if no picks made
    if &1,a eq UNDEFINED
    break
    endif
    setbb beg &1,a& ; setbb end &1,f&
    rh %files% ; ch a %beg f %end ka %phase ; wh
    endif

    * Rotate horizontal components to radial-tangential frame
    * if %rt% ne rt
    r %hfiles% ; rmean ; rotate to gcp reversed ; w %rfiles%
    message "%hfiles% rewritten as %rfiles%"
    * endif

    * Build input file for measurement program, then invoke it.
    setbb ofiles "%rfcns%" ; setbb dur (&1,f& - &1,a&)

    do f list %rfiles% %zfile%
    setbb rff (before " " "%ofiles% ")
    sc mtdecon -freq $fmax$ %args% -window &1,a &1,f -noise (&1,a& -
    %dur%) &1,a& -wavelet &1,a& &1,f& %zfile% $f$ %rff%
    setbb ofiles (after " " "%ofiles%")
    enddo

    * Write measurement parameters to station log file
    sc echo "$file$ mtd $fmax$" >> %sta%

    if _no ne _$plot
    bd more sgf
    setbb ok ok
    endif
    r %rfcns% ; p1
    enddo

    if $plot$_no ne $plot$_%ok%
    bd previous
    endif

    unsetbb hfiles rfiles ofiles zfile sta rfcns rff rt ok
    unsetbb prompt phase pick



    On Sun, Jul 4, 2021 at 3:44 PM David Schlaphorst (via IRIS)
    <sac-help-bounce<at>lists.ds.iris.edu> wrote:

    Hello,

    I have a problem running a SAC macro (“mtrf”) on a Linux machine. It has the following lines:

    77 * Read files to determine component orientations
    78 rh %files%
    79 do fn list %files%
    80 if &1,filename& eq $fn$
    81 setbb temp &1,cmpinc&
    82 elseif &2,filename& eq $fn$
    83 setbb temp &2,cmpinc&
    84 else
    85 setbb temp &3,cmpinc&
    86 endif
    87 if (abs (90 - %temp%)) lt 1
    88 setbb hfiles APPEND " $fn$"
    89 setbb rt APPEND (substring end end $fn$)
    90 else
    91 setbb zfile $fn$
    92 endif
    93 enddo

    Trying to run this macro in SAC (version 102.0) it gives an error in line 87 not being able to understand the brackets (the error is “Unexpected character”, pointing to the first open bracket). This problem I could solve by introducing a line right before that and doing something like this:

    setbb tmp_var (abs (90 - %temp%))
    if tmp_var lt 1

    Then it seemed to have a problem with the word “end” in line 89 and at the moment I’m not quite sure how to change this line to make it work. Also, in general, is there something fundamentally different in terms of syntax on this machine that I just missed so far, since it does not seem to be very happy with curved brackets?

    Thank you very much!
    David Schlaphorst


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


    • David Schlaphorst
      2021-07-09 12:27:11
      Dear Fiona Darbyshire,

      Thank you very much for this fast help. We made the changes now and they worked.

      Kind regards,
      David

      On 5 Jul 2021, at 14:58, Fiona Darbyshire (via IRIS) <sac-help-bounce<at>lists.ds.iris.edu> wrote:

      Dear David Schlaphorst,

      I am a regular MTRF user on a Linux machine, so I had a look at the
      version that works for me on my system.The two differences from your
      version are (i) the use of the blackboard variable as you'd mentioned,
      (ii) the line with the "end end" is commented out. In fact, apart from
      the initial definition setbb rt "" at the very beginning of the macro,
      all references to this blackboard variable are commented out. Here is
      the entire macro. I don't know if it's the latest version, but I've
      been using it successfully for a few years now.

      Best regards,

      Fiona Darbyshire
      Université du Québec à Montréal

      * mtrf calculates receiver functions by multitaper cross-correlation in the
      * frequency domain.
      *
      * It builds input and runs the receiver function program.
      *
      * Assumes A variable in file header set to begin of measurement interval, F
      * variable set to end. If variables not set, then you are prompted.
      * Other parameters:
      * file xxxx - prefix to file names
      * comps ce cn cz - three component suffixes, east north vertical components.
      * File names are thus xxxx.ce xxxx.cn xxxx.cz, OK?
      * plot yes - make SGF plot file and plot to screen
      * plot no - plot only to screen (default)
      * phase xxx - name of phase to measure, just a comment saved in file hdr.
      * fmax xxx - max frequency to deal with in frequency domain.
      * pick [ yes | maybe ] - If yes, force re-picking of seismogram even if
      * A and F are set.
      * window xxx - window length around arrival for display purposes.
      *
      * G. Helffrich/U. Bristol Jan-Oct. 2005
      * Updated 8 Aug. 2013
      *
      * Assumes two programs are available in your search path:
      * mtdecon, sacsetomarker.
      * Assumes macros available in macro search path:
      * prompt, ttimes
      *
      * There is a pause between panels of the results. If you are viewing them
      * and wish to abort, respond by typing a nonblank response.
      **** NOTE before opening any windows type the following command to get
      * proper windowing
      * window 1 x 0.05 0.80 y 0.05 0.74
      * then type 'bd xwindow' or 'bd sunwindow' or 'bd macwindow'
      ****
      * Copyright (c) 2013 by G. Helffrich.
      * All rights reserved.
      *
      * Redistribution and use in source form, with or without
      * modification, is permitted provided that the following conditions are met:
      * * Redistributions of source code must retain the above copyright
      * notice, this list of conditions and the following disclaimer:
      * THERE IS NO WARRANTY EXPRESSED OR IMPLIED, NOR LIABILITY FOR DAMAGES ASSUMED,
      * IN PROVIDING THIS SOFTWARE.
      *
      $keys file comps phase plot fmax pick window tables debug
      $default phase default
      $default plot no
      $default fmax 3.0
      $default pick maybe
      $default window 120
      $default tables ak135
      $default debug no
      setbb sta (CONCAT (BEFORE "." "$file$") ".dpar")
      setbb pick $pick
      setbb args ""
      setbb files ""
      setbb hfiles ""
      setbb rfiles ""
      setbb rt ""
      setbb ok no

      *echo on errors warnings output commands macros processed


      * Build file names from prefix and suffix list
      do sfx list $comps
      setbb files APPEND " $file$.$sfx$"
      enddo

      * Check for upper/lower case suffixes
      setbb case (change z Z "$sfx$")
      if "$sfx$" eq "%case%"
      setbb rfcns "$file$.NRFR $file$.NRFT $file$.NRFZ"
      setbb rad (change Z R "$sfx$")
      setbb tan (change Z T "$sfx$")
      setbb radfile "$file$.%rad%"
      setbb tanfile "$file$.%tan%"
      setbb rfiles "%radfile% %tanfile%
      else
      setbb rfcns "$file$.nrfr $file$.nrft $file$.nrfz"
      setbb rad (change z r "$sfx$")
      setbb tan (change z t "$sfx$")
      setbb radfile "$file$.%rad%"
      setbb tanfile "$file$.%tan%"
      setbb rfiles "%radfile% %tanfile%
      endif

      * Read files to determine component orientations
      rh %files%
      do fn list %files%
      if &1,filename& eq $fn$
      setbb temp &1,cmpinc&
      elseif &2,filename& eq $fn$
      setbb temp &2,cmpinc&
      else
      setbb temp &3,cmpinc&
      endif
      setbb incdiff (abs (90 - %temp%))
      if %incdiff% lt 1
      setbb hfiles APPEND " $fn$"
      * setbb rt APPEND (substring end end $fn$)
      else
      setbb zfile $fn$
      endif
      enddo

      * Horizontal component suffixes to lower case for rt checking later
      *setbb rt "(change R r (change T t %rt%))"
      *if %rt% eq tr
      * setbb rt rt
      *endif

      * Phase being measured is taken from KA marker in the file, if present.
      if $phase eq default
      if UNDEFINED ne &1,ka
      setbb phase "&1,ka "
      else
      setbb phase P
      endif
      else
      setbb phase $phase
      endif

      * Pass debug flags to program
      if _no ne "_$debug$"
      setbb args append " -debug $debug$"
      endif

      do loopo list once
      * if &1,a eq UNDEFINED
      setbb pick yes
      * endif
      * Invite user to pick measurement window if not yet set. If no pick made,
      * or picking declined, escape DO loop and don't measure.
      if %pick% eq yes
      r %files% ; rmean
      setbb prompt (REPLY "Hit return, then pick window - A begins
      window, F ends it ")
      * Escape loop if no picking wanted after seismogram examined
      if "%prompt%_" ne "_"
      break
      endif
      plotpk zero markall on bell off
      * Escape loop if no picks made
      if &1,a eq UNDEFINED
      break
      endif
      setbb beg &1,a& ; setbb end &1,f&
      rh %files% ; ch a %beg f %end ka %phase ; wh
      endif

      * Rotate horizontal components to radial-tangential frame
      * if %rt% ne rt
      r %hfiles% ; rmean ; rotate to gcp reversed ; w %rfiles%
      message "%hfiles% rewritten as %rfiles%"
      * endif

      * Build input file for measurement program, then invoke it.
      setbb ofiles "%rfcns%" ; setbb dur (&1,f& - &1,a&)

      do f list %rfiles% %zfile%
      setbb rff (before " " "%ofiles% ")
      sc mtdecon -freq $fmax$ %args% -window &1,a &1,f -noise (&1,a& -
      %dur%) &1,a& -wavelet &1,a& &1,f& %zfile% $f$ %rff%
      setbb ofiles (after " " "%ofiles%")
      enddo

      * Write measurement parameters to station log file
      sc echo "$file$ mtd $fmax$" >> %sta%

      if _no ne _$plot
      bd more sgf
      setbb ok ok
      endif
      r %rfcns% ; p1
      enddo

      if $plot$_no ne $plot$_%ok%
      bd previous
      endif

      unsetbb hfiles rfiles ofiles zfile sta rfcns rff rt ok
      unsetbb prompt phase pick



      On Sun, Jul 4, 2021 at 3:44 PM David Schlaphorst (via IRIS)
      <sac-help-bounce<at>lists.ds.iris.edu> wrote:

      Hello,

      I have a problem running a SAC macro (“mtrf”) on a Linux machine. It has the following lines:

      77 * Read files to determine component orientations
      78 rh %files%
      79 do fn list %files%
      80 if &1,filename& eq $fn$
      81 setbb temp &1,cmpinc&
      82 elseif &2,filename& eq $fn$
      83 setbb temp &2,cmpinc&
      84 else
      85 setbb temp &3,cmpinc&
      86 endif
      87 if (abs (90 - %temp%)) lt 1
      88 setbb hfiles APPEND " $fn$"
      89 setbb rt APPEND (substring end end $fn$)
      90 else
      91 setbb zfile $fn$
      92 endif
      93 enddo

      Trying to run this macro in SAC (version 102.0) it gives an error in line 87 not being able to understand the brackets (the error is “Unexpected character”, pointing to the first open bracket). This problem I could solve by introducing a line right before that and doing something like this:

      setbb tmp_var (abs (90 - %temp%))
      if tmp_var lt 1

      Then it seemed to have a problem with the word “end” in line 89 and at the moment I’m not quite sure how to change this line to make it work. Also, in general, is there something fundamentally different in terms of syntax on this machine that I just missed so far, since it does not seem to be very happy with curved brackets?

      Thank you very much!
      David Schlaphorst


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


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



00:16:37 v.22510d55