New to FORTRAN, Error message I don't understand

  • Context: Fortran 
  • Thread starter Thread starter Trolll
  • Start date Start date
  • Tags Tags
    Error Fortran
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting error messages encountered while compiling Fortran code, specifically focusing on type mismatches and issues related to file handling and writing data to files. Participants are exploring the implications of variable types, file access methods, and the behavior of specific Fortran commands.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • A participant reports a type mismatch error when trying to assign a binary file name to a character variable, suggesting that the filename should be enclosed in quotes.
  • Another participant proposes that the variable JPLEPH may not be declared and could be assumed to be an integer due to its naming convention, recommending the use of 'IMPLICIT NONE' for better error messages.
  • A later post presents a code snippet involving file operations and expresses confusion about the behavior of the WRITE command, particularly the meaning of the REC and IOSTAT parameters.
  • One participant suggests modifying the REC parameter in the WRITE command to troubleshoot the issue, while another confirms that REC indicates the record number in the direct access file.
  • Participants discuss the implications of the IOSTAT variable, which indicates whether an error occurred during the WRITE operation.

Areas of Agreement / Disagreement

Participants express differing views on the cause of the errors and the correct usage of Fortran commands. There is no consensus on the specific solution to the WRITE command issue, as participants continue to explore various aspects of the code and its behavior.

Contextual Notes

There are unresolved assumptions regarding variable declarations and the implications of using implicit typing in Fortran. The discussion also highlights the complexity of file handling and error reporting in the context of direct access files.

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 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
8K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 17 ·
Replies
17
Views
5K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 6 ·
Replies
6
Views
2K