1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-12-22 12:23:56 +01:00

Added some iso_c_bindings

This commit is contained in:
Anthony Scemama 2020-10-14 01:43:13 +02:00
parent be89fd6fe2
commit baf48d1987
3 changed files with 65 additions and 18 deletions

View File

@ -1,11 +1,18 @@
CC=gcc
CFLAGS=
FC=gfortran
FFLAGS=
SOURCE_FILES=$(wildcard *.org)
%.o: %.c.org
- emacs --quick --no-init-file --batch --eval "(require 'org)" --eval '(org-babel-tangle-file "$^")'
- $(CC) $(CFLAGS) -c $*.c -o $@
- rm -f $*.c $*.h
%.c %_f.f90 %.h: %.c.org
emacs --quick --no-init-file --batch --eval "(require 'org)" --eval '(org-babel-tangle-file "$^")'
%.o: %.c
$(CC) $(CFLAGS) -c $*.c -o $*.o
%.o: %.f90
$(FC) $(FFLAGS) -c $*.f90 -o $*.o

View File

@ -2,15 +2,16 @@
** Introduction
Source files are written in org-mode format, to provide useful comments and
LaTex formulas close to the code. There exists multiple possibilities to convert
org-mode files into different formats such as HTML or pdf.
Source files are written in org-mode format, to provide useful
comments and LaTex formulas close to the code. There exists multiple
possibilities to convert org-mode files into different formats such as
HTML or pdf.
The code is extracted from the org files using Emacs in the =Makefile=, and
then the produced files are compiled.
The code is extracted from the org files using Emacs in the =Makefile=,
and then the produced files are compiled.
For a better experience, editing can be done with Emacs. Note that Emacs can
behave like Vim when switched into ``Evil'' mode.
For a better experience, editing can be done with Emacs. Note that
Emacs can behave like Vim when switched into ``Evil'' mode.
** Documentation

View File

@ -1,12 +1,16 @@
# -*- mode: org -*-
This file is written in C because it is more natural to express the context in
C than in Fortran. This file also produces the Fortran binding.
#+BEGIN_SRC C :tangle qmckl_context.c
#include <stdlib.h> /* malloc */
#include "qmckl_context.h"
#+END_SRC
* Context
The context variable is a handle for the state of the library, and
is stored in the following data structure, which can't be seen
outside of the library.
@ -15,15 +19,15 @@
#define QMCKL_DEFAULT_PRECISION 53
#define QMCKL_DEFAULT_RANGE 2
typedef long int qmckl_context ;
typedef long long int qmckl_context ;
#+END_SRC
#+BEGIN_SRC C :tangle qmckl_context.c
typedef struct qmckl_context_struct_ {
struct qmckl_context_struct_ * prev;
int precision;
int range;
int precision;
int range;
} qmckl_context_struct;
#+END_SRC
@ -52,7 +56,23 @@ qmckl_context qmckl_context_create() {
return (qmckl_context) context;
}
#+END_SRC
#+BEGIN_SRC fortran :tangle qmckl_context_f.f90
integer(8) function qmckl_context_create()
use, intrinsic :: iso_c_binding
implicit none
interface
integer(c_long_long) function c_qmckl_context_create() &
bind(C, name='qmckl_context_create')
use, intrinsic :: iso_c_binding, only : c_long_long
end function
end interface
qmckl_context_create = c_qmckl_context_create()
end
#+END_SRC
#+BEGIN_SRC C :tangle qmckl_context.h
qmckl_context qmckl_context_copy(qmckl_context context);
@ -72,13 +92,32 @@ qmckl_context qmckl_context_copy(qmckl_context context) {
old_context = (qmckl_context_struct*) context;
new_context->prev = old_context;
new_context->precision = old_context->precision;
new_context->precision = old_context->precision;
new_context->range = old_context->range;
return (qmckl_context) new_context;
}
#+END_SRC
#+BEGIN_SRC fortran :tangle qmckl_context_f.f90
integer(8) function qmckl_context_copy(context)
use, intrinsic :: iso_c_binding
implicit none
integer(8), intent(in) :: context
interface
integer(c_long_long) function c_qmckl_context_copy(context) &
bind(C, name='qmckl_context_copy')
use, intrinsic :: iso_c_binding, only : c_long_long
integer(c_long_long), intent(in) :: context
end function
end interface
qmckl_context_copy = c_qmckl_context_copy(context)
end
#+END_SRC
* Precision