USAGE:

     cxa [options] [[z] z ...] z [OP] [[z] OP] ...
cat <file> | cxa -
cat
<file> | cxa options ...
    

PURPOSE:
Complex arithmetic in reverse polish notation. Stack height is 100.

In the second and third kind of usage, every line of the file presents an argument list.
Every new line resets the stack. In the second kind, all options must be included in the input pipe.
(we haven't tried this yet with the ellipse occurring amidst values and operators)

The mechanism of importing environment variables as in tsfedit (see usage in repenvl) is supported.
OBS! The string must be quoted to prevent the shell from interpolation.

 Operators:
   u - push stack (level 1 keeps its value)
   p - convert z to polar: cxa -Fef 1,1 p : 1.4142E+00,45.000

   c - convert z to plane
   a - add:                cxa  1,2 3,4 a : 4.0000E+00,6.0000E+00
   s - subtract:           cxa  1,2 2,4 s : -1.0000E+00,-2.0000E+00
   m - multiply
   d - divide
   j - conjugate
   @ - , synonymous with...
  '|' - absolute to real-part                   1)
   ^ - power z(1)**z(2) (consider swap, X)     1)
  ^v - z(1)**v (v see Numbers)                 1)
  +- - error value (1-sigma)
   V - show stack
   X - swap the two lowest stack levels
 exp - complex exponential function
 log - complex logarithm
 1) does not work with error values (yet)

 Numbers:
Polar values: phase is always in degrees
 
  '(
1,2)' 1,2  1 2     three ways to enter complex values. At least
                       the parentheses must be quoted: '(' ')'.

                       The comma-free form works only with numerical values.
  r1.23  1.23r         two ways for real values
  i1.23  1.23i         two ways for imaginary values
r1/1.23  1/1.23r       two ways for reciprocal real values

i1/1.23  1/1.23i       two ways for reciprocal imag values
  b1.23  1.23b         sets real=imag
  h1.23  1.23h         phase, i.e. in polar (1, 1.23 deg))

  sqr2                 evaluates to dsqrt(2.d0)
  pi                   evaluates to pi
  rpd                  evaluates to pi/180.

 Options:
In the sequel, `#┬┤ emphasises that the slanted word following symbolizes a numerical value (not a `Number┬┤ in the sense above).
Other symbols in slanted style symbolize strings.

First option only: Cut a string from stdin into a leader text and an argument part
  /string   - split at the string (string ends the leader; matching operation is not greedy!)
  ^#n       - split after the n'th character
  -c#cut    - value where to cut phase circle (degrees)
  -Sstring  - add heading string.
  +Sstring  - add trailing string.
  -R        - write out only real-part 
  -r        - write out only real-part if imag is zero.

  -F[+]format     - output format; devise for two numbers and a comma
  -F
[+]ef         - for polar, a standard format E-form, F-form
  -F[+]ff#a.#b    - output format f#a.#b,f#a.#b   for z in plane
  -F[+]fp#a.#b    - output format f#a.#b,f8.3     for z in polar
  -F[+]l   -F[+]L - short forms for e13.5 or e22.14, respectively.
  -F+               ... in each of the above prints positive numbers with +sign
 
  -,        - delete comma in output
              (Obs! the comma in the format is a must.)
  -_        - delete commas in heading and trailing strings

  +P        - add parentheses
  +Q        - add double-quotes

  +e        - compute with errors

  +DBG -DBG - debug on / off (not much scope yes)
  -n        - with reading from STDIN: show line numbers

 Examples:
   cxa -Fef +e 1,2 3r +- 4,5 3r +- a j p
  Result: 8.6023E+00,54.462 4.2426E+00,29.551 +-

   cxa -S'set val =' +P -Fef +e 1,2 3r +- 4,5 3r +- a -c180 j p
  Result: set val = ( 8.6023E+00,-54.462 4.2426E+00,29.551 +- )

   eval set val = `cxa +P -Fef +e 1,2 3r +- 4,5 3r +- a p`
   echo $val
  Result: 8.60233E+00,54.462 4.24264E+00,29.551 +-

   cxa 4,0 ^-1r
  Result: 2.50000E-01,0.00000E+00

   cxa -r
4,0 ^-1r
  Result: 2.50000E-01

   cxa 4,0 ^1,-1
  Result: 7.33828E-01,-3.93211E+00

   cxa 4,0 ^1,-1 @
  Result: 4.00000E+00,0.00000E+00

   setenv AMP 5.0,0.0
   cxa '${AMP}' ^1,-1
  Result: -1.93160E-01,-4.99627E+00

Example for STDIN:
   awk '{s=substr($0,1,46);r=substr($0,48);gsub(/ /,"",r);sub(/\r/,"",r);print s " (" r ") c"}' CARGA_GB.csv |\
      cxa /m2 -F+ ...
  Result:
BRFT , GOT4.7 , 0, m2 +2.93183E+01,+1.98851E+01
WTZR , GOT4.7 , 0, m2 +1.63250E+00,-4.84528E+00
ALBH , GOT4.7 , 0, m2 +4.25606E+00,+1.44739E+01
ALRT , GOT4.7 , 0, m2 -4.44832E-01,-6.52858E-01
...

from CARGA_GB,csv
BRFT                    , GOT4.7      , 0, m2 ,  35.4257,   34.147
WTZR                    , GOT4.7      , 0, m2 ,   5.1129,  -71.380
ALBH                    , GOT4.7      , 0, m2 ,  15.0867,   73.614
ALRT                    , GOT4.7      , 0, m2 ,   0.7900, -124.269



      
Source code is in ~/math/afor/p/m/cxa.f

,bye