20.07.2015 Views

PhD Thesis - staffweb - University of Greenwich

PhD Thesis - staffweb - University of Greenwich

PhD Thesis - staffweb - University of Greenwich

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

APPENDIX 2 : Journal Paper "Case Study : An Incremental Approach to Re-Engineeringa Legacy FORTRAN C.F.D. Code in C++", Ewer J., Knight B. and Cowell D.,Advances in Engineering S<strong>of</strong>tware, Vol. 22, pp 153-168, 1995LOGICAL variables and comparisons were replaced with integers and integer comparisonsrespectively. The complexity <strong>of</strong> replacing the LOGICAL values was significantly reducedby working within the FORTRAN version <strong>of</strong> the code. This also prevented errors in logicthat could occur when too many translation steps had to be performed simultaneously. Thereplacement <strong>of</strong> a LOGICAL sometimes required introducing " IF ( )" constructs toassign appropriate "boolean" values to integer variables. The integer parameters "False" and"True" (representing 0 and 1 respectively) were used throughout the code to match theultimate C++ representation.Stage (5):Translate FORTRAN to procedural C++.When the above stages had been completed and th e FORTRAN code was stillrunning consistently it was necessary to translate the FORTRAN to procedural C++. Thiswas because no appreciable advantage could be gained by further FORTRAN code changes.The serious limitations <strong>of</strong> the available FORTRAN-to-C translators led to the decision totranslate the CFD code to procedural C++ manually. The natural course <strong>of</strong> action would beto use parsing or compiler writing tools such as lex [14] and yacc [15] but because <strong>of</strong> the highlearning overheads and non-interactive nature <strong>of</strong> these utilities, an alternate approach wassought. The tool actually chosen was a powerful programmer's editor with regularexpression search and replace facilities, macro record and playback, and multi-file editingcapabilities. It should be pointed out that a simple text editor would not be sufficientbecause <strong>of</strong> the large syntactic variation that may be encountered in the source code.Using the editor facilities, the translation to procedural C++ took 10 days andinvolved writing a set <strong>of</strong> individual macros to replace specific code constructs. Again SPAGwas used prior to this task so that a consistent style and control syntax would persistthroughout the code. This was necessary to enable the searches within the macros to workcorrectly. Figure 9 indicates some <strong>of</strong> the macro text replacements that were used during themanual translation from FORTRAN-77 to procedural C++. The use <strong>of</strong> regular expressionsearches and macro replacements does require that care was taken to perform thereplacements in order <strong>of</strong> most complex to least complex to prevent incorrect matching withparts <strong>of</strong> other expressions. The main problems are with DO, END and IF which can be part<strong>of</strong> other keywords like END IF or END DO. There are also potential problems withaccidentally matching search expressions with literal strings or parts <strong>of</strong> variable names.Using case sensitive searches, after SPAG had been used to consistently set the case <strong>of</strong>keywords and identifiers, minimised the potential for problems. Clearly these problemswould not be present using compiler writing tools (e.g. yacc or lex) because all identifiersare recognised as whole tokens. The program editor was useful in one respect because theregular expression text replacements are interactively controlled.Appendix 11.2 Page 142-13 13

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!