4

I have the following two variants of a (96 file) code, and the ONLY differences between them are in brackets:

  1. DOUBLE-PRECIION ( every variable is defined as REAL*8 and every number is defined like 1234D+02 )
  2. QUADRUPLE-PRECISION ( every variable is defined as REAL*16 and every number is defined like 1234Q+02 )

If I every change anything in the software, I want this change to be consistent in both of the above variants of the code.

In Git(Hub), should I:

  1. Build a separate repository (how am I going to easily merge changes ?),
  2. Build a different branch (but branching seems to be best for when all code is to merge),
  3. Build a fork (but this seems to be for people that can't push to the main branch) ?

Here are some questions that are related, but not what I want. I've written why I haven't swallowed their answers:

  1. maintain different versions of the code simultaneously using git: Tobu's answer says "git cherry-pick may not work in many cases"
  2. managing multiple versions of a web application using git: suggests git submodules but there's reasons not to.
  3. Keeping track of source code variants: suggests using #define , but is there a FORTRAN equivalent ?
  4. How to track two version of a project in one GIT repository?: suggests a 3rd branch for "common" code, but I don't see the benefit of having more than 2. And would I not need to use git cherry-pick here ?
Community
  • 1
  • 1
Nike
  • 1,223
  • 2
  • 19
  • 42
  • I assume this code that needs near-duplication is in more than a couple of files, correct? Also, Fortran preprocessor commands: http://software.intel.com/sites/products/documentation/doclib/stdxe/2013/composerxe/compiler/fortran-mac/GUID-F6619F6F-7D70-4B06-A266-6F39EF6D51B7.htm – BlackVegetable Aug 10 '13 at 23:30
  • I think a preprocessor command is probably what you want (listed as your #3). – BlackVegetable Aug 10 '13 at 23:32
  • Thanks @BlackVegetable ! I considered this option but seeing just a handful of upvotes for the question AND answer, over more than a year meant it didn't strike me as an obvious best solution. I can see myself using #define to change REAL*8 to REAL*16 , but not so much to convert every instance of "4d3" into "4q3" and "2D+01" to "2Q+01" , do you know if I can just list these full numbers (without scientific notation at all) and rely on the compiler to convert them to whatever type of number their respective variables were defined as ? – Nike Aug 11 '13 at 00:15
  • Hmm, I honestly don't know much about Fortran. While it wouldn't be optimal, you *could* write a script in whatever language you like to run a regex find/replace over those patterns that is executed at build-time. It is not that uncommon to have to run a certain kind of "make" command after checking out a branch in git. – BlackVegetable Aug 11 '13 at 03:13

1 Answers1

0

Long time since I did any Fortran but if you can have parametrised macros based like you can in C you best bet would be to have a conditional macro something like

#define DECLARE_HIGH_PRECISION(Name, Val, Exp) \
#ifdef QUAD_PREC \
REAL*8 %Name% = %Val%Q%Exp% \
#else \
REAL*4 %Name% = %Val%D%Exp% \
#endif 

The declare and initialise your values as DECLARE_HIGH_PRECISION(Fred, 23, -3) you will probably also need a macro for inline values that don't need a name so as to be able to do things like Fred = Fred * HIGH_PRECISION(43, +6), etc.

Steve Barnes
  • 27,618
  • 6
  • 63
  • 73