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

Using defined symbol in code

smedvedoff
Beginner
947 Views
I'd like to imbed a version number in my program that can be printed during execution. I'd like to do it without having to modify the source code. I was hoping I could do something like this:

On command line, /DVersion_Definition="10.1.1"

And in code, something like:

!DEC$ IF DEFINED (Version_Definition)
Set some Fortran variable to Version_Definition
!DEC$ ENDIF

Is this possible? Or is there another way to do it?

Thanks,
Steve
0 Kudos
7 Replies
joerg_kuthe
Novice
947 Views
The first idea which comes to my mind is to use resources, in particular: "Version".
Let the Intel Visual Fortran create a Windows Application for you, then check the resource file (.rc) being created for the resource called "Version". Then have a look at the source code to see how the information in the resource is being read.

If you don't need a version number, then, maybe a date & time stamp is sufficient. I once learned (here?) that there are preprocessor symbols __DATE__ and __TIME__ available (by the way: I don't find that piece of information in the IVF online help).
I used them this way:
CHARACTER (30) :: cDateVersion =__DATE__//' '//__TIME__ ! FPP has to be turned ON ("Preprocess Source File = Yes")
Note, you have to re-compile the file containing that source line each time you want have the version stamp being updated.

Another possibility (probably the simplest one) is to use an INCLUDE file which simply contains your version info. Then your "original" source remains unchanged.

Hopes this helps.

Jrg Kuthe
www.qtsoftware.de





0 Kudos
smedvedoff
Beginner
947 Views
Quoting - joerg_kuthe
The first idea which comes to my mind is to use resources, in particular: "Version".
Let the Intel Visual Fortran create a Windows Application for you, then check the resource file (.rc) being created for the resource called "Version". Then have a look at the source code to see how the information in the resource is being read.

If you don't need a version number, then, maybe a date & time stamp is sufficient. I once learned (here?) that there are preprocessor symbols __DATE__ and __TIME__ available (by the way: I don't find that piece of information in the IVF online help).
I used them this way:
CHARACTER (30) :: cDateVersion =__DATE__//' '//__TIME__ ! FPP has to be turned ON ("Preprocess Source File = Yes")
Note, you have to re-compile the file containing that source line each time you want have the version stamp being updated.

Another possibility (probably the simplest one) is to use an INCLUDE file which simply contains your version info. Then your "original" source remains unchanged.

Hopes this helps.

Jrg Kuthe
www.qtsoftware.de






Joerg,

Thank you for the great suggestions. Ireally like the idea of using the__DATE__ and __TIME__ preprocessor symbols - I had no idea they existed.

Thanks again,
Steve
0 Kudos
jimdempseyatthecove
Honored Contributor III
947 Views

Using FPP you can also do the following

Right click on project | Properties | Fortran | General

Add to Preprocessor definitions _MyVersionNumber="10.0.1" (use semicolon for seperator between other definitions)

In your applicaiton

#ifdef _MyVersionNumber
(do something with the version number here)
#endif
0 Kudos
smedvedoff
Beginner
947 Views

Using FPP you can also do the following

Right click on project | Properties | Fortran | General

Add to Preprocessor definitions _MyVersionNumber="10.0.1" (use semicolon for seperator between other definitions)

In your applicaiton

#ifdef _MyVersionNumber
(do something with the version number here)
#endif

Jim,

Thanks for that suggestion. In the (do something...) section, is there a way to set a Fortran Parameter to the value of _MyVersionNumber? I tried creating a string parameter and assigning it _MyVersionNumber, but the compiler complains about type mismatch. If you have an example that would be great.

Thanks,
Steve
0 Kudos
gib
New Contributor II
947 Views
Quoting - smedvedoff

Jim,

Thanks for that suggestion. In the (do something...) section, is there a way to set a Fortran Parameter to the value of _MyVersionNumber? I tried creating a string parameter and assigning it _MyVersionNumber, but the compiler complains about type mismatch. If you have an example that would be great.

Thanks,
Steve
If all else fails, you could construct your version string laboriously. E.g. set definitions for 10.0.2

set _VersionFirst_10
set _VersionMid_0
set _VersionLast_2

then in the code, cover all possibilities:

#ifdef _VersionFirst_10
firststr = '10'
#endif
#ifdef _VersionFirst_11
firststr = '11'
#endif
#ifdef _VersionMid_0
midstr = '0'
#endif
#ifdef _VersionMid_1
midstr = '1'
#endif
#ifdef _VersionMid_2
midstr = '2'
#endif
...
etc., then construct the version string as firststr + '.' + midstr + '.' + laststr
0 Kudos
jimdempseyatthecove
Honored Contributor III
947 Views
Quoting - smedvedoff

Jim,

Thanks for that suggestion. In the (do something...) section, is there a way to set a Fortran Parameter to the value of _MyVersionNumber? I tried creating a string parameter and assigning it _MyVersionNumber, but the compiler complains about type mismatch. If you have an example that would be great.

Thanks,
Steve

Steve,

Enquote a string containing 'your string here' with double " marks
_MY_VERSION="'V10.0.1 Beta'"

(_MY_VERSION=) + (") + (') + (V10.0.1 Beta) + (') + (")

Remove ()+ and spaces

Fortran accepts single dit quotes ('), FPP can accept double dit (") quotes.

Jim Dempsey

0 Kudos
smedvedoff
Beginner
947 Views

Steve,

Enquote a string containing 'your string here' with double " marks
_MY_VERSION="'V10.0.1 Beta'"

(_MY_VERSION=) + (") + (') + (V10.0.1 Beta) + (') + (")

Remove ()+ and spaces

Fortran accepts single dit quotes ('), FPP can accept double dit (") quotes.

Jim Dempsey


Jim,

What I did (and I'm sure this is equivalent to what you're suggesting) is:

In Preprocessor Definitions:

_MyVersionNumber='Build_10.1.1'

In Fortran code:

#ifdef _MyVersionNumber
CHARACTER*60 :: cVersion = _MyVersionNumber
#endif


And this worked well.

Thanks. And thanks to all for taking the time to help.

- Steve

0 Kudos
Reply