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

Force line-breaks in preprocessor macros

Matthias_M_
Beginner
2,367 Views
Dear all,
is it possible to enforce line breaks in preprocessor macros with the fpp?
The reason for my question is as follows: I use macros of the form
#define GAMMA 1.4
#define DENSITY(U) (U(1))
#define X_VELOCITY(U) (U(2)/DENSITY(U))
#define Y_VELOCITY(U) (U(3)/DENSITY(U))
#define Z_VELOCITY(U) (U(4)/DENSITY(U))
#define TOTAL_ENERGY(U) (U(5)/DENSITY(U))
#define KINETIC_ENERGY(U) \\
(0.5*((X_VELOCITY(U)**2)+ \\
(Y_VELOCITY(U)**2)+ \\
(Z_VELOCITY(U)**2)))
#define INTERNAL_ENERGY(U) \\
(TOTAL_ENERGY(U)-KINETIC_ENERGY(U))
#define PRESSURE(U) \\
((GAMMA-1.4)*DENSITY(U)*INTERNAL_ENERGY(U))
The preprocessors performs macro expansion and produces a single line which may become arbitrarily long (longer than 132 characters). Is there any possibility to enforce line-breaks, e.g.
#define KINETIC_ENERGY(U) \\
(0.5*((X_VELOCITY(U)**2)+ & \\
(Y_VELOCITY(U)**2)+ & \\
(Z_VELOCITY(U)**2)))
Many thanks in advance.
Best regards,
Matthias
0 Kudos
5 Replies
mecej4
Honored Contributor III
2,367 Views
What you propose would have the effect of creating input source code to the compiler pass that may have lines longer than 132 characters, which would run afoul of the standard, section 3.3.1:

If a line consists entirely of characters of
27 default kind (4.4.4), it may contain at most 132 characters.


Thus, your proposal would produce preprocessor output that the compiler will not accept. Have you considered inserting Fortran continuation characters into your macro definitions?
0 Kudos
Matthias_M_
Beginner
2,367 Views
Thus, your proposal would produce preprocessor output that the compiler will not accept. Have you considered inserting Fortran continuation characters into your macro definitions?

Well, that actually was my question how to force fpp to keep line breaks because I wanted to avoid generating lines with more than 132 characters.
This is the definition of a typical macro
#define VELOCITY_MAGNITUDE(U) \
(sqrt(X_VELOCITY(U)**2+&
Y_VELOCITY(U)**2+&
Z_VELOCITY(U)**2))
Application of fpp yields one single line
Dvalue(ieq) = (sqrt(((Ddata(2,ieq))/& (Ddata(1,ieq)))**2+& ((Ddata(3,ieq))/& (Ddata(1,ieq)))**2+& ((Ddata(4,ieq))/& (Ddata(1,ieq)))**2))
The same happens if I finish each line of the macro with ''. Moreover, the same happens if I add an additional & at the beginning of each continuing line (i.e. &Y_VELOCITY..., &Z_VELOCITY...)
Any idea how to keep line breaks?
0 Kudos
mecej4
Honored Contributor III
2,367 Views
Sorry to have misunderstood your requirements.

If it is permissible to use a makefile and a separate preprocess step in the make rule, you could use this in the makefile, along with using a marker such as to indicate where you want lines broken:

[bash].SUFFIXES:
.SUFFIXES: .f90 .o

.f90.o:
	fpp -P $< | sed -e 's//n/g' > $*.ftn
	ifort -free -c $*.ftn

all: moelle.o
[/bash]
If you like, you can add a command to remove the .ftn file(s).
0 Kudos
Matthias_M_
Beginner
2,367 Views
I should have told the whole story. On all Unix-like systems we have a working solution. In short, we (1) use the GNU cpp to preprocess the Fortran source file, (2) use some sed command to introduce line breaks (as in your solution) and (3) pass the result to the ifort compiler.
It is Windows which causes troubles. Under Windows, we use MS Visual Studio and the only thing we can do at the moment is turn on the Fortran preprocessor by adding /fpp. I do need a solution without makefiles, etc. for that.
0 Kudos
jimdempseyatthecove
Honored Contributor III
2,367 Views

As a hack, you can place a C++ program you write and name FPP.EXE situated in PATH prior to IVF bin directory.
This program can call IVF FPP first using fully qualified path, then reparse replacing say "<%CRLF%>" or other such text with a line break. Then on return from program IVF will continue with munged up temp file.

Jim Dempsey

0 Kudos
Reply