Re: printing in fortran




Gary Scott wrote:
lane straatman wrote:
Richard E Maine wrote:

Q3) I've only thumbed through the section on interoperability with C;
could a guy use a properly-interfaced call to printf ?

Can't be done with the standard f2003 stuff. Printf has a variable
number of arguments. That specifically is one of the feature that is not
supported by the F2003 interop stuff.

Also, be aware of the fine print relating to I/O and C interop. All bets
are off if you use both C and Fortran to do I/O on the same file during
a single OPEN. Might work. Might not. Might do "odd" things like doing
the I/O in a non-obvious order (for example, if there is buferring going
on). So I advise against jumping back and forth willy nilly. If you open
a file in C, do the I/O to it only in C. If you open a file in Fortran,
do the I/O only in Fortran.
Would Cbfalconer's ggets be a good candidate?
/* File ggets.h - goodgets is a safe alternative to gets */
/* By C.B. Falconer. Public domain 2002-06-22 */
/* attribution appreciated. */


/* Revised 2002-06-26 New prototype.
2002-06-27 Incomplete final lines
*/

/* fggets and ggets [which is fggets(ln, stdin)] set *ln to
a buffer filled with the next complete line from the text
stream f. The storage has been allocated within fggets,
and is normally reduced to be an exact fit. The trailing
\n has been removed, so the resultant line is ready for
dumping with puts. The buffer will be as large as is
required to hold the complete line.

Note: this means a final file line without a \n terminator
has an effective \n appended, as EOF occurs within the read.

If no error occurs fggets returns 0. If an EOF occurs on
the input file, EOF is returned. For memory allocation
errors some positive value is returned. In this case *ln
may point to a partial line. For other errors memory is
freed and *ln is set to NULL.

Freeing of assigned storage is the callers responsibility
*/

#ifndef ggets_h_
# define ggets_h_

# ifdef __cplusplus
extern "C" {
# endif

int fggets(char* *ln, FILE *f);

#define ggets(ln) fggets(ln, stdin)

# ifdef __cplusplus
}
# endif
#endif
/* END ggets.h */
He has claimed that the all the linking information is properly in the
header file, and he seems like the type that would follow his own
advice, although a cplusplus wrapper wouldn't really seem to matter
over here. A good reason to use this function is that he has a grab
bag of other files to test this with (at his site).

[Mr. Scott's last sentences on FAQ:]
Yes, there have been various faq-like documents and web sites. One is
http://www.fortran.com where the most faq-like file is posted. I used
to have fortranfaq.com but never finished it. I have
http://www.fortranlib.com which has a lot of general stuff but not much
on programming itself. Since I've been unable to keep it up to date,
most of the content of fortranlib.com has been ported or duplicated to
http://www.dmoz.com/Computers/Programming/Languages/Fortran/

If I ever finish my master's degree...if somebody want so volunteer to help.
I'd need a baud rate that is faster than I can clap to commit to it.
LS

------------------
"What struck me, as I wandered the show floor, is that Fortran, a
fifty-year-old language considered long-dead by many, has a customer
base vibrant enough to support (at least) seven commercial vendors
offering compilers on the same platforms, plus two (why two?) competing
open source compiler projects! What other widely-adopted programming
language can say the same?"
I tell people that fortran is sexy.

.



Relevant Pages

  • Re: a modest proposal
    ... OS/360 object programs are 80 byte fixed ... I/O using A format. ... file with JCL and associate it with a Fortran I/O unit number? ...
    (comp.lang.fortran)
  • Re: a modest proposal
    ... OS/360 object programs are 80 byte fixed ... I/O using A format. ... file with JCL and associate it with a Fortran I/O unit number? ...
    (comp.lang.fortran)
  • Re: [gfortran43] opening file twice...
    ... I can well imagine an embedded system which doesn't even have files. ... in a non-hosted environment (which means that I/O doesn't have to ... Fortran was used in some embedded environments. ... with development environments like Win AVR. ...
    (comp.lang.fortran)
  • Re: close(status=delete) on a missing file
    ... The same Fortran program will often still be able to open ... not capable of doing I/O on all the files present in a UNIX environment? ... no deficiencies and the other way is to make it so complicated ...
    (comp.lang.fortran)
  • Fortran I/O performance versus file size
    ... I have an application which needs to do a lot of I/O on large files ... enable system calls ... The BINARY file type is not necessarily a fortran standard (to my ... Intel quad core 64-bit ...
    (comp.lang.fortran)