home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / fortran / 4778 < prev    next >
Encoding:
Text File  |  1992-12-16  |  2.3 KB  |  58 lines

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!caen!sol.ctr.columbia.edu!still3.chem.columbia.edu!shenkin
  3. From: shenkin@still3.chem.columbia.edu (Peter Shenkin)
  4. Subject: Re: Reinventing WRITE...
  5. References: <29011.9212161323@thor.cf.ac.uk <SUNDARAM.92Dec16101715@me.uta.edu>
  6. Sender: nobody@ctr.columbia.edu
  7. Organization: Dept. of Chem, Columbia U, New York
  8. Date: Wed, 16 Dec 1992 20:20:30 GMT
  9. Message-ID: <1992Dec16.202030.18917@sol.ctr.columbia.edu>
  10. X-Posted-From: still3.chem.columbia.edu
  11. NNTP-Posting-Host: sol.ctr.columbia.edu
  12. Lines: 44
  13.  
  14. This followup addresses the question of line-buffering Fortran output
  15. under UNIX.
  16.  
  17. In article <29011.9212161323@thor.cf.ac.uk>
  18.  spxsjm@thor.cf.ac.uk (Mr S J Morris 92) writes:
  19. >   I want to define a subroutine which will take the same input paramters
  20. >   as a WRITE procedure; that is, I'd like to define
  21. >
  22. >     SUBROUTINE WRITELN(A,B)
  23. >
  24. >   in such a way that
  25. >
  26. >     WRITELN (7,100) X,Y
  27. >     WRITELN (6,*) 'HELLO THERE'
  28. >     WRITELN (*,*) 'HE''S GETTING CLEVER NOW'
  29. >
  30. >   all work more or less the same as the corresponding WRITE statements (by
  31. >   the way, the reason I'm doing this is to open a file, find the endfile
  32. >   record, append a new record and then close the file again, all in a
  33. >   single call - so that I can flush the output buffer in SUN Fortran)...
  34.  
  35. This is both machine-dependent and incomplete, but under UNIX, Fortran IO-unit
  36. 6 is almost always bound to the standard output.  So if unit 6 is all you
  37. really care about, you can write a little C program callable from Fortran;
  38. you call this routine just before you OPEN the file, and have this C program 
  39. call setvbuf() for the standard output using the right arguments to line-buffer
  40. the output.  This fragment (reasonably portable in the UNIX world, I
  41. believe) reads:
  42.  
  43. #include <stdio.h
  44. ...
  45.     setvbuf( stdout, NULL, _IOLBF, BUFSIZ );
  46.  
  47. Is there any way to figure out what UNIX file-pointer an arbitrary Fortran
  48. io unit is associated with?  If so, this trick could be used for arbitrary
  49. files.
  50.  
  51.     -P.
  52.  
  53. -- 
  54. ************************f*u*cn*rd*ths*u*cn*gt*a*gd*jb************************
  55. Peter S. Shenkin, Box 768 Havemeyer Hall, Dept. of Chemistry, Columbia Univ.,
  56. New York, NY  10027;  shenkin@still3.chem.columbia.edu;  (212) 854-5143
  57. ******* ...ghostlier demarcations, keener sounds.  (Wallace Stevens) ********
  58.