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

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

This discussion addresses issues related to IMPLICIT definitions and variable type errors in FORTRAN code while using REFPROP subroutines. The user encounters problems with IMPLICIT definitions that prevent the use of "IMPLICIT NONE" and receives errors about type conversions between REAL(4) and REAL(8). Solutions include defining all variables as REAL(8) and using intrinsic functions for type conversion, which allows for proper arithmetic operations between floating-point and integer values.

PREREQUISITES
  • Understanding of FORTRAN programming language
  • Familiarity with REFPROP subroutines for thermodynamic properties
  • Knowledge of IMPLICIT definitions in FORTRAN
  • Experience with COMMON blocks for variable sharing
NEXT STEPS
  • Research FORTRAN intrinsic functions for type conversion
  • Learn about effective use of COMMON blocks in FORTRAN
  • Explore best practices for managing IMPLICIT definitions in FORTRAN
  • Investigate the implications of using REAL(8) versus REAL(4) in numerical computations
USEFUL FOR

FORTRAN developers, engineers working with thermodynamic simulations, and programmers troubleshooting variable type issues in scientific computing.

Aerospark
Messages
2
Reaction score
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
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.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 25 ·
Replies
25
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 59 ·
2
Replies
59
Views
12K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 10 ·
Replies
10
Views
6K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K