How do I declare the precision of a number to be an adjustable parameter?

user1271772

In 2013 there was a question on converting a big working code from double to quadruple precision: "Converting a working code from double-precision to quadruple-precision: How to read quadruple-precision numbers in FORTRAN from an input file", and the consensus was to declare variables using an adjustable parameter "WP" that specifies the "working precision", instead of having a separate version of the program with variables declared using D+01, and another version using Q+01. This way we can easily switch back and forth by defining WP=real128 or WP=real64 at the top, and the rest doesn't need to change.

But how do we do this?

I tried the suggestion in the answer to that question, by making a simple code TEST.F90:

  PROGRAM TEST
  use ISO_FORTRAN_ENV
  WP= real128
  IMPLICIT NONE
  real (WP) ::  X
  X= 5.4857990945E-4_WP
  END PROGRAM TEST

compiled with:

~/gcc-4.6/bin/gfortran -o tst.x TEST.F90

But it gives:

      IMPLICIT NONE
                   1
Error: Unexpected IMPLICIT NONE statement at (1)
QLEVEL16.F90:5.12:

      real (WP) ::  MEL 
            1
Error: Parameter 'wp' at (1) has not been declared or is a variable, which does not reduce to a constant expression
QLEVEL16.F90:6.29:

      MEL= 5.4857990945E-4_WP
                             1
Error: Missing kind-parameter at (1)
Alexander Vogt

The kind specifier must be an integer parameter - and you do not declare it appropriately. Furthermore, implicit none must go before any declaration.

Here is a working version addressing both issues:

PROGRAM TEST
  use ISO_FORTRAN_ENV
  IMPLICIT NONE
  integer, parameter :: WP= real128
  real (WP) ::  X

  X= 5.4857990945E-4_WP
END PROGRAM TEST

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I declare a function parameter to accept functions that throw?

From Dev

How do I find the number of template arguments used to declare a class?

From Dev

How do I format a number to have a fixed precision AND a fixed number of integral digits?

From Dev

How do I convert a hexadecimal number in IEEE 754 double precision (64bit) format to a decimal number?

From Dev

How do I print a Rust floating-point number with all available precision?

From Dev

std::setprecision sets the number of significant figures. How do I use iomanip to set the precision?

From Dev

How do i declare a function which takes a variable of a yet unidentified type as parameter

From Dev

How do you create 3 adjustable divs?

From Dev

How do I get millisecond precision in hive?

From Dev

How do I declare a public enum in typescript?

From Java

How do I declare and initialize an array in Java?

From Java

How do I declare a namespace in JavaScript?

From Java

How do I declare typedef in Swift

From Dev

How do I declare a driver as global?

From Dev

How do I declare a composite interface in Go?

From Dev

How do I declare a block that returns a UIView?

From Dev

How do I declare a generic async Task?

From Dev

How do I declare a vector in OpenCV?

From Dev

How do I declare process type with Procfile?

From Dev

IP Prefix - how do I declare this?

From Dev

How do I declare an array of bytes in Java?

From Dev

How do I declare a object for use with this function

From Dev

How do I declare a vector in OpenCV?

From Dev

How do I declare a String[] in an Arraylist?

From Dev

How can I get the n-th double precision number

From Dev

How declare for in function with parameter

From Dev

How do I declare a Generic Promise in Typescript, so that when the Generic type is "<void>", one of its methods won't take a parameter?

From Dev

How can I declare an array inside a function according to the size of a parameter?

From Dev

graphql why do I need to declare a extra parameter within a resolvers parameter

Related Related

  1. 1

    How do I declare a function parameter to accept functions that throw?

  2. 2

    How do I find the number of template arguments used to declare a class?

  3. 3

    How do I format a number to have a fixed precision AND a fixed number of integral digits?

  4. 4

    How do I convert a hexadecimal number in IEEE 754 double precision (64bit) format to a decimal number?

  5. 5

    How do I print a Rust floating-point number with all available precision?

  6. 6

    std::setprecision sets the number of significant figures. How do I use iomanip to set the precision?

  7. 7

    How do i declare a function which takes a variable of a yet unidentified type as parameter

  8. 8

    How do you create 3 adjustable divs?

  9. 9

    How do I get millisecond precision in hive?

  10. 10

    How do I declare a public enum in typescript?

  11. 11

    How do I declare and initialize an array in Java?

  12. 12

    How do I declare a namespace in JavaScript?

  13. 13

    How do I declare typedef in Swift

  14. 14

    How do I declare a driver as global?

  15. 15

    How do I declare a composite interface in Go?

  16. 16

    How do I declare a block that returns a UIView?

  17. 17

    How do I declare a generic async Task?

  18. 18

    How do I declare a vector in OpenCV?

  19. 19

    How do I declare process type with Procfile?

  20. 20

    IP Prefix - how do I declare this?

  21. 21

    How do I declare an array of bytes in Java?

  22. 22

    How do I declare a object for use with this function

  23. 23

    How do I declare a vector in OpenCV?

  24. 24

    How do I declare a String[] in an Arraylist?

  25. 25

    How can I get the n-th double precision number

  26. 26

    How declare for in function with parameter

  27. 27

    How do I declare a Generic Promise in Typescript, so that when the Generic type is "<void>", one of its methods won't take a parameter?

  28. 28

    How can I declare an array inside a function according to the size of a parameter?

  29. 29

    graphql why do I need to declare a extra parameter within a resolvers parameter

HotTag

Archive