Compare commits

...

3 Commits

Author SHA1 Message Date
tTh f8d5e66a5c ugly but working 2023-06-03 12:05:56 +02:00
tTh 86553a65b5 boilerplate 2023-06-03 11:50:48 +02:00
tTh 5beab6c306 bla 2023-06-03 11:50:04 +02:00
8 changed files with 165 additions and 0 deletions

2
Call_the_C/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
call_the_c
*.o

20
Call_the_C/Makefile Normal file
View File

@ -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 $@
# ----------------------------------------------------------

12
Call_the_C/README.md Normal file
View File

@ -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.

15
Call_the_C/call_the_c.f90 Normal file
View File

@ -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

24
Call_the_C/first-try.c Normal file
View File

@ -0,0 +1,24 @@
/*
* first try of a C func called from Fortran
*/
#include <stdio.h>
#include <unistd.h>
/* --------------------------------------------------------------- */
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;
}
/* --------------------------------------------------------------- */

11
Call_the_C/soundfiles.c Normal file
View File

@ -0,0 +1,11 @@
/*
* SOUNDFILES
* ----------
*
* Interface pour libsndfile
*/
#include <stdio.h>
/* --------------------------------------------------------------- */
/* --------------------------------------------------------------- */

48
Modules/centermag.f90 Normal file
View File

@ -0,0 +1,48 @@
module centermag
implicit none
!-----------------------------------------------------------------------
! definition of structures
!-
type t_centermag
integer :: wscr, hscr ! "physycal" screen size
real :: mag = 1.0 ! magnitude factor
real :: cx, cy ! the center
integer :: flag = 0
end type
!-------------------------------------------------------------------
contains
!-------------------------------------------------------------------
subroutine print_centermag (cm)
type(t_centermag), intent(in) :: cm
print *, "Screen ", cm%wscr, cm%hscr
print *, "MagFactor ", cm%mag
print *, "Center ", cm%cx, cm%cy
end subroutine
!-------------------------------------------------------------------
subroutine centermag_scr2real (sx, sy, rx, ry)
integer, intent(in) :: sx, sy
real, intent(out) :: rx, ry
print *, 'from scr :', sx, sy
rx = 999.999
ry = 666.666
end subroutine
!-------------------------------------------------------------------
subroutine centermag_real2scr (rx, ry, sx, sy)
real, intent(in) :: rx, ry
integer, intent(out) :: sx, sy
print *, 'from real :', rx, ry
sx = -1
sy = -1
end subroutine
!-------------------------------------------------------------------
end module

33
Modules/mathstuff2.f90 Normal file
View File

@ -0,0 +1,33 @@
module mathstuff2
! XXX This module was a copy of mathstuff.f90 fromthe BloubWorld
! XXX will be moved in an other place some day...
implicit none
contains
! ----------------------------------------------------------------
! really quick'n'dirty hack
! not really tested yet...
subroutine init_random_seed()
integer, dimension(3) :: tarray
integer :: t3, foo
real :: dummy
call itime(tarray)
t3 = 3600*tarray(1) + 60*tarray(2) + tarray(3)
! write(0, '(A,3I3,A,I6)') "sranding: ", tarray, " --> ", t3
call srand(t3)
! after initializing the random generator engine,
! you MUST use it for initializing the initializer
do foo=1, tarray(1)+5
dummy = rand()
enddo
end subroutine
! ----------------------------------------------------------------
end module mathstuff2