Path: news.mathworks.com!newsfeed-00.mathworks.com!panix!usenet.stanford.edu!news.ucr.edu!nntp-server.caltech.edu!not-for-mail
From: glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups: comp.lang.fortran,comp.soft-sys.matlab
Subject: Re: Fortran formatted read problem (for matlab MEX file)
Date: Fri, 6 Nov 2009 20:04:17 +0000 (UTC)
Organization: California Institute of Technology, Pasadena
Lines: 31
Message-ID: <hd1vg1$h90$1@naig.caltech.edu>
References: <7af025a1-6d40-4458-aab0-35bc43418c00@i12g2000prg.googlegroups.com>
NNTP-Posting-Host: thalia.ugcs.caltech.edu
X-Trace: naig.caltech.edu 1257537857 17696 131.215.176.116 (6 Nov 2009 20:04:17 GMT)
X-Complaints-To: abuse@caltech.edu
NNTP-Posting-Date: Fri, 6 Nov 2009 20:04:17 +0000 (UTC)
User-Agent: tin/1.9.3-20080506 ("Dalintober") (UNIX) (Linux/2.6.26-2-686 (i686))
Xref: news.mathworks.com comp.lang.fortran:213340 comp.soft-sys.matlab:583104


In comp.lang.fortran Nathan <ngreco32@gmail.com> wrote:

> I don't know Fortran well enough to do file i/o, let alone formatted
> file i/o.

(snip)

> 20       FORMAT(I5,A33,5EN12.4)
> 21         FORMAT(I5,A33,4EN12.4)

> 1003    METHYL OLEATE                           3.2997E+05     9.7160E
> +05     1.6456E+03     6.7448E+05     7.4800E+02

  1234567890123456789012345678901234567890123456789012345678901234567890

Your format gives 5 columns for the integer, 33 for the character variable,
and then 12 for each of the floating point values, but that doesn't
match the data.

More specifically, the first five columns are the integer, the next 33
the character, then 12 each for the rest.  You might want to use
the X format descriptor to skip some columns, maybe

 20    FORMAT(I5, 3X, A33, 5X, 5EN15.4)

You could also use X between the E descriptors, but it is more usual
to just use a wide enough field, 15 in this case.

You might read the section on FORMAT statemens in your Fortran book.

-- glen