### 61.2 Functions for Gentran

Function: gentran (stmt1, stmt2, ... , stmtn , [f1, f2, ... , fm])

  Translates each stmt into formatted code in the target language. A substantial subset of expressions and statements in the Maxima programming language can be translated directly into numerical code. The gentran command translates Maxima statements or procedure definitions into code in the target language (gentranlang: fortran, c, or ratfor). Expressions may optionally be given to Maxima for evaluation prior to translation.

  stmt1, stmt2, ... , stmtn is a sequence of one or more statements, each of which is any Maxima user level expression, (simple, group, or block) statement, or procedure definition that can be translated into the target language.

  [f1, f2, ... , fm] is an optional list of output files to which translated output will be written. They can be any of the following:

  string = the name of an output file in quotes

  true (no quotes) = the terminal

  false = the current output file(s)

  all = all files currently open for output by gentran

  If the files are not open they will be opened; if they are open, output will be appended to them. Filenames are given as quoted strings. If the optional variable genoutpath (string, including the final /) default false is set, it will be prepended to the output file names. If the output file list is omitted, output will be written to the current output, generally the terminal. gentran returns (a list of) the name(s) of file(s) to which code was written.

Function: gentranout (f1, f2, ... , fn)

  Gentran maintains a list of files currently open for output by gentran commands only. gentranout inserts each file name represented by f1, f2,... , fn into that list and opens each one for output. It also resets the current output file(s) to include all files in f1, f2, ... , fn. gentranout returns the list of files represented by f1, f2, ... , fn; i.e., the current output file(s) after the command has been executed.

Function: gentranshut (f1, f2, ... , fn)

  gentranshut creates a list of file names from f1, f2, ... , fn, deletes each from the output file list, and closes the corresponding files. If (all of) the current output file(s) are closed, then the current output file is reset to the terminal. gentranshut returns (a list of) the current output file(s) after the command has been executed. gentranshut(all) will close all gentran output files.

Function: gentranpush (f1, f2, ... , fn)

  gentranpush pushes the file list onto the output stack. Each file in the list that is not already open for output is opened at this time. The current output file is reset to this new element on the top of the stack.

Function: gentranpop (f1, f2, ... , fn)

  gentranpop deletes the top-most occurrence of the single element containing the file name(s) represented by f1, f2, ... , fn from the output stack. Files whose names have been completely removed from the output stack are closed. The current output file is reset to the (new) element on the top of the output stack. gentranpop returns the current output file(s) after this command has been executed.

Function: gentranin (f1, f2, ... , fn, [f1,f2, ... , fm])

  gentranin processes mixed-language template files consisting of active parts (delimited by <<…>>) containing Maxima statements, including calls to gentran, and passive parts, assumed to contain statements in the target language (including comments), which are transcribed verbatim. Input files are processed sequentially and the results appended to the output. The presence of >> in passive parts of the file (except for in comments) is interpreted as an end-of-file and terminates processing of that file. The optional list of output files [f1,f2, ... , fm] each receive a copy of the entire output. All filespecs are quoted strings. Input files may be given as (quoted string) filenames, which will be located by Maxima file_search. The optional variable geninpath (default false ) must be a list of quoted strings describing the paths to be searched for the input files. If it is set, that list replaces the standard Maxima search paths.

  Active parts may contain any number of Maxima expressions and statements. They are not copied directly to the output. Instead, they are given to Maxima for evaluation. All output generated by each evaluation is sent to the output file(s). Returned values are only printed on the terminal. Active parts will most likely contain calls to gentran to generate code. This means that the result of processing a template file will be the original template file with all active parts replaced by generated code. If [f1, f2, ... , fm] is not supplied, then generated code is simply written to the current output file(s). However, if it is given, then the current output file is temporarily overridden. Generated code is written to each file represented by f1, f2, ... , fn for this command only. Files which were open prior to the call to gentranin will remain open after the call, and files which did not exist prior to the call will be created, opened, written to, and closed. The output file stack will be exactly the same both before and after the call. gentranin returns (to the terminal) the name(s) of (all) file(s) written to by this command.

Function: gentraninshut ()

  A cleanup function to close input files in case where gentranin hung due to error in template.

Function: tempvar (type)

  Generates temporary variable names by concatenating tempvarname (default ’t) with sequence numbers. If type is non-false, e.g. "real*8" the corresponding type is assigned to the variable in the gentran symbol table, which may be used to generate declarations depending on the setting of the gendecs flag. It is the users responsibility to make sure temporary variable names do not conflict with the main program.

Function: markvar (vname)

  markvar "marks" variable name vname to indicate that it currently holds a significant value.

Function: unmarkvar (vname)

  unmarkvar "unmarks" variable name vname to indicate that it no longer holds a significant value.

Function: markedvarp (vname)

  markedvarp tests whether the variable name vname is currently marked.

Function: gendecs (name)

  The gendecs command can be called any time the gendecs flag is switched off to retrieve all type declarations from Gentran’s symbol table for the given subprogram name (or the "current" subprogram if false is given as its argument).

Function: gentran_on (sw)

  Turns on the mode switch sw.

Function: gentran_off (sw)

  Turns the given switch, sw, off.