Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

TIme stamp for time series data

Gerdes_Gerhard_J
Beginner
908 Views

Task: create time stamps to check times series data (10-minute data, one year) in an ASCII-file

To check data, I use UNPACKTIMEQQ to create continous time stamps to compare to a file with measurment data (time series with 10 minute steps) and I reversly use PACKTIMEQQ.

UNPACKTIMEQQ creates this time series, but unfortunately it does not neglect day light changing. It switches to summer time in March and back to winter time in autumn. This makes it difficult to use for measurement data, which consequently stick to UTC.

UNPACKTIMEQQ and PACKTIMEQQ are easy to use routines. Are there alterntative routine without the day light saving restriction, easy to use?

Thanks

Example of daylight saving shift at 2h:

...

25.03.2012 00:00:00
25.03.2012 00:10:00
25.03.2012 00:20:00
25.03.2012 00:30:00
25.03.2012 00:40:00
25.03.2012 00:50:00
25.03.2012 01:00:00
25.03.2012 01:10:00
25.03.2012 01:20:00
25.03.2012 01:30:00
25.03.2012 01:40:00
25.03.2012 01:50:00
25.03.2012 03:00:00
25.03.2012 03:10:00
25.03.2012 03:20:00
25.03.2012 03:30:00
25.03.2012 03:40:00
25.03.2012 03:50:00
25.03.2012 04:00:00
25.03.2012 04:10:00
....

0 Kudos
4 Replies
mecej4
Honored Contributor III
908 Views
You can probably find hundreds of solutions by searching on the Web. If you do not mind giving up the Intel/Digital extensions, here are two solutions (one is pure Fortran, the other uses the underlying C runtime; verify before using)

[fortran]program showgmt use ifport character (len=8) locdate character (len=10) loctime character (len=5) loczone character (len=10) gmtim integer ltim(8) ! ! First method: use Fortran date_and_time ! call date_and_time(locdate,loctime,loczone,ltim) ! adjust for time zone to get UTC imin=ltim(5)*60+ltim(6)-ltim(4) if(imin < 0)then imin=imin+24*60 else if(imin > 24*60)then imin=imin-24*60 endif write(*,10)imin/60,mod(imin,60),ltim(7) ! ! Second method: use C routine gmtime() ! call cgmtime(gmtim) write(*,*)gmtim 10 format(1x,2(I2,':'),I2) end program showgmt [/fortran] Here is the interface between Fortran and C (you could redo this using the Fortran 2000 C-Interops).

[cpp]#include void CGMTIME(char *gmt){ struct tm *sgmt; time_t t0; t0=time(NULL); sgmt=gmtime(&t0); sprintf(gmt,"%2d:%2d:%2d",sgmt->tm_hour,sgmt->tm_min,sgmt->tm_sec); } [/cpp] Output:
[bash] 4:28: 8 4:28: 8 [/bash] You may want to replace blanks in the output by zeros if you prefer.
0 Kudos
DavidWhite
Valued Contributor II
908 Views

change "I2" to "I2.2" to get the leading zeros.

David

0 Kudos
mecej4
Honored Contributor III
908 Views
change "I2" to "I2.2" to get the leading zeros

Yes, and in the C routine, change "%2d" to "%02d".
0 Kudos
Gerdes_Gerhard_J
Beginner
908 Views
Thank you for your reply and your efforts

The GMTIME routine (also in Fortran) helps, even so it is a little less comfortable than UNPACKTIMEQQ. But in addition I need the reverse routine (like PACKTIMEQQ) to convert time into unix-format. In the Web I could not find a combination like PACKTIMEQQ and UNPACKTIMEQQ, converting and reconverting to/from the same (unix) format.

PACKTIMEQQ and UNPACKTIMEQQ would be perfect for my purpose, if they would omit time changes due to day-light saving.

By the way, I am not interested in dealing with real time data, it's all about "historical" data.
0 Kudos
Reply