Fortran New to FORTRAN, Error message I don't understand

  • Thread starter Thread starter Trolll
  • Start date Start date
  • Tags Tags
    Error Fortran
AI Thread Summary
The user is encountering a type mismatch error in Fortran when trying to assign a binary file name to a character variable. The solution involves enclosing the file name in quotes, changing the assignment to NAMFIL="JPLEPH". Additionally, the user faces issues with the WRITE statement, where the IOSTAT variable indicates an error during file writing. The discussion highlights the importance of understanding the REC and IOSTAT parameters in the WRITE command, as well as ensuring proper loop structure in the code. Overall, the user is advised to review Fortran documentation and tutorials for better comprehension.
Trolll
Messages
5
Reaction score
0
Hi!
I am completely new to Fortran and I'm trying to compile a source code someone else has written. I get the following error:

[Error] TESTEPH.F(187); type mismatch: intg JPLEPH assigned to char*80 NAMFIL.


The code around line 187:

183 C NAMFIL IS THE EXTERNAL NAME OF THE BINARY EPHEMERIS FILE
184
185 CHARACTER*80 NAMFIL
186
187 NAMFIL=JPLEPH

JPLEPH is a binary file that lies in the same catalogue as TESTEPH.F. So I am just wondering if anyone know what I've done wrong?
 
Technology news on Phys.org
Trolll said:
Hi!
I am completely new to Fortran and I'm trying to compile a source code someone else has written. I get the following error:

[Error] TESTEPH.F(187); type mismatch: intg JPLEPH assigned to char*80 NAMFIL.The code around line 187:

183 C NAMFIL IS THE EXTERNAL NAME OF THE BINARY EPHEMERIS FILE
184
185 CHARACTER*80 NAMFIL
186
187 NAMFIL=JPLEPH

JPLEPH is a binary file that lies in the same catalogue as TESTEPH.F. So I am just wondering if anyone know what I've done wrong?
There may be file named JPLEPH in the "catalogue", but a this point in your program it is just a string. So you need to enclose it in quotes.

NAMFIL="JPLEPH"
 
Last edited:
Actually, most probably, "at this point" is not even a string just yet, either...instead when JPLEPH is used like that, it is probably assumed that it is a variable that was never declared and because its name starts with J it is assumed to be integer.

If you would add the statement

IMPLICIT NONE

at the beginning of your program (after 'program' but before any variable declaration), then, you would get a more meaningful message when something like this happens.
 
Thank you, both of you! Well, I have now encountered another problem. The code is:C
C Open direct-access output file ('JPLEPH')
C
OPEN ( UNIT = 12,
. FILE = 'JPLEPH',
. ACCESS = 'DIRECT',
. FORM = 'UNFORMATTED',
. RECL = IRECSZ,
. STATUS = 'NEW' )


C
C Read and write the ephemeris data records (GROUP 1070).
C
CALL NXTGRP ( HEADER )

IF ( HEADER .NE. 'GROUP 1070' ) CALL ERRPRT(1070,'NOT HEADER')

NROUT = 0
IN = 0
OUT = 0


1 READ(*,'(2i6)')NRW,NCOEFF
if(NRW .EQ. 0) GO TO 1
READ (*,'(3D26.18)',IOSTAT =IN) (DB(K),K=1,NCOEFF)


DO WHILE ( ( IN .EQ. 0 )
. .AND. ( DB(2) .LT. T2) )

IF ( 2*NCOEFF .NE. KSIZE ) THEN
CALL ERRPRT(NCOEFF,' 2*NCOEFF not equal to KSIZE')
ENDIF

C
C Skip this data block if the end of the interval is less
C than the specified start time or if the it does not begin
C where the previous block ended.
C
IF ( (DB(2) .GE. T1) .AND. (DB(1) .GE. DB2Z) ) THEN

IF ( FIRST ) THEN
C
C Don't worry about the intervals overlapping
C or abutting if this is the first applicable
C interval.
C
DB2Z = DB(1)
FIRST = .FALSE.
ENDIF

IF (DB(1) .NE. DB2Z ) THEN
C
C Beginning of current interval is past the end
C of the previous one.

CALL ERRPRT (NRW, 'Records do not overlap or abut')
ENDIF

DB2Z = DB(2)
NROUT = NROUT + 1

print*,'Out =', OUT

WRITE (12,REC=NROUT+2,IOSTAT=OUT) (DB(K),K=1,NCOEFF)

print*,'Out2 =', OUT IF ( OUT .NE. 0 ) THEN
CALL ERRPRT (NROUT,
. 'th record not written because of error')
ENDIF

So, when I print "Out" and "Out2" to the screen I find that Out=0 and Out2=110. As it is not longer equal to zero, the programme gives me an error. Therefore I am basically wondering about what is happening here:

WRITE (12,REC=NROUT+2,IOSTAT=OUT) (DB(K),K=1,NCOEFF)

I assume that 12 refers to the file I have opened, and want to write something in. What does the rest of the first brackets, and what is the point of the second ? Generally what is going wrong? Why does OUT change value?

NCOEFF is defined as an Integer in the beginning of the programme, and DB: as DOUBLE PRECISION DB(3000), DB2Z/0.d0/ , so I assume DB is an array of some sort.
 
I suspect it's this part in the write command:

REC=NROUT+2

Try setting it to REC=NROUT+0 and see what happens.
 
Now I've tried it, but unfortunately I've got the same error. What does that part of the brackets mean?
 
Just openned my book: REC is an integer that shows the order of that integer in the direct access file that you have created.

IOSTAT is an integer whose value shows whether there has been an error.

The elements in the second bracket have to do with the data you are actually writting.

Also, you have a DO WHILE, but I did not see its enddo anywhere, are you sure this is the whole code?

Check this out as well:

http://publib.boulder.ibm.com/infoc...sp?topic=/com.ibm.xlf101a.doc/xlflr/write.htm
 
Last edited:
Please help a bit by at least doing a google on the matter first; let alone that, you could probably benefit from reading a short fortran tutorial.

Asking trivial things on the forum gets old really quick and I will just not answer to those requests. I am already typing more that it would take to give you the answer, but I just will not do it out of principle.
 
Thank you :)
 

Similar threads

Replies
2
Views
2K
Replies
7
Views
4K
Replies
6
Views
3K
Replies
3
Views
3K
Replies
4
Views
2K
Replies
9
Views
5K
Replies
6
Views
2K
Back
Top