diff --git a/Bash/ezfio.sh b/Bash/ezfio.sh index 9d36360..991688d 100644 --- a/Bash/ezfio.sh +++ b/Bash/ezfio.sh @@ -4,7 +4,7 @@ EZFIO_ROOT=$( cd $(dirname "${BASH_SOURCE}")/.. ; pwd -P ) function _ezfio_py() { - python ${EZFIO_ROOT}/Python/ezfio.py $@ + python "${EZFIO_ROOT}/Python/ezfio.py" $@ } @@ -84,11 +84,11 @@ function _ezfio_set_file() { _require_first_argument $@ || return 1 - if [[ ! -d $1 ]] + if [[ ! -d "$1" ]] then - mkdir -p $1 || return 1 + mkdir -p "$1" || return 1 fi - export EZFIO_FILE=$1 + export EZFIO_FILE="$1" _ezfio_info "Set file ${EZFIO_FILE}" return 0 } @@ -106,12 +106,12 @@ function _ezfio_has() _require_ezfio_file || return 1 _require_first_argument $@ || return 1 - if [[ ! -d ${EZFIO_FILE}/${1,,} ]] + if [[ ! -d "${EZFIO_FILE}/${1,,}" ]] then return 1 fi - if [[ -z $2 ]] + if [[ -z "$2" ]] then return 0 fi @@ -123,14 +123,14 @@ function _ezfio_get() { _require_ezfio_file || return 1 - if [[ -z $1 ]] + if [[ -z "$1" ]] then ls ${EZFIO_FILE} && return 0 || return 1 fi - if [[ -z $2 ]] + if [[ -z "$2" ]] then - ls ${EZFIO_FILE}/${1,,} && return 0 || return 1 + ls "${EZFIO_FILE}/${1,,}" && return 0 || return 1 fi _ezfio_py get $@ && return 0 || return 1 @@ -142,11 +142,11 @@ function _ezfio_set() _require_first_argument $@ || return 1 _require_second_argument $@ || return 2 - if [[ -z $3 ]] + if [[ -z "$3" ]] then _ezfio_py set $@ || return 1 else - echo $3 | _ezfio_py set $1 $2 || return 1 + echo "$3" | _ezfio_py set "$1" "$2" || return 1 fi return 0 } diff --git a/C/.empty b/C/.empty new file mode 100644 index 0000000..e69de29 diff --git a/Makefile b/Makefile index 5ac6182..88b078f 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ include make.config .PHONY: default clean veryclean archive default: make.config - cd src && $(MAKE) + cd src && BUILD_SYSTEM=make $(MAKE) clean: - bash -c "[[ -f lib/libezfio.a ]] && rm $$PWD/lib/*" diff --git a/bin/archive_ezfio.py b/bin/archive_ezfio.py index 82a5140..cb09c9f 100755 --- a/bin/archive_ezfio.py +++ b/bin/archive_ezfio.py @@ -37,7 +37,7 @@ def main(): f_name = f[4:] try: exec """d['%s'] = ezfio.%s"""%(f_name,f_name) - except: + except IOError: if do_verbose: print "%-40s [%5s]"%(f_name, "Empty") else: diff --git a/configure.py b/configure.py index 86e8773..0f86bb3 100755 --- a/configure.py +++ b/configure.py @@ -26,7 +26,7 @@ d_default = { "FCFLAGS" : '-O2', "RANLIB" : 'ranlib', "AR" : 'ar', - "NINJA" : 'ninja', + "BUILD_SYSTEM" : 'make' } CONFIG_FILES=' '.join([ os.path.join("config",x) for x in os.listdir('config') if x != '.empty']) @@ -112,7 +112,7 @@ rule build_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 + command = cp lib/libezfio.a lib/libezfio_irp.a ; {RANLIB} lib/libezfio_irp.a description = Building libezfio_irp.a rule build_python @@ -141,5 +141,4 @@ build Ocaml/ezfio.ml: build_ocaml | lib/libezfio.a if __name__ == '__main__': - - create_build_ninja() + create_build_ninja() diff --git a/src/Makefile b/src/Makefile index 91f9ae6..66cdeb5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,60 +1,71 @@ -# EZFIO is an automatic generator of I/O libraries -# Copyright (C) 2009 Anthony SCEMAMA, CNRS -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Anthony Scemama -# LCPQ - IRSAMC - CNRS -# Universite Paul Sabatier -# 118, route de Narbonne -# 31062 Toulouse Cedex 4 -# scemama@irsamc.ups-tlse.fr - -DEFAULT_TARGET: all - +.EXPORT_ALL_VARIABLES: include ../make.config -export -include irpf90.make +# Dark magic below modify with caution! +# "You are Not Expected to Understand This" +# . +# /^\ . +# /\ "V", +# /__\ I O o +# //..\\ I . +# \].`[/ I +# /l\/j\ (] . O +# /. ~~ ,\/I . +# \\L__j^\/I o +# \/--v} I o . +# | | I _________ +# | | I c(` ')o +# | l I \. ,/ +# _/j L l\_! _//^---^\\_ -irpf90.make: $(wildcard *.irp.f) ../config/* - $(IRPF90) -include ../version +ifeq ($(BUILD_SYSTEM),ninja) + BUILD_FILE=IRPF90_temp/build.ninja + IRPF90FLAGS += -j +else ifeq ($(BUILD_SYSTEM),make) + BUILD_FILE=IRPF90_temp/build.make + BUILD_SYSTEM += -j +else +DUMMY: + $(error 'Wrong BUILD_SYSTEM: $(BUILD_SYSTEM)') +endif + +define run_and_touch + $(BUILD_SYSTEM) -C $(dir $(1) ) -f $(notdir $(1) ) $(addprefix $(CURDIR)/, $(2)) && touch $(2) +endef + +export PYTHONPATH:=$(CURDIR):$(PYTHONPATH) + .PHONY: static all all: static ../Python/ezfio.py ../Ocaml/ezfio.ml - static: ../lib/libezfio.a ../lib/libezfio_irp.a ../lib/libezfio.a: IRPF90_temp/irpf90.a rm -f ../lib/libezfio.a - $(AR) cru ../lib/libezfio.a $(OBJ1) + cp IRPF90_temp/irpf90.a ../lib/libezfio.a $(RANLIB) ../lib/libezfio.a +#No more irp_stack ../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 - $(RANLIB) ../lib/libezfio_irp.a -../Python/ezfio.py: +../Python/ezfio.py: ../lib/libezfio.a python create_python.py -../Ocaml/ezfio.ml: +../Ocaml/ezfio.ml: ../lib/libezfio.a python create_ocaml.py +IRPF90_temp/irpf90.a: $(BUILD_FILE) + $(call run_and_touch, $<, $@) +$(BUILD_FILE): $(shell find . -maxdepth 2 -path ./IRPF90_temp -prune -o -name '*.irp.f' -print) ../config/* + $(IRPF90) $(IRPF90FLAGS) + +clean: + rm -f -- $(BUILD_FILE) $(shell find IRPF90_temp -type f \( -name "*.o" -o -name "*.mod" -name "*.a" \) -delete;) + rm -f ../lib/libezfio.a ../lib/libezfio_irp.a + +veryclean: clean + rm -rf IRPF90_temp/ IRPF90_man/ irpf90_entities dist tags diff --git a/src/f_types.py b/src/f_types.py index d1c5d43..b70bfd2 100644 --- a/src/f_types.py +++ b/src/f_types.py @@ -27,7 +27,7 @@ format= { 'integer' : ["'(I20)'", "%20d"], 'real' : ["'(E24.15)'","%24.15E"], 'double precision': ["'(E24.15)'","%24.15E"], - 'logical' : ["'(L)'","%c"], + 'logical' : ["'(L1)'","%c"], 'character*(*)' : ["'(A)'","%s"] } diff --git a/src/groups.py b/src/groups.py index 83dd175..27f69c8 100644 --- a/src/groups.py +++ b/src/groups.py @@ -40,6 +40,9 @@ print >>file_py, """ version = property(fset=None,fget=get_version) """%(v) +file_c = open("../C/ezfio.h","w") +print >>file_c, c_header + import sys for group in groups.keys(): @@ -77,6 +80,7 @@ for group in groups.keys(): 'group': group, 'dims': strdims} print attributes%d + print >>file_c, attributes_c%d print >>file_py, attributes_py%d else: d = { 'type': type, @@ -96,6 +100,7 @@ for group in groups.keys(): 'dims_py': dims_py, 'dims': dims } print buffered%d + print >>file_c, buffered_c%d print >>file_py, buffered_py%d else: dims_loop = '' @@ -142,5 +147,9 @@ for group in groups.keys(): 'declar_loop' : declar_loop} print attributes_arr%d print >>file_py, attributes_arr_py%d + print >>file_c, attributes_arr_c%d +print >>file_c, c_footer file_py.close() +file_c.close() + diff --git a/src/groups_templates.py b/src/groups_templates.py index 4e14c24..1150088 100644 --- a/src/groups_templates.py +++ b/src/groups_templates.py @@ -239,38 +239,48 @@ end #--------- attributes_c = """ -void ezfio_set_%(group)s_%(var)s(%(type)s %(var)s) +void ezfio_set_%(group)s_%(var)s(%(ctype)s %(var)s) { ezfio_set_%(group)s_%(var)s_(&%(var)s); } + +void ezfio_get_%(group)s_%(var)s(%(ctype)s *%(var)s) +{ + ezfio_get_%(group)s_%(var)s_(%(var)s); +} + +int ezfio_has_%(group)s_%(var)s() +{ + ezfio_has_%(group)s_%(var)s_(); +} """ -c_header = """ -#ifndef EZFIO_H -#define EZFIO_H +attributes_arr_c = """ +void ezfio_set_%(group)s_%(var)s(%(ctype)s %(var)s) +{ + ezfio_set_%(group)s_%(var)s_(&%(var)s); +} + +void ezfio_get_%(group)s_%(var)s(%(ctype)s *%(var)s) +{ + ezfio_get_%(group)s_%(var)s_(%(var)s); +} + +int ezfio_has_%(group)s_%(var)s() +{ + ezfio_has_%(group)s_%(var)s_(); +} +""" + +calculated_c = attributes_c + +c_header = """#ifndef EZFIO_H\n#define EZFIO_H + +#include #ifdef __cplusplus extern "C" { #endif -""" - -c_footer = """ -#ifdef __cplusplus -} -#endif -#endif -""" - - -file_h = [c_header] -file_h +=[ """ -void ezfio_set_file_(char* filename, long filename_size); - -void ezfio_read_buffer_(int* indices,double* values, int* isize); -void ezfio_write_buffer_(int* indices,double* values, int* isize); -"""] - -file_c = [ """ typedef struct { @@ -282,7 +292,7 @@ void ezfio_set_file(char* filename) { long len; len = strlen(filename); - ezfio_set_file_(filename,mlen); + ezfio_set_file_(filename,len); } sparse ezfio_read_buffer(int isize) @@ -297,7 +307,15 @@ void ezfio_write_buffer(sparse data, int isize) ezfio_write_buffer_(data.indices,data.values,&isize); } -""" ] +""" + +c_footer = """ +#ifdef __cplusplus +} +#endif +#endif +""" + diff --git a/src/libezfio_file.irp.f b/src/libezfio_file.irp.f index 860eb8e..9334a2a 100644 --- a/src/libezfio_file.irp.f +++ b/src/libezfio_file.irp.f @@ -128,16 +128,16 @@ logical function exists(path) character*(*) :: path character*(32) :: V inquire(file=trim(path)//'/.version',exist=exists) - if (exists) then - open(libezfio_iunit,file=trim(path)//'/.version') - read(libezfio_iunit,*) V - close(libezfio_iunit) +! if (exists) then +! open(libezfio_iunit,file=trim(path)//'/.version') +! read(libezfio_iunit,*) V +! close(libezfio_iunit) ! integer :: char_to_version ! if (char_to_version(V) > char_to_version(libezfio_version)) then ! call ezfio_error(irp_here, 'This file was generated with version '//trim(V)//& ! ' but the current installed version is '//trim(libezfio_version)//'') ! endif - endif +! endif end function subroutine ezfio_set_file(filename_in) diff --git a/src/libezfio_util.irp.f b/src/libezfio_util.irp.f index 3d6a9b0..1ab88b4 100644 --- a/src/libezfio_util.irp.f +++ b/src/libezfio_util.irp.f @@ -23,14 +23,21 @@ ! scemama@irsamc.ups-tlse.fr BEGIN_PROVIDER [ integer, PID ] -&BEGIN_PROVIDER [ character*(8), PID_str ] +&BEGIN_PROVIDER [ character*(256), PID_str ] implicit none BEGIN_DOC ! Current process ID END_DOC integer :: getpid + character*(240) :: hostname PID = getpid() write(PID_str,'(I8.8)') PID + call HOSTNM(hostname) + write(PID_str,'(A,''.'',I8.8,X)') trim(hostname), PID + PID_str = trim(PID_str) + print *, PID_str + call sleep(1) + END_PROVIDER logical function ezfio_exists(path) @@ -75,7 +82,7 @@ subroutine libezfio_openz(filename,mode,err) character*(*) :: filename, mode character*(1024) :: fifo integer :: err - fifo = trim(filename)//'.'//PID_str + fifo = trim(filename)//'.'//trim(PID_str) err=1 if (mode(1:1) == 'r') then @@ -97,7 +104,7 @@ subroutine libezfio_closez(filename,mode) END_DOC character*(*) :: filename, mode character*(1024) :: fifo - fifo = trim(filename)//'.'//PID_str + fifo = trim(filename)//'.'//trim(PID_str) if (mode(1:1) == 'w') then close(unit=libezfio_iunit) call system('gzip -c < '//trim(fifo)//' > '//trim(filename)) @@ -141,7 +148,7 @@ subroutine ezfio_write_%(type_short)s(dir,fil,dat) if (libezfio_read_only) then call ezfio_error(irp_here,'Read-only file.') endif - l_filename(1)=trim(dir)//'/.'//fil//'.'//PID_str + l_filename(1)=trim(dir)//'/.'//fil//'.'//trim(PID_str) l_filename(2)=trim(dir)//'/'//fil open(unit=libezfio_iunit,file=l_filename(1),form='FORMATTED',action='WRITE') write(libezfio_iunit,%(fmt)s) dat @@ -216,7 +223,7 @@ subroutine ezfio_write_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat) if (libezfio_read_only) then call ezfio_error(irp_here,'Read-only file.') endif - l_filename(1)=trim(dir)//'/.'//fil//PID_str//'.gz' + l_filename(1)=trim(dir)//'/.'//fil//trim(PID_str)//'.gz' l_filename(2)=trim(dir)//'/'//fil//'.gz' err = 0