00001
00011 #if 0
00012
00013 #include <stdlib.h>
00014 #include <stdio.h>
00015 #include <errno.h>
00016 #include <math.h>
00017 #include <cctype>
00018
00019 #include "loadshape.h"
00020
00022
00024 CLASS* loadshape::oclass = NULL;
00025 loadshape *loadshape::defaults = NULL;
00026
00027 loadshape::loadshape(MODULE *module)
00028 {
00029
00030
00031 if (oclass==NULL)
00032 {
00033
00034 oclass = gl_register_class(module,"loadshape",sizeof(loadshape),PC_BOTTOMUP);
00035 if (oclass==NULL)
00036 GL_THROW("unable to register object class implemented by %s",__FILE__);
00037
00038
00039 if (gl_publish_variable(oclass,
00040 PT_int32, "interval", PADDR(interval),
00041 PT_int32, "limit", PADDR(limit),
00042 PT_enumeration, "integral", PADDR(integral),
00043 PT_KEYWORD, "NONE", LSI_NONE,
00044 PT_KEYWORD, "TIME", LSI_TIME,
00045 PT_enumeration, "period", PADDR(period),
00046 PT_KEYWORD, "NOT_USED", LSP_NOT_USED,
00047 PT_KEYWORD, "DAILY", LSP_DAILY,
00048 PT_KEYWORD, "HOURLY", LSP_HOURLY,
00049 PT_KEYWORD, "WEEKLY", LSP_WEEKLY,
00050 PT_KEYWORD, "MONTHLY", LSP_MONTHLY,
00051 PT_KEYWORD, "QUARTERLY", LSP_QUARTERLY,
00052 PT_KEYWORD, "YEARLY", LSP_YEARLY,
00053 PT_int32, "period_ex", PADDR(period_ex),
00054 PT_int32, "samples", PADDR(samples),
00055 PT_int32, "sample_rate", PADDR(sample_rate),
00056 PT_enumeration, "sample_mode", PADDR(sample_mode),
00057 PT_KEYWORD, "NOT_USED", LSS_NOT_USED,
00058 PT_KEYWORD, "EVERY_MINUTE", LSS_EVERY_MINUTE,
00059 PT_KEYWORD, "EVERY_HOUR", LSS_EVERY_HOUR,
00060 PT_KEYWORD, "EVERY_DAY", LSS_EVERY_DAY,
00061 PT_enumeration, "output_mode", PADDR(output_mode),
00062 PT_KEYWORD, "CSV", LSO_CSV,
00063 PT_KEYWORD, "SHAPE", LSO_SHAPE,
00064 PT_KEYWORD, "PLOT", LSO_PLOT,
00065 PT_KEYWORD, "PNG", LSO_PNG,
00066 PT_KEYWORD, "JPG", LSO_JPG,
00067 PT_enumeration, "state", PADDR(state), PT_ACCESS, PA_REFERENCE,
00068 PT_KEYWORD, "INIT", TS_INIT,
00069 PT_KEYWORD, "OPEN", TS_OPEN,
00070 PT_KEYWORD, "DONE", TS_DONE,
00071 PT_KEYWORD, "ERROR", TS_ERROR,
00072 PT_char256, "output_name", PADDR(output_name),
00073 PT_char256, "property", PADDR(prop),
00074 PT_char256, "selection", PADDR(selection),
00075 PT_char1024, "group", PADDR(group),
00076
00077 NULL)<1)
00078 GL_THROW("unable to publish properties in %s",__FILE__);
00079
00080
00081 defaults = this;
00082 memset(this, 0, sizeof(loadshape));
00083 interval = -1;
00084 limit = -1;
00085
00086 }
00087 }
00088
00089 int loadshape::create()
00090 {
00091
00092 memcpy(this,defaults,sizeof(loadshape));
00093 return 1;
00094 }
00095
00096
00097
00098
00099
00100 int loadshape::init(OBJECT *parent)
00101 {
00102 OBJECT *hdr = OBJECTHDR(this);
00103
00104 state = TS_INIT;
00105
00106 gl_error("loadshape is under development and will not contribute to the simulation results");
00107
00108 if(prop[0] == 0){
00109 gl_error("loadshapes require a target property!");
00110 state = TS_ERROR;
00111 return 1;
00112 }
00113
00114 if(parent == NULL && group[0] == 0){
00115 gl_error("loadshapes require either a parent object or a target group");
00116 state = TS_ERROR;
00117 return 1;
00118 }
00119
00120 if(parent != NULL && group[0] != 0){
00121 gl_warning("loadshape has both parent & group ~ using the parent and not the group");
00122 }
00123
00124
00125 if(sample_mode != LSS_NOT_USED){
00126 switch(sample_mode){
00127 case LSS_EVERY_MINUTE:
00128 sample_len = 60;
00129 break;
00130 case LSS_EVERY_HOUR:
00131 sample_len = 3600;
00132 break;
00133 case LSS_EVERY_DAY:
00134 sample_len = 86400;
00135 break;
00136 default:
00137 gl_error("Invalid sample mode!");
00138 return 0;
00139 }
00140 } else if(samples > 0){
00141 sample_len = 0;
00142 } else if(sample_rate > 0){
00143 sample_len = sample_rate;
00144 }
00145
00146
00147 if(period != LSP_NOT_USED){
00148 if(period_ex > 0){
00149 period_len = period_ex;
00150 } else {
00151 sprintf(errmsg, "No period length data found");
00152 gl_error(errmsg);
00153 state = TS_ERROR;
00154 return 1;
00155 }
00156 } else if(period_ex > 0){
00157 if(sample_len > 0){
00158 period_len = period_ex * sample_len;
00159 } else {
00160 sprintf(errmsg, "Cannot use explicit period length (in samples) without defining the sample length with sample_mode or sample_rate");
00161 gl_error(errmsg);
00162 state = TS_ERROR;
00163 return 1;
00164 }
00165 }
00166
00167
00168 if(samples > 0 && period_len > 0){
00169 if(period_len % samples > 0){
00170 sprintf(errmsg, "Cannot create %i equal sample periods given a period length of %i seconds!", samples, period_len);
00171 gl_error(errmsg);
00172 state = TS_ERROR;
00173 return 1;
00174 }
00175 sample_len = period_len / samples;
00176 }
00177
00178
00179 if(selection[0] != 0){
00180 sel_list = parse_cron(selection);
00181 if(sel_list == NULL){
00182 gl_error("Unable to parse the selection list ~ ignoring & continuing ungrouped");
00183 }
00184 }
00185
00186 return 1;
00187 }
00188
00189 TIMESTAMP loadshape::presync(TIMESTAMP t0, TIMESTAMP t1){
00190 return TS_NEVER;
00191 }
00192
00193 TIMESTAMP loadshape::sync(TIMESTAMP t0, TIMESTAMP t1){
00194 return TS_NEVER;
00195 }
00196
00197 int loadshape::commit(){
00198 return 1;
00199 }
00200
00202
00204
00205 EXPORT void new_loadshape(MODULE *mod){
00206 new loadshape(mod);
00207 }
00208
00209 EXPORT int create_loadshape(OBJECT **obj, OBJECT *parent)
00210 {
00211 *obj = gl_create_object(loadshape::oclass);
00212 if (*obj!=NULL)
00213 {
00214 loadshape *my = OBJECTDATA(*obj,loadshape);
00215 gl_set_parent(*obj,parent);
00216 my->create();
00217 return 1;
00218 }
00219 return 0;
00220 }
00221
00222 EXPORT int init_loadshape(OBJECT *obj)
00223 {
00224 loadshape *my = OBJECTDATA(obj,loadshape);
00225 return my->init(obj->parent);
00226 }
00227
00228 EXPORT TIMESTAMP sync_loadshape(OBJECT *obj, TIMESTAMP t0, PASSCONFIG pass)
00229 {
00230 loadshape *my = OBJECTDATA(obj, loadshape);
00231 TIMESTAMP t1 = my->sync(obj->clock, t0);
00232
00233 try {
00234 switch (pass)
00235 {
00236 case PC_PRETOPDOWN:
00237 t1 = my->presync(obj->clock, t0);
00238 break;
00239
00240 case PC_BOTTOMUP:
00241 t1 = my->sync(obj->clock, t0);
00242 obj->clock = t0;
00243 break;
00244
00245 default:
00246 gl_error("house::sync- invalid pass configuration");
00247 t1 = TS_INVALID;
00248 }
00249 }
00250 catch (char *msg)
00251 {
00252 gl_error("house::sync exception caught: %s", msg);
00253 t1 = TS_INVALID;
00254 }
00255 catch (...)
00256 {
00257 gl_error("house::sync exception caught: no info");
00258 t1 = TS_INVALID;
00259 }
00260
00261 obj->clock = t0;
00262 return t1;
00263 }
00264
00265 EXPORT int commit_loadshape(OBJECT *obj){
00266 loadshape *my = OBJECTDATA(obj,loadshape);
00267 return my->commit();
00268 }
00269
00272 #endif // zero