From chuck at sharpsteen.net  Tue Apr 13 20:49:00 2010
From: chuck at sharpsteen.net (Sharpie)
Date: Tue, 13 Apr 2010 10:49:00 -0800 (PST)
Subject: [Rd] .Fortran interface error
In-Reply-To: <48252.86.0.54.218.1271165265.squirrel@paleo.ija.csic.es>
References: <48821.86.0.54.218.1271155366.squirrel@paleo.ija.csic.es>
	<alpine.LFD.2.00.1004131213290.17471@gannet.stats.ox.ac.uk>
	<48252.86.0.54.218.1271165265.squirrel@paleo.ija.csic.es>
Message-ID: <1271184540992-1838888.post@n4.nabble.com>



jgarcia-2 wrote:
> 
> Hi,
> I've stripped all the code, and it seems that any simple attempt to
> open/close a file from fortran is the cause of the error, and the error
> appears in f77 as well as in f95 code. Please, find attached a foo package
> that reproduce the errors, it should build/check/install without any
> problem (it does in my computer). If the code
> 
>  OPEN( UNIT=5, FILE=runfile, STATUS='OLD', ACTION='READ', &
>        IOSTAT=status)
>  WRITE (*,*) 'status:   ', status
>  IF ( status == 0 ) THEN
>    READ(5,'(A)') modelsel
>    READ(5,'(A)') modelfile
>    READ(5,'(A)') datdirpid
>    CLOSE(5)
> 
>    WRITE (*,*) 'selected model:   ', modelsel
>    WRITE (*,*) 'model input file: ', modelfile
>    WRITE (*,*) 'datdirpid: ', datdirpid
>  ELSE
>    WRITE (*,1002) status
>     1002 FORMAT (1X,'open runfile failed--status = ', I6)
>    STOP
>  END IF
> 
> is commented out in any of the two sources files (the f77 or the f95 one),
> none of the two corresponding wrappers (as they appear in the examples)
> give an error. Thus it seems clear that the operation causing it is the
> OPEN/CLOSE. Without commenting out these pieces of code, everything seems
> to work right but R halts after a call to the wrapper functions. I cannot
> find any comment about this in the documentation. Please, could you tell
> me if this is a known error?
> 
> Thanks,
> 
> Javier
> 

It looks like you may have some I/O collisions occurring.  Some Fortran
compilers treat unit 5 as being STDIN, so attempting to read from that
stream when the Fortran program is embedded may be giving R a headache.  I
would recommend either passing "modelsel", "modelfile" and "datadirpid" as
parameters from R, or reading from a file using a different unit number.

For output, instead of using write(*,*) you may need to use some of the R
output callbacks described in section 6.5.1 of "Writing R Extensions".

Hope this helps!

-Charlie



-----
Charlie Sharpsteen
Undergraduate-- Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: http://n4.nabble.com/Fortran-interface-error-tp1838225p1838888.html
Sent from the R devel mailing list archive at Nabble.com.



[Rd] .Fortran interface error
Sharpie