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