PCL and Customization > The PATRAN Command Language (PCL) Introduction > The C Preprocessor
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX''">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX''">   
The C Preprocessor
During the development of Patran, the C preprocessor is used with C, FORTRAN and PCL source code. In other words, our source files are automatically sent through the C preprocessor prior to being sent to the specific compiler.
Use of the C preprocessor has many advantages. It allows for substitutions which make the source much more readable. For example, with the C preprocessor a section of code could be written like this:
#define NODE    1
#define ELEMENT 2 
IF ( entity == NODE ) THEN 
xxx 
ELSE IF ( entity == ELEMENT ) THEN 
xxx 
END IF 
instead of like this:
IF ( entity == 1 ) THEN 
xxx 
ELSE IF ( entity == 2 ) THEN 
xxx 
END IF 
Furthermore, these substitutions can be placed into an include file which would allow for centralization of the “#define” statements. Centralization of definitions into include files allows for cleaner and simpler code, ensures consistency and allows for changes throughout the code to be made very simply. If the two “#define” statements mentioned above were put into an include file called “entity_codes.p” then the above piece of code would be as follows:
#include “entity_code.p” 
IF ( entity == NODE ) THEN 
xxx 
ELSE IF ( entity == ELEMENT ) THEN 
xxx 
END IF 
If the “entity_codes.p” include file were used consistently through out all source then the element entity code could change from 2 to 3 by simply changing one line in the “entity_code.p” file. The same idea applies to character strings. If all character strings used in code are placed into include files then changing the text strings is a simple task. If the name of an application changed from “in-house-code 5.3” to “in-house-code 5.4” it would only require one change in one file.
The naming convention for include files in Patran is that PCL include files are suffixed with a “.p,” FORTRAN include files are suffixed with a “.i” and C include files are suffixed with a “.h.” An include file is only used for one language, so if the same type of file is to be used in FORTRAN, C and PCL there would be three files. In such a case there is always one master include file and then slave files which merely “#include” the master file. Continuing with our “entity_code.p” example, if this file were to be used in PCL, FORTRAN and C then there would be three include files (entity_codes.p, entity_codes.i and entity_codes.h) whose contents would be:
--------   Contents of entity_codes.p   -------------- 
/* Include file containing entity codes */ 
#define NODE    1 
#define ELEMENT 2 
 
--------   Contents of entity_codes.i   -------------- 
/* Include file containing entity codes */ 
#include “entity_codes.p” 
 
--------   Contents of entity_codes.h   -------------- 
/* Include file containing entity codes */ 
#include “entity_codes.p” 
Such exclusiveness of include files allows the developer to easily accommodate for the different requirements of different computer languages.
Standard C compilers automatically send source files through the C preprocessor, so C source files do not need to be preprocessed prior to compilation. But, whenever C preprocessor commands are imbedded in FORTRAN or PCL source the source file must first be sent through the C preprocessor and the resulting file sent to the appropriate compiler. A typical C preprocessor command would be:
cpp -P -I$P3_HOME/customization <input_file_name> <output_file_name> 
See any C language manual for more on the C preprocessor.
There are many PCL include files which are delivered with Patran in the $P3_HOME/customization directory: appforms.p, appstrings.p, uistrings.p, etc. Two of these include files, appforms.p and uiforms.p, are heavily used in the PCL functions which create Patran forms. The contents of these files are discussed in User Interface and List Processor Functions (Ch. 5).