From GridLAB-D Wiki
Jump to: navigation, search

 Proposed for review 

SEQ_ - Sequence global variables Template:NEW30

Synopsis

${SEQ_name}
${SEQ_name:INIT}
${SEQ_name:INC}

Description

The SEQ_ global variables provide a mechanism for automatically generating a sequence of integers during the loading process. When the sequence options are referenced, the appropriate action is taken. Sequence actions are as follows.

INIT

Initialize the sequence to the value 0 before evaluating the variable.

INC

Increment the sequence value before evaluating the variable.

Example

The following GLM file

#print Initializing: SEQ_A=${SEQ_A:INIT}
#print SEQ_A=${SEQ_A}
#print Incrementing: SEQ_A=${SEQ_A:INC}
#print SEQ_A=${SEQ_A}

outputs the following text

example.glm(1): Initializing: SEQ_A=0
example.glm(2): SEQ_A=0
example.glm(3): Incrementing: SEQ_A=1
example.glm(4): SEQ_A=1

Caveat

The INC action can be applied to any global of type int32. This means that you can define a global variable of type int32 using the global directive and start with a non-zero value. For example:

global int32 SEQ_B 12;
#print ${SEQ_B:INC}

is acceptable.

Also note that using the SEQ variables in macros may result in unexpected behavior because the macros are processed before certain load functions can be processed. For example, to create multiple objects using sequences, you must use expansions rather than macros, such as

module residential;
global int32 SEQ_A 0;
object house:..10 {
  name "House_${SEQ_A:INC}";
  name `House_{SEQ_A:INC}`;
}

Version

The SEQ_ globals were introduced in Hassayampa (Version 3.0).

See also