I wrote a FORTRAN program using the date_and_time function. The source follows below. The date_and_time function returns the wrong time in the cygwin environment: I am not in UTC, so czone should be +0100. However, in the windows cmd environment, the results are correct. The question is now: Why does the date_and_time function not work properly in the cygwin environment, when compiled with the ifort compiler, whereas date() and time() do? Do I miss setting some environment variables? Should I use some compiler options? I have posted this question also in the Cygwin mailing list, but so far, I still have no clue about what may be wrong.
In the following output, the lines "ctime:..." to "milliseconds..." are based on time_and_date. The line 15:54:49 is the correct time obtained by the time function, and the line 23-JAN-13 is the correct date obtained by the date function.
ctime: 20130123
cdate: 145449.947
czone: -0000
@ 2013-01-23 14:54:49.947
year 2013
month 1
day 23
diff wrt UTC 0 minutes
hours 14
minutes 54
seconds 49
milliseconds 947
15:54:49
23-JAN-13
I have done some experiments to narrow down the problem:
* compiling with gfortran: time_gfortran.exe gives correct result in Cygwin
* compiling with g95: time_g95.exe gives the correct result in Cygwin
* compiling with ifort: time_ifort.exe gives the wrong time in Cygwin
After copying cygwin1.dll, cyggfortran-3.dll and cyggcc_s-1.dll to the working directory, I get correct results
using the three executables in c:\windows\system32\cmd.exe.
I suspect that the intel compiler does a different system call for time_and_date than for date and time. I am still baffled why the same source runs fine for gfortran and g95. Notice however that for these compilers, the _date_ and _time_ functions are not defined. Hence the preprocessor exclusion in the source.
Regards,
Marten Jan
The following example comes from the documentation:
Consider the following
example executed on 2000 March 28 at 11:04:14.5:
INTEGER DATE_TIME (8)
CHARACTER (LEN = 12)
REAL_CLOCK (3)
CALL DATE_AND_TIME (REAL_CLOCK (1), REAL_CLOCK (2), &
REAL_CLOCK (3), DATE_TIME)
This assigns the value "20000328" to REAL_CLOCK (1), the value "110414.500" to REAL_CLOCK (2), and the value "-0500" to REAL_CLOCK (3). The following values are assigned to DATE_TIME:
2000, 3, 28, -300, 11, 4, 14, and 500.
The following is the source of my program:
program time_and_date
implicit none
character (len=8) cdate
character (len=10) ctime
character (len=5) czone
integer(4) ival(8)
integer(4) yr,mon,day,hr,min,sec,ms
call date_and_time(cdate,ctime,czone,ival)
read (cdate(1:4),*) yr
read (cdate(5:6),*) mon
read (cdate(7:8),*) day
read (ctime(1:2),*) hr
read (ctime(3:4),*) min
read (ctime(5:6),*) sec
read (ctime(8:10),*) ms
print *,'cdate ',cdate
print *,'ctime ',ctime
print *,'czone ',czone
print "('@ ',i4,'-',i2.2,'-',i2.2,'',i2.2,':',i2.2,':',i2.2,'.',i3.3)", yr,mon,day,hr,min,sec,ms
print *,'year ',ival(1)
print *,'month ',ival(2)
print *,'day ',ival(3)
print *,'diff wrt UTC ',ival(4),' minutes'
print *,'hours ',ival(5)
print *,'minutes ',ival(6)
print *,'seconds ',ival(7)
print *,'milliseconds ',ival(8)
print *
#ifdef IFORT
call time(ctime)
print *,ctime
call date(ctime)
print *,ctime
#endif
print *,'done'
end program