fortran: how to call intrinsic function time() when I already have an array time -
i need time routine , want wallclock time, using time() routine. however, code has 2d array called time, when do: startt=time() thinks referring array. how around without changing array name?
i tried make function outside main program bypass doesn't work:
program timetest real time(0:10,0:10) ! dummy array demonstrate problem integer*8 startt,endt,tdif time=0 ! initialize dummy array 0 startt=gettime() call sleep(2) !stuff timed endt=gettime() tdif=endt-startt print*,"tdif= ",tdif end integer*8 function gettime() gettime=time() print*,"gettime= ",gettime end function
output:
gettime= 0
gettime= -9223372036854775808
tdif= 0
you can't have 2 different things visible in program unit same name. first recommendation use fortran standard intrinsic subroutine system_clock rather time().
the approach took separate routine should work if declared gettime correct datatype in caller. have it, gettime integer(4) in main program integer(8) in function itself. these need match.
Comments
Post a Comment