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

iso_c_bindings

This commit is contained in:
Anthony Scemama 2019-01-21 18:01:02 +01:00
parent 6b215092c6
commit 744cbac511
5 changed files with 49 additions and 14 deletions

View File

@ -29,7 +29,7 @@ export
include irpf90.make
irpf90.make: $(wildcard *.irp.f) ../config/*
irpf90.make: $(wildcard *.irp.f) ../config/* system.c
$(IRPF90)
include ../version
@ -40,15 +40,21 @@ 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
system_f.o: system_f.f90
$(FC) -c system_f.f90 -o system_f.o
../lib/libezfio.a: IRPF90_temp/irpf90.a
rm -f ../lib/libezfio.a
$(AR) cru ../lib/libezfio.a $(OBJ1)
$(AR) cru ../lib/libezfio.a system_c.o system_f.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
$(AR) dv ../lib/libezfio_irp.a irp_stack.irp.o system_c.o system_f.o
$(RANLIB) ../lib/libezfio_irp.a

View File

@ -147,6 +147,9 @@ subroutine ezfio_set_file(filename_in)
END_DOC
character*(*) :: filename_in
character(8) :: date
character(10) :: time
character(32) :: user
if (filename_in == '') then
call ezfio_error(irp_here,'EZFIO file name is empty.')
@ -157,16 +160,16 @@ subroutine ezfio_set_file(filename_in)
if (.not.exists(libezfio_filename)) then
call ezfio_mkdir(libezfio_filename)
call ezfio_mkdir(trim(libezfio_filename)//'/ezfio')
call system('LANG= date > '//trim(libezfio_filename)//'/ezfio/creation')
call system('echo $USER > '//trim(libezfio_filename)//'/ezfio/user')
BEGIN_SHELL [ /usr/bin/env python2 ]
import os
command = "'echo %s > '//trim(libezfio_filename)//'/ezfio/library'"
cwd = os.getcwd()
cwd = cwd.split('src')[:-1]
cwd = '/'.join(cwd)
print "call system("+command%cwd+")"
END_SHELL
! 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')
call getenv('USER',user)
write(10,*) user
close(10)
endif
TOUCH libezfio_filename

View File

@ -53,6 +53,7 @@ logical function ezfio_exists(path)
end function
subroutine ezfio_mkdir(path)
use system
implicit none
BEGIN_DOC
! Creates a directory
@ -63,7 +64,7 @@ subroutine ezfio_mkdir(path)
call ezfio_error(irp_here,'Read-only file.')
endif
if (.not.ezfio_exists(path)) then
call system('mkdir '//trim(path))
call mkdir(trim(path))
open(unit=libezfio_iunit,file=trim(path)//'/.version')
write(libezfio_iunit,'(A)') libezfio_version
close(libezfio_iunit)

13
src/system_c.c Normal file
View File

@ -0,0 +1,13 @@
#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));
}
}

12
src/system_f.f90 Normal file
View File

@ -0,0 +1,12 @@
MODULE system
USE iso_c_binding
INTERFACE
SUBROUTINE mkdir(filename) BIND(C,name="fortran_mkdir")
USE iso_c_binding
CHARACTER(kind=C_CHAR),INTENT(in) :: filename(*)
END SUBROUTINE
END INTERFACE
END MODULE