From 0ee6c2d791a1ce24b86f1919c8bafd9576582790 Mon Sep 17 00:00:00 2001 From: Sylvain Tricot Date: Mon, 28 Sep 2020 15:09:47 +0200 Subject: [PATCH] Fix bug in spec (files not closed). Some files were not closed in spec at the end of the program. This caused some troubles in runing the phagen-spec cycle several times. A function (CLOSE_ALL_FILES) was added in misc.f to force opened units in the range [7,200] to be closed before exiting the main subroutine. --- src/msspec/calculator.py | 2 +- src/msspec/phagen/fortran/phagen_scf_2.1_dp.f | 13 ++++++++++++- src/msspec/spec/fortran/common_sub/misc.f | 12 ++++++++++++ src/msspec/spec/fortran/eig/mi/main.f | 1 + src/msspec/spec/fortran/eig/pw/do_main.f | 10 +++++++--- src/msspec/spec/fortran/eig/pw/main.f | 4 +++- .../spec/fortran/phd_mi_noso_nosp_nosym/main.f | 1 + .../spec/fortran/phd_se_noso_nosp_nosym/main.f | 1 + 8 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 src/msspec/spec/fortran/common_sub/misc.f diff --git a/src/msspec/calculator.py b/src/msspec/calculator.py index 1a6e116..eedefbc 100644 --- a/src/msspec/calculator.py +++ b/src/msspec/calculator.py @@ -385,7 +385,7 @@ class _MSCALCULATOR(Calculator): 'NPH_M' : 2000, 'NDIM_M' : 100000, 'N_TILT_M' : 11, # to change see extdir.f - 'N_ORD_M' : 200, + 'N_ORD_M' : 250, 'NPATH_M' : 500, 'NGR_M' : 10,}) diff --git a/src/msspec/phagen/fortran/phagen_scf_2.1_dp.f b/src/msspec/phagen/fortran/phagen_scf_2.1_dp.f index cfc0e01..deb8bef 100644 --- a/src/msspec/phagen/fortran/phagen_scf_2.1_dp.f +++ b/src/msspec/phagen/fortran/phagen_scf_2.1_dp.f @@ -5860,7 +5860,7 @@ c endif c print 770 -770 format( 1x,' generating t_l (for030) and', +770 format( 1x,' generating t_l (for030) and', &' atomic cross section (for050)') c c construct log-linear x mesh @@ -14807,6 +14807,7 @@ c check = .true. i = 1 ! + write(6,*) 'Below is the bug!' do ! if ( r_real ( i ) > r_in ) then @@ -23986,3 +23987,13 @@ c c--------------------------------- c + subroutine my_test() + logical ok + integer u + do 11 u=0,100 + inquire(unit=u, opened=ok) + if (ok) then + print *,"unit ", u, " is opened" + endif +11 continue + end subroutine diff --git a/src/msspec/spec/fortran/common_sub/misc.f b/src/msspec/spec/fortran/common_sub/misc.f new file mode 100644 index 0000000..655a492 --- /dev/null +++ b/src/msspec/spec/fortran/common_sub/misc.f @@ -0,0 +1,12 @@ + SUBROUTINE CLOSE_ALL_FILES() + IMPLICIT NONE + LOGICAL Ok + INTEGER U + + DO U=7,200 + INQUIRE(UNIT=U, OPENED=Ok) + IF (Ok) THEN + CLOSE(U) + ENDIF + ENDDO + END SUBROUTINE CLOSE_ALL_FILES diff --git a/src/msspec/spec/fortran/eig/mi/main.f b/src/msspec/spec/fortran/eig/mi/main.f index 4bdf296..0407352 100644 --- a/src/msspec/spec/fortran/eig/mi/main.f +++ b/src/msspec/spec/fortran/eig/mi/main.f @@ -16,5 +16,6 @@ CF2PY INTEGER, INTENT(IN,COPY) :: N_TILT_M_, N_ORD_M_, NPATH_M_, NGR_M_ & N_TILT_M_, N_ORD_M_, NPATH_M_, NGR_M_) CALL DO_MAIN() + CALL CLOSE_ALL_FILES() END SUBROUTINE RUN diff --git a/src/msspec/spec/fortran/eig/pw/do_main.f b/src/msspec/spec/fortran/eig/pw/do_main.f index c2c8bdf..a07fb81 100644 --- a/src/msspec/spec/fortran/eig/pw/do_main.f +++ b/src/msspec/spec/fortran/eig/pw/do_main.f @@ -1227,10 +1227,14 @@ c ENDIF ENDIF ENDIF C - IF((ISOM.NE.0).OR.(NFICHLEC.EQ.1)) CLOSE(IUO1) +CST IF((ISOM.NE.0).OR.(NFICHLEC.EQ.1)) CLOSE(IUO1) + IF(ISOM.NE.0) CLOSE(IUO2) CST STOP - return +CST REMOVE STOP and add GOTO +CST Next line added for test + GOTO 999 + C 1 WRITE(IUO1,60) STOP @@ -1553,7 +1557,7 @@ C &ATOMS >>>>>>>>>>',/,10X,'<<<<<<<<<< ATOMS ',I4,' AND ',I4,' &ARE IDENTICAL >>>>>>>>>>') C - END + 999 END C C======================================================================= C diff --git a/src/msspec/spec/fortran/eig/pw/main.f b/src/msspec/spec/fortran/eig/pw/main.f index 4bdf296..86be347 100644 --- a/src/msspec/spec/fortran/eig/pw/main.f +++ b/src/msspec/spec/fortran/eig/pw/main.f @@ -16,5 +16,7 @@ CF2PY INTEGER, INTENT(IN,COPY) :: N_TILT_M_, N_ORD_M_, NPATH_M_, NGR_M_ & N_TILT_M_, N_ORD_M_, NPATH_M_, NGR_M_) CALL DO_MAIN() + CALL CLOSE_ALL_FILES() + + end subroutine - END SUBROUTINE RUN diff --git a/src/msspec/spec/fortran/phd_mi_noso_nosp_nosym/main.f b/src/msspec/spec/fortran/phd_mi_noso_nosp_nosym/main.f index 4210b6f..61fe47c 100644 --- a/src/msspec/spec/fortran/phd_mi_noso_nosp_nosym/main.f +++ b/src/msspec/spec/fortran/phd_mi_noso_nosp_nosym/main.f @@ -16,5 +16,6 @@ CF2PY INTEGER, INTENT(IN,COPY) :: N_TILT_M_, N_ORD_M_, NPATH_M_, NGR_M_ & N_TILT_M_, N_ORD_M_, NPATH_M_, NGR_M_) CALL MAIN_PHD_NS_MI() + CALL CLOSE_ALL_FILES() END SUBROUTINE RUN diff --git a/src/msspec/spec/fortran/phd_se_noso_nosp_nosym/main.f b/src/msspec/spec/fortran/phd_se_noso_nosp_nosym/main.f index 4bdf296..0407352 100644 --- a/src/msspec/spec/fortran/phd_se_noso_nosp_nosym/main.f +++ b/src/msspec/spec/fortran/phd_se_noso_nosp_nosym/main.f @@ -16,5 +16,6 @@ CF2PY INTEGER, INTENT(IN,COPY) :: N_TILT_M_, N_ORD_M_, NPATH_M_, NGR_M_ & N_TILT_M_, N_ORD_M_, NPATH_M_, NGR_M_) CALL DO_MAIN() + CALL CLOSE_ALL_FILES() END SUBROUTINE RUN