10
0
mirror of https://gitlab.com/scemama/EZFIO.git synced 2024-12-22 04:13:34 +01:00

Removed Ninja

Version:1.4.0

Version:1.4.0
This commit is contained in:
Anthony Scemama 2019-01-21 23:21:20 +01:00
parent 744cbac511
commit fa6d40a857
15 changed files with 127 additions and 251 deletions

View File

@ -1,4 +1,7 @@
#!/bin/bash
#
# ezfio shell command with completion
#
EZFIO_ROOT=$( cd $(dirname "${BASH_SOURCE}")/.. ; pwd -P )

View File

@ -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}

View File

@ -4,8 +4,8 @@ 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
@ -19,7 +19,8 @@ The following packages are needed:
* `IRPF90 <http://irpf90.ups-tlse.fr>`_
* `Python <http://www.python.org>`_
* `GNU make <http://www.python.org>`_ or `Ninja <http://github.com/martine/ninja>`_
* `GNU make <https://www.gnu.org/software/make>`_
* `Zlib <https://www.zlib.net>`_
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 ``<container>_<data>`` 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 ``<container>_<data>`` 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

View File

@ -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

View File

@ -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()

View File

@ -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

9
make.config Normal file
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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')

45
src/system.c Normal file
View File

@ -0,0 +1,45 @@
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "zlib.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
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);
}

View File

@ -1,13 +0,0 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <string.h>
void ezfio_mkdir(char* filename) {
errno = 0;
if (mkdir (filename, S_IRWXU)) {
perror (strerror (errno));
}
}

View File

@ -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

View File

@ -1 +1 @@
VERSION=1.3.5
VERSION=1.4.0