REQUIRE

From ASCEND
Jump to: navigation, search

The REQUIRE statement is used in ASCEND to read in other model files. This is part of the code-reuse mechanism in ASCEND, because it allows you to re-use previously defined models, types, units, methods, etc., in your newer higher-level models.

For C/C++ programmers, the REQUIRE statement is analogous to the #include preprocessor command. For Python programmers, it is analogous to the import statement.

(* include standard variable types *)
REQUIRE "system.a4l";

(* include definitions of standard atomic types *)
REQUIRE "atoms.a4l";

(* include definitions of common units of measurement *)
REQUIRE "measures.a4l";

What REQUIRE does

When ASCEND sees a REQUIRE statement, it searches for the file using the locations specified in the ASCENDLIBRARY environment variable. Once the file is found, it is read as though the file's contents were typed verbatim into the corresponding part of the including file.

Note: the behaviour of the REQUIRE statement can be affected by earlier instances of the PROVIDE statement.

Not the same as IMPORT

The IMPORT statement is different from the REQUIRE statement, although the distinction is arguably a bit arbitrary. The REQUIRE statement is used to load ASCEND model files (*.a4c, *.a4l) into the library. On the other hand, the IMPORT statement is used to load various types of 'plug-in' extensions to ASCEND including external relations (equations that are coded in C code, for example, rather than as ASCEND models) and external methods (for example ExtPy scripts that create special types of output using your model) and external import handlers (code that allows ASCEND to read other types of plug-ins).

The IMPORT statement uses file extensions to work out what type of file is being read, so there is no reason why the IMPORT and REQUIRE statements couldn't be merged. But for the moment, they're separate and the consensus of the group is that they should stay that way.

See also