Dealing with IMPLICIT Definitions and Variable Type Errors in FORTRAN Code?

In summary: The specific command for converting from integer to real is INT. So for example, you could use a statement like this:x = INT(tempInt)This will convert the integer value stored in tempInt to a real value and store it in x.
  • #1
Aerospark
2
0
So I have been trying to write a code which calls from REFPROP subroutines to get thermodynamic properties and then uses these to do some other calculations. I am facing two issues:

1) The REFPROP subroutines require IMPLICIT definitions so I can't say IMPLICIT none at the top, and this may cause some errors popping up where I don't know, is there a way to get around this?

i.e. this must be at the top of my code
Code:
!SETUP REFPROP
IMPLICIT DOUBLE PRECISION (a-h,o-z)
IMPLICIT INTEGER (i-k,m,n)
PARAMETER (ncmax=20)   !max number of components in mixture
DIMENSION x(ncmax),xliq(ncmax),xvap(ncmax),f(ncmax)
CHARACTER hrf*3, herr*255
CHARACTER*255 hf(ncmax)
CHARACTER*7 hfmix

2) It kept saying "possible change of value from REAL(4) to REAL(8)" as an error, so I defined all of my variables as REAL(8) and the errors went away.. But now all my variables are floating point values and can't be multiplied with integers where they need to..

Are there any ways of avoiding these issues? Also, I am using COMMON blocks to send variable values between subroutines, functions and main program.

Thank you for your time
 
Technology news on Phys.org
  • #2
Hey Aerospark and welcome to the forums.

I'm not sure what the command is in FORTRAN, but you should consider that if you want to multiply a float by an integer, then create a new temporary float and cast the integer value to the float.

In C we write this as:

Code:
   // x is our temporary float
   float x = 0;
   x = (float)(tempInt);

FORTRAN should have something like this, and if you know what the command is then you can use it to convert integer to float and then everything is done with floating point arithmetic for that floating point word data type.
 

Related to Dealing with IMPLICIT Definitions and Variable Type Errors in FORTRAN Code?

What is a FORTRAN REAL*INT error?

A FORTRAN REAL*INT error is an error that occurs when the data type of a variable in a FORTRAN program is not compatible with the specified REAL*INT data type. This can happen when a variable is declared as REAL*INT, but is then assigned a value that is not an integer.

How can I fix a FORTRAN REAL*INT error?

To fix a FORTRAN REAL*INT error, you need to make sure that the data types of your variables match the specified REAL*INT data type. This can be done by either changing the data type of the variable or by making sure that the assigned value is an integer.

Why does a FORTRAN REAL*INT error occur?

A FORTRAN REAL*INT error occurs because the data type of a variable is not compatible with the specified REAL*INT data type. This can happen if the programmer accidentally assigns a non-integer value to a variable declared as REAL*INT or if the programmer does not declare the variable before using it.

Can a FORTRAN REAL*INT error cause my program to crash?

Yes, a FORTRAN REAL*INT error can cause your program to crash if it is not handled properly. The program will terminate and an error message will be displayed if the error is not caught and dealt with in the code.

How do I prevent FORTRAN REAL*INT errors from occurring?

To prevent FORTRAN REAL*INT errors, it is important to carefully declare and assign data types to variables. It is also helpful to use proper error-handling techniques in the code to catch and handle any potential errors. Additionally, double-checking all variable assignments can help prevent these types of errors.

Similar threads

  • Programming and Computer Science
Replies
4
Views
797
  • Programming and Computer Science
Replies
25
Views
680
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
2
Replies
59
Views
9K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
9
Views
4K
Back
Top