From 48074748898b699d28f744aa94e26d2febe4c732 Mon Sep 17 00:00:00 2001 From: Sylvain Tricot Date: Wed, 20 Nov 2019 18:14:00 +0100 Subject: [PATCH] Work on continuous integration * Started port of the previous CI.bash * Also fix bug in spec.f (stdout was closed so nothing appeared on screen at the second call to libspec) * Work on test suite - utils to create clusters are tested - PED calculator for polar and azimutal scans are tested --- .gitignore | 1 + CI/CI.bash | 176 ++++++++++++++++++ Makefile | 11 +- src/Makefile | 4 + src/install.sh | 1 + src/msspec/calculator.py | 24 +-- src/msspec/iodata.py | 2 +- src/msspec/phagen/fortran/Makefile | 5 +- src/msspec/spec/fortran/Makefile | 9 +- src/msspec/spec/fortran/modules.f | 277 ++++++++++++++++++++++++++++- src/msspec/spec/fortran/spec.f | 4 +- src/msspec/tests.py | 3 +- src/setup.py | 1 + utils/process.py | 8 +- 14 files changed, 497 insertions(+), 29 deletions(-) create mode 100644 CI/CI.bash diff --git a/.gitignore b/.gitignore index b5578b2..05ec978 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ __pycache__ *.py[cod] *.so *.bak +package/ diff --git a/CI/CI.bash b/CI/CI.bash new file mode 100644 index 0000000..67aea44 --- /dev/null +++ b/CI/CI.bash @@ -0,0 +1,176 @@ +#!/bin/bash + +SCRIPT_NAME=$(basename $0) +TOPLEVEL=$(git rev-parse --show-toplevel) +VERSION=$(git describe|sed 's/-\([[:digit:]]\+\)-.*/\.post\1/') +(return 0 2>/dev/null) && sourced=1 || sourced=0 + +pythonpath_prepend() { + if [ -d "$1" ]; then + PYTHONPATH=${PYTHONPATH//":$1:"/:} #delete all instances in the middle + PYTHONPATH=${PYTHONPATH/%":$1"/} #delete any instance at the end + PYTHONPATH=${PYTHONPATH/#"$1:"/} #delete any instance at the beginning + PYTHONPATH="$1${PYTHONPATH:+":$PYTHONPATH"}" #prepend $1 or if $PATH is empty set to $1 + export PYTHONPATH + fi +} + +# Setup or upgrade the Python virtual environment +setup_virtualenv(){ + VENV_PATH="$1" + virtualenv --python=python3 --system-site-packages "$VENV_PATH" + source "$VENV_PATH/bin/activate" + pip install --upgrade pip + pip install --upgrade numpy ase h5py lxml pint terminaltables pycairo + pip install --upgrade sphinx + status=$? + deactivate + [ $status -eq 0 ] || exit 1 +} + +activate_msspec_python3_virtualenv() { + VENV_PATH="$1" + # do not activate virtualenv if already activated + if [ x"${VIRTUAL_ENV}" == x ]; then + # We are not in a virtualenv + if [ x"${VENV_PATH}" != x ]; then + # activate the specified venv + export MSSPEC_ROOT="${TOPLEVEL}" + pythonpath_prepend "$MSSPEC_ROOT/src" + #PYTHONPATH="$PYTHONPATH":"$MSSPEC_ROOT"/src + source "$VENV_PATH/bin/activate" + else + # error + echo "Error: No venv specified!!" + fi + else + # We are in a virtualenv so load only variables + export MSSPEC_ROOT="${TOPLEVEL}" + pythonpath_prepend "$MSSPEC_ROOT/src" + fi +} + + +make_pymsspec_package() { + echo "Running setuptools for pymsspec, please wait... " + VERSION=$(get_package_version) + DEST=${TOPLEVEL}/install_resources/packages/${VERSION} + mkdir -p $DEST + cd ${TOPLEVEL}/src/python/pymsspec && python setup.py sdist 2>&1 > /dev/null + cp ${TOPLEVEL}/src/python/pymsspec/dist/pymsspec-${VERSION}.tar.gz ${DEST}/ + rm -rf ${TOPLEVEL}/src/python/pymsspec/{*.egg-info,dist} +} + + +make_pybinding() { + echo "Creating Python library for Fortran code, please wait... " + activate_msspec_python3_virtualenv + cd ${TOPLEVEL}/src/ && make pybinding +} + + +make_selfex() { + echo "Creating the self-extractible setup program... " + VERSION=$(get_package_version) + DEST=${TOPLEVEL}/install_resources/packages/${VERSION} + LICENSE="${TOPLEVEL}/src/CI/license.txt" + REQUIREMENTS="${TOPLEVEL}/src/CI/requirements" + SETUPFILE="MsSpec-${VERSION}.setup" + MAKESELF=${TOPLEVEL}/src/CI/makeself/makeself.sh + #pip freeze > "${REQUIREMENTS}" + mkdir -p $DEST + cp "${TOPLEVEL}/src/CI/install.sh" "${DEST}" + chmod u+x "${DEST}/install.sh" + cp "${TOPLEVEL}/src/CI/uninstall.sh" "${DEST}" + cp "${TOPLEVEL}/src/CI/msspec" "${DEST}" + cp "${TOPLEVEL}/src/CI/requirements" "${DEST}" + cp "${TOPLEVEL}/src/CI/distro-requirements" "${DEST}" + get_makeself + cd "${DEST}/../" && ${MAKESELF} --license ${LICENSE} --quiet ${VERSION} ${SETUPFILE} "MsSpec - pymsspec" ./install.sh + rm -rf ${SETUPFILE}.bak + rm -rf "${DEST}" + #rm -rf "${REQUIREMENTS}" +} + +make_pdf() { + DEST=${TOPLEVEL}/package + mkdir -p ${DEST} + # first activate the virtual environment + activate_msspec_python3_virtualenv + # then build the documentation. + cd "${TOPLEVEL}/doc" + make --no-print-directory latexpdf || exit 1 + # remove previous pdf + rm -rf "${DEST}"/*.pdf + # copy the produced pdf file to the final location + cp "build/latex/MsSpec-python.pdf" "${TOPLEVEL}/package/MsSpec-${VERSION}.pdf" +} + +make_html () { + make_pdf + # first activate the virtual environment + activate_msspec_python3_virtualenv + # then build the documentation. + cd "${TOPLEVEL}/doc" + make --no-print-directory html || exit 1 +} + +make_tests() { + echo "generate results for unit tests..." + activate_msspec_python3_virtualenv + python -c "from msspec.tests import create_tests_results; create_tests_results()" +} + + +create_package() { + VENV_PATH="$1" + source "$VENV_PATH/bin/activate" + + #update_version + #make_tests + #make_pdf + #make_pymsspec_package + #make_msspecgui_package + #make_fortran_package + #make_selfex + #cleanup + + deactivate +} + +cleanup() { + echo "cleaning up..." + # remove results.txt file + python -c "from msspec.tests import delete_results_file; delete_results_file()" + VERSION=$(get_package_version) + rm -f ${TOPLEVEL}/guide/MsSpec-${VERSION}.pdf +} + +show_help () { + echo "Usage: $SCRIPT_NAME [OPTIONS]" + echo "List of possible options:" + echo " -i Initialize a Python virtual environnment in FOLDER" + echo " -d Build the html documentation within the Python " + echo " virtual environnment in FOLDER" +} + + + +if [ "$sourced" == 0 ]; then + + while getopts "hi:dt" option; do + case $option in + i) setup_virtualenv "$OPTARG" + ;; + d) make_html + ;; + t) make_tests + ;; + h) show_help + ;; + *) show_help + ;; + esac + done + +fi diff --git a/Makefile b/Makefile index 59531f2..b5a30b0 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,11 @@ SETUPFILE:=pymsspec-$(VERSION).setup clean: - @rm -rf *.setup + @echo "Cleaning all..." + @find ./src -type f -name '*.pyc' -exec rm {} + + @find ./src -type d -name '__pycache__' -exec rm -r {} + + +$(MAKE) -C src/ clean + +$(MAKE) -C doc/ clean version: @python ./CI/update_version.py @@ -16,9 +20,8 @@ version: purge: clean @echo "Purging all..." - @find ./src -type f -name '*.pyc' -exec rm {} + - @find ./src -type d -name '__pycache__' -exec rm -r {} + - +$(MAKE) -C src/ clean + @rm -rf *.setup + +$(MAKE) -C src/ purge selfex: purge @echo "Creating the self-extractible setup program... " diff --git a/src/Makefile b/src/Makefile index b85875b..3ddcfb8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -16,3 +16,7 @@ clean: @rm -rf dist @rm -rf *.egg* +purge: clean + +$(MAKE) -C msspec/spec/fortran purge + +$(MAKE) -C msspec/phagen/fortran purge + diff --git a/src/install.sh b/src/install.sh index f1bad36..715958d 100755 --- a/src/install.sh +++ b/src/install.sh @@ -1,6 +1,7 @@ #!/bin/bash # vim: set ts=4 sw=4 sts noet mouse=a fdm=indent: +SCRIPT_NAME=$(basename "$0") PYTHON=python3 VERSION=$(cat ./msspec/version.py|cut -d\" -f2) DEFAULT_DEST="${HOME}/.local/share" diff --git a/src/msspec/calculator.py b/src/msspec/calculator.py index f8b653d..b4e6f70 100644 --- a/src/msspec/calculator.py +++ b/src/msspec/calculator.py @@ -68,14 +68,14 @@ from terminaltables.ascii_table import AsciiTable -try: - MSSPEC_ROOT = os.environ['MSSPEC_ROOT'] -except KeyError: - cfg = Config() - MSSPEC_ROOT = cfg.get('path') +#try: +# MSSPEC_ROOT = os.environ['MSSPEC_ROOT'] +#except KeyError: +# cfg = Config() +# MSSPEC_ROOT = cfg.get('path') -if MSSPEC_ROOT == str(None): - raise NameError('No path to the MsSpec distribution found !!') +#if MSSPEC_ROOT == str(None): +# raise NameError('No path to the MsSpec distribution found !!') @@ -185,7 +185,7 @@ class _MSCALCULATOR(Calculator): LOGGER.debug(' create a space dedicated to the calculation') ######################################################################## self.init_folder = os.getcwd() - self.msspec_folder = os.path.join(MSSPEC_ROOT) + #self.msspec_folder = os.path.join(MSSPEC_ROOT) self.tmp_folder = os.path.abspath(folder) LOGGER.debug(' folder: \'%s\'', self.tmp_folder) if not os.path.exists(self.tmp_folder): @@ -195,7 +195,7 @@ class _MSCALCULATOR(Calculator): #copyfile(os.path.join(self.msspec_folder, 'ase', 'Makefile'), # os.path.join(self.tmp_folder, 'Makefile')) - os.chdir(self.tmp_folder) + #os.chdir(self.tmp_folder) inv = cor = 'NO' if algorithm == 'expansion': @@ -225,8 +225,8 @@ class _MSCALCULATOR(Calculator): calctype_spectro = self.spec_parameters.get_parameter('calctype_spectro') calctype_spectro = calctype_spectro.value - self._make_opts = (MSSPEC_ROOT, calctype_spectro, inv, cor, - spin, sorb, self.tmp_folder) + #self._make_opts = (MSSPEC_ROOT, calctype_spectro, inv, cor, + # spin, sorb, self.tmp_folder) # Initialize the working environment #self._make('init') @@ -306,6 +306,7 @@ class _MSCALCULATOR(Calculator): os.rename('fort.10', 'cluster.clu') os.rename('fort.35', 'tmatrix.tl') os.rename('fort.55', 'tmatrix.rad') + os.chdir(self.init_folder) def run_spec(self): @@ -366,6 +367,7 @@ class _MSCALCULATOR(Calculator): t1 = time.time() self.resources['spec_time'] = t1 - t0 + os.chdir(self.init_folder) def get_tmatrix(self): LOGGER.info("Getting the TMatrix...") diff --git a/src/msspec/iodata.py b/src/msspec/iodata.py index f6ba048..b0d8065 100644 --- a/src/msspec/iodata.py +++ b/src/msspec/iodata.py @@ -67,7 +67,7 @@ from distutils.version import StrictVersion, LooseVersion import sys #sys.path.append('../../MsSpecGui/msspecgui/msspec/gui') -from .msspecgui.msspec.gui.clusterviewer import ClusterViewer +from msspec.msspecgui.msspec.gui.clusterviewer import ClusterViewer def cols2matrix(x, y, z, nx=88*1+1, ny=360*1+1): # mix the values of existing theta and new theta and return the diff --git a/src/msspec/phagen/fortran/Makefile b/src/msspec/phagen/fortran/Makefile index 0af3e19..6e409f7 100644 --- a/src/msspec/phagen/fortran/Makefile +++ b/src/msspec/phagen/fortran/Makefile @@ -6,7 +6,7 @@ objects_src := phagen_scf.f objects := $(patsubst %.f,%.o, $(objects_src)) -.PHONY: clean pybinding +.PHONY: clean purge pybinding pybinding: libphagen.so @@ -24,5 +24,8 @@ $(objects): $(objects_src) clean: @echo "cleaning..." rm -rf *.so *.o *.mod + +purge: clean + @echo "Purging..." rm -rf ../*.so diff --git a/src/msspec/spec/fortran/Makefile b/src/msspec/spec/fortran/Makefile index d7cebbb..0488c03 100644 --- a/src/msspec/spec/fortran/Makefile +++ b/src/msspec/spec/fortran/Makefile @@ -8,7 +8,7 @@ OPTS := -g -Wall -Wextra -Warray-temporaries -Wconversion -fbacktrace -ffree-lin EXE=prog -.PHONY: clean pybinding +.PHONY: clean purge pybinding pybinding: libspec.so @@ -33,6 +33,9 @@ $(objects): $(objects_src) clean: @echo "cleaning..." - @rm -rf *.so *.o *.mod $(EXE) - @rm -rf ../*.so + @rm -rf *.so *.o *.mod +purge: clean + @echo "Purging..." + @rm -rf $(EXE) + @rm -rf ../*.so diff --git a/src/msspec/spec/fortran/modules.f b/src/msspec/spec/fortran/modules.f index e778ee7..32754af 100644 --- a/src/msspec/spec/fortran/modules.f +++ b/src/msspec/spec/fortran/modules.f @@ -11,6 +11,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_ADSORB() USE DIM_MOD + IF (ALLOCATED(ADS)) THEN + DEALLOCATE(ADS) + ENDIF ALLOCATE(ADS(3,900)) END SUBROUTINE ALLOC_ADSORB END MODULE ADSORB_MOD @@ -37,8 +40,17 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_APPROX() USE DIM_MOD + IF (ALLOCATED(RTHFWD)) THEN + DEALLOCATE(RTHFWD) + ENDIF ALLOCATE(RTHFWD(NATP_M)) + IF (ALLOCATED(IBWD)) THEN + DEALLOCATE(IBWD) + ENDIF ALLOCATE(IBWD(NATP_M)) + IF (ALLOCATED(RTHBWD)) THEN + DEALLOCATE(RTHBWD) + ENDIF ALLOCATE(RTHBWD(NATP_M)) END SUBROUTINE ALLOC_APPROX END MODULE APPROX_MOD @@ -55,8 +67,17 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_ATOMS() USE DIM_MOD + IF (ALLOCATED(VALZ)) THEN + DEALLOCATE(VALZ) + ENDIF ALLOCATE(VALZ(NATCLU_M)) + IF (ALLOCATED(NZAT)) THEN + DEALLOCATE(NZAT) + ENDIF ALLOCATE(NZAT(NATCLU_M)) + IF (ALLOCATED(CHEM)) THEN + DEALLOCATE(CHEM) + ENDIF ALLOCATE(CHEM(NATCLU_M)) END SUBROUTINE ALLOC_ATOMS END MODULE ATOMS_MOD @@ -70,7 +91,13 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_AUGER() USE DIM_MOD + IF (ALLOCATED(NLIN_A)) THEN + DEALLOCATE(NLIN_A) + ENDIF ALLOCATE(NLIN_A(0:20)) + IF (ALLOCATED(L_BOUNDS)) THEN + DEALLOCATE(L_BOUNDS) + ENDIF ALLOCATE(L_BOUNDS(0:20,2)) END SUBROUTINE ALLOC_AUGER END MODULE AUGER_MOD @@ -83,7 +110,13 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_BASES() USE DIM_MOD + IF (ALLOCATED(ATBAS)) THEN + DEALLOCATE(ATBAS) + ENDIF ALLOCATE(ATBAS(3*NATP_M)) + IF (ALLOCATED(VECBAS)) THEN + DEALLOCATE(VECBAS) + ENDIF ALLOCATE(VECBAS(9)) END SUBROUTINE ALLOC_BASES END MODULE BASES_MOD @@ -100,10 +133,25 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_CLUSLIM() USE DIM_MOD + IF (ALLOCATED(X_MAX)) THEN + DEALLOCATE(X_MAX) + ENDIF ALLOCATE(X_MAX(NATCLU_M)) + IF (ALLOCATED(X_MIN)) THEN + DEALLOCATE(X_MIN) + ENDIF ALLOCATE(X_MIN(NATCLU_M)) + IF (ALLOCATED(Y_MAX)) THEN + DEALLOCATE(Y_MAX) + ENDIF ALLOCATE(Y_MAX(NATCLU_M)) + IF (ALLOCATED(Y_MIN)) THEN + DEALLOCATE(Y_MIN) + ENDIF ALLOCATE(Y_MIN(NATCLU_M)) + IF (ALLOCATED(VAL)) THEN + DEALLOCATE(VAL) + ENDIF ALLOCATE(VAL(NATCLU_M)) END SUBROUTINE ALLOC_CLUSLIM END MODULE CLUSLIM_MOD @@ -121,10 +169,25 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_COOR() USE DIM_MOD + IF (ALLOCATED(NATYP)) THEN + DEALLOCATE(NATYP) + ENDIF ALLOCATE(NATYP(NATM)) + IF (ALLOCATED(NCHTYP)) THEN + DEALLOCATE(NCHTYP) + ENDIF ALLOCATE(NCHTYP(NATP_M)) + IF (ALLOCATED(NCORR)) THEN + DEALLOCATE(NCORR) + ENDIF ALLOCATE(NCORR(NAT_EQ_M,NATP_M)) + IF (ALLOCATED(INEW_AT)) THEN + DEALLOCATE(INEW_AT) + ENDIF ALLOCATE(INEW_AT(NATCLU_M)) + IF (ALLOCATED(SYM_AT)) THEN + DEALLOCATE(SYM_AT) + ENDIF ALLOCATE(SYM_AT(3,NATCLU_M)) END SUBROUTINE ALLOC_COOR END MODULE COOR_MOD @@ -142,6 +205,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_DEBWAL() USE DIM_MOD + IF (ALLOCATED(UJ2)) THEN + DEALLOCATE(UJ2) + ENDIF ALLOCATE(UJ2(NATM)) END SUBROUTINE ALLOC_DEBWAL END MODULE DEBWAL_MOD @@ -153,6 +219,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_INDAT() USE DIM_MOD + IF (ALLOCATED(INDATA)) THEN + DEALLOCATE(INDATA) + ENDIF ALLOCATE(INDATA(100)) END SUBROUTINE ALLOC_INDAT END MODULE INDAT_MOD @@ -280,6 +349,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_MASSAT() USE DIM_MOD + IF (ALLOCATED(XMT)) THEN + DEALLOCATE(XMT) + ENDIF ALLOCATE(XMT(NATM)) END SUBROUTINE ALLOC_MASSAT END MODULE MASSAT_MOD @@ -296,6 +368,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_MILLER() USE DIM_MOD + IF (ALLOCATED(IVN)) THEN + DEALLOCATE(IVN) + ENDIF ALLOCATE(IVN(3)) END SUBROUTINE ALLOC_MILLER END MODULE MILLER_MOD @@ -350,6 +425,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_RELADS() USE DIM_MOD + IF (ALLOCATED(PCRELA)) THEN + DEALLOCATE(PCRELA) + ENDIF ALLOCATE(PCRELA(3)) END SUBROUTINE ALLOC_RELADS END MODULE RELADS_MOD @@ -365,6 +443,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_RELAX() USE DIM_MOD + IF (ALLOCATED(PCREL)) THEN + DEALLOCATE(PCREL) + ENDIF ALLOCATE(PCREL(10)) END SUBROUTINE ALLOC_RELAX END MODULE RELAX_MOD @@ -429,10 +510,25 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_TRANS() USE DIM_MOD + IF (ALLOCATED(DLT)) THEN + DEALLOCATE(DLT) + ENDIF ALLOCATE(DLT(NE_M,NATM,0:18,2)) + IF (ALLOCATED(TL)) THEN + DEALLOCATE(TL) + ENDIF ALLOCATE(TL(0:NT_M,4,NATM,NE_M)) + IF (ALLOCATED(VK)) THEN + DEALLOCATE(VK) + ENDIF ALLOCATE(VK(NE_M)) + IF (ALLOCATED(VK2)) THEN + DEALLOCATE(VK2) + ENDIF ALLOCATE(VK2(NE_M)) + IF (ALLOCATED(LMAX)) THEN + DEALLOCATE(LMAX) + ENDIF ALLOCATE(LMAX(NATM,NE_M)) END SUBROUTINE ALLOC_TRANS END MODULE TRANS_MOD @@ -450,10 +546,25 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_TL_AED() USE DIM_MOD + IF (ALLOCATED(DLT_A)) THEN + DEALLOCATE(DLT_A) + ENDIF ALLOCATE(DLT_A(NE_M,NATM,0:18,2)) + IF (ALLOCATED(TL_A)) THEN + DEALLOCATE(TL_A) + ENDIF ALLOCATE(TL_A(0:NT_M,4,NATM,NE_M)) + IF (ALLOCATED(VK_A)) THEN + DEALLOCATE(VK_A) + ENDIF ALLOCATE(VK_A(NE_M)) + IF (ALLOCATED(VK2_A)) THEN + DEALLOCATE(VK2_A) + ENDIF ALLOCATE(VK2_A(NE_M)) + IF (ALLOCATED(LMAX_A)) THEN + DEALLOCATE(LMAX_A) + ENDIF ALLOCATE(LMAX_A(NATM,NE_M)) END SUBROUTINE ALLOC_TL_AED END MODULE TL_AED_MOD @@ -502,6 +613,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_TYPEM() USE DIM_MOD + IF (ALLOCATED(IEMET)) THEN + DEALLOCATE(IEMET) + ENDIF ALLOCATE(IEMET(NEMET_M)) END SUBROUTINE ALLOC_TYPEM END MODULE TYPEM_MOD @@ -532,6 +646,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_VALIN() USE DIM_MOD + IF (ALLOCATED(NONVOL)) THEN + DEALLOCATE(NONVOL) + ENDIF ALLOCATE(NONVOL(100)) END SUBROUTINE ALLOC_VALIN END MODULE VALIN_MOD @@ -544,7 +661,13 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_XMRHO() USE DIM_MOD + IF (ALLOCATED(XMAT)) THEN + DEALLOCATE(XMAT) + ENDIF ALLOCATE(XMAT(0:99)) + IF (ALLOCATED(RHOAT)) THEN + DEALLOCATE(RHOAT) + ENDIF ALLOCATE(RHOAT(0:99)) END SUBROUTINE ALLOC_XMRHO END MODULE XMRHO_MOD @@ -570,8 +693,17 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_VECSYS() USE DIM_MOD + IF (ALLOCATED(ASYS)) THEN + DEALLOCATE(ASYS) + ENDIF ALLOCATE(ASYS(3)) + IF (ALLOCATED(BSYS)) THEN + DEALLOCATE(BSYS) + ENDIF ALLOCATE(BSYS(3)) + IF (ALLOCATED(CSYS)) THEN + DEALLOCATE(CSYS) + ENDIF ALLOCATE(CSYS(3)) END SUBROUTINE ALLOC_VECSYS END MODULE VECSYS_MOD @@ -583,6 +715,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_VIBRAT() USE DIM_MOD + IF (ALLOCATED(I_FREE)) THEN + DEALLOCATE(I_FREE) + ENDIF ALLOCATE(I_FREE(NATP_M)) END SUBROUTINE ALLOC_VIBRAT END MODULE VIBRAT_MOD @@ -594,6 +729,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_COEFRLM() USE DIM_MOD + IF (ALLOCATED(CF)) THEN + DEALLOCATE(CF) + ENDIF ALLOCATE(CF(0:2*NL_M-2,0:2*NL_M-2,0:2*NL_M-2)) END SUBROUTINE ALLOC_COEFRLM END MODULE COEFRLM_MOD @@ -605,6 +743,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_EXPROT() USE DIM_MOD + IF (ALLOCATED(EXPR)) THEN + DEALLOCATE(EXPR) + ENDIF ALLOCATE(EXPR(0:2*NL_M-2,0:2*NL_M-2)) END SUBROUTINE ALLOC_EXPROT END MODULE EXPROT_MOD @@ -616,6 +757,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_EXPFAC() USE DIM_MOD + IF (ALLOCATED(EXPF)) THEN + DEALLOCATE(EXPF) + ENDIF ALLOCATE(EXPF(0:2*NL_M-2,0:2*NL_M-2)) END SUBROUTINE ALLOC_EXPFAC END MODULE EXPFAC_MOD @@ -627,6 +771,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_LOGAMAD() USE DIM_MOD + IF (ALLOCATED(GLD)) THEN + DEALLOCATE(GLD) + ENDIF ALLOCATE(GLD(0:N_GAUNT,2)) END SUBROUTINE ALLOC_LOGAMAD END MODULE LOGAMAD_MOD @@ -638,6 +785,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_EXPFAC2() USE DIM_MOD + IF (ALLOCATED(EXPF2)) THEN + DEALLOCATE(EXPF2) + ENDIF ALLOCATE(EXPF2(0:2*NL_M-2,0:2*NL_M-2)) END SUBROUTINE ALLOC_EXPFAC2 END MODULE EXPFAC2_MOD @@ -649,6 +799,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_FACTSQ() USE DIM_MOD + IF (ALLOCATED(FSQ)) THEN + DEALLOCATE(FSQ) + ENDIF ALLOCATE(FSQ(0:2*NL_M-2)) END SUBROUTINE ALLOC_FACTSQ END MODULE FACTSQ_MOD @@ -715,7 +868,13 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_VALIN_AV() USE DIM_MOD + IF (ALLOCATED(TH_0)) THEN + DEALLOCATE(TH_0) + ENDIF ALLOCATE(TH_0(NTH_M)) + IF (ALLOCATED(PH_0)) THEN + DEALLOCATE(PH_0) + ENDIF ALLOCATE(PH_0(NPH_M)) END SUBROUTINE ALLOC_VALIN_AV END MODULE VALIN_AV_MOD @@ -797,6 +956,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_C_G() USE DIM_MOD + IF (ALLOCATED(CG)) THEN + DEALLOCATE(CG) + ENDIF ALLOCATE(CG(-LI_M:LI_M+1,2,2)) END SUBROUTINE ALLOC_C_G END MODULE C_G_MOD @@ -808,8 +970,11 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_C_G_A() USE DIM_MOD - ALLOCATE(CGA(0:NCG_M,-NCG_M:NCG_M,0:NCG_M,-NCG_M:NCG_M,0:2*NCG - &_M)) + IF (ALLOCATED(CGA)) THEN + DEALLOCATE(CGA) + ENDIF + ALLOCATE(CGA(0:NCG_M,-NCG_M:NCG_M,0:NCG_M,-NCG_M:NCG_M,0: + & 2*NCG_M)) END SUBROUTINE ALLOC_C_G_A END MODULE C_G_A_MOD @@ -820,6 +985,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_C_G_M() USE DIM_MOD + IF (ALLOCATED(CG_S)) THEN + DEALLOCATE(CG_S) + ENDIF ALLOCATE(CG_S(2,2,2)) END SUBROUTINE ALLOC_C_G_M END MODULE C_G_M_MOD @@ -831,6 +999,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_DEXPFAC2() USE DIM_MOD + IF (ALLOCATED(DEXPF2)) THEN + DEALLOCATE(DEXPF2) + ENDIF ALLOCATE(DEXPF2(0:2*NL_M-2,0:2*NL_M-2)) END SUBROUTINE ALLOC_DEXPFAC2 END MODULE DEXPFAC2_MOD @@ -842,6 +1013,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_DFACTSQ() USE DIM_MOD + IF (ALLOCATED(DFSQ)) THEN + DEALLOCATE(DFSQ) + ENDIF ALLOCATE(DFSQ(0:2*NL_M-2)) END SUBROUTINE ALLOC_DFACTSQ END MODULE DFACTSQ_MOD @@ -912,7 +1086,13 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_LINLBD() USE DIM_MOD + IF (ALLOCATED(LBD)) THEN + DEALLOCATE(LBD) + ENDIF ALLOCATE(LBD(-N_MU_M:N_MU_M,0:N_NU_M)) + IF (ALLOCATED(NUMAX)) THEN + DEALLOCATE(NUMAX) + ENDIF ALLOCATE(NUMAX(NATP_M)) END SUBROUTINE ALLOC_LINLBD END MODULE LINLBD_MOD @@ -952,6 +1132,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_RA() USE DIM_MOD + IF (ALLOCATED(N_RA)) THEN + DEALLOCATE(N_RA) + ENDIF ALLOCATE(N_RA(NATP_M)) END SUBROUTINE ALLOC_RA END MODULE RA_MOD @@ -963,6 +1146,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_SPECTRUM() USE DIM_MOD + IF (ALLOCATED(I_SPECTRUM)) THEN + DEALLOCATE(I_SPECTRUM) + ENDIF ALLOCATE(I_SPECTRUM(NE_M)) END SUBROUTINE ALLOC_SPECTRUM END MODULE SPECTRUM_MOD @@ -979,9 +1165,21 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_DIRECT() USE DIM_MOD + IF (ALLOCATED(DIRANA)) THEN + DEALLOCATE(DIRANA) + ENDIF ALLOCATE(DIRANA(3,49)) + IF (ALLOCATED(ANADIR)) THEN + DEALLOCATE(ANADIR) + ENDIF ALLOCATE(ANADIR(3,49)) + IF (ALLOCATED(THETAR)) THEN + DEALLOCATE(THETAR) + ENDIF ALLOCATE(THETAR(49)) + IF (ALLOCATED(PHIR)) THEN + DEALLOCATE(PHIR) + ENDIF ALLOCATE(PHIR(49)) END SUBROUTINE ALLOC_DIRECT END MODULE DIRECT_MOD @@ -998,9 +1196,21 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_DIRECT_A() USE DIM_MOD + IF (ALLOCATED(DIRANA_A)) THEN + DEALLOCATE(DIRANA_A) + ENDIF ALLOCATE(DIRANA_A(3,49)) + IF (ALLOCATED(ANADIR_A)) THEN + DEALLOCATE(ANADIR_A) + ENDIF ALLOCATE(ANADIR_A(3,49)) + IF (ALLOCATED(THETAR_A)) THEN + DEALLOCATE(THETAR_A) + ENDIF ALLOCATE(THETAR_A(49)) + IF (ALLOCATED(PHIR_A)) THEN + DEALLOCATE(PHIR_A) + ENDIF ALLOCATE(PHIR_A(49)) END SUBROUTINE ALLOC_DIRECT_A END MODULE DIRECT_A_MOD @@ -1016,9 +1226,21 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_PATH() USE DIM_MOD + IF (ALLOCATED(NPATH)) THEN + DEALLOCATE(NPATH) + ENDIF ALLOCATE(NPATH(0:NDIF_M)) + IF (ALLOCATED(NPATH2)) THEN + DEALLOCATE(NPATH2) + ENDIF ALLOCATE(NPATH2(0:NDIF_M)) + IF (ALLOCATED(NPMA)) THEN + DEALLOCATE(NPMA) + ENDIF ALLOCATE(NPMA(0:NDIF_M)) + IF (ALLOCATED(NPMI)) THEN + DEALLOCATE(NPMI) + ENDIF ALLOCATE(NPMI(0:NDIF_M)) END SUBROUTINE ALLOC_PATH END MODULE PATH_MOD @@ -1030,6 +1252,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_ROT() USE DIM_MOD + IF (ALLOCATED(RLM01)) THEN + DEALLOCATE(RLM01) + ENDIF ALLOCATE(RLM01(1-NL_M:NL_M-1,1-NL_M:NL_M-1,0:NL_M-1)) END SUBROUTINE ALLOC_ROT END MODULE ROT_MOD @@ -1043,7 +1268,13 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_TESTPA() USE DIM_MOD + IF (ALLOCATED(IT)) THEN + DEALLOCATE(IT) + ENDIF ALLOCATE(IT(0:NDIF_M)) + IF (ALLOCATED(IN)) THEN + DEALLOCATE(IN) + ENDIF ALLOCATE(IN(0:NDIF_M)) END SUBROUTINE ALLOC_TESTPA END MODULE TESTPA_MOD @@ -1067,6 +1298,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_TLDW() USE DIM_MOD + IF (ALLOCATED(TLT)) THEN + DEALLOCATE(TLT) + ENDIF ALLOCATE(TLT(0:NT_M,4,NATM,NE_M)) END SUBROUTINE ALLOC_TLDW END MODULE TLDW_MOD @@ -1080,8 +1314,17 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_VARIA() USE DIM_MOD + IF (ALLOCATED(CEX)) THEN + DEALLOCATE(CEX) + ENDIF ALLOCATE(CEX(0:NDIF_M)) + IF (ALLOCATED(CEXDW)) THEN + DEALLOCATE(CEXDW) + ENDIF ALLOCATE(CEXDW(0:NDIF_M)) + IF (ALLOCATED(DW)) THEN + DEALLOCATE(DW) + ENDIF ALLOCATE(DW(0:NDIF_M)) END SUBROUTINE ALLOC_VARIA END MODULE VARIA_MOD @@ -1093,7 +1336,10 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_LBD() USE DIM_MOD - INTEGER I,J + INTEGER I, J + IF (ALLOCATED(LBDM)) THEN + DEALLOCATE(LBDM) + ENDIF ALLOCATE(LBDM(2,NDIF_M)) DO I=1,NDIF_M DO J=1,2 @@ -1110,6 +1356,9 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_SCATMAT() USE DIM_MOD + IF (ALLOCATED(F21)) THEN + DEALLOCATE(F21) + ENDIF ALLOCATE(F21(NSPIN2_M,NLAMBDA_M,NLAMBDA_M,NDIF_M)) END SUBROUTINE ALLOC_SCATMAT END MODULE SCATMAT_MOD @@ -1123,7 +1372,13 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_EXTREM() USE DIM_MOD + IF (ALLOCATED(FMIN)) THEN + DEALLOCATE(FMIN) + ENDIF ALLOCATE(FMIN(0:NDIF_M)) + IF (ALLOCATED(FMAX)) THEN + DEALLOCATE(FMAX) + ENDIF ALLOCATE(FMAX(0:NDIF_M)) END SUBROUTINE ALLOC_EXTREM END MODULE EXTREM_MOD @@ -1139,11 +1394,25 @@ C======================================================================= CONTAINS SUBROUTINE ALLOC_PRINTP() USE DIM_MOD - INTEGER I,J + IF (ALLOCATED(FMN)) THEN + DEALLOCATE(FMN) + ENDIF ALLOCATE(FMN(NPATH_M)) + IF (ALLOCATED(PATH)) THEN + DEALLOCATE(PATH) + ENDIF ALLOCATE(PATH(NPATH_M)) + IF (ALLOCATED(DMN)) THEN + DEALLOCATE(DMN) + ENDIF ALLOCATE(DMN(NPATH_M)) + IF (ALLOCATED(JON)) THEN + DEALLOCATE(JON) + ENDIF ALLOCATE(JON(NPATH_M)) + IF (ALLOCATED(JPON)) THEN + DEALLOCATE(JPON) + ENDIF ALLOCATE(JPON(NPATH_M,NDIF_M)) END SUBROUTINE ALLOC_PRINTP END MODULE PRINTP_MOD diff --git a/src/msspec/spec/fortran/spec.f b/src/msspec/spec/fortran/spec.f index 932d9e0..7b23fc9 100644 --- a/src/msspec/spec/fortran/spec.f +++ b/src/msspec/spec/fortran/spec.f @@ -1285,7 +1285,7 @@ C WRITE(IUO1,562) ENDIF IF(ISOM.EQ.0) CLOSE(IUO2) - IF((ISOM.EQ.0).AND.(NFICHLEC.NE.1)) CLOSE(IUO1) +C! IF((ISOM.EQ.0).AND.(NFICHLEC.NE.1)) CLOSE(IUO1) C C.......... End of the loop on the data files .......... C @@ -1309,7 +1309,7 @@ c ENDIF ENDIF ENDIF C - IF((ISOM.NE.0).OR.(NFICHLEC.EQ.1)) CLOSE(IUO1) +C! IF((ISOM.NE.0).OR.(NFICHLEC.EQ.1)) CLOSE(IUO1) IF(ISOM.NE.0) CLOSE(IUO2) C STOP GOTO 999 diff --git a/src/msspec/tests.py b/src/msspec/tests.py index 2ca9b5f..1d3da78 100644 --- a/src/msspec/tests.py +++ b/src/msspec/tests.py @@ -144,8 +144,9 @@ def create_tests_results(): create_results(tc, 'test_cut_plane') tc = PEDCopperTestCase() - create_results(tc, 'test_phi_scan') create_results(tc, 'test_theta_scan') + tc = PEDCopperTestCase() + create_results(tc, 'test_phi_scan') def delete_results_file(): os.remove(RESULTS_FILENAME) diff --git a/src/setup.py b/src/setup.py index 6d6e8be..9662760 100644 --- a/src/setup.py +++ b/src/setup.py @@ -9,6 +9,7 @@ setup(name='msspec', include_package_data=True, packages=find_packages(include='msspec.*'), install_requires=[ + 'numpy', 'ase', 'h5py', 'lxml', diff --git a/utils/process.py b/utils/process.py index 90be471..9a4b561 100644 --- a/utils/process.py +++ b/utils/process.py @@ -266,7 +266,7 @@ class CommonBlockInfo(BaseInfo): #exit() else: if re.match("^[A-HO-Z].*", v.name, re.I): - v.type = "DOUBLE PRECISION" + v.type = "REAL" else: v.type = "INTEGER" @@ -808,6 +808,9 @@ def write_modules(infile): # for each variable with a defined dimension for variable in variables: if variable.dimension is not None: + s += f" IF (ALLOCATED({variable.name})) THEN\n" + s += f" DEALLOCATE({variable.name})\n" + s += f" ENDIF\n" s += f" ALLOCATE({variable})\n" s += f" END SUBROUTINE ALLOC_{cbi.name.upper()}\n" @@ -832,10 +835,11 @@ def write_modules(infile): if __name__ == "__main__": - infile = 'spec.f' + infile = 'spec.f.orig' # write the modules.f file write_modules(infile) + exit() fi = FileInfo(filename=infile)