aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWojtek Kosior <kwojtus@protonmail.com>2019-06-30 21:50:10 +0200
committerWojtek Kosior <kwojtus@protonmail.com>2019-06-30 21:50:10 +0200
commitf390347bb4bdab0e57543cae65701dab7200501b (patch)
treecabd58b87291d48685fd78ec8b380dc614a8b837 /src
parent252e7692bb85bb813d6442be3de7aa1fe99c8372 (diff)
downloadfortran-assignment3-f390347bb4bdab0e57543cae65701dab7200501b.tar.gz
fortran-assignment3-f390347bb4bdab0e57543cae65701dab7200501b.zip
error handling using GOTO
Diffstat (limited to 'src')
-rw-r--r--src/main.f9045
1 files changed, 33 insertions, 12 deletions
diff --git a/src/main.f90 b/src/main.f90
index 8c7467a..c671b8c 100644
--- a/src/main.f90
+++ b/src/main.f90
@@ -1,6 +1,7 @@
PROGRAM integrator
USE quadratures
USE functions
+ USE iso_fortran_env, ONLY: error_unit
IMPLICIT none
real(kind=8) :: ibeg, iend, val
@@ -8,9 +9,14 @@ PROGRAM integrator
procedure(integrate), pointer :: numerical_int
procedure(funint), pointer :: fun
procedure(analytical_integral), pointer :: analytical_int
- character(100) :: arg
+ character(100) :: arg, errmsg
+ logical :: isok = .true.
- IF (command_argument_count() < 4) STOP "4 arguments required"
+ IF (command_argument_count() < 4) THEN
+ errmsg = "at least 4 arguments required"
+ isok = .false.
+ GOTO 1
+ END IF
call get_command_argument(2, arg)
@@ -24,7 +30,9 @@ PROGRAM integrator
fun => my_poly
analytical_int => my_poly_int
ELSE
- STOP "bad second argument (should be 'exp', 'sin' or 'poly')"
+ errmsg = "bad second argument (should be 'exp', 'sin' or 'poly')"
+ isok = .false.
+ GOTO 1
END IF
@@ -44,17 +52,22 @@ PROGRAM integrator
ELSE IF (arg == "newton-cotes") THEN
numerical_int => newton_cotes
ELSE IF (arg == "analytical") THEN
- IF (this_image() == 1) write (*,*) analytical_int(ibeg, iend)
- STOP
+ if (this_image() == 1) write (*,*) analytical_int(ibeg, iend)
+ GOTO 1
ELSE
- STOP "bad first argument (should be 'gauss', 'newton-cotes'" &
- // " or 'analytical')"
+ errmsg = "bad first argument (should be 'gauss'," &
+ // " 'newton-cotes' or 'analytical')"
+ isok = .false.
+ GOTO 1
END IF
- IF (command_argument_count() < 5) &
- STOP "5th argument (polynomial order) required" &
- // " for numerical integration"
+ IF (command_argument_count() < 5) THEN
+ errmsg = "5th argument (polynomial order) required" &
+ // " for numerical integration"
+ isok = .false.
+ GOTO 1
+ END IF
call get_command_argument(5, arg)
read (arg,*) poly_order
@@ -63,11 +76,19 @@ PROGRAM integrator
IF (command_argument_count() > 5) THEN
call get_command_argument(6, arg)
read (arg,*) subintervals
- IF (subintervals < 1) STOP "subintervals number must be positive"
+ IF (subintervals < 1) THEN
+ errmsg = "subintervals number must be positive"
+ isok = .false.
+ GOTO 1
+ END IF
END IF
val = numerical_int(ibeg, iend, fun, poly_order)
- IF (this_image() == 1) write (*,*) val
+ if (this_image() == 1) write (*,*) val
+
+ 1 if (this_image() == 1 .and. .not. isok) write(*,*) trim(errmsg)
+CONTAINS
+
END PROGRAM integrator