aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <kwojtus@protonmail.com>2019-04-25 13:28:00 +0200
committerWojtek Kosior <kwojtus@protonmail.com>2019-04-25 13:28:00 +0200
commite85891390f90732d8b940d4c4a62cecf727e809c (patch)
tree8957e41fd4bfa548be3df4ded4b3ddb1f9c62387
parentb7d4d9aec166afa85a67b467eab499f3d2a676a5 (diff)
downloadfortran-assignment1-e85891390f90732d8b940d4c4a62cecf727e809c.tar.gz
fortran-assignment1-e85891390f90732d8b940d4c4a62cecf727e809c.zip
accept floating point kind as command line argument
-rw-r--r--src/main.F9022
1 files changed, 19 insertions, 3 deletions
diff --git a/src/main.F90 b/src/main.F90
index b0f0ffb..97e8e2d 100644
--- a/src/main.F90
+++ b/src/main.F90
@@ -7,11 +7,27 @@ PROGRAM mul
integer, parameter :: seed = 123456
real :: time
- integer :: dim = 10, multype = 1, realtype = 8
+ integer :: dim = 10, multype = 1, real_kind, stat
+ character(5) :: kind_arg
+ IF (command_argument_count() < 1) THEN
+ write (error_unit, *) "Usage: mul KIND", char(10), &
+ "where KIND is one of: 4, 8, 16"
+ STOP
+ END IF
+
+ call get_command_argument(1, kind_arg)
+
+ read (kind_arg, *, iostat = stat) real_kind
+
+ IF (stat .ne. 0) THEN
+ write (error_unit, *) "Couldn't parse kind number argument"
+ STOP
+ END IF
+
DO WHILE (dim < 2000)
- SELECT CASE(realtype)
+ SELECT CASE(real_kind)
CASE (4,1)
time = measure_4(dim)
CASE (8,2)
@@ -19,7 +35,7 @@ PROGRAM mul
CASE (16,3)
time = measure_16(dim)
CASE default
- write (error_unit, *) "wrong kind for real: ", realtype
+ write (error_unit, *) "wrong kind for real: ", real_kind
STOP
END SELECT