sleep in g95 is a basically a wrapper for the libc sleep, which also
sleeps in seconds. If you read the libc info for sleep
http://www.delorie.com/gnu/docs/glibc/libc_445.html
you'll find that they suggest to use 'select'
http://www.delorie.com/gnu/docs/glibc/libc_248.html
so I would suggest that you code a simple 'sleep' function that takes
a real argument and write the corresponding C code based on select to
do just that. If you have something working, I would suggest to send
the code to Andy, I think that a sleep command that takes a real would
be a nice extension.
Cheers,
Joost
an integer number of nano seconds is another option, like e.g. below
Helge
/avle@fimm: > cat sleep.c
#include <time.h>
int ftnsleep_(long *nano_seconds, int *ierr){
struct timespec sleeptime ;
sleeptime.tv_sec = 0 ;
sleeptime.tv_nsec = *nano_seconds ;
*ierr = nanosleep(&sleeptime, NULL);
}
/avle@fimm: > cat wait.f90
integer(8) :: ns=800000000
call ftnsleep(ns,ierr)
print *,'waited',ns,'nano seconds',ierr
end
/avle@fimm: > gcc -c sleep.c
/avle@fimm: > g95 wait.f90 sleep.o && ./a.out
waited 800000000 nano seconds 0
/avle@fimm: >
Helge
MODULE TEST
USE ISO_C_BINDING, ONLY : C_INT
IMPLICIT NONE
INTERFACE
SUBROUTINE millisleep(n) BIND(C,name="Sleep")
USE ISO_C_BINDING, ONLY : C_INT
INTEGER(C_INT), VALUE :: n
END SUBROUTINE millisleep
END INTERFACE
END MODULE TEST
USE TEST
INTEGER :: count1,count2,count_rate
REAL :: t1,t2
write(6,*) "Hi 1"
CALL sleep(1)
write(6,*) "Hi 2"
CALL CPU_TIME(t1)
CALL SYSTEM_CLOCK(count=count1,count_rate=count_rate)
CALL millisleep(%VAL(150_C_INT))
CALL SYSTEM_CLOCK(count=count2)
CALL CPU_TIME(t2)
write(6,*) "Hi 3, CPU TIME: ",t2-t1," REAL TIME
",REAL(count2-count1)/count_rate
END
> ./a.exe
Hi 1
Hi 2
Hi 3, CPU TIME: 0. REAL TIME 0.1492
However, I also think it highlights some bugs in the g95 ISO_C_BINDING
implementation, since I seem to need the first call to sleep to pull in
the Sleep, the %VAL should also be unneeded, and there are some
warnings at link time concerning stdcall... However,all of this is just
tested in a cygwin setup, things might be different from mingw.
Joost
SUBROUTINE millisleep(n) BIND(C,name="Sleep@4")
instead of the original declaration. I don't know if this is papering
over a real problem...
Joost
The need for a first call to sleep must be a cygwin thing, because I
can comment that out without effect under MinGW. Thanks to both of
you. Although I really needed the Win32 solution, I'm sure someone
will be glad to find the BSD solution as well. And having them both on
the same thread points to the portability issues here.
Thanks again!
Joost