3.1.1. Requirements for Writing a FORTRAN Program

3.1.1.1. Declare Variable Types

Inclusion of the statement DOUBLE PRECISION (A-H, O-Z), INTEGER (I-N) will automatically assign a variable type depending on its initial character, else each variable must be explicitly typed, that is,

INTEGER KK
DOUBLE PRECISION RHO
CHARACTER*16 KNAME

Note:  A CHARACTER type must also establish a character-string length.


3.1.1.2. Allocate Arrays

Arrays specific to a mechanism Linking File may be allocated by an estimate of its requirements, shown as:

PARAMETER (LENIWK=1000, LENRWK=1000, LENCWK=500, LENSYM=16)
DIMENSION ICKWRK(LENIWK)
DIMENSION RCKWRK(LENRWK)
CHARACTER*(LENSYM) CCKWRK(LENCWK)

If the Linking File has been opened (see Open the Linking File ), the exact requirements may be obtained by the Ansys Chemkin subroutine call CALL CKLEN (LINKCK,LENI,LENR,LENC,IFLAG) in order to check that sufficient memory has been allocated.

3.1.1.3. Open the Linking File

An integer FORTRAN unit number is assigned to the existing Linking File; IFLAG will be non-zero on return if there was an error, as shown:

LINKCK = 25
IFLAG = 0
OPEN(UNIT=LINKCK,FORM='FORMATTED',STATUS='OLD',FILE='chem.asc',IOS=IFLAG)

3.1.1.4. Initialize the Linking File Data

Messages from the subroutine will be sent to a screen or window by assigning output to FORTRAN unit 6, as shown:

LOUT=6
IFLAG=0
CALL CKINIT (LENICK,LENRCK,LENCCK,LINKCK,LOUT,ICKWRK,RCKWRK,CCKWRK,IFLAG)

3.1.1.5. Obtain or Manipulate Data

After the Linking File data has been stored into the Ansys Chemkin work arrays, they are the means by which further information about the mechanism is obtained, or data manipulation facilitated.

CALL CKINDX (ICKWRK,RCKWRK,MM,KK,II,NFIT)

where MM is the ELEMENTS count of the mechanism, KK is the SPECIES count, II is the REACTIONS count and NFIT is the number of C p polynomial coefficients for the species.

CALL CKWT (ICKWRK,RCKWRK,WT)

where DOUBLE PRECISION WT(KK) is initialized with the KK species' molecular weights.

CKXTY (X,ICKWRK,RCKWRK,Y)

Converts DOUBLE PRECISION X(1..KK) mole fractions to DOUBLE PRECISION Y(1..KK) mass fractions for the KK species.

3.1.1.6. Compile and Link

The Ansys Chemkin installation file include/chemkin_make_unix.inc (include\chemkin_make_pc.inc for PC), defines make (nmake) macros for required compile and link flags, as well as library names and locations. You MUST use this installation file when compiling your own code to ensure that the compiler directives are consistent with those used in Chemkin, and to avoid errors during linking. A user makefile can set a few additional macros to compile and link a program; the user macro, CKROOT for example, must be defined as the root location of your Chemkin installation. Since CKROOT must not contain any spaces, you may need to use directory short names for Windows Installations. For example, rather than:

CKROOT = Program Files\ANSYS Inc\V242\reaction

you will need to use something like

CKROOT = c:\progra~1\ANSY~1\v242\reaction

You can determine the short name for directories by using the Windows DOS command:

dir /x~

!include $(CKROOT)\include\chemkin_make_pc.inc
ALL : MY_EXE
MY_OBJ = my_program$(OBJECT)
MY_EXE:        $(MY_OBJ)
               $(LINK) $? $(F77_LIBFLAGS) \
               $(CHEMKIN_LIBRARY) $(CHEMKIN_USER_LIBRARY) \
               $(CHEMKIN_PUB_LIBRARY) $(F77_SYSTEM_LIBS)

If CKROOT is not defined as an environment variable already, the Ansys Chemkin make file will use its own CKROOT definition. All the other directories (include, bin, etc.) are referenced using a relative path based on CKROOT.

There are two general scenarios about how CKROOT has to be set:

  1. The first is that the entire Ansys Chemkin file structure is intact when you try to rebuild some DLL or executable. Even if you are not working in the original Chemkin installation, as long as all the other Chemkin directories (bin, include, etc.) are under the same parent directory as the build directory, you do not need to set CKROOT. The make file will use the default setting of '..' and you can commit a make with the command

     > nmake -f drivers_cpp_pc.mak ..\bin\premixdll.dll 

    Please note that the definition of CKROOT as '..' enables the use of "..\bin\premixdll.dll" as the target. If you have defined CKROOT as "c:\progra~1\ANSY~1\v242\reaction", you have to use "c:\progra~1\ANSY~1\v242\reaction\chemkinpro.win64\bin\premixdll.dll" as the target instead.

  2. If you have installed the sample directories in a separate location, when you try to rebuild the samples, you will need to re-define CKROOT in the make files of the sample to point it to the Ansys Chemkin installation.