Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!2g2000prl.googlegroups.com!not-for-mail
From: Nathan <ngreco32@gmail.com>
Newsgroups: comp.lang.fortran,comp.soft-sys.matlab
Subject: Re: Fortran formatted read problem (for matlab MEX file)
Date: Fri, 6 Nov 2009 11:38:17 -0800 (PST)
Organization: http://groups.google.com
Lines: 101
Message-ID: <d039a82a-256d-411d-a100-2b07c196cb0f@2g2000prl.googlegroups.com>
References: <7af025a1-6d40-4458-aab0-35bc43418c00@i12g2000prg.googlegroups.com> 
	<hd1sg5$u5k$1@news.eternal-september.org>
NNTP-Posting-Host: 198.206.219.34
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1257536298 25439 127.0.0.1 (6 Nov 2009 19:38:18 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 6 Nov 2009 19:38:18 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: 2g2000prl.googlegroups.com; posting-host=198.206.219.34; 
	posting-account=_KeVcAoAAAB7j3xn35ujaQ0BoQhuzwJP
User-Agent: G2/1.0
X-HTTP-Via: 1.1 wwwproxy-son-ca-02.ca.sandia.gov:80 (squid/2.5.STABLE14)
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.4) 
	Gecko/20091016 Firefox/3.5.4,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.lang.fortran:213335 comp.soft-sys.matlab:583093


On Nov 6, 11:13 am, dpb <n...@non.net> wrote:
> Nathan wrote:
> > Hi.
> > I don't know Fortran well enough to do file i/o, let alone formatted
> > file i/o.
> > I am trying to read data into my fortran code that is to be used for
> > calculations that will be returned to Matlab.
> > What I have tried, and what doesn't seem to work is as follows:
> > NFUEL is the fuel number (look at data example below. 1003 corresponds
> > to METHYL OLEATE)
>
> >    IF (NFUEL .GT. 1000) THEN
> >    OPEN(13, FILE = 'dipprig.dat', Access = 'sequential',
> >      +     Form = 'formatted', STATUS = 'unknown')
> >    OPEN(14, FILE = 'dipprld.dat', Access = 'sequential',
> >      +     Form = 'formatted', STATUS = 'unknown')
> >  20       FORMAT(I5,A33,5EN12.4)
> >  21            FORMAT(I5,A33,4EN12.4)
> >            NF = -999
> >    DO WHILE (NF .NE. NFUEL .AND. NF .NE. 0) !Read IG
> >  READ(13,20) NF, FUELNAME,IGCOEF(1),IGCOEF(2),IGCOEF(3),
> >      +             IGCOEF(4),IGCOEF(5)
> >    ENDDO
> >            NF = -999
> >    DO WHILE (NF .NE. NFUEL .AND. NF .NE. 0) !Read LD
> >         READ(14,21) NF, FUELNAME,LDCOEF(1),LDCOEF(2),LDCOEF(3),
> >      +             LDCOEF(4)
> >    ENDDO
> >    ENDIF
>
> > Examples of the corresponding data files are as follows (the data is
> > contained within 1 line, for each file)
> > (dipprig.dat data example):
> > 1003       METHYL OLEATE                           3.2997E+05     9.7160E
> > +05     1.6456E+03     6.7448E+05     7.4800E+02
>
> > (dipprld.dat data example):
> > 1003       METHYL OLEATE                           2.4755E-01
> > 2.6240E-01     7.6400E+02     3.3247E-01
>
> > The data values may contain a - in front of them, depending on the
> > fuel.
> > If there is any more information you need to help me, please ask.
> > I know that this doesn't work because while debugging, nothing is read
> > into the variables.
>
> Well, several things--
>
> You don't show declarations so can't tell what variables are.  Implicit
> typing would have IG-&LDCOEF() as integer variables so the values that
> are non-integers would be wrong at best.
>
> Second, are you sure the IF section is actually being executed?
>
> The formatting appears reasonable except if I count characters it looks
> like the spacing for the name is wider than 33 characters.
>
> Note that TAB is not a valid Fortran character; you'll want to make sure
> your input data files don't contain same--it's possible maybe that has
> something to do w/ the spacing of the data lines.
>
> Too bad your names include embedded spaces, then you could use
> list-directed formatting.
>
> OBTW, the OPENs could be more like
>
> OPEN(13, FILE = 'dipprig.dat', STATUS = 'old')
>
> as sequential and formatted will be default.
>
> You don't want "unknown" as a status as it will create an empty file of
> that name if one doesn't exist and if you're planning on reading from
> it, you had best already have one containing data.
>
> Adding error handling will in the end be desirable altho for
> testing/debugging seeing any runtime errors directly is probably just as
> useful.
>
> Those are places to start, anyway.
>
> --

Hm. Alright. My data files do contain tabs, as I wanted to make them
in a readable format. (They were created through Matlab, after reading
in real data sheets and extracting information). Perhaps I'll try to
find a way to remedy that first. Thanks for pointing that out to me. I
think I understand how the formatting is supposed to work now, but
I'll definitely be back when more errors occur.

My variable declarations are spread across multiple files, I think.
(The code I am working on was passed down to me by previous student
interns, and I am still trying to figure it out. I have no fortran
experience beyond the last couple of months, reading this code)

Some of my variables seem to just appear out of nowhere, with no data
type declaration... Could this be a problem?

-Nathan