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 + +/* --------------------------------------------------------------- */ +/* --------------------------------------------------------------- */