Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!h14g2000pri.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 12:27:58 -0800 (PST)
Organization: http://groups.google.com
Lines: 179
Message-ID: <b87dd7a0-6f66-4c79-9762-81c476165822@h14g2000pri.googlegroups.com>
References: <7af025a1-6d40-4458-aab0-35bc43418c00@i12g2000prg.googlegroups.com> 
	<hd1sg5$u5k$1@news.eternal-september.org> <d039a82a-256d-411d-a100-2b07c196cb0f@2g2000prl.googlegroups.com> 
	<hd1v00$kib$1@news.eternal-september.org> <dd6e3ab8-fd69-4aba-bfc7-377b2392841d@f1g2000prf.googlegroups.com>
NNTP-Posting-Host: 198.206.219.33
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1257539279 11195 127.0.0.1 (6 Nov 2009 20:27:59 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 6 Nov 2009 20:27:59 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: h14g2000pri.googlegroups.com; posting-host=198.206.219.33; 
	posting-account=_KeVcAoAAAB7j3xn35ujaQ0BoQhuzwJP
User-Agent: G2/1.0
X-HTTP-Via: 1.1 wwwproxy-son-ca-01.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:213344 comp.soft-sys.matlab:583111


On Nov 6, 12:09 pm, Nathan <ngrec...@gmail.com> wrote:
> On Nov 6, 11:55 am, dpb <n...@non.net> wrote:
>
>
>
> > Nathan wrote:
>
> > ...
>
> > > 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.
>
> > Well, fixing that is pretty easy, just don't write tabs... :)
>
> > > 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?
>
> > ...
>
> > Possibly, remember implicit typing rules are i-n are integers by default.
>
> > The strongest thing to do would be to add
>
> > IMPLICIT NONE
>
> > to each routine, but that will undoubtedly require quite some time to
> > sort out all the errors that will suddenly show up.  But, then again, it
> > could potentially find real errors as well.
>
> > The arrays will have to have been declared somewhere/somehow in order to
> > have become arrays.  One would presume they were declared as floats of
> > default or double precision, but then again, mistakes have been known to
> > be made...
>
> > --
>
> In my main routine, a separate file from my MEX driver file, I have
> this:
>         SUBROUTINE LIQVAP(IDB,NFUEL,NGAS,MTYPE,MNUM,XL, XLIQret, TSATret,
>         +BTret, NCOMP,ICOMPG,MWG,TCGF,PCG,ACENG,CONC,TCGC,tanang,FUELNAME,
>      +ICOMP,MW,TBF,TFCF,PC,ZC,ACEN,ZRA,ACENW,VCH,zz,TFCC)
>
>       IMPLICIT DOUBLE PRECISION (A-H,O-Z)
>       DOUBLE PRECISION MW, MWG(5), MWMG, MCONC(5), MCONCSUM
>         DOUBLE PRECISION IGCOEF(5), LDCOEF(4) !DIPPR equation coefficient
> variables
>       DIMENSION ICOMPG(5), ACENG(5), TCGC(5), TCGF(5), XL(20)
>       DIMENSION PCG(5), CONC(5), ENTHIGG(5), VCG(5), ZCG(5)
>       DIMENSION IER(11), IERF(7), IERZ1(4), IERZ2(4),IERZ3(4),IERZ4(4)
>       CHARACTER FUELNAME*45
>
> In the routine used to read in the dippr.dat, I only have
>         SUBROUTINE FUELSDAT (NFUEL, FUELNAME,ICOMP,MW,TBF,TFCF,PC,ZC,
>      +             ACEN,ZRA,ACENW,VCH,zz,TFCC)
>
>         IMPLICIT DOUBLE PRECISION (A-H,M,O-Z)
>         CHARACTER FUELNAME*45
>
> In my driver file, as a subroutine (which calls LIQVAP), I have this:
>         SUBROUTINE liqvapMex(XLIQ,TSAT, BT, nsteps,conv_nfuel,tanang,Ca,
>         +                                        DCONC,Ta,rhoa,Tfuel,Snozzle)
>
>         IMPLICIT DOUBLE PRECISION (A-H,O-Z)
>         DIMENSION Ta(0:nsteps), rhoa(0:nsteps), Tfuel(0:nsteps)
>         DIMENSION Snozzle(0:nsteps), pressure(0:nsteps), XL(20)
>         DIMENSION XLIQ(0:nsteps), TSAT (0:nsteps), BT (0:nsteps)
>         DIMENSION DCONC(1:5)
>         DIMENSION ICOMPG(5), ACENG(5), TCGC(5), TCGF(5),PCG(5), CONC(5)
>         DOUBLE PRECISION MW, MWG(5)
>         CHARACTER FUELNAME*45
>
> and call the FUELSDAT routine as such (within this liqvapmex
> subroutine):
>         CALL FUELSDAT (NFUEL, FUELNAME,ICOMP,MW,TBF,TFCF,PC,ZC,
>      +             ACEN,ZRA,ACENW,VCH,zz,TFCC)
>
> Notice that ICOMP,TBF,TFCF,PC,ZC,ACEN,ZRA,ACENW,VCH,zz, and TFCC are
> all "poofed" into existence (according to the IMPLICIT DOUBLE
> PRECISION declaration above, I presume)
>
> I fixed the formatting for each of my data files to correctly match
> the format statements.
> The only one I might be concerned with is the E format terms regarding
> numbers such as:
>      9.7160E+02 and the like.
> I used the format statement %E15.4  such that from the first white
> space until the last digit (2), there are 15 characters and 4
> decimals. Is that correct?
>
> I am still receiving errors when trying to run with MEX.
>
> -Nathan

Updated data format and format code:
code regarding dippr.dat:
	  IF (NFUEL .GT. 899) THEN
		OPEN (10, FILE = 'dippr.dat', Access = 'sequential',
     +	Form = 'formatted', STATUS = 'unknown')
		NF = -999
		DO WHILE (NF .NE. NFUEL .AND. NF .NE. 0)
			READ(10,301) NF, FUELNAME,MW,TBF,TFCF,PC,VC,ZC,ACEN,ZRA,
     +		ACENW,VCH
		ENDDO
	  ENDIF
 301		FORMAT(I5,A33,3F10.3,E15.4,6F13.5)

dippr.dat data:
1001 METHYL OLEATE                       296.494   650.930
915.530     1.8565E+02      1.06000      0.21400      1.04940
-1.00000     -1.00000     16.97957


code regarding dipprig.dat:
		OPEN(13, FILE = 'dipprig.dat', Access = 'sequential',
     +	Form = 'formatted', STATUS = 'unknown')
 20       FORMAT(I5,A33,5E15.4) !IG coef
		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

dipprig.dat data:
1001 METHYL OLEATE                         3.2997E+05     9.7160E
+05    -1.6456E+03     6.7448E+05     7.4800E+02


code regarding dipprld.dat:
		OPEN(14, FILE = 'dipprld.dat', Access = 'sequential',
     +	Form = 'formatted', STATUS = 'unknown')
 21	    FORMAT(I5,A33,4E15.4) !LD coef
		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

dipprld.dat data:
1001 METHYL OLEATE                         2.4755E-01
2.6240E-01     7.6400E+02     3.3247E-01


One thing I have a question about:
Trying to run this through fortran (using Compaq Visual Fortran 6.6),
it also does not like to read in files. (I based my formatting for
dippr.dat off of a previous format for reading a different file that
seems to have worked in the past. I'm not certain, however, because I
didn't write it)

I noticed one thing when I received these files to work with: After
opening each file, neither version bothered trying to close the
files...
Could that be another problem?

-Nathan