Skip to content

Code Generation

The Code Generation option in the File menu of the Surface-Fit Graph is used to write generated code for the current surface-fit equation.

help_55.png

Supported Languages

You can export any TableCurve 3D built-in Surface-Fit equation to program code in the following languages:

  • C (double)
  • C(long double)
  • FORTRAN 77
  • FORTRAN 90
  • QBASIC
  • Visual Basic
  • Turbo PASCAL
  • JAVA
  • Matlab
  • C++

Code Generation

You have the option of generating only the function code, or a full code option that contains simple calling code to test the function. The Full Test Code option writes the function, any auxiliary function such as the error function or the Chebyshev or Fourier series evaluators, and simple calling code to test the equation. The Function Code Only omits the code that tests the function.

You must also specify the name of the function, subroutine, or procedure for the surface-fit equation. After the file is written, you are presented with a Generated Code Display. The generated code will contain 16 digits precision and will use double precision variables. Code can be generated for all of TableCurve 3D's 453,697,363 built-in equations.

The generated code will normally contain 15-16 digits precision and will use double precision (64-bit) variables. The C (long double) and PASCAL options will use long double precision (80-bit) and will be written to 19 digits precision.

Matlab Considerations

For the Matlab language, the Full Test Code and Function Code Only options are identical, since the m-file function can be readily tested from the Matlab environment. Unless the generated code is to be a subsidiary function in another m-file, you will want to specify identical names for the function and the m-file. Matlab requires that the m-file name and the function have the same name in order to be available within the Matlab environment.

User-Defined Functions

While code is not generated for user-defined functions, TableCurve 3D will write the current UDF into the generated code as it appears in the program. This should assist you in the manual coding that is required. If your UDF uses a special function such as a Bessel or one of the statistical functions, you will have to supply your own version of the function.

No Constraint Code

Note that this generated code will contain only the native mathematical computation. There will be no conditional statements to manage undefined regions.

C++ and JAVA Classes

These options produce classes which have a built in evaluation and root finding member functions. If the classes are not suitable in their present form, they can be modified by editing the template file for the specific language, as explained below.

Inserting BASIC Module in Excel

For Excel 97 and higher versions supporting VBA (Visual Basic for Applications), you can add a BASIC module containing the curve-fit equation to the XLS file. Although it involves several steps, this approach has the advantage of producing a viable formula for all TableCurve 3D equations, including the Chebyshev and Fourier Series equations.

This approach makes the surface-fit function global to Excel just as if it were a built-in Excel function. Further, the BASIC code is generally easier to understand than the single line formula generated in the Save Excel option since the coefficients appear directly rather than as cell references.

Note that you can use this option even if you have no experience with BASIC because no language understanding is needed.

The necessary steps are as follows:

In TableCurve 3D:

  • Generate Function Code using Visual Basic or QBASIC, Function Code Only.
  • Generate the Excel file using this Save Excel export option

In Excel:

  • Open the generated Excel file
  • Tools/Macro/Visual Basic Editor to open the VB editor
  • File/Import File with the generated BASIC file name to add the VB module to the worksheet
  • Use the generated function name in formulas anywhere within the Excel sheets as in =eqn324(A1,B1)

Customizing the Generated Code

Each of the code languages uses a template file for the code language generation. These TCL extension files are found in the main distribution directory. These files can be edited as you choose, although you should save a backup of the original file before you begin. The tokens where substitutions occur in the code generation process are clearly evident and must not be removed.