FORTRAN Carriage Control

Implementing Carriage Control Under UNIX

Under VS FORTRAN, carriage control is implemented by default; under UNIX FORTRAN it is not. On UNIX, the statements

   write(8,'(" This is the first line of output")')
   write(8,'("0This is the second line of output")')
will produce the following output

   This is the first line of output
    0This is the second line of output
The "blank" and "0" carriage control characters are treated like ordinary text. You can activate carriage control characters on UNIX in one of two ways:

  1. Define form='print' in an OPEN statement for the output file.

    or

  2. Filter the output through "asa".


    Example 1: Program sample1.f

         % cat sample1.f
    
           c** This program demonstrates the use of the
           c   open statement "form" attribute to activate
           c   carriage control symbols.
                 open(unit=8,file='output.dat',form='print')
                                .
                 write(8,1000)....
           1000  format('1',.....
                 write(8,1010)....
           1010  format('0',....  
                                .
                 end   
                            
                    
         % f77 sample1.f
         % qpr -q smips output.dat
    

    Example 2: Program sample2.f
         % cat sample2.f
                                                                 
           c*** This program does not use the open statement 
           c    "form" attribute. Therefore, to activate 
           c    the carriage control symbols in the output file,
           c    "output.dat", the file must be processed by "asa".
                 open(unit=8,file='output.dat')
                                    .
                 write(8,1000)....
           1000  format('1',.....  
                 write(8,1010)....
           1010  format('0',....
    
                 end       
    
    
          % f77 sample2.f
          % asa output.dat | qpr -q  smips
    
    

    Carriage Control Abilities Under UNIX and UDelVM

    Under UDelVM, carriage control is available for advancing one, two or three lines via the control characters "blank", "0" and "-" respectively. Also the control character "+" produces no line feed (overstrikes) and the control "1" advances to the top of the next page. Under UNIX, carriage control is available for advancing one or two lines and to the top of the page via the control characters "blank", "0", and "1" respectively, but there is no control to advance three lines. Also, the "+" control is not implemented in UNIX FORTRAN. UNIX FORTRAN uses the special edit descriptor "$" at the end of a format to suppress the carriage return. However, this is not the same thing as overstrike mode (see Example 3 below). You can still produce lines with overstrikes by applying the asa command to output files produced by programs not using the "form = 'print'" attribute in an open statement (see Example 3 below).


    Example 3: Program sample3.f

           % cat sample3.f
    
    
             c** This program demonstrates the use of carriage
                 control characters.
     
             open(unit=8,file='output.dat')
             write(8,'(" Carriage Control Demo Program")')
             write(8,'(" Blank advances 1 line")')
             write(8,'("0Zero advances 2 lines")')
             write(8,'(" A $ at the end suppress the CR",$)')
             write(8,'(" , OK?")')
             write(6,'(" A $ allows input on the same line as",
            1 " a prompt."/" For example, enter x: ",$)')
             read(5,*)x
             write(8,'(" Let''s underline this statement")')
             write(8,'("+_______________________________")') 
             write(8,'("1One advances to the top of the next page")')
             end
    
              % f77 sample3.f
              % a.out
                A $ allows input on the same line as a prompt.
                For example, enter x: 1
              % asa output.dat | qpr -q smips
    
    
    Note: Also see tip sheet: "Printing VS FORTRAN Output Files with Carriage Control Symbols on UNIX".

        
     ****************************************************************
     *                                                              *
     *                Correspondence to VS FORTRAN                  * 
     *                ============================                  *
     *                                                              *
     ****************************************************************
     *                                                              *
     *            VS FORTRAN                        UNIX            *
     *            ==========                        ====            *
     *                                                              *
     *                      Implementing Carriage Control           *
     *                      =============================           *
     *                                                              *
     * Under VS FORTRAN, carriage     Under UNIX, carriage control  * 
     * control characters appearing   is not implemented by         *
     * in output statements are       default.  To implement        *
     * implemented by default.        carriage control,             *
     *                                (1) Define form='print' in    *
     *                                    an "open" statement:      *
     *                                                              *
     *                                 open(unit=9,form='print',..) *
     *                                                              *
     *                                               or             *
     *                                                              *
     *                                (2) Use the "asa" filter      *
     *                                    on the output file:       *
     *                                                              *
     *                                    Examples:                 *
     *                                                              *
     *                                  Output from stdout,unit 6:  *
     *                                  a.out | asa | qpr -q smips  *
     *                                                              *
     *                                Output from disk file, "out": *
     *                                  asa out | qpr -q smips      *
     *                                                              *
     *                                 Note: Use the "asa" filter   *
     *                                       for programs that use  *
     *                                       the "+" carriage       *
     *                                       control symbol.        *
     *                                                              *             
     *                                                              *
     *                      Carriage Control Examples               *
     *                      =========================               *
     *                                                              * 
     *  write(8,'(" Blank adv. 1 line")')                           *
     *                                                              *
     *                          write(8,'(" Blank adv. 1 line")')   *
     *                                                              *   
     *  write(8,'("0Zero adv. 2 lines")')                           *
     *                                                              *
     *                          write(8,'("0Zero adv. 2 lines")')   *
     *                                                              *
     *  write(8,'("-Minus adv. 3 lines")')                          *
     *                                                              *
     *                          write(8,'(" ")')                    *
     *                          write(8,'("0Blank and 0 for 3")')   *
     *                                                              *
     *  write(8,'("1One to top of page")')                          *
     *                                                              *
     *                          write(8,'("1One to top of page")')  *
     *                                                              *
     *  write(8,'(" Plus for")')                                    * 
     *  write(8,'("+____     overstrike")')                         *
     *                                                              *
     *                          write(8,'(" Plus for")')            *
     *                          write(8,'("+____     overstrike")') *
     *                                                              *
     *                              Note: Overstriking can only be  * 
     *                                    implemented by using asa. *
     *                                    See Example 3 above.      *
     *                                                              *               
     *                                                              * 
     ****************************************************************
     
    University of Delaware
    June 19, 1994