core/schedule.c File Reference


Detailed Description

$Id$ Copyright (C) 2008 Battelle Memorial Institute

Definition in file schedule.c.

Go to the source code of this file.

Functions

int find_value_index (SCHEDULE *sch, unsigned char block, double value)
 find_value_index -- search for a value in a schedule index
SCHEDULE * schedule_create (char *name, char *definition)
 Create a schedule.
long schedule_dtnext (SCHEDULE *sch, SCHEDULEINDEX index)
 reads the time until the next change in the schedule
long schedule_duration (SCHEDULE *sch, SCHEDULEINDEX index)
SCHEDULE * schedule_find_byname (char *name)
 Find a schedule by its name.
SCHEDULE * schedule_getnext (SCHEDULE *sch)
 Iterate through the schedule list.
SCHEDULEINDEX schedule_index (SCHEDULE *sch, TIMESTAMP ts)
 get the index value for the given timestamp
int schedule_normalize (SCHEDULE *sch, int flags)
 normalizes a schedule, if possible
TIMESTAMP schedule_sync (SCHEDULE *sch, TIMESTAMP t)
 synchronize the schedule to the time given
TIMESTAMP schedule_syncall (TIMESTAMP t1)
 synchronized all the schedules to the time given
int schedule_validate (SCHEDULE *sch, int flags)
 validate a schedule, if desired See SN_* flags for validation options
double schedule_value (SCHEDULE *sch, SCHEDULEINDEX index)
 reads the value on the schedule
double schedule_weight (SCHEDULE *sch, SCHEDULEINDEX index)


Function Documentation

int find_value_index ( SCHEDULE *  sch,
unsigned char  block,
double  value 
)

find_value_index -- search for a value in a schedule index

Returns:
the index number value to find
Parameters:
block  schedule to search
value  block to search

Definition at line 177 of file schedule.c.

SCHEDULE* schedule_create ( char *  name,
char *  definition 
)

Create a schedule.

If the schedule has already been defined, the existing structure is returned, otherwise a new one is created. If the definition is not provided, then the named schedule is searched and NULL is returned if it is not found.

Example: schedule_create("weekdays 8am-5pm 100%, weekends 9-noon 50%","* 8-17 * * 1-5; * 9-12 * * 0,6 0.5");

Returns:
a pointer to the new schedule, NULL if failed
Parameters:
name  the name of the schedule
definition  the definition of the schedule (using crontab format with semicolon delimiters), NULL is only a search

Definition at line 513 of file schedule.c.

References output_debug(), output_error(), schedule_find_byname(), schedule_normalize(), and schedule_validate().

long schedule_dtnext ( SCHEDULE *  sch,
SCHEDULEINDEX  index 
)

reads the time until the next change in the schedule

Returns:
time until next value change (in minutes)
Parameters:
sch  the schedule to read
index  the index of the value to read (see schedule_index)

Definition at line 796 of file schedule.c.

Referenced by schedule_sync().

long schedule_duration ( SCHEDULE *  sch,
SCHEDULEINDEX  index 
)

Parameters:
sch  the schedule to read
index  the index of the value to read (see schedule_index)

Definition at line 802 of file schedule.c.

Referenced by schedule_sync().

SCHEDULE* schedule_find_byname ( char *  name  ) 

Find a schedule by its name.

Returns:
the schedule pointer
Parameters:
name  the name of the schedule

Definition at line 68 of file schedule.c.

Referenced by convert_to_loadshape(), and schedule_create().

SCHEDULE* schedule_getnext ( SCHEDULE *  sch  ) 

Iterate through the schedule list.

Returns:
the next schedule pointer (or first schedule)
Parameters:
sch  the schedule (or NULL to get first)

Definition at line 60 of file schedule.c.

SCHEDULEINDEX schedule_index ( SCHEDULE *  sch,
TIMESTAMP  ts 
)

get the index value for the given timestamp

Returns:
negative on error, 0 or positive on success

Definition at line 757 of file schedule.c.

References FMT_INT64, local_datetime(), and throw_exception().

Referenced by schedule_sync().

int schedule_normalize ( SCHEDULE *  sch,
int  flags 
)

normalizes a schedule, if possible

Note:
the sum of the values is equal to 1.0, not the sum of the absolute values
Returns:
number of block that could be normalized, 0 if none, -1 if already normalized
Parameters:
sch  the schedule to normalize
flags  schedule normalization flag (see SN_WEIGHTED and SN_ABSOLUTE)

Definition at line 693 of file schedule.c.

Referenced by schedule_create().

TIMESTAMP schedule_sync ( SCHEDULE *  sch,
TIMESTAMP  t 
)

synchronize the schedule to the time given

Returns:
the time of the next schedule change
Parameters:
sch  the schedule that is to be synchronized
t  the time to which the schedule is to be synchronized

Definition at line 818 of file schedule.c.

References schedule_dtnext(), schedule_duration(), schedule_index(), schedule_value(), and schedule_weight().

Referenced by schedule_syncall().

TIMESTAMP schedule_syncall ( TIMESTAMP  t1  ) 

synchronized all the schedules to the time given

Returns:
the time of the next schedule change
Parameters:
t1  the time to which the schedule is synchronized

Definition at line 850 of file schedule.c.

References schedule_sync().

double schedule_value ( SCHEDULE *  sch,
SCHEDULEINDEX  index 
)

reads the value on the schedule

Returns:
current value on schedule
Parameters:
sch  the schedule to read
index  the index of the value to read (see schedule_index)

Definition at line 785 of file schedule.c.

References min.

Referenced by schedule_sync().

double schedule_weight ( SCHEDULE *  sch,
SCHEDULEINDEX  index 
)

Parameters:
sch  the schedule to read
index  the index of the value to read (see schedule_index)

Definition at line 809 of file schedule.c.

Referenced by schedule_sync().


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