PCL and Customization > Accessing the Patran Database > Calling the Database Access Functions from C and FORTRAN
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX''">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX''">   
Calling the Database Access Functions from C and FORTRAN
User written PCL functions can be incorporated into the main Patran program or can be part of an external program run using the p3pclcomp utility program. PCL which is incorporated into Patran will extract the functions documented in this chapter from the “p3patran.plb” PCL library. This happens automatically and requires no user intervention. Standalone PCL functions can satisfy references to functions described in this chapter with p3patran.plb or through other PCL libraries.
Any C or FORTRAN code written by the user cannot be incorporated into the main Patran program and thus must always be part of an external program. Run time support of the functions listed in this chapter is demonstrated by simple C and FORTRAN programs which are delivered in the $P3_HOME/customization directory. The source code filenames for these demonstration programs are CAccessCalls.c, fort_access_calls.F, fort_access_calls.f, wrapper_c.C, and wrapper_f.C.
Script files which demonstrate a compilation and link of these files are delivered in the $P3_HOME/customization directory under the filenames LinkCAccess, LinkCAccess.cmd, LinkFAccess, LinkFAccess.cmd, and dbxs_link. All of the header files, libraries, archive libraries, and shared objects needed to compile and link the example programs are located in $P3_HOME/customization, $P3_HOME/customizaton/CXX_LIBS, and $P3_HOME/lib directories.
The LinkCAccess script may have to be edited to reflect the location of the system FORTRAN libraries on your local machine before it will run correctly. To run either of the link scripts simply type its name. For example:
Prompt> $P3_HOME/customization/LinkCAccess
or
Prompt> $P3_HOME/customization/LinkFAccess
The run of the script is successful if it creates a “CAccessCalls” or “fort_access_calls” executable in your current directory without any link error messages. The C and FORTRAN utility programs which are created do not call the dbaccess functions that they use with the appropriate arguments. These utility programs are designed to demonstrate the compilation and link of an executable using dbaccess, not the use of the functions themselves. The main for the utility program written using C must be a C++ style main and be compiled using a C++ compiler to allow all links to be resolved correctly.
The internal structure of multidimensional arrays is the same for C and PCL but is different for FORTRAN. A multidimensional array in FORTRAN is the transpose of the same array in C. This can create problems if the underlying code for a function is C but is called from FORTRAN or vice versa. If an output multidimensional array is the transpose of what you expect, simply re-shuffle the contents or the array. If a function which has an input multidimensional array argument is not working correctly, input the transpose of the current array to see if that will work. Below is an example of a FORTRAN function with calls a database access function and then transposes the output multidimensional array. The “USABLE_ARRAY” would be the array actually used throughout the rest of the program.
SUBROUTINE XYZ ( )
C
C---Purpose: blah blah blah
C
#define DIM1 3
#define DIM2 5
C
	INTEGER I, J, STATUS, DB_XYZ
C
	REAL OUTPUT_ARRAY(DIM2,DIM1), USABLE_ARRAY(DIM1,DIM2)
C
C---Tons of comments
C
	STATUS = DB_XYZ ( OUTPUT_ARRAY )
C
C---Even more comments
C
	DO 30 I = 1, DIM1
C
		DO 20 J = 1, DIM2
C
			USABLE_ARRAY(I,J) = OUTPUT_ARRAY(J,I)
C
	20CONTINUE
C
	30CONTINUE
C
	RETURN
C
	END