home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / fortran / 3035 < prev    next >
Encoding:
Internet Message Format  |  1992-08-14  |  1.8 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!ames!haven.umd.edu!mimsy!afterlife!adm!aos!lapoint
  2. From: lapoint@adios.brl.mil (Claude LaPointe )
  3. Newsgroups: comp.lang.fortran
  4. Subject: RE: programming style question
  5. Message-ID: <982@aos.brl.mil>
  6. Date: 14 Aug 92 12:25:59 GMT
  7. Sender: news@aos.brl.mil
  8. Lines: 42
  9. Nntp-Posting-Host: adios.brl.mil
  10.  
  11.  
  12. tholen@galileo.ifa.hawaii.edu (Dave Tholen) writes:
  13.  
  14.  
  15.   >  A question about programming style:  How many of you explicitly OPEN
  16.   >  preconnected units, which nowadays usually mean standard input, standard
  17.   >  output, and sometimes standard error (typically units 5, 6, and 0)?  In
  18.   >  the old days, 5 and 6 were often card reader and printer.  I haven't
  19.   >  been doing so myself, but the question came up recently because I've
  20.   >  ...
  21.  
  22.  
  23. Given that 0,1,2,5,6 and probably others are highly non-portable
  24. ways of addressing standard in, out, and error. It is better not to
  25. use them.
  26.  
  27. Because the 77 standard didn't much consider the kinds of output
  28. capabilities now available, it didn't address standard error,
  29. so there is no choice but to use a unit number - however it should
  30. be done with the realization that porting may require a change in the
  31. value. That is, isolate its use as much as possible in a subprogram
  32. and define it with a parameter statement.
  33.  
  34. With respect to standard in & out use "*" which must not appear in
  35. OPEN and CLOSE statements.
  36.  
  37. Some time ago, an objection was raised to this on the basis that the
  38. "*" must be present at compile time, and so cannot be passed as an
  39. argument. Actually, it can, but clumsily. When the intent is to write
  40. to standard out, set the calling argument not to "*" but to some
  41. negative integer. Similarly for input.
  42.  
  43.  
  44.       subroutine out (unit)
  45.       integer unit
  46.       ...
  47.       if (unit.lt.0) then
  48.          write (*,...
  49.       else
  50.          write (unit,...
  51.       endif
  52.       ...
  53.