Programs for Programmers

QMERGE - version selection

QMERGE is a small tool which tackles a common problem – how to keep control of programs which exist in a number of different versions. Some common examples are programs which run on a variety of different machines, and require slight changes to the source code for each one. For example, changes may be necessary because of different file naming conventions, word length, or different ways of accessing the system.

QMERGE allows the user to keep all the code variants within the master version of the source code. It comments and un-comments sections of code depending on the settings of user-defined logical flags. Unlike a macro pre-processor or conditional compilation tool, QMERGE does not require that you deviate in any way from standard Fortran, or that you pre-process code before submitting it to a compiler – the master version is legal Fortran and can be compiled directly. QMERGE is needed only when you create a version for porting to a different machine.

The operation of QMERGE can be understood by reference to a simple example, such as that shown belowe. This program fragment consists of one section which is activated if the the user defined condition named LINUX is TRUE, and another which is activated if LINUX is FALSE, and at least one of the conditions MAC, VMS and WINDOWS is TRUE (the commas between them may be read as ‘OR’). Inside the LINUX section is a nested !-IF construct containing sections which may be activated depending on the values of the DEMO and DEBUG conditions. The condition names are not case sensitive, and may be
up to 32 characters long. They are defined simply by using them.

Version 1 of the program fragment is consistent with the condition LINUX being FALSE, and one of MAC, VMS or WINDOWS being TRUE. The values of DEMO and DEBUG are irrelevant in this case. Version 2 could be obtained by passing version 1 through QMERGE and specifying LINUX as TRUE, DEMO as FALSE, and DEBUG as TRUE (the ‘-‘ in front of DEBUG may be read as ‘NOT’). In fact, the result does not depend on which lines are commented out in version 1, but only on values of the conditions. It is quite possible to convert version 2 back to version 1 (by running QMERGE with LINUX set to FALSE and MAC set to TRUE).

 

 

Version 1

Version 2

!-IF LINUX
!-      PRINT *,'LINUX'
!-IF DEMO
!-      PRINT *
!-      PRINT *,'Demo'
!-ELSEIF -DEBUG
!-      PRINT *
!-      PRINT *,'Debug off'
!-ELSE
!-      PRINT *
!-      PRINT *,'Debug on'
!-ENDIF
!-      X = Y
!-      A = B
!-ELSEIF MAC,VMS,WINDOWS
      PRINT *,'Default'
!-ENDIF
!-IF LINUX
      PRINT *,'LINUX'
!-IF DEMO
!-      PRINT *
!-      PRINT *,'Demo'
!-ELSEIF -DEBUG
!-      PRINT *
!-      PRINT *,'Debug off'
!-ELSE
      PRINT *
      PRINT *,'Debug on'
!-ENDIF
      X = Y
      A = B
!-ELSEIF MAC,VMS,WINDOWS
!-      PRINT *,'Default'
!-ENDIF

 

Conditions may be specified in a configuration file, or specified on the command line:

e.g. QMERGE *.f90 SELECT=+LINUX,-DEMO

means that LINUX is true and DEMO is false. If QMERGE needs to know the value of a condition which is not specified, it issues a prompt

Is MAC true? (Y or N) ==>

Other QMERGE facilities allow you to specify defaults, select from a list of alternatives, concatenate and nest conditions etc.