From fa6d40a85733ace000f79ce5a4b862b6b42a4bb2 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 21 Jan 2019 23:21:20 +0100 Subject: [PATCH] Removed Ninja Version:1.4.0 Version:1.4.0 --- Bash/ezfio.sh | 3 + LICENSE | 2 +- Makefile | 6 +- README.rst | 56 +++++++------- build.ninja | 31 -------- configure.py | 146 ------------------------------------- git-tools/install_tools.sh | 2 +- make.config | 9 +++ src/Makefile | 20 ++--- src/libezfio_file.irp.f | 14 ++-- src/libezfio_util.irp.f | 9 ++- src/system.c | 45 ++++++++++++ src/system_c.c | 13 ---- src/system_f.f90 | 20 ++++- version | 2 +- 15 files changed, 127 insertions(+), 251 deletions(-) delete mode 100644 build.ninja delete mode 100755 configure.py create mode 100644 make.config create mode 100644 src/system.c delete mode 100644 src/system_c.c diff --git a/Bash/ezfio.sh b/Bash/ezfio.sh index f8f0322..bd756dc 100644 --- a/Bash/ezfio.sh +++ b/Bash/ezfio.sh @@ -1,4 +1,7 @@ #!/bin/bash +# +# ezfio shell command with completion +# EZFIO_ROOT=$( cd $(dirname "${BASH_SOURCE}")/.. ; pwd -P ) diff --git a/LICENSE b/LICENSE index 63bb6f7..1e1fbae 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ - GNU GENERAL PUBLIC LICENSE + GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., diff --git a/Makefile b/Makefile index e574683..82b29ef 100644 --- a/Makefile +++ b/Makefile @@ -38,19 +38,15 @@ clean: - bash -c "[[ -f Bash/ezfio.sh ]] && rm $$PWD/Bash/*" - $(MAKE) -C $$PWD/src veryclean -archive: distclean +archive: veryclean git archive --format=tar HEAD > EZFIO.$(VERSION).tar mkdir EZFIO ; cd EZFIO ; tar -xvf ../EZFIO.$(VERSION).tar rm EZFIO.$(VERSION).tar tar -zcvf EZFIO.$(VERSION).tar.gz EZFIO rm -rf EZFIO -make.config: - ./configure.py - veryclean: $(MAKE) -C src veryclean - rm -f make.config rm -f Ocaml/ezfio.ml rm -f Python/ezfio.py rm -f lib/{libezfio.a,libezfio_irp.a} diff --git a/README.rst b/README.rst index 32ff6e5..ef35abe 100644 --- a/README.rst +++ b/README.rst @@ -4,13 +4,13 @@ EZFIO EZFIO is the Easy Fortran I/O library generator. It generates automatically an I/O library from a simple configuration file. The produced library contains Fortran subroutines to read/write the data -from/to disk, and to check if the data exists. -A Python and an Ocaml API are also provided. +from/to disk, and to check if the data exists. A Python and an Ocaml API +are also provided. With EZFIO, the data is organized in a file system inside a main directory. This main directory contains subdirectories, which contain files. Each file corresponds to a data. For atomic data the file is a -plain text file, and for array data the file is a gzipped text file. +plain text file, and for array data the file is a gzipped text file. Download ======== @@ -19,7 +19,8 @@ The following packages are needed: * `IRPF90 `_ * `Python `_ -* `GNU make `_ or `Ninja `_ +* `GNU make `_ +* `Zlib `_ Tutorial @@ -32,7 +33,8 @@ the 3D space. Preparation of the library -------------------------- -Create an empty directory for your project and unpack the ``EZFIO.tar.gz`` file in this directory. This directory now contains: +Create an empty directory for your project and unpack the +``EZFIO.tar.gz`` file in this directory. This directory now contains: .. code-block:: bash @@ -40,9 +42,8 @@ Create an empty directory for your project and unpack the ``EZFIO.tar.gz`` file EZFIO/ Get into the ``EZFIO`` directory and configure the library to produce the -desired suboutines. Get into the ``config`` directory and create a new file -``test.config`` -containing:: +desired suboutines. Get into the ``config`` directory and create a new +file ``test.config`` containing:: molecule num_atoms integer @@ -56,14 +57,13 @@ containing:: In this example, ``molecule`` and ``properties`` are containers of data. Those are defined in the config file by their name at the beginning of a -new line. -Each data contained inside a container is characterized by a triplet -(name,type,dimension), preceded by at least one white space at the -beginning of the line. +new line. Each data contained inside a container is characterized by a +triplet (name,type,dimension), preceded by at least one white space at +the beginning of the line. -If the dimension of an array is a data, the name of the data can be used -as ``_`` in the definition of the dimension. For -example, the dimension (``molecule_num_atoms``) uses the data +If the dimension of an array is a data, the name of the data can be +used as ``_`` in the definition of the dimension. +For example, the dimension (``molecule_num_atoms``) uses the data ``num_atoms`` of container ``molecule``. Data can also be the result of a simple operation. In that case, the @@ -83,16 +83,10 @@ Now, go back to the EZFIO root directory. To build with GNU make, run: $ make -Or you can use Ninja to build the library: - -.. code-block:: bash - - $ ninja - - -The ``lib`` directory now contains the static library ``libezfio.a``, and a static -library for use under the IRPF90 environment (``libezfio_irp.a``). -The ``Python``, ``Ocaml`` and ``Bash`` directories contain the binding for these languages. +The ``lib`` directory now contains the static library ``libezfio.a``, +and a static library for use under the IRPF90 environment +(``libezfio_irp.a``). The ``Python``, ``Ocaml`` and ``Bash`` directories +contain the binding for these languages. Using the produced library @@ -232,7 +226,8 @@ Execute the script: $ python2 create_input.py 18.0 -The printed mass is correct, and a new directory (``Water``) was created with our data: +The printed mass is correct, and a new directory (``Water``) was created +with our data: .. code-block:: bash @@ -309,12 +304,12 @@ the EZFIO file. end -Compile the fortran program and link it the ``libezfio.a`` library, and run the -executable. +Compile the fortran program and link it the ``libezfio.a`` library and +``zlib``, and run the executable. .. code-block:: bash - $ gfortran test.f90 EZFIO/lib/libezfio.a -o test.x + $ gfortran test.f90 EZFIO/lib/libezfio.a -lz -o test.x $ ./test.x Data in the EZFIO file: 16.0000000 0.00000000 0.222396001 0.00000000 @@ -362,7 +357,8 @@ The usage of the ``ezfio`` bash command is:: ezfio unset_verbose -Here is the same script as the Python script, but using Bash (``create_input.sh``): +Here is the same script as the Python script, but using Bash +(``create_input.sh``): .. code-block:: bash diff --git a/build.ninja b/build.ninja deleted file mode 100644 index feeb8fa..0000000 --- a/build.ninja +++ /dev/null @@ -1,31 +0,0 @@ -include version - -rule build_generated_ninja - command = python2 configure.py - description = Creating generated.ninja - -rule run_ninja - command = bash -c 'source .make.config.sh ; $$NINJA -f $in' - description = Building Fortran library - pool = console - -rule build_archive - command = git archive --format=tar HEAD > EZFIO.${VERSION}.tar && mkdir -p EZFIO && cd EZFIO && tar -xvf ../EZFIO.${VERSION}.tar && cd .. && rm EZFIO.${VERSION}.tar && tar -zcvf EZFIO.${VERSION}.tar.gz EZFIO && rm -rf EZFIO - description = Building archive - -rule clean_all - command = bash -c 'source .make.config.sh ; bash -c "$$NINJA -f $in -t clean ; $$NINJA -t clean" ; rm -rf src/IRPF90_{temp,man} src/*.pyc' - description = Cleaning directory - - -build make.config .make.config.sh generated.ninja impossible_target: build_generated_ninja - -build all: run_ninja generated.ninja - -default all - -build EZFIO.${VERSION}.tar.gz: build_archive - -build archive: phony EZFIO.${VERSION}.tar.gz - -build clean: clean_all generated.ninja diff --git a/configure.py b/configure.py deleted file mode 100755 index f1cd118..0000000 --- a/configure.py +++ /dev/null @@ -1,146 +0,0 @@ -#!/usr/bin/env python2 - -import os,sys - -def write_if_different(filename,s): - try: - with open(filename, "r") as f: - ref = f.read() - except: - ref = "" - - if ref == s: - return - else: - with open(filename, "w") as f: - f.write(s) - - -with open("version",'r') as f: - version = f.read().strip().rsplit('=')[1] - -d_default = { - "VERSION" : version, - "IRPF90" : 'irpf90', - "FC" : 'gfortran -g -ffree-line-length-none -fPIC -fopenmp', - "FCFLAGS" : '-O2', - "RANLIB" : 'ranlib', - "AR" : 'ar', - "BUILD_SYSTEM" : 'make', - "NINJA" : 'ninja', -} - -CONFIG_FILES=' '.join([ os.path.join("config",x) for x in os.listdir('config') if x != '.empty']) - -def create_make_config(): - - try: - d = read_make_config() - except: - d = {} - - fmt = { "make.config" :'{0}={1}\n' , - ".make.config.sh": 'export {0}="{1}"\n' } - - for var,default in d_default.iteritems(): - if var not in d: - try: - cur = os.environ[var] - except KeyError: - cur = default - d[var]=cur - - for filename in fmt: - out = "" - for var,default in d_default.iteritems(): - cur = d[var] - out += fmt[filename].format(var,cur) - write_if_different(filename,out) - - return d - - - -def read_make_config(): - result = {} - with open("make.config",'r') as f: - for line in f.readlines(): - try: - key, value = line.strip().split('=',1) - except: - print "Error in make.config:" - print line - sys.exit(1) - result[key] = value - return result - - -def create_build_ninja(): - - d=create_make_config() - - d["irpf90_files"] = [ "src/{0}".format(x) for x in - """ - IRPF90_temp/build.ninja irpf90.make irpf90_entities - tags libezfio_groups-gen.py libezfio_util-gen.py - """.split() ] - - d["irpf90_sources"] = [ "src/{0}".format(x) for x in - """ - libezfio_error.irp.f create_ocaml.py groups_templates.py - libezfio_file.irp.f create_python.py - libezfio_groups.irp.f ezfio-head.py - libezfio_util.irp.f ezfio-tail.py read_config.py - f_types.py test.py groups.py - """.split() ] + [ "make.config" ] - - d["irpf90_files"] = ' '.join(d["irpf90_files"]) - d["irpf90_sources"] = ' '.join(d["irpf90_sources"]) - - - template = """ - -rule compile_irpf90 - command = bash -c 'source .make.config.sh ; cd src ; {IRPF90} --ninja' - description = Compiling IRPF90 - -rule build_irpf90_a - command = {NINJA} -C src/IRPF90_temp && touch $out - description = Compiling Fortran files - -rule build_libezfio_a - command = cp src/IRPF90_temp/irpf90.a lib/libezfio.a ; {RANLIB} lib/libezfio.a - description = Building libezfio.a - -rule build_libezfio_irp_a - command = cp lib/libezfio.a lib/libezfio_irp.a ; {AR} dv lib/libezfio_irp.a irp_stack.irp.o > /dev/null ; {RANLIB} lib/libezfio_irp.a - description = Building libezfio_irp.a - -rule build_python - command = cd src ; python2 create_python.py - description = Building Python module - -rule build_ocaml - command = cd src ; python2 create_ocaml.py - description = Building Ocaml module - -build {irpf90_files}: compile_irpf90 | {irpf90_sources} {CONFIG_FILES} - -build src/IRPF90_temp/irpf90.a: build_irpf90_a | {irpf90_files} - -build lib/libezfio.a: build_libezfio_a | src/IRPF90_temp/irpf90.a - -build lib/libezfio_irp.a: build_libezfio_irp_a | lib/libezfio.a - -build Python/ezfio.py: build_python | lib/libezfio.a - -build Ocaml/ezfio.ml: build_ocaml | lib/libezfio.a - -""" - d["CONFIG_FILES"] = CONFIG_FILES - write_if_different('generated.ninja',template.format(**d)) - - -if __name__ == '__main__': - - create_build_ninja() diff --git a/git-tools/install_tools.sh b/git-tools/install_tools.sh index 6eee1c2..4c8cca8 100755 --- a/git-tools/install_tools.sh +++ b/git-tools/install_tools.sh @@ -5,6 +5,6 @@ cd ../.git/hooks/ for i in commit-msg post-commit do - rm $i + rm --force -- $i ln -s $OLD_DIR/$i $PWD/$i done diff --git a/make.config b/make.config new file mode 100644 index 0000000..e37d250 --- /dev/null +++ b/make.config @@ -0,0 +1,9 @@ +VERSION ?= 1.4.0 +RANLIB ?= ranlib +IRPF90 ?= irpf90 +CC ?= gcc +FC ?= gfortran -g -ffree-line-length-none -fPIC # -fopenmp +FCFLAGS ?= -fPIC +AR ?= ar +RANLIB ?= ranlib +PYTHON ?= python2 diff --git a/src/Makefile b/src/Makefile index 085dadb..42cb4f6 100644 --- a/src/Makefile +++ b/src/Makefile @@ -29,7 +29,7 @@ export include irpf90.make -irpf90.make: $(wildcard *.irp.f) ../config/* system.c +irpf90.make: $(wildcard *.irp.f) ../config/* IRPF90_temp/system.o IRPF90_temp/system_f.o $(IRPF90) include ../version @@ -40,28 +40,30 @@ all: static ../Python/ezfio.py ../Ocaml/ezfio.ml static: ../lib/libezfio.a ../lib/libezfio_irp.a -system_c.o: system_c.c - $(CC) -c system_c -o system_c.o +IRPF90_temp/system.o: system.c + mkdir -p IRPF90_temp/ + $(CC) -c system.c -o IRPF90_temp/system.o -system_f.o: system_f.f90 - $(FC) -c system_f.f90 -o system_f.o +IRPF90_temp/system_f.o: system_f.f90 + mkdir -p IRPF90_temp/ + $(FC) -c system_f.f90 -o IRPF90_temp/system_f.o && cp system.mod IRPF90_temp/ ../lib/libezfio.a: IRPF90_temp/irpf90.a rm -f ../lib/libezfio.a - $(AR) cru ../lib/libezfio.a system_c.o system_f.o $(OBJ1) + $(AR) cru ../lib/libezfio.a IRPF90_temp/system_f.o IRPF90_temp/system.o $(OBJ1) $(RANLIB) ../lib/libezfio.a ../lib/libezfio_irp.a: ../lib/libezfio.a rm -f ../lib/libezfio_irp.a cp ../lib/libezfio.a ../lib/libezfio_irp.a - $(AR) dv ../lib/libezfio_irp.a irp_stack.irp.o system_c.o system_f.o + $(AR) dv ../lib/libezfio_irp.a irp_stack.irp.o $(RANLIB) ../lib/libezfio_irp.a ../Python/ezfio.py: ../lib/libezfio.a - python2 create_python.py + $(PYTHON) create_python.py ../Ocaml/ezfio.ml: ../lib/libezfio.a - python2 create_ocaml.py + $(PYTHON) create_ocaml.py diff --git a/src/libezfio_file.irp.f b/src/libezfio_file.irp.f index 65420f0..f43f5fa 100644 --- a/src/libezfio_file.irp.f +++ b/src/libezfio_file.irp.f @@ -148,7 +148,7 @@ subroutine ezfio_set_file(filename_in) character*(*) :: filename_in character(8) :: date - character(10) :: time + character(73) :: time character(32) :: user if (filename_in == '') then @@ -163,13 +163,13 @@ subroutine ezfio_set_file(filename_in) ! using keyword arguments call date_and_time(DATE=date,TIME=time) - open (unit=10, file=trim(libezfio_filename)//'/ezfio/creation', ACTION='WRITE', STATUS='UNKNOWN') - write(10,*), time, ' ', date - close(10) - open (unit=10, file=trim(libezfio_filename)//'/ezfio/user', ACTION='WRITE', STATUS='UNKNOWN') + open (unit=73, file=trim(libezfio_filename)//'/ezfio/creation', ACTION='WRITE', STATUS='UNKNOWN') + write(73,*) time, ' ', date + close(73) + open (unit=73, file=trim(libezfio_filename)//'/ezfio/user', ACTION='WRITE', STATUS='UNKNOWN') call getenv('USER',user) - write(10,*) user - close(10) + write(73,*) user + close(73) endif TOUCH libezfio_filename diff --git a/src/libezfio_util.irp.f b/src/libezfio_util.irp.f index dc174a8..429a722 100644 --- a/src/libezfio_util.irp.f +++ b/src/libezfio_util.irp.f @@ -22,6 +22,7 @@ ! 31062 Toulouse Cedex 4 ! scemama@irsamc.ups-tlse.fr + BEGIN_PROVIDER [ integer, PID ] &BEGIN_PROVIDER [ character*(256), PID_str ] implicit none @@ -64,7 +65,7 @@ subroutine ezfio_mkdir(path) call ezfio_error(irp_here,'Read-only file.') endif if (.not.ezfio_exists(path)) then - call mkdir(trim(path)) + call mkdir(trim(path)//char(0)) open(unit=libezfio_iunit,file=trim(path)//'/.version') write(libezfio_iunit,'(A)') libezfio_version close(libezfio_iunit) @@ -73,6 +74,7 @@ end subroutine subroutine libezfio_openz(filename,mode,err) + use system implicit none BEGIN_DOC ! Opens a compressed file @@ -84,7 +86,7 @@ subroutine libezfio_openz(filename,mode,err) err=1 if (mode(1:1) == 'r') then - call system('zcat '//trim(filename)//' > '//trim(fifo)) + call zcat(trim(filename)//char(0), trim(fifo)//char(0)) open(unit=libezfio_iunit,file=trim(fifo),form='FORMATTED',action='READ') err=0 else if (mode(1:1) == 'w') then @@ -118,6 +120,7 @@ subroutine libezfio_reopenz_unformatted(filename,mode,err) end subroutine libezfio_closez(filename,mode) + use system implicit none BEGIN_DOC ! Closes a compressed file @@ -127,7 +130,7 @@ subroutine libezfio_closez(filename,mode) fifo = trim(filename)//'.'//trim(PID_str) if (mode(1:1) == 'w') then close(unit=libezfio_iunit) - call system('gzip -c < '//trim(fifo)//' > '//trim(filename)) + call gzip(trim(fifo)//char(0), trim(filename)//char(0)) open(unit=libezfio_iunit,file=trim(fifo),form='FORMATTED',action='WRITE') endif close(unit=libezfio_iunit,status='DELETE') diff --git a/src/system.c b/src/system.c new file mode 100644 index 0000000..c04c006 --- /dev/null +++ b/src/system.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include "zlib.h" + +#include +#include +#include + + + +void fortran_mkdir(char* filename) { + if (mkdir (filename, S_IRWXU)) { + perror (strerror (errno)); + } +} + + +#define BUFSIZE 16384 +void gzip(char* filename, char* output) { + FILE* in = fopen(filename,"r"); + gzFile out = gzopen(output,"w"); + char buffer[BUFSIZE]; + unsigned int size; + while (!feof(in)) { + size = (unsigned int) fread (buffer, sizeof(char), BUFSIZE, in); + gzwrite(out, buffer, size); + } + fclose(in); + gzclose(out); +} + +void zcat(char* filename, char* output) { + gzFile in = gzopen(filename,"r"); + FILE* out = fopen(output,"w"); + char buffer[BUFSIZE]; + int size; + while (!gzeof(in)) { + size = gzread (in, buffer, BUFSIZE); + fwrite(buffer, sizeof(char), (size_t) size, out); + } + gzclose(in); + fclose(out); +} + diff --git a/src/system_c.c b/src/system_c.c deleted file mode 100644 index 2bd3ae5..0000000 --- a/src/system_c.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include -#include - - -void ezfio_mkdir(char* filename) { - errno = 0; - if (mkdir (filename, S_IRWXU)) { - perror (strerror (errno)); - } -} - diff --git a/src/system_f.f90 b/src/system_f.f90 index 8a9de58..0b35ae7 100644 --- a/src/system_f.f90 +++ b/src/system_f.f90 @@ -1,5 +1,4 @@ -MODULE system - +module system USE iso_c_binding INTERFACE @@ -7,6 +6,19 @@ MODULE system USE iso_c_binding CHARACTER(kind=C_CHAR),INTENT(in) :: filename(*) END SUBROUTINE - END INTERFACE -END MODULE + SUBROUTINE gzip(filename,output) BIND(C,name="gzip") + USE iso_c_binding + CHARACTER(kind=C_CHAR),INTENT(in) :: filename(*) + CHARACTER(kind=C_CHAR),INTENT(in) :: output(*) + END SUBROUTINE + + SUBROUTINE zcat(filename,output) BIND(C,name="zcat") + USE iso_c_binding + CHARACTER(kind=C_CHAR),INTENT(in) :: filename(*) + CHARACTER(kind=C_CHAR),INTENT(in) :: output(*) + END SUBROUTINE + + END INTERFACE +end module + diff --git a/version b/version index db1aeb8..8b0c5c7 100644 --- a/version +++ b/version @@ -1 +1 @@ -VERSION=1.3.5 +VERSION=1.4.0