From d6491505438eb0e77eee6eab29fc741f77947683 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 3 Apr 2014 01:45:22 +0200 Subject: [PATCH] Added scripts --- scripts/check_dependencies.sh | 63 +++++++++++++++ scripts/create_Makefile.sh | 48 ++++++++++++ scripts/create_Makefile_depend.sh | 36 +++++++++ scripts/create_module.sh | 28 +++++++ scripts/prepare_module.sh | 3 +- scripts/save_current_mos.sh | 4 + src/coding_rules.rst | 77 +++++++++++++++++++ ...ci.ezfio_config => q_package.ezfio_config} | 0 8 files changed, 258 insertions(+), 1 deletion(-) create mode 100755 scripts/check_dependencies.sh create mode 100755 scripts/create_Makefile.sh create mode 100755 scripts/create_Makefile_depend.sh create mode 100755 scripts/create_module.sh create mode 100644 src/coding_rules.rst rename src/{selected_ci.ezfio_config => q_package.ezfio_config} (100%) diff --git a/scripts/check_dependencies.sh b/scripts/check_dependencies.sh new file mode 100755 index 00000000..4ff0cf80 --- /dev/null +++ b/scripts/check_dependencies.sh @@ -0,0 +1,63 @@ +#!/bin/bash +# +# usage: +# check_dependencies.sh MOs AOs Electrons +# +# Checks that the list of dependencies given in +# argument is consistent. If the dependencies +# are OK the exit code is 0, otherwise it is 1. +# If no argument is given, the dependencies are +# read in the Makefile. +# Thu Apr 3 01:44:23 CEST 2014 + +function unique_list() +{ + for d in $@ + do + echo $d + done | sort | uniq +} + +if [[ -z $1 ]] +then + exit 0 +fi + +if [[ $1 == "-" ]] +then + COMMAND_LINE=$(grep -e "^INCLUDE_DIRS" Makefile 2>/dev/null | cut -d '=' -f 2) +else + COMMAND_LINE=$(unique_list $@) +fi + +for d in $COMMAND_LINE +do + if [[ ! -d ${SCI_ROOT}/src/$d ]] + then + echo Error: Directory $d does not exist + exit 2 + fi + +done + +DEPS_LONG="" +for i in $COMMAND_LINE +do + DEPS_LONG+=" $i " + DEPS_LONG+=$(grep -e '^INCLUDE_DIRS' ${SCI_ROOT}/src/${i}/Makefile 2>/dev/null | cut -d '=' -f 2) +done + +DEPS=$(unique_list $DEPS_LONG) + +if [[ ! "$COMMAND_LINE" == "$DEPS" ]] +then + DEPS=$(check_dependencies.sh $DEPS) +fi +echo $DEPS + +if [[ "$COMMAND_LINE" == "$DEPS" ]] +then + exit 0 +else + exit 1 +fi diff --git a/scripts/create_Makefile.sh b/scripts/create_Makefile.sh new file mode 100755 index 00000000..ea43d144 --- /dev/null +++ b/scripts/create_Makefile.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# +# usage: +# create_Makefile.sh MOs AOs Electrons +# Creates the Makefile with the dependencies on other modules given +# in the command line. This command is supposed to be run in a module +# directory and searches the dependencies in ../ +# Thu Apr 3 01:44:41 CEST 2014 + +DEPS_LONG="" +for i in $@ +do + DEPS_LONG+=" $i " + DEPS_LONG+=$(grep 'INCLUDE_DIRS' ${SCI_ROOT}/src/${i}/Makefile 2>/dev/null | cut -d '=' -f 2) +done + +DEPS=($( +for d in $DEPS_LONG +do + echo $d +done | sort | uniq +)) + +# Create the Makefile +cat << EOF > Makefile +default: all + +# Define here all other modules on which the current module depends +INCLUDE_DIRS = ${DEPS[@]} + +# Define here all new external source files and objects.Don't forget to prefix the +# object files with IRPF90_temp/ +SRC= +OBJ= + +include Makefile.depend +include \$(SCI_ROOT)/src/Makefile.config +include \$(SCI_ROOT)/src/Makefile.common +include irpf90.make + +irpf90.make: \$(filter-out IRPF90_temp/%, \$(wildcard */*.irp.f)) \$(wildcard *.irp.f) \$(wildcard *.inc.f) Makefile \$(EZFIO) + \$(IRPF90) + +Makefile.depend: Makefile + \$(SCI_ROOT)/scripts/create_Makefile_depend.sh +EOF + + diff --git a/scripts/create_Makefile_depend.sh b/scripts/create_Makefile_depend.sh new file mode 100755 index 00000000..48663cf7 --- /dev/null +++ b/scripts/create_Makefile_depend.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# +# This script is automatically invoked by Makefiles and should not be invoked +# by users. +# Creates the Makefile.depend file. This file contains all the external source +# files included by including other modules. +# Thu Apr 3 01:44:09 CEST 2014 + +SRC="" +OBJ="" +DEPS=$(grep "INCLUDE_DIRS" Makefile 2>/dev/null | cut -d '=' -f 2) + +for M in ${DEPS} +do + # X is the list of external source files + X=$(grep 'SRC=' ${SCI_ROOT}/src/${M}/Makefile 2>/dev/null |cut -d '=' -f 2) + for f in ${X} + do + SRC+=" ${M}/${f}" + done + X=$(grep 'OBJ=' ${SCI_ROOT}/src/${M}/Makefile 2>/dev/null |cut -d '=' -f 2) + for f in ${X} + do + OBJ+=" IRPF90_temp/${M}/${f/IRPF90_temp//}" + done +done + +# Create the Makefile.depend +cat << EOF > Makefile.depend +# This file was created by the $0 script. Do not modify it by hand. + +SRC+=${SRC} +OBJ+=${OBJ} +EOF + + diff --git a/scripts/create_module.sh b/scripts/create_module.sh new file mode 100755 index 00000000..ac4125e1 --- /dev/null +++ b/scripts/create_module.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# +# usage: +# create_module.sh MOs AOs Electrons +# Prepares all the files for the creation of a new module. +# The first argument is the name of the module +# All remaining aruments are dependencies. +# Thu Apr 3 01:44:58 CEST 2014 + +MODULE=$1 +shift +DEPS=$@ + +# Check if module already exists +if [ -d ${MODULE} ] +then + echo "Error: Module $MODULE already exists" + exit 1 +fi + +# Create module directory and go into it +mkdir ${MODULE} +cd ${MODULE} + +# Create the Makefile +${SCI_ROOT}/create_Makefile.sh + + diff --git a/scripts/prepare_module.sh b/scripts/prepare_module.sh index ab41fbc4..287c3663 100755 --- a/scripts/prepare_module.sh +++ b/scripts/prepare_module.sh @@ -1,7 +1,8 @@ #!/bin/bash - +# This script is used by module Makefiles, and should not be used by users. # Checks if all the other module directories are properly linked in the # current directory. If not, the links are created. +# Wed Apr 2 14:35:42 CEST 2014 for dir in $@ do diff --git a/scripts/save_current_mos.sh b/scripts/save_current_mos.sh index acf740ae..941f4ed8 100755 --- a/scripts/save_current_mos.sh +++ b/scripts/save_current_mos.sh @@ -1,4 +1,8 @@ #!/bin/bash +# This script is used by the MOs module, and should not be used by users. +# It copies the EZFIO/mo_basis directory in the save/EZFIO/mo_basis/xxx +# directory, where xxx is the corresponding mo_label. +# Wed Apr 2 14:35:15 CEST 2014 EZFIO=$1 diff --git a/src/coding_rules.rst b/src/coding_rules.rst new file mode 100644 index 00000000..8b86388d --- /dev/null +++ b/src/coding_rules.rst @@ -0,0 +1,77 @@ +====================== +Programming guidelines +====================== + +Each module (directory) contains the following: + +* A :file:`readme.rst` file to document the current module. +* An :file:`assumptions.rst` file. This file should document all the implicit + assumptions used in the module. For example, if the atomic orbitals are + assumed to be normalized, this should be mentioned in the + :file:`AOs/assumptions.rst` file. +* A set of :file:`.irp.f` files containing provider, subroutines and functions +* A :file:`tests` directory that should contain the test programs of the module + (see testing section) +* A :file:`Makefile` that should compile +* Optionally some :file:`*.ezfio_config` configuration files for the EZFIO + library + +A new module may be created by invoking the :file:`create_module.sh` script. + +Every subroutine, function or provider should be documented using the +BEGIN_DOC ... END_DOC block. The documentation should be written in +ReStructured Text format to enable the automatic generation of the Sphinx +documentation. + + +Testing +======= + +Each module contains a :file:`tests` directory which contains the test script. +Each module should be tested by running:: + + make test + +Before merging into the master branch, the module should pass **all** the tests. +This enables the possibility tu use :command:`git bisect` to quickly find bugs. + + +Input data +========== + +Every program is supposed to use an EZFIO database containing all the +persistent data. This database can be modified in using the generated Fortran +functions or the generated Python module. + +The definition of the data needed by the module should be put in the +:file:`*.ezfio_config` file. + +Input data can also be read from the standard input to enable the use of +a program with a pipe, but the read statements should be present **only** in +the main program. + + +Output data +=========== + + Print to stdout statements should only appear in programs, not in providers, +subroutines or functions. This enables the possibility easily use the programs +with pipes. + +To print, you should write in an output file provided by the :file:`Output` +module. + + + +Modifying MOs +============= + +When modifying MOs, the label of the current MOs should change accordingly by changing the mo_label. For example: + +.. code-block:: fortran + + mo_coef = new_mo_coef + mo_label = "MyNewLabel" + TOUCH mo_coef mo_label + + diff --git a/src/selected_ci.ezfio_config b/src/q_package.ezfio_config similarity index 100% rename from src/selected_ci.ezfio_config rename to src/q_package.ezfio_config