GLM file loader


Detailed Description

Note:
The function of GLM files has evolved from Version 1. Now GLM files are used to synthesize models, whereas XML files are used to store models.
Bug:
This loader uses a crude parser. Someday it will be replaced by a more robust implementation that will be easier to fix, manage, improve, update, grow, etc.
Comments
All text from the first instance of "//" to the end of a line is treated as a comment. The "//" must follow a whitespace to be considered a comment delimiter. When a "//" follows a non-white character, it is not recognized as a comment delimiter.
    // comments are preceded by two slashes, which must follow a white-space
    #set urlbase=http://www.nowhere.net/ // www.nowhere.net/ is not a comment
Variables
Any global variable or environment variable can be substituted into the incoming stream by using the ${varname} syntax. First global variables are matched, and if none is found, then environment variables are matched. If the global variable name is provided in the form ${module::varname} then the module global is substituted if it exists.
Todo:
Command substitution using .
Todo:
Regular expressions using ${varname/from/to} and ${varname//from/to}.
Macros
The "#" character at the beginning of a line followed by a non-white character will cause the word that follows to be treated as a macro. When a "#" is followed by a white-space it will cause the parser to consider the file to be an old-style GLM file and abandon the loading process.
The following macros are recognized:
#set <global>="<value>" // sets the existing global variable to the value

#define <global>="<value>" // defines a new global variable as the value

#setenv <variable>=<expression> // set the environment variable to the expression

#include "<file>" // includes the file in the load process

#if <expression> // includes the text if expression is non-zero otherwise includes alternate
... <text> ...
#else
... <alternate> ...
#endif

#ifdef <global> // includes the text if global is defined otherwise includes alternate
... <text> ...
#else
... <alternate> ...
#endif

#ifndef <global> // includes the text if global is undefined otherwise includes alternate
... <text> ...
#else
... <alternate> ...
#endif

#ifexist <file> // includes the text if file exists otherwise includes alternate
... <text> ...
#else
... <alternate> ...
#endif

#print <expression> // displays the expression on the output stream

#error <expression> // displays the expression on the error stream and fails the load

#warning <expression> // displays the warning on the warning stream

The following blocks are recognized at the root level:

clock {
    timezone "ZZZTTTZZZ"; // sets the timezone to use for the simulation
    timestamp "YYYY-MM-DD HH:MM:SS ZZZ"; // sets the global clock starting time
}

global {
    <global> <expression>; // sets the global to the expression
}

module {
    <variable> <expression>; // sets the module variable to expression
    class <class> { // verifies existing static class
        <type> <property>[<unit>]; // defines /verifies a property in class
    }
}
    
class <class> { // creates a new runtime class

    // publish a GridLAB-D property
    <type> <property>[<unit>]; 

    // define an intrinsic function (i.e., create, init, presync, sync, postsync, etc.)
    intrinsic <name> ( <arglist> ) 
    {
        <C++ code>
    };

    // embed a C++ member variable or function
    public|protected|private <C++ member definition>;

    // declare a function in another class
    function <class-name>::<function-name>;

    // publish a C++ member function
    export <C++ member definition>;
}

object <class>[:<spec>] { // spec may be <id>, or <startid>..<endid>, or ..<count>
    <property> <expression>;
    [parent] object ...; // create a child object
    <object-property> object ...; // reference another object
}


Functions

STATUS loadall (char *file)
 Load a file.
STATUS loadall_glm (char *file)
STATUS loadall_glm_roll (char *file)


Function Documentation

STATUS loadall ( char *  file  ) 

Load a file.

Returns:
STATUS is SUCCESS if the load was ok, FAILED if there was a problem
Todo:
Rollback the model data if the load failed (ticket #32)
Todo:
Support nested loads and maintain context during subloads (ticket #33)

Definition at line 5121 of file load.c.

References find_file(), loadall_glm_roll(), object_get_count(), output_error(), and output_warning().

Referenced by cmdarg_load(), and cmex_load().

STATUS loadall_glm ( char *  file  ) 

Parameters:
file  a pointer to the first character in the file name string

Definition at line 4941 of file load.c.

References object_get_count(), object_get_first(), object_set_parent(), output_error(), output_error_raw(), and output_verbose().

STATUS loadall_glm_roll ( char *  file  ) 

Parameters:
file  a pointer to the first character in the file name string

Definition at line 5024 of file load.c.

References object_get_count(), object_get_first(), object_set_parent(), output_error(), output_error_raw(), and output_verbose().

Referenced by loadall().


GridLAB-DTM Version 2.0
An open-source project initiated by the US Department of Energy