From f8d5e66a5cdd60f065e007e0efed735437c409a6 Mon Sep 17 00:00:00 2001 From: tTh Date: Sat, 3 Jun 2023 12:05:56 +0200 Subject: [PATCH] ugly but working --- Call_the_C/.gitignore | 2 ++ Call_the_C/Makefile | 20 ++++++++++++++++++++ Call_the_C/README.md | 12 ++++++++++++ Call_the_C/call_the_c.f90 | 15 +++++++++++++++ Call_the_C/first-try.c | 24 ++++++++++++++++++++++++ Call_the_C/soundfiles.c | 11 +++++++++++ 6 files changed, 84 insertions(+) create mode 100644 Call_the_C/.gitignore create mode 100644 Call_the_C/Makefile create mode 100644 Call_the_C/README.md create mode 100644 Call_the_C/call_the_c.f90 create mode 100644 Call_the_C/first-try.c create mode 100644 Call_the_C/soundfiles.c diff --git a/Call_the_C/.gitignore b/Call_the_C/.gitignore new file mode 100644 index 0000000..6f37e65 --- /dev/null +++ b/Call_the_C/.gitignore @@ -0,0 +1,2 @@ +call_the_c +*.o diff --git a/Call_the_C/Makefile b/Call_the_C/Makefile new file mode 100644 index 0000000..6b27e6e --- /dev/null +++ b/Call_the_C/Makefile @@ -0,0 +1,20 @@ +# +# Fortran calls to a C function +# + +all: call_the_c + +# ---------------------------------------------------------- + +first-try.o: first-try.c Makefile + gcc -Wall -g -c $< + +soundfiles.o: soundfiles.c Makefile + gcc -Wall -g -c $< + +# ---------------------------------------------------------- + +call_the_c: call_the_c.f90 Makefile first-try.o + gfortran -Wall -g $< first-try.o -o $@ + +# ---------------------------------------------------------- diff --git a/Call_the_C/README.md b/Call_the_C/README.md new file mode 100644 index 0000000..8b88f35 --- /dev/null +++ b/Call_the_C/README.md @@ -0,0 +1,12 @@ +# Calling a C function + +WARNING : THIS IS A WIP ! + +## Unix utilities + +getpid, sleep, ... + +## libsndfile + +Bibliothèque de fonctions pour lire et écrire les fichiers sonores. + diff --git a/Call_the_C/call_the_c.f90 b/Call_the_C/call_the_c.f90 new file mode 100644 index 0000000..29cfbfd --- /dev/null +++ b/Call_the_C/call_the_c.f90 @@ -0,0 +1,15 @@ +program call_the_c + implicit none + + integer :: foo + integer, external :: give_me_my_pid + + print *, "XXX we are calling a C func" + call first_try () + foo = give_me_my_pid() + print *, "process id = ", foo + print *, "XXX are we alive ?" + +end program + + diff --git a/Call_the_C/first-try.c b/Call_the_C/first-try.c new file mode 100644 index 0000000..5dcd848 --- /dev/null +++ b/Call_the_C/first-try.c @@ -0,0 +1,24 @@ +/* + * first try of a C func called from Fortran + */ + +#include +#include + +/* --------------------------------------------------------------- */ +void first_try_(void) +{ +fprintf(stderr, " pid=%u file='%s' func='%s' \n", + (long)getpid(), __FILE__, __func__); +} +/* --------------------------------------------------------------- */ +long give_me_my_pid_ (void) +{ +pid_t my_pid; + +my_pid = (long)getpid(); +fprintf(stderr, " %s -> %d\n", __func__, my_pid); + +return my_pid; +} +/* --------------------------------------------------------------- */ diff --git a/Call_the_C/soundfiles.c b/Call_the_C/soundfiles.c new file mode 100644 index 0000000..3757662 --- /dev/null +++ b/Call_the_C/soundfiles.c @@ -0,0 +1,11 @@ +/* + * SOUNDFILES + * ---------- + * + * Interface pour libsndfile + */ + +#include + +/* --------------------------------------------------------------- */ +/* --------------------------------------------------------------- */