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

Getting compile date/time

georgeg
Beginner
1,672 Views
Is there any way to get the compile date and time into a compiled program?

Lots of ways of getting the current date and time but how about when it was compiled?


0 Kudos
10 Replies
TimP
Honored Contributor III
1,672 Views
I guess it comes down to traditional methods, such as a script which grabs the information and sets it as a #define usable with /Qfpp. If you use a C compatible pre-processor, __DATE__ and __TIME__ would be available to be written into the initialization of a character string. As the fpp which comes with ifort seems to have such built-in macros, you could try it and cross your fingers.
Did you try something along the lines of
program datetime
character(len=80):: datetimestring=__DATE__//' '//__TIME__
write(*,*)datetimestring
end
?
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,672 Views

These work with FPP enabled

write(*,*) __DATE__
write(*,*) __TIME__
#define __TIMESTAMP__ __DATE__//' '//__TIME__
write(*,*) __TIMESTAMP__
write(*,*) __FILE__
write(*,*) __LINE__

Note, __LINE__ is an integer not a text string as are the others.

Jim Dempsey

0 Kudos
georgeg
Beginner
1,672 Views
Thanks for the suggestions to use the preprocessor. I want to avoid that as I've gotten burned by the preprocessor sometimes goofing up the __LINE__ numbers.


0 Kudos
DavidWhite
Valued Contributor II
1,672 Views
While not infallible, either, you could use GETFILEINFOQQ on the .exe file to get the creation date.
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,672 Views

Since you are reluctant to use FPP (Fortran PreProcessor)...

Create a batch file of the name IFORT.BAT and place in PATH(or current directory) such that IFORT.BAT is run in lieu of IFORT.EXE. The batch file will run whenever a file (or files) are to be compiled. The batch file is written such that for each source file being compiled that a call to a program of your writing is made to auto edit the file to locate placed to insert the __FILE__ and or __LINE__ information.

if(SomethingBad) call BUG("me",0,"SomethingBad happened") ! __FILE__ __LINE__ (and __DATE__ __TIME__ __DATETIME__)

Where the source file is searced for lines containing__FILE__ and or __LINE__ (and __DATE__ __TIME__ __DATETIME__)

If any present the line is researched for CALL. The subroutine name is ignored and then the 1st token is replaced with the enquoted file name and the second token is replaced with the line number. (you get the idea).

When the edit program is complete then the batch file runs IFORT.EXE from the IVF BIN directory.

This will modify files (to be compiled). Therefore a rebuild all will force changes into the source files (not a good idea).

The alternative would be to produce a different output file from the original input file and have IFORT compile that instead (essentialy what FPP does).

A third alternative is to replace FPP.EXE with your own program (which performs the edits as discussed above).

Jim Dempsey

0 Kudos
Steven_L_Intel1
Employee
1,672 Views
I think it would be simpler to have your batch procedure write a small INCLUDE file that defines PARAMETER constants and then INCLUDE these into sources as needed.
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,672 Views

Steve,

The problem you have with that method is the include file becomes a file on which your source (having the include) is dependent. Therefore a build causes all files with that include to become stale (i.e. will require building on the next build).

I don't know if exclude from build also means exclude from dependency check.

Jim

0 Kudos
DavidWhite
Valued Contributor II
1,672 Views

Jim,

As long as the include file is updated as a Pre-Build Event, then the updates to the dependencies should occur during this build. It gets a little tricky, however, if you have mulitple projects in a solution, as the Pre-Build Event is specific to one project. If that project isn't built this time around, the include file is not updated.

I have built a small routine today (in Fortran) to edit the .rc file to update the build number within version number and to write an include file with the create date set as a parameter character string which can be used by the App.

regards,

David

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,672 Views

That may be suitable for the build date of the execuitable or lib but it is not suitable for the compile date and time of the constituent .OBJ files going into the execuitable or lib.

Inside the .OBJ file is the information you need to go into the RC file or into the execuitable (where the RC data resides). Using DUMPBIN you can find the time and date stamp within the .OBJ file

FILE HEADER VALUES
14C machine (x86)
6 number of sections
46AE4937 time date stamp Mon Jul 30 15:25:27 2007

Just prior to link you could concievably collect the OBJ file names along with the time date stamps and place them in the RC area. Then add to the About box a feature to display this information.

Jim

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,672 Views

David,

I forgot to add.

Editing the RC file might cause build to perform a new link as opposed to a do nothing if everything (else) is up to date. Not entirely bad.

A better route might be: when anything built - edit the RC info inside the .EXE file. Or simply concatinate the text file containing the information you wantto the tail end of the .EXE file. That's essentially how the RC file(s) are added onto the execuitable.

Jim

0 Kudos
Reply