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

FPP for non-Fortran text files

Mark_J_
Beginner
996 Views

Hi

Are there any pitfalls when using FPP to manipulate non-Fortran text files?

We have some text data files. We want to build multiple versions of the data files from one master copy, using FPP and #ifdef #else #endif. I've tried this and it does work. But I am aware that FPP was not designed to do this, but only to preprocess Fortran code. I am worried that there could be pitfalls: certain text sequences that will cause behaviour that I don't want. 

The text files are code-like: they contain lines like these below. They do not contain lines starting with the hash character #. The lines could be any length (I worry that there could be a maximum length.) 

  Begin Something
    Element
      ' Comment
      Property="Value"
      OtherProperty=Value2
  End Something

We are running FPP like this: fpp /P /undef /DPREPROCVAR=1 inputfile.txt outputfile.txt

Are there any pitfalls with this approach or things I should be aware of?

Thanks in advance

MarkJ

0 Kudos
5 Replies
Steven_L_Intel1
Employee
996 Views

Don't do this - Intel's fpp will completely mangle your text files as it restructures lines thinking they are Fortran statements.

0 Kudos
mecej4
Honored Contributor III
996 Views

You can use the standard Unix/Linux macro processor m4 for this purpose. On Windows, it is available under Cygwin, and other similar utility packages.

0 Kudos
Mark_J_
Beginner
996 Views

Oh dear! FPP worked very well in my tests, but maybe that's because my text file contents are fairly similar to Fortran statements. 

0 Kudos
Lorri_M_Intel
Employee
996 Views

I hate contradicting Steve, so I'm not *exactly* doing that ... however, if it's working for you, then please continue to use it.

it is true that fpp tries to ever-so-briefly parse the syntax, but it is not a complete compiler.

What you will need to worry about, however, is the line length.   Fpp will try to re-format lines wider than 132 characters.

              --Lorri

0 Kudos
Mark_J_
Beginner
996 Views

Thanks Lorri. In my experience you cannot go wrong following Steve's advice, so I have already switched over to using M4 as suggested by mecej4! I used a GNU Windows build rather than cygwin. 

It did seem to be working fine with FPP but we feel more confident using M4. We have no long lines at the moment but it could happen in future

--Mark

0 Kudos
Reply