%N rtfmt %F $MIR/src/subs/rtfmt.for
%D Construct a format during run time
%: strings
%P bpw
%B
      character*(*)  function rtfmt( string, vals, nvals )
      character*(*)  string
      integer        vals( * )
      integer        nvals

 Rtfmt takes as input a format string. It replaces characters between
 < and > with a number, which is given by the array vals. The first
 occurence of <...> corresponds to vals(1), etc. This allows to make up
 the format in a write statement during runtime, thereby making it
 possible to print only as many characters as needed and avoiding unused
 empty spaces. To get a '<' character in the output format string,
 stutter it, i.e. use '<<'.

 Example 1:
 write(*,rtfmt( '''Date is:'',i<>,''-'',i<>,''-'',i<>', rtf, 3 )) date
 where date is a 3-element array. The 3-element array rtf contains the
 number of digits of each of the three elements (see function nfig for
 how to obtain these numbers). If rtf has e.g. the values 1, 1 and 4,
 the format string that is produced will be:
 '''Date is:'',i1,''-'',i1,''-'',i4'. The output on the c terminal will
 look something like: '1-1-1900' or '1-10-90' or '12-12-1991', i.e.
 there are never any obsolete spaces.

 Example 2:
 if(    abs( x-int(x) ) .lt. 1.e-10   ) ndec(2) = 0
 if(    abs( x-int(x) ) .ge. 1.e-10   ) ndec(2) = 2
 ndec(1) = nfigi( int(x) ) + 3
 write( *, rtfmt( '''x='',f<>.<>', ndec, 2 ) ) x
 Now the f-format with which a variable is written depends on the value
 of the variable, so that the output will be 'x=1.02' or 'x=1' or
 'x=100' or 'x=1000', i.e. no distracting spaces come out.

 Example 3:
 nspac = 60 - len1(message)
 write(*,rtfmt('a, <nspac>x, ''>'',$',nspac,1)) message(:len1(message))
 This puts out a message on the screen, with the prompt character >
 always in column 60, no matter how long the string 'message' was.

 Input:
   string:     A format.
   vals:       Values to replace characters between < and > with
   nvals:      Number of values
