home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / video / render / radiance.lzh / ray / doc / cat1 / rcalc.doc < prev    next >
Encoding:
Text File  |  1991-11-24  |  7.5 KB  |  265 lines

  1.  
  2.  
  3.  
  4. RCALC(1)                 USER COMMANDS                   RCALC(1)
  5.  
  6.  
  7.  
  8. NAME
  9.      rcalc - record calculator
  10.  
  11. SYNOPSIS
  12.      rcalc [ -b ][ -l ][ -n ][ -tS ][ -i format ][ -o  format  ][
  13.      -f source ][ -e expr ][ -s svar=sval ] file ..
  14.  
  15. DESCRIPTION
  16.      Rcalc transforms ``records'' from each file according to the
  17.      given   set  of  literal  and  relational  information.   By
  18.      default, records are  separated  by  newlines,  and  contain
  19.      numeric fields separated by tabs.  The -tS option is used to
  20.      specify an alternate tab  character.   A  -i  format  option
  21.      specifies  a  template for an alternate input record format.
  22.      Format is interpreted as a specification string if  it  con-
  23.      tains  a  dollar  sign '$'.  Otherwise, it is interpreted as
  24.      the name of the file containing  the  format  specification.
  25.      In  either  case, if the format does not end with a newline,
  26.      one will be added automatically.  A -o format option  speci-
  27.      fies  an  alternate output record format.  It is interpreted
  28.      the same as an input specification.  The variable and  func-
  29.      tion  definitions  in  each -f source file are read and com-
  30.      piled.  The -e expr option can be used to  define  variables
  31.      on  the  command  line.   Since many of the characters in an
  32.      expression have special meaning to the shell, it should usu-
  33.      ally  be enclosed in single quotes.  The -s svar=sval option
  34.      can be used to assign a string variable a string value.  The
  35.      -b  option  instructs  the  program  to  accept  only  exact
  36.      matches.  By default, tabs and spaces are ignored except  as
  37.      field  separators.   The  -l option instructs the program to
  38.      ignore newlines in the input, basically  treating  them  the
  39.      same  as  tabs  and  spaces.   Normally, the beginning of an
  40.      input format matches the beginning of a line.  With  the  -l
  41.      option,  an  input format can match anywhere on a line.  The
  42.      -n option tells the program not to get  any  input,  but  to
  43.      produce  a single output record.  Otherwise, if no files are
  44.      given, the standard input is read.
  45.  
  46.      Format files associate names with string and numeric  fields
  47.      separated  by  literal  information  in a record.  A numeric
  48.      field is given in a format file as a dollar  sign,  followed
  49.      by curly braces enclosing a variable name:
  50.  
  51.           This is a numeric field: ${vname}
  52.  
  53.      A string variable is enclosed in parentheses:
  54.  
  55.           This is a string field: $(sname)
  56.  
  57.      The program attempts to match  literal  information  in  the
  58.      input  format  to  its  input  and assign string and numeric
  59.      fields accordingly.  For each valid input record, an  output
  60.  
  61.  
  62.  
  63. Sun Release 4.1           Last change:                          1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RCALC(1)                 USER COMMANDS                   RCALC(1)
  71.  
  72.  
  73.  
  74.      record  is  produced  in  its  corresponding format.  Output
  75.      field widths are given implicitly by the space  occupied  in
  76.      the format file, including the dollar sign and braces.  This
  77.      makes it impossible to produce fields with fewer  than  four
  78.      characters.   If  the  -b option is specified, input records
  79.      must exactly match the template.  By default, the  character
  80.      following  each  input  field  is used as a delimiter.  This
  81.      implies that string fields that are followed by white  space
  82.      cannot  contain  strings  with  white  space.  Also, numeric
  83.      fields followed but not preceded by  white  space  will  not
  84.      accept  numbers  preceded  by  white  space.  Adjacent input
  85.      fields are advisable only with the -b option.  Numeric  out-
  86.      put  fields may contain expressions as well as variables.  A
  87.      dollar sign may appear in a  literal  as  two  dollar  signs
  88.      ($$).
  89.  
  90.      The definitions  specified  in  -e  and  -f  options  relate
  91.      numeric  output  fields  to  numeric  input fields.  For the
  92.      default record format, a field is a variable of the form $N,
  93.      where  N  is  the  column  number, beginning with 1.  Output
  94.      columns appear on the left-hand side of  assignments,  input
  95.      columns appear on the right-hand side.
  96.  
  97.      A variable definition has the form:
  98.  
  99.           var = expression ;
  100.  
  101.  
  102.      Any instance of  the  variable  in  an  expression  will  be
  103.      replaced with its definition.
  104.  
  105.      An expression contains real numbers, variable  names,  func-
  106.      tion calls, and the following operators:
  107.  
  108.           +  -  *  /  ^
  109.  
  110.      Operators are evaluated left  to  right.   Powers  have  the
  111.      highest   precedence;   multiplication   and   division  are
  112.      evaluated before addition and subtraction.  Expressions  can
  113.      be  grouped  with parentheses.  All values are double preci-
  114.      sion real.
  115.  
  116.      A function definition has the form:
  117.  
  118.           func(a1, a2, ..) = expression ;
  119.  
  120.  
  121.      The expression can contain instances of the  function  argu-
  122.      ments  as  well  as other variables and functions.  Function
  123.      names can be passed as arguments.  Recursive  functions  can
  124.      be  defined  using  calls  to  the defined function or other
  125.      functions calling the defined function.
  126.  
  127.  
  128.  
  129. Sun Release 4.1           Last change:                          2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RCALC(1)                 USER COMMANDS                   RCALC(1)
  137.  
  138.  
  139.  
  140.      The variable cond, if defined, will  determine  whether  the
  141.      current  input record produces an output record.  If cond is
  142.      positive, output is produced.  If cond is less than or equal
  143.      to  zero, the record is skipped and no other expressions are
  144.      evaluated.  This provides a convenient method  for  avoiding
  145.      inappropriate  calculations.   The following library of pre-
  146.      defined functions and variables is provided:
  147.  
  148.      if(cond, then, else)
  149.                if cond is greater than zero, then  is  evaluated,
  150.                otherwise  else  is  evaluated.   This function is
  151.                necessary for recursive definitions.
  152.  
  153.      select(N, a1, a2, ..)
  154.                return aN (N is rounded to the  nearest  integer).
  155.                This  function  provides array capabilities.  If N
  156.                is zero, the  number  of  available  arguments  is
  157.                returned.
  158.  
  159.      rand(x)   compute a random number between 0 and 1  based  on
  160.                x.
  161.  
  162.      floor(x)  return largest integer not greater than x.
  163.  
  164.      ceil(x)   return smallest integer not less than x.
  165.  
  166.      sqrt(x)   return square root of x.
  167.  
  168.      exp(x)    compute  e  to  the  power  of  x  (e   approx   =
  169.                2.718281828).
  170.  
  171.      log(x)    compute the logarithm of x to the base e.
  172.  
  173.      log10(x)  compute the logarithm of x to the base 10.
  174.  
  175.      PI        the ratio of a circle's circumference to its diam-
  176.                eter.
  177.  
  178.      recno     the number of records recognized thus far.
  179.  
  180.      sin(x), cos(x), tan(x)
  181.                trigonometric functions.
  182.  
  183.      asin(x), acos(x), atan(x)
  184.                inverse trigonometric functions.
  185.  
  186.      atan2(y, x)
  187.                inverse tangent of y/x (range -pi to pi).
  188.  
  189. EXAMPLE
  190.      To print the square root of column two in  column  one,  and
  191.      column one times column three in column two:
  192.  
  193.  
  194.  
  195. Sun Release 4.1           Last change:                          3
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RCALC(1)                 USER COMMANDS                   RCALC(1)
  203.  
  204.  
  205.  
  206.        rcalc -e '$1=sqrt($2);$2=$1*$3' inputfile > outputfile
  207.  
  208. AUTHOR
  209.      Greg Ward
  210.  
  211. BUGS
  212.      String variables can only be used in input and  output  for-
  213.      mats and -s options, not in definitions.
  214.  
  215.      Tabs count as single spaces inside fields.
  216.  
  217. SEE ALSO
  218.      calc(1), ev(1)
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261. Sun Release 4.1           Last change:                          4
  262.  
  263.  
  264.  
  265.