New to FORTRAN, Error message I don't understand

In summary, the source code includes a type mismatch between an int and char* and when compiling it, the compiler gives the following error.
  • #1
Trolll
5
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
  • #2
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:
  • #3
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.
 
  • #4
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.
 
  • #5
I suspect it's this part in the write command:

REC=NROUT+2

Try setting it to REC=NROUT+0 and see what happens.
 
  • #6
Now I've tried it, but unfortunately I've got the same error. What does that part of the brackets mean?
 
  • #7
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:
  • #8
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.
 
  • #9
Thank you :)
 

FAQ: New to FORTRAN, Error message I don't understand

1. What is the most common error message in FORTRAN and how do I fix it?

The most common error message in FORTRAN is "Syntax error". This means that there is a mistake in the structure or format of your code. To fix this, carefully check your code for any missing or misplaced punctuation, incorrect variable names, or other syntax errors.

2. Why am I getting an "Undefined variable" error in my FORTRAN code?

This error means that you are trying to use a variable that has not been defined or assigned a value. Make sure all variables are properly declared and initialized before using them in your code.

3. How do I interpret the "Out of memory" error in FORTRAN?

The "Out of memory" error means that your program has requested more memory than is available. This could be due to a large amount of data or a memory leak in your code. Consider optimizing your code or increasing the memory allocation for your program.

4. Why am I getting a "Floating point error" in my FORTRAN program?

A "Floating point error" occurs when there is an issue with the representation or manipulation of decimal numbers in your code. This could be caused by dividing by zero, using incorrect data types, or other mathematical errors. Double check your calculations and make sure you are using the correct data types for your variables.

5. How can I debug my FORTRAN code if I don't understand the error message?

If you are unsure about the specific error message you are receiving, you can try using a debugger to step through your code line by line and identify where the error is occurring. You can also try searching for the error message online or consulting with other FORTRAN users for assistance.

Similar threads

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