From 128265a983249541b27d0c7b9a7199e972f10124 Mon Sep 17 00:00:00 2001
From: kamischi <karl-michael.schindler@web.de>
Date: Thu, 25 Apr 2024 11:56:06 +0200
Subject: [PATCH] move debug from inside of doeels to calling code

---
 source/Lazarus-GUI/UEELSBoson.pas                      |  3 +++
 source/Lazarus-GUI/UMainForm.pas                       |  3 ++-
 source/f90/INSTALL                                     |  2 +-
 source/f90/doeels.f90                                  |  7 ++++---
 source/f90/eels-boson.f90                              |  3 ++-
 source/f90/eels.f90                                    |  4 +++-
 source/f90/fcat-analysis/eels_all.f90                  | 10 ++++++----
 .../f90/fcat-analysis/eels_all.f90.fcat-analysis.f90   |  8 +++++---
 .../f90/fcat-analysis/eels_all.f90.fcat-analysis.txt   | 10 ++++++----
 tests/phintlog/doeels.f90                              |  6 +++---
 tests/phintlog/eels.f90                                |  4 +++-
 11 files changed, 38 insertions(+), 22 deletions(-)

diff --git a/source/Lazarus-GUI/UEELSBoson.pas b/source/Lazarus-GUI/UEELSBoson.pas
index 7d5b64d..234ef30 100644
--- a/source/Lazarus-GUI/UEELSBoson.pas
+++ b/source/Lazarus-GUI/UEELSBoson.pas
@@ -12,6 +12,7 @@ type
 // Fortran equivalents
   Finteger = int32;
   Fdouble  = double;
+  Flogical  = boolean;
   Fosc_array = array[1..3] of Fdouble;
 
 var
@@ -40,6 +41,7 @@ var
   Control: string;
   Mode:    string;
   Wn_Array: array of Fdouble;
+  Debug: Flogical;
   F_Array:  array of Fdouble;
 // for Boson
   TargetTemperature: Fdouble;
@@ -71,6 +73,7 @@ procedure doeels(var e0: Fdouble;
                  var contrl: string;
                  var mode:   string;
                  var wn_array: array of Fdouble;
+                 var debug: Flogical;
                  var f_array:  array of Fdouble;
                  var size_wn_array: Finteger);
   cdecl; external name 'doeels_';
diff --git a/source/Lazarus-GUI/UMainForm.pas b/source/Lazarus-GUI/UMainForm.pas
index 7cb8873..827972c 100644
--- a/source/Lazarus-GUI/UMainForm.pas
+++ b/source/Lazarus-GUI/UMainForm.pas
@@ -599,7 +599,7 @@ begin
          IntervalWMin, IntervalWMax, IntervalWDelta, Comment1, Comment1_length,
          NumberOfLayers, NumberOfEpsilons, NumberOfPeriodic, LayerName, LayerName_length,
          Thickness, Epsilon, NumberOfOscillators, Oscillator, Oscillator_length,
-         Control, Mode, Wn_Array, F_Array, IntervalNW);
+         Control, Mode, Wn_Array, Debug, F_Array, IntervalNW);
 
   doboson(TargetTemperature, InstrumentalWidth, GaussianFraction, Asymmetry, EMin, EMax,
           IntervalWMin, IntervalWMax, IntervalNW, F_Array, xout, yout, nout);
@@ -653,6 +653,7 @@ begin
   IntervalNW := 1 + round((IntervalWMax - IntervalWMin) / IntervalWDelta);
   setlength(Wn_Array, IntervalNW);
   setlength(F_Array, IntervalNW);
+  Debug := false;
   Control := ' ';
   Mode := ' ';
 
diff --git a/source/f90/INSTALL b/source/f90/INSTALL
index 627fc19..6f9f3fd 100644
--- a/source/f90/INSTALL
+++ b/source/f90/INSTALL
@@ -26,7 +26,7 @@ Example:
 
 >>> import doeels
 >>> print(doeels.doeels.__doc__)
-doeels(e0,theta,phia,phib,wmin,wmax,dw,comment,layers,neps,nper,name,thick,epsinf,nos,osc,contrl,mode,wn_array,f_array,[comment_size,name_size,osc_size,wn_array_size])
+doeels(e0,theta,phia,phib,wmin,wmax,dw,comment,layers,neps,nper,name,thick,epsinf,nos,osc,contrl,mode,wn_array,debug,f_array,[comment_size,name_size,osc_size,wn_array_size])
 
 Wrapper for ``doeels``.
 
diff --git a/source/f90/doeels.f90 b/source/f90/doeels.f90
index 533d1bd..40f39fb 100644
--- a/source/f90/doeels.f90
+++ b/source/f90/doeels.f90
@@ -2,7 +2,7 @@ module mod_doeels
 contains
 subroutine doeels (e0, theta, phia, phib, wmin, wmax, dw, comment, comment_size,   &
               layers, neps, nper, name, name_size, thick, epsinf, nos, osc, osc_size,&
-              contrl, mode, wn_array, f_array, wn_array_size)
+              contrl, mode, wn_array, debug, f_array, wn_array_size)
 
 ! ******************************************************************
 ! *                                                                *
@@ -29,6 +29,7 @@ subroutine doeels (e0, theta, phia, phib, wmin, wmax, dw, comment, comment_size,
 ! * contrl:         'image' for image-charge screening             *
 ! * mode:           'kurosawa' for kurosawa model                  *
 ! * wn_array:       frequencies                                    *
+! * debug:          logical                                        *
 ! * f_array:        spectrum                                       *
 ! * wn_array_size:  number of frequencies                          *
 ! *                                                                *
@@ -50,8 +51,9 @@ subroutine doeels (e0, theta, phia, phib, wmin, wmax, dw, comment, comment_size,
   integer, intent(in) :: comment_size, name_size, osc_size, wn_array_size
   integer, intent(in out) :: layers, nper, nos(name_size)
   double precision, intent(in out) :: wn_array(wn_array_size), f_array(wn_array_size)
+  logical, intent(in), optional :: debug
 
-  logical :: rational, user, debug
+  logical :: rational, user
   integer :: i, iw, neps, nofu, nout, nw, lmax
   double precision :: a, acoef, aerr, alpha, argmin, argmax, b, bcoef, beta,  &
       c1, c2, ccoef, cospsi, dlimf, dx, elleps, ener, epsmac, facru, f, f0,   &
@@ -68,7 +70,6 @@ subroutine doeels (e0, theta, phia, phib, wmin, wmax, dw, comment, comment_size,
 
   data aerr / 0.0d0 /, rerr / 1.0d-06 /, f / 0.0d0 /, f1 / 0.0d0 /
 
-  debug = .false.
   if (debug) then
     write (*,*) 'doeels:'
     write (*,*) 'comment: ',  size(comment)
diff --git a/source/f90/eels-boson.f90 b/source/f90/eels-boson.f90
index 2da9ecd..3c5363a 100644
--- a/source/f90/eels-boson.f90
+++ b/source/f90/eels-boson.f90
@@ -145,9 +145,10 @@ program eels_boson
   nw = 1 + int((wmax - wmin) / dw)
   allocate (wn_array(nw), f(nw))
 
+  debug = .false.
   call doeels(e0, theta, phia, phib, wmin, wmax, dw, comment, size(comment),   &
               layers, neps, nper, name, size(name), thick, epsinf, nos, osc, size(osc, 2),&
-              contrl, mode, wn_array, f, size(wn_array))
+              contrl, mode, wn_array, debug, f, size(wn_array))
 
   open(unit = 13, file = bosin_name)
 ! target temperature (Kelvin)
diff --git a/source/f90/eels.f90 b/source/f90/eels.f90
index ae45580..85c9105 100644
--- a/source/f90/eels.f90
+++ b/source/f90/eels.f90
@@ -23,6 +23,7 @@ program eels
 
   integer :: old_size_1, old_size_2
   double precision, allocatable :: tmp_osc(:, :)
+  logical :: debug
   integer :: ioStatus
 
 !  integer, parameter :: name_length = 10
@@ -129,9 +130,10 @@ program eels
   nw = 1 + int((wmax - wmin) / dw)
   allocate (wn_array(nw), f(nw))
 
+  debug = .false.
   call doeels(e0, theta, phia, phib, wmin, wmax, dw, comment, size(comment),   &
               layers, neps, nper, name, size(name), thick, epsinf, nos, osc, size(osc, 2),&
-              contrl, mode, wn_array, f, size(wn_array))
+              contrl, mode, wn_array, debug, f, size(wn_array))
 
   open (unit = 12, file = 'eelsou')
   write (12, 207) e0, theta, phia, phib
diff --git a/source/f90/fcat-analysis/eels_all.f90 b/source/f90/fcat-analysis/eels_all.f90
index 99598ed..9374255 100644
--- a/source/f90/fcat-analysis/eels_all.f90
+++ b/source/f90/fcat-analysis/eels_all.f90
@@ -23,6 +23,7 @@ program eels
 
   integer :: old_size_1, old_size_2
   double precision, allocatable :: tmp_osc(:, :)
+  logical :: debug
   integer :: ioStatus
 
 !  integer, parameter :: name_length = 10
@@ -129,9 +130,10 @@ program eels
   nw = 1 + int((wmax - wmin) / dw)
   allocate (wn_array(nw), f(nw))
 
+  debug = .false.
   call doeels(e0, theta, phia, phib, wmin, wmax, dw, comment, size(comment),   &
               layers, neps, nper, name, size(name), thick, epsinf, nos, osc, size(osc, 2),&
-              contrl, mode, wn_array, f, size(wn_array))
+              contrl, mode, wn_array, debug, f, size(wn_array))
 
   open (unit = 12, file = 'eelsou')
   write (12, 207) e0, theta, phia, phib, comment(1)
@@ -1082,7 +1084,7 @@ end subroutine seteps
 
 subroutine doeels (e0, theta, phia, phib, wmin, wmax, dw, comment, comment_size,   &
               layers, neps, nper, name, name_size, thick, epsinf, nos, osc, osc_size,&
-              contrl, mode, wn_array, f_array, wn_array_size)
+              contrl, mode, wn_array, debug, f_array, wn_array_size)
 
 ! ******************************************************************
 ! *                                                                *
@@ -1104,8 +1106,9 @@ subroutine doeels (e0, theta, phia, phib, wmin, wmax, dw, comment, comment_size,
   integer, intent(in) :: comment_size, name_size, osc_size, wn_array_size
   integer, intent(in out) :: layers, nper, nos(name_size)
   double precision, intent(in out) :: wn_array(wn_array_size), f_array(wn_array_size)
+  logical, intent(in), optional :: debug
 
-  logical :: rational, user, debug
+  logical :: rational, user
   integer :: i, iw, neps, nofu, nout, nw, lmax
   double precision :: a, acoef, aerr, alpha, argmin, argmax, b, bcoef, beta,  &
       c1, c2, ccoef, cospsi, dlimf, dx, elleps, ener, epsmac, facru, f, f0,   &
@@ -1163,7 +1166,6 @@ subroutine doeels (e0, theta, phia, phib, wmin, wmax, dw, comment, comment_size,
 
   data aerr / 0.0d0 /, rerr / 1.0d-06 /, f / 0.0d0 /, f1 / 0.0d0 /
 
-  debug = .false.
   if (debug) then
     write (*,*) 'doeels:'
     write (*,*) 'comment: ',  size(comment)
diff --git a/source/f90/fcat-analysis/eels_all.f90.fcat-analysis.f90 b/source/f90/fcat-analysis/eels_all.f90.fcat-analysis.f90
index a276938..4fde649 100644
--- a/source/f90/fcat-analysis/eels_all.f90.fcat-analysis.f90
+++ b/source/f90/fcat-analysis/eels_all.f90.fcat-analysis.f90
@@ -23,6 +23,7 @@ program eels
 
   integer :: old_size_1, old_size_2
   double precision, allocatable :: tmp_osc(:, :)
+  logical :: debug
   integer :: ioStatus
 
 !  integer, parameter :: name_length = 10
@@ -129,6 +130,7 @@ program eels
 1   nw = 1 + int((wmax - wmin) / dw)
 1   allocate (wn_array(nw), f(nw))
 
+1   debug = .false.
 1   call doeels(e0, theta, phia, phib, wmin, wmax, dw, comment, size(comment),   &
               layers, neps, nper, name, size(name), thick, epsinf, nos, osc, size(osc, 2),&
               contrl, mode, wn_array, f, size(wn_array))
@@ -1082,7 +1084,7 @@ end subroutine seteps
 
 subroutine doeels (e0, theta, phia, phib, wmin, wmax, dw, comment, comment_size,   &
               layers, neps, nper, name, name_size, thick, epsinf, nos, osc, osc_size,&
-              contrl, mode, wn_array, f_array, wn_array_size)
+              contrl, mode, wn_array, debug, f_array, wn_array_size)
 
 ! ******************************************************************
 ! *                                                                *
@@ -1104,8 +1106,9 @@ subroutine doeels (e0, theta, phia, phib, wmin, wmax, dw, comment, comment_size,
   integer, intent(in) :: comment_size, name_size, osc_size, wn_array_size
   integer, intent(in out) :: layers, nper, nos(name_size)
   double precision, intent(in out) :: wn_array(wn_array_size), f_array(wn_array_size)
+  logical, intent(in), optional :: debug
 
-  logical :: rational, user, debug
+  logical :: rational, user
   integer :: i, iw, neps, nofu, nout, nw, lmax
   double precision :: a, acoef, aerr, alpha, argmin, argmax, b, bcoef, beta,  &
       c1, c2, ccoef, cospsi, dlimf, dx, elleps, ener, epsmac, facru, f, f0,   &
@@ -1163,7 +1166,6 @@ subroutine doeels (e0, theta, phia, phib, wmin, wmax, dw, comment, comment_size,
 
   data aerr / 0.0d0 /, rerr / 1.0d-06 /, f / 0.0d0 /, f1 / 0.0d0 /
 
-1   debug = .false.
 1   if (debug) then
 *>     write (*,*) 'doeels:'
 *>     write (*,*) 'comment: ',  size(comment)
diff --git a/source/f90/fcat-analysis/eels_all.f90.fcat-analysis.txt b/source/f90/fcat-analysis/eels_all.f90.fcat-analysis.txt
index 1feb9ef..dda7d14 100644
--- a/source/f90/fcat-analysis/eels_all.f90.fcat-analysis.txt
+++ b/source/f90/fcat-analysis/eels_all.f90.fcat-analysis.txt
@@ -23,6 +23,7 @@ program eels
 
   integer :: old_size_1, old_size_2
   double precision, allocatable :: tmp_osc(:, :)
+  logical :: debug
   integer :: ioStatus
 
 !  integer, parameter :: name_length = 10
@@ -129,9 +130,10 @@ program eels
 1   nw = 1 + int((wmax - wmin) / dw)
 1   allocate (wn_array(nw), f(nw))
 
+1   debug = .false.
 1   call doeels(e0, theta, phia, phib, wmin, wmax, dw, comment, size(comment),   &
               layers, neps, nper, name, size(name), thick, epsinf, nos, osc, size(osc, 2),&
-              contrl, mode, wn_array, f, size(wn_array))
+              contrl, mode, wn_array, debug, f, size(wn_array))
 
 1   open (unit = 12, file = 'eelsou')
 1   write (12, 207) e0, theta, phia, phib, comment(1)
@@ -1072,7 +1074,7 @@ subroutine seteps(neps, nos, osc, epsinf, wn, name, eps, layers, mode)
 end subroutine seteps
 subroutine doeels (e0, theta, phia, phib, wmin, wmax, dw, comment, comment_size,   &
               layers, neps, nper, name, name_size, thick, epsinf, nos, osc, osc_size,&
-              contrl, mode, wn_array, f_array, wn_array_size)
+              contrl, mode, wn_array, debug, f_array, wn_array_size)
 
 ! ******************************************************************
 ! *                                                                *
@@ -1094,8 +1096,9 @@ subroutine doeels (e0, theta, phia, phib, wmin, wmax, dw, comment, comment_size,
   integer, intent(in) :: comment_size, name_size, osc_size, wn_array_size
   integer, intent(in out) :: layers, nper, nos(name_size)
   double precision, intent(in out) :: wn_array(wn_array_size), f_array(wn_array_size)
+  logical, intent(in), optional :: debug
 
-  logical :: rational, user, debug
+  logical :: rational, user
   integer :: i, iw, neps, nofu, nout, nw, lmax
   double precision :: a, acoef, aerr, alpha, argmin, argmax, b, bcoef, beta,  &
       c1, c2, ccoef, cospsi, dlimf, dx, elleps, ener, epsmac, facru, f, f0,   &
@@ -1153,7 +1156,6 @@ subroutine doeels (e0, theta, phia, phib, wmin, wmax, dw, comment, comment_size,
 
   data aerr / 0.0d0 /, rerr / 1.0d-06 /, f / 0.0d0 /, f1 / 0.0d0 /
 
-1   debug = .false.
 1   if (debug) then
 *>     write (*,*) 'doeels:'
 *>     write (*,*) 'comment: ',  size(comment)
diff --git a/tests/phintlog/doeels.f90 b/tests/phintlog/doeels.f90
index 2ca42d3..366a2ff 100644
--- a/tests/phintlog/doeels.f90
+++ b/tests/phintlog/doeels.f90
@@ -1,6 +1,6 @@
 subroutine doeels (e0, theta, phia, phib, wmin, wmax, dw, comment, comment_size,   &
               layers, neps, nper, name, name_size, thick, epsinf, nos, osc, osc_size,&
-              contrl, mode, wn_array, f_array, wn_array_size)
+              contrl, mode, wn_array, debug, f_array, wn_array_size)
 
 ! ******************************************************************
 ! *                                                                *
@@ -48,8 +48,9 @@ subroutine doeels (e0, theta, phia, phib, wmin, wmax, dw, comment, comment_size,
   integer, intent(in) :: comment_size, name_size, osc_size, wn_array_size
   integer, intent(in out) :: layers, nper, nos(name_size)
   double precision, intent(in out) :: wn_array(wn_array_size), f_array(wn_array_size)
+  logical, intent(in), optional :: debug
 
-  logical :: rational, user, debug
+  logical :: rational, user
   integer :: i, iw, neps, nofu, nout, nw, lmax
   double precision :: a, acoef, aerr, alpha, argmin, argmax, b, bcoef, beta,  &
       c1, c2, ccoef, cospsi, dlimf, dx, elleps, ener, epsmac, facru, f, f0,   &
@@ -66,7 +67,6 @@ subroutine doeels (e0, theta, phia, phib, wmin, wmax, dw, comment, comment_size,
 
   data aerr / 0.0d0 /, rerr / 1.0d-06 /, f / 0.0d0 /, f1 / 0.0d0 /
 
-  debug = .false.
   if (debug) then
     write (*,*) 'doeels:'
     write (*,*) 'comment: ',  size(comment)
diff --git a/tests/phintlog/eels.f90 b/tests/phintlog/eels.f90
index f2a80cf..396fde2 100644
--- a/tests/phintlog/eels.f90
+++ b/tests/phintlog/eels.f90
@@ -23,6 +23,7 @@ program eels
 
   integer :: old_size_1, old_size_2
   double precision, allocatable :: tmp_osc(:, :)
+  logical :: debug
   integer :: ioStatus
 
 !  integer, parameter :: name_length = 10
@@ -132,9 +133,10 @@ program eels
   nw = 1 + int((wmax - wmin) / dw)
   allocate (wn_array(nw), f(nw))
 
+  debug = .false.
   call doeels(e0, theta, phia, phib, wmin, wmax, dw, comment, size(comment),   &
               layers, neps, nper, name, size(name), thick, epsinf, nos, osc, size(osc, 2),&
-              contrl, mode, wn_array, f, size(wn_array))
+              contrl, mode, wn_array, debug, f, size(wn_array))
 
   open (unit = 12, file = 'eelsou')
   write (12, 207) e0, theta, phia, phib
-- 
GitLab