Example #1
0
void print_class_d(CLASS *oclass, int tabdepth){
	PROPERTY *prop;
	FUNCTION *func;
	char tabs[33];

	set_tabs(tabs, tabdepth);

	printf("%sclass %s {\n", tabs, oclass->name);
	if (oclass->parent){
		printf("%s\tparent %s;\n", tabs, oclass->parent->name);
		print_class_d(oclass->parent, tabdepth+1);
	}
	for (func=oclass->fmap; func!=NULL && func->oclass==oclass; func=func->next)
		printf( "%s\tfunction %s();\n", tabs, func->name);
	for (prop=oclass->pmap; prop!=NULL && prop->oclass==oclass; prop=prop->next)
	{
		char *propname = class_get_property_typename(prop->ptype);
		if (propname!=NULL){
			if(PA_HIDDEN == (prop->access & PA_HIDDEN) ){
				continue;
			}
			if(prop->unit != NULL)
			{
				printf("%s\t%s %s[%s];", tabs, propname, prop->name, prop->unit->name);
			}
			else if (prop->ptype==PT_set || prop->ptype==PT_enumeration)
			{
				KEYWORD *key;
				printf("%s\t%s {", tabs, propname);
				for (key=prop->keywords; key!=NULL; key=key->next)
					printf("%s=%"FMT_INT64"u%s", key->name, (int64)key->value, key->next==NULL?"":", ");
				printf("} %s;", prop->name);
			} 
			else 
			{
				printf("%s\t%s %s;", tabs, propname, prop->name);
			}
			if (prop->description!=NULL)
				printf(" // %s%s",prop->flags&PF_DEPRECATED?"(DEPRECATED) ":"",prop->description);
			printf("\n");
		}
	}
	printf("%s}\n\n", tabs);
}
void CGldEditorView::LoadGlobals(void)
{
	CListCtrl &list = GetListCtrl();
	
	int nColumns = list.GetHeaderCtrl()?list.GetHeaderCtrl()->GetItemCount():0;
	for (int i=0; i<nColumns; i++)
		list.DeleteColumn(0);

	CRect wr;
	list.GetClientRect(&wr);
	int nCol=0;
	int nWid=0;
	#define W(X) (nWid+=X,X)
	int Name = list.InsertColumn(nCol++,"Name",LVCFMT_LEFT,W(150),nCol);
	int Module = list.InsertColumn(nCol++,"Module",LVCFMT_LEFT,W(150),nCol);
	int Type = list.InsertColumn(nCol++,"Type",LVCFMT_LEFT,W(100),nCol);
	int Access = list.InsertColumn(nCol++,"Access",LVCFMT_LEFT,W(150),nCol);
	int Data = list.InsertColumn(nCol++,"Data",LVCFMT_LEFT,wr.Width()-nWid,nCol);
	#undef W

	GLOBALVAR *var = NULL;
	while ((var=global_getnext(var))!=NULL)
	{
		char modname[1024], varname[1024];
		int nItem = list.InsertItem(list.GetItemCount(),var->name);
		char buffer[1024]="";

		if (sscanf(var->name,"%[^:]::%s", modname, varname)==2)
		{
			list.SetItemText(nItem,Name,varname);
			list.SetItemText(nItem,Module,modname);
		}

		list.SetItemText(nItem,Type,class_get_property_typename(var->prop->ptype));

		convert_from_enumeration(buffer,sizeof(buffer),&(var->prop->access),object_access_property());
		list.SetItemText(nItem,Access,buffer);

		global_getvar(var->name,buffer,sizeof(buffer));
		list.SetItemText(nItem,Data,buffer);
	}
}
Example #3
0
/**	Fetches the property requested and uses the appropriate op on the value.
	@return boolean value
**/
static int compare_property_alt(OBJECT *obj, char *propname, FINDOP op, void *value){
	complex *complex_target = NULL;
	char *char_target = NULL;
	int16 *int16_target = NULL;
	int32 *int32_target = NULL;
	int64 *int64_target = NULL;
	PROPERTY *prop = object_get_property(obj, propname);

	if(prop == NULL){
		/* property not found in object ~ normal operation */
		return 0;
	}

	switch(prop->ptype){
		case PT_void:
			return 0;	/* no comparsion to be made */
		case PT_double:
			break;
		case PT_complex:
			complex_target = object_get_complex(obj, prop);
			if(complex_target == NULL)
				return 0; /* error value */
			break;
		case PT_enumeration:
		case PT_set:
			break;		/* not 100% sure how to make these cooperate yet */
		case PT_int16:
			int16_target = (int16 *)object_get_int16(obj, prop);
			if(int16_target == NULL)
				return 0;
			return compare_int16(*int16_target, op, *(int64 *)value);
		case PT_int32:
			int32_target = (int32 *)object_get_int32(obj, prop);
			return compare_int32(*int32_target, op, *(int64 *)value);
			break;
		case PT_int64:
			int64_target = (int64 *)object_get_int64(obj, prop);
			return compare_int64(*int64_target, op, *(int64 *)value);
			break;
		case PT_char8:
		case PT_char32:
		case PT_char256:
		case PT_char1024:
			char_target = (char *)object_get_string(obj, prop);
			if(char_target == NULL)
				return 0;
			return compare_string(char_target, op, value);
			break;
		case PT_object:

			break;
		case PT_bool:
			break;
		case PT_timestamp:
		case PT_double_array:
		case PT_complex_array:
			break;
#ifdef USE_TRIPLETS
		case PT_triple:
		case PT_triplex:
			break;
#endif
		default:
			output_error("comparison operators not supported for property type %s", class_get_property_typename(prop->ptype));
			/* TROUBLESHOOT
				This error is caused when an object find procedure uses a comparison operator
			that isn't allowed on a that type of property.  Make sure the property type
			and the comparison operator are compatible and try again.  If your GLM file
			isn't the cause of the problem, try reducing the complexity of the GLM file 
			you are using to isolate which module is causing the error and file a report 
			with the GLM file attached.
			 */
			return 0;
	}
}
void CGldEditorView::LoadObject(OBJECT *obj)
{
	CListCtrl &list = GetListCtrl();
	
	int nColumns = list.GetHeaderCtrl()?list.GetHeaderCtrl()->GetItemCount():0;
	for (int i=0; i<nColumns; i++)
		list.DeleteColumn(0);

	CRect wr;
	list.GetClientRect(&wr);
	int nCol=0;
	int nWid=0;
	#define W(X) (nWid+=X,X)
	int Name = list.InsertColumn(nCol++,"Name",LVCFMT_LEFT,W(150),nCol);
	int Type = list.InsertColumn(nCol++,"Type",LVCFMT_LEFT,W(100),nCol);
	int Class = list.InsertColumn(nCol++,"Class",LVCFMT_LEFT,W(150),nCol);
	int Access = list.InsertColumn(nCol++,"Access",LVCFMT_LEFT,W(100),nCol);
	int Data = list.InsertColumn(nCol++,"Data",LVCFMT_RIGHT,W(100),nCol);
	int Description = list.InsertColumn(nCol++,"Description",LVCFMT_LEFT,wr.Width()-nWid,nCol);
	#undef W

	int nItem;
	char buffer[1024]="";
	CLASS *oclass;
	PROPERTY *prop;

	nItem = list.InsertItem(list.GetItemCount(),"clock");
	list.SetItemText(nItem,Type,"TIMESTAMP");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"PROTECTED");
	list.SetItemText(nItem,Data,convert_from_timestamp(obj->clock,buffer,sizeof(buffer))?buffer:"");

	nItem = list.InsertItem(list.GetItemCount(),"name");
	list.SetItemText(nItem,Type,"OBJECTNAME");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"PUBLIC");
	list.SetItemText(nItem,Data,object_name(obj));

	nItem = list.InsertItem(list.GetItemCount(),"id");
	list.SetItemText(nItem,Type,"OBJECTNUM");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"REFERENCE");
	sprintf(buffer,"%d",obj->id);
	list.SetItemText(nItem,Data,buffer);

	nItem = list.InsertItem(list.GetItemCount(),"class");
	list.SetItemText(nItem,Type,"CLASSNAME");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"REFERENCE");
	list.SetItemText(nItem,Data,obj->oclass->name);

	nItem = list.InsertItem(list.GetItemCount(),"size");
	list.SetItemText(nItem,Type,"OBJECTRANK");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"REFERENCE");
	sprintf(buffer,"%d",obj->oclass->size);
	list.SetItemText(nItem,Data,buffer);

	nItem = list.InsertItem(list.GetItemCount(),"parent");
	list.SetItemText(nItem,Type,"OBJECTNAME");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"PUBLIC");
	list.SetItemText(nItem,Data,object_name(obj->parent));

	nItem = list.InsertItem(list.GetItemCount(),"rank");
	list.SetItemText(nItem,Type,"OBJECTRANK");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"PUBLIC");
	sprintf(buffer,"%d",obj->rank);
	list.SetItemText(nItem,Data,buffer);

	nItem = list.InsertItem(list.GetItemCount(),"in_svc");
	list.SetItemText(nItem,Type,"TIMESTAMP");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"PUBLIC");
	list.SetItemText(nItem,Data,convert_from_timestamp(obj->in_svc,buffer,sizeof(buffer))?buffer:"");

	nItem = list.InsertItem(list.GetItemCount(),"out_svc");
	list.SetItemText(nItem,Type,"TIMESTAMP");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"PUBLIC");
	list.SetItemText(nItem,Data,convert_from_timestamp(obj->out_svc,buffer,sizeof(buffer))?buffer:"");

	nItem = list.InsertItem(list.GetItemCount(),"latitude");
	list.SetItemText(nItem,Type,"double");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"PUBLIC");
	list.SetItemText(nItem,Data,convert_from_latitude(obj->latitude,buffer,sizeof(buffer))?buffer:"");

	nItem = list.InsertItem(list.GetItemCount(),"longitude");
	list.SetItemText(nItem,Type,"double");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"PUBLIC");
	list.SetItemText(nItem,Data,convert_from_latitude(obj->longitude,buffer,sizeof(buffer))?buffer:"");

	nItem = list.InsertItem(list.GetItemCount(),"flags");
	list.SetItemText(nItem,Type,"set");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"PROTECTED");
	list.SetItemText(nItem,Data,convert_from_set(buffer,sizeof(buffer),&(obj->flags),object_flag_property())?buffer:"");

	for (oclass=obj->oclass; oclass!=NULL; oclass=oclass->parent)
	{
		list.InsertItem(list.GetItemCount(),"");
		for (prop=class_get_first_property(oclass); prop!=NULL; prop=class_get_next_property(prop))
		{
			nItem = list.InsertItem(list.GetItemCount(),prop->name);
			list.SetItemText(nItem,Type,class_get_property_typename(prop->ptype));
			list.SetItemText(nItem,Class,oclass->name);
			list.SetItemText(nItem,Access,convert_from_enumeration(buffer,sizeof(buffer),&(prop->access),object_access_property())?buffer:"");
			list.SetItemText(nItem,Data,object_get_value_by_name(obj,prop->name,buffer,sizeof(buffer))?buffer:"(error)");
			list.SetItemText(nItem,Description,prop->description);
		}
	};
}
void CGldEditorView::LoadClass(CLASS *oclass)
{
	CListCtrl &list = GetListCtrl();
	
	int nColumns = list.GetHeaderCtrl()?list.GetHeaderCtrl()->GetItemCount():0;
	for (int i=0; i<nColumns; i++)
		list.DeleteColumn(0);

	CRect wr;
	list.GetClientRect(&wr);
	int nCol=0;
	int nWid=0;
	#define W(X) (nWid+=X,X)
	int Name = list.InsertColumn(nCol++,"Name",LVCFMT_LEFT,W(150),nCol);
	int Type = list.InsertColumn(nCol++,"Type",LVCFMT_LEFT,W(100),nCol);
	int Class = list.InsertColumn(nCol++,"Class",LVCFMT_LEFT,W(150),nCol);
	int Access = list.InsertColumn(nCol++,"Access",LVCFMT_LEFT,W(100),nCol);
	int Data = list.InsertColumn(nCol++,"Data",LVCFMT_LEFT,wr.Width()-nWid,nCol);
	#undef W

	char buffer[1024]="";
	int nItem;

	nItem = list.InsertItem(list.GetItemCount(),"inherit");
	list.SetItemText(nItem,Type,"CLASS");
	list.SetItemText(nItem,Class,"");
	list.SetItemText(nItem,Access,"PROTECTED");
	list.SetItemText(nItem,Data,oclass->parent?oclass->parent->name:"");

	nItem = list.InsertItem(list.GetItemCount(),"passconfig");
	list.SetItemText(nItem,Type,"set");
	list.SetItemText(nItem,Class,"");
	list.SetItemText(nItem,Access,"PROTECTED");
	strcpy(buffer,"");
	if (oclass->passconfig&PC_PRETOPDOWN) strcat(buffer,"PRETOPDOWN");
	if (oclass->passconfig&PC_BOTTOMUP) strcat(buffer,buffer[0]=='\0'?"":"|"),strcat(buffer,"BOTTOMUP");
	if (oclass->passconfig&PC_POSTTOPDOWN) strcat(buffer,buffer[0]=='\0'?"":"|"),strcat(buffer,"POSTTOPDOWN");
	list.SetItemText(nItem,Data,buffer);

	nItem = list.InsertItem(list.GetItemCount(),"module");
	list.SetItemText(nItem,Type,"MODULE");
	list.SetItemText(nItem,Class,"");
	list.SetItemText(nItem,Access,"PROTECTED");
	list.SetItemText(nItem,Data,oclass->module->name);

	list.InsertItem(list.GetItemCount(),"");

	PROPERTY *prop;
	for (prop=class_get_first_property(oclass); prop!=NULL; prop=class_get_next_property(prop))
	{
		nItem = list.InsertItem(list.GetItemCount(),prop->name);

		list.SetItemText(nItem,Type,class_get_property_typename(prop->ptype));

		list.SetItemText(nItem,Class,oclass->name);

		convert_from_enumeration(buffer,sizeof(buffer),&(prop->access),object_access_property());
		list.SetItemText(nItem,Access,buffer);

		list.SetItemText(nItem,Data,"");
	}
}
Example #6
0
/** Load and process the command-line arguments
	@return a STATUS value

	Arguments are processed immediately as they are seen.  This means that
	models are loaded when they are encountered, and in relation to the
	other flags.  Thus
	@code
	gridlabd --warn model1 --warn model2
	@endcode
	will load \p model1 with warnings on, and \p model2 with warnings off.
 **/
STATUS cmdarg_load(int argc, /**< the number of arguments in \p argv */
				   char *argv[]) /**< a list pointers to the argument string */
{
	int test_mod_num = 1;
	unsigned int pos=0;
	int i;
	char *pd1, *pd2;

	/* capture the execdir */
	strcpy(global_execname,argv[0]);
	strcpy(global_execdir,argv[0]);
	pd1 = strrchr(global_execdir,'/');
	pd2 = strrchr(global_execdir,'\\');
	if (pd1>pd2) *pd1='\0';
	else if (pd2>pd1) *pd2='\0';

	/* capture the command line */
	for (i=0; i<argc; i++)
	{
		if (pos<sizeof(global_command_line)-strlen(argv[i]))
			pos += sprintf(global_command_line+pos,"%s%s",pos>0?" ":"",argv[i]);
	}

	while (argv++,--argc>0)
	{
		if (strcmp(*argv,"--copyright")==0)
			legal_notice();
		else if (strcmp(*argv,"-w")==0 || strcmp(*argv,"--warn")==0)
			global_warn_mode=!global_warn_mode;
		else if (strcmp(*argv,"--bothstdout")==0)
			output_both_stdout();
		else if (strcmp(*argv,"-c")==0 || strcmp(*argv,"--check")==0)
			global_runchecks=!global_runchecks;
		else if (strcmp(*argv,"--debug")==0)
			global_debug_output=!global_debug_output;
		else if (strcmp(*argv,"--debugger")==0){
			global_debug_mode=1;
			global_debug_output=!global_debug_output;
		}
		else if (strcmp(*argv,"--dumpall")==0)
			global_dumpall=!global_dumpall;
		else if (strcmp(*argv,"-q")==0 || strcmp(*argv,"--quiet")==0)
			global_quiet_mode=!global_quiet_mode;
		else if (strcmp(*argv,"-v")==0 || strcmp(*argv,"--verbose")==0){
			global_verbose_mode=!global_verbose_mode;
		}
		else if (strcmp(*argv,"--profile")==0)
			global_profiler=!global_profiler;
		else if (strcmp(*argv,"--pause")==0)
			global_pauseatexit=!global_pauseatexit;
		else if (strcmp(*argv,"--compile")==0)
			global_compileonly = !global_compileonly;
		else if (strcmp(*argv,"--license")==0)
			legal_license();
		else if (strcmp(*argv,"--server_portnum")==0 || strcmp(*argv,"-P")==0)
		{
			if (argc-1>0)
				global_server_portnum = (argc--,atoi(*++argv));
			else
			{
				output_fatal("missing server port number");
				/*	TROUBLESHOOT
					The <b>-P</b> or <b>--server_portnum</b> command line directive
					was not followed by a valid number.  The correct syntax is
					<b>-P <i>number</i></b> or <b>--server_portnum <i>number</i></b>.
				 */
			}
		}
		else if (strcmp(*argv, "-V")==0 ||strcmp(*argv, "--version")==0)
		{
			char *buildinfo = strstr(BUILD,":");
			int build = buildinfo ? atoi(strstr(BUILD,":")+1) : 0;
			output_message("Revision major: %d", REV_MAJOR);
			output_message("Revision minor: %d", REV_MINOR);
			output_message("Patch number  : %d", REV_PATCH);
			output_message("Branch name   : %s", BRANCH);
			if (build>0)
				output_message("Build number  : %d", build);
			else
				output_message("Build number  : %s",
#ifdef WIN32
#ifdef _DEBUG
#ifdef _M_X64
			"WIN64-DEBUG"
#else
			"WIN32-DEBUG" 
#endif
#else
#ifdef _M_X64
			"WIN64-RELEASE"
#else
			"WIN32-RELEASE"
#endif
#endif
#else
			"DEV"
#endif		
			);
		}
		else if (strcmp(*argv,"--dsttest")==0)
			timestamp_test();
		else if (strcmp(*argv,"--randtest")==0)
			random_test();
		else if (strcmp(*argv,"--unitstest")==0)
			unit_test();
		else if (strcmp(*argv,"--scheduletest")==0)
			schedule_test();
		else if (strcmp(*argv,"--loadshapetest")==0)
			loadshape_test();
		else if (strcmp(*argv,"--endusetest")==0)
			enduse_test();
		else if (strcmp(*argv,"--xmlstrict")==0)
			global_xmlstrict = !global_xmlstrict;
		else if (strcmp(*argv,"--globaldump")==0)
		{
			global_dump();
			exit(0);
		}
		else if (strcmp(*argv,"--relax")==0)
			global_strictnames = FALSE;
		else if (strncmp(*argv,"--pidfile",9)==0)
		{
			char *filename = strchr(*argv,'=');
			if (filename==NULL)
				strcpy(global_pidfile,"gridlabd.pid");
			else
				strcpy(global_pidfile,filename+1);
		}
		else if (strncmp(*argv,"--kml",5)==0)
		{
			char *filename = strchr(*argv,'=');
			if (filename)
				strcpy(global_kmlfile,filename+1);
			else
				strcpy(global_kmlfile,"gridlabd.kml");
		}
		else if (strcmp(*argv, "--avlbalance") == 0){
			global_no_balance = !global_no_balance;
		}
		else if (strcmp(*argv,"--testall")==0){
			FILE *fd = NULL;
			if(*++argv != NULL)
				fd = fopen(*argv,"r");
			else {
				output_fatal("no filename for testall");
				/*	TROUBLESHOOT
					The --testall parameter was found on the command line, but
					if was not followed by a filename containing the test
					description file.
				*/
				return FAILED;
			}
			argc--;
			global_test_mode=TRUE;

			if(fd == NULL)
			{
				output_fatal("incorrect module list file name");
				/*	TROUBLESHOOT
					The --testall parameter was found on the command line, but
					if was not followed by a valid filename containing the test
					description file.
				*/
				return FAILED;
			}
			if(load_module_list(fd,&test_mod_num) == FAILED)
				return FAILED;
		}
		else if (strcmp(*argv,"--modhelp")==0)
		{
			if(argc-1 > 0){
				MODULE *mod = NULL;
				CLASS *oclass = NULL;
				argv++;
				argc--;
				if(strchr(argv[0], ':') == 0){ // no class
					mod = module_load(argv[0],0,NULL);
				} else {
					GLOBALVAR *var=NULL;
					char *cname;
					cname = strchr(argv[0], ':')+1;
					mod = module_load(strtok(argv[0],":"),0,NULL);
					oclass = class_get_class_from_classname(cname);
					if(oclass == NULL){
						output_fatal("Unable to find class '%s' in module '%s'", cname, argv[0]);
						/*	TROUBLESHOOT
							The <b>--modhelp</b> parameter was found on the command line, but
							if was followed by a class specification that isn't valid.
							Verify that the class exists in the module you specified.
						*/
						return FAILED;
					}

					/* dump module globals */
					printf("module %s {\n", mod->name);
					while ((var=global_getnext(var))!=NULL)
					{
						PROPERTY *prop = var->prop;
						char *proptype = class_get_property_typename(prop->ptype);
						if (strncmp(var->prop->name,mod->name,strlen(mod->name))!=0)
							continue;
						if (proptype!=NULL){
							if(prop->unit != NULL)
							{
								printf("\t%s %s[%s];", proptype, strrchr(prop->name,':')+1, prop->unit->name);
							}
							else if (prop->ptype==PT_set || prop->ptype==PT_enumeration)
							{
								KEYWORD *key;
								printf("\t%s {", proptype);
								for (key=prop->keywords; key!=NULL; key=key->next)
									printf("%s=%"FMT_INT64"u%s", key->name, (int64)key->value, key->next==NULL?"":", ");
								printf("} %s;", strrchr(prop->name,':')+1);
							} 
							else 
							{
								printf("\t%s %s;", proptype, strrchr(prop->name,':')+1);
							}
							if (prop->description!=NULL)
								printf(" // %s%s",prop->flags&PF_DEPRECATED?"(DEPRECATED) ":"",prop->description);
							printf("\n");
						}
					}
					printf("}\n");
				}
				if(mod == NULL){
					output_fatal("module %s is not found",*argv);
					/*	TROUBLESHOOT
						The <b>--modhelp</b> parameter was found on the command line, but
						if was followed by a module specification that isn't valid.
						Verify that the module exists in GridLAB-D's <b>lib</b> folder.
					*/
					return FAILED;
				}
				if(oclass != NULL)
				{
					print_class(oclass);
				}
				else
				{
					CLASS	*oclass;
					pntree	*ctree;
					/* lexographically sort all elements from class_get_first_class & oclass->next */

					oclass=class_get_first_class();
					ctree = (pntree *)malloc(sizeof(pntree));
					
					if(ctree == NULL){
						throw_exception("--modhelp: malloc failure");
						/* TROUBLESHOOT
							The memory allocation needed for module help to function has failed.  Try freeing up system memory and try again.
						 */
					}
					
					ctree->name = oclass->name;
					ctree->oclass = oclass;
					ctree->left = ctree->right = 0;
					
					for(; oclass != NULL; oclass = oclass->next){
						modhelp_alpha(&ctree, oclass);
						//print_class(oclass);
					}

					/* flatten tree */
					print_modhelp_tree(ctree);
				}
			}
		}
		else if (strcmp(*argv,"--modtest")==0)
		{
			if (argc-1>0)
			{
				MODULE *mod = module_load(argv[1],0,NULL);
				if (mod==NULL)
					output_fatal("module %s is not found",argv[1]);
					/*	TROUBLESHOOT
						The <b>--modtest</b> parameter was found on the command line, but
						if was followed by a module specification that isn't valid.
						Verify that the module exists in GridLAB-D's <b>lib</b> folder.
					*/
				else 
				{
					argv++;argc--;
					if (mod->test==NULL)
						output_fatal("module %s does not implement a test routine", argv[0]);
						/*	TROUBLESHOOT
							The <b>--modtest</b> parameter was found on the command line, but
							if was followed by a specification for a module that doesn't
							implement any test procedures.  See the <b>--libinfo</b> command
							line parameter for information on which procedures the
							module supports.
						*/
					else
					{
						output_test("*** modtest of %s beginning ***", argv[0]);
						mod->test(0,NULL);
						output_test("*** modtest of %s ended ***", argv[0]);
					}
				}			
			}
			else
			{
				output_fatal("definition is missing");
				/*	TROUBLESHOOT
					The <b>--modtest</b> parameter was found on the command line, but
					if was not followed by a module specification.  The correct
					syntax is <b>gridlabd --modtest <i>module_name</i></b>.
				*/
				return FAILED;
			}
		}
		else if (strcmp(*argv,"--test")==0){
			global_test_mode=TRUE;
			global_strictnames = FALSE;
			output_debug("disabling strict naming for tests");
			if (argc-1>0)
			{
				char mod_test[100];
				sprintf(mod_test,"mod_test%d=%s",test_mod_num++,*++argv);
				if (global_setvar(mod_test)==SUCCESS)
					argc--;
			}
			else
			{
				output_fatal("test module name is missing");
				/*	TROUBLESHOOT
					The <b>--test</b> parameter was found on the command line, but
					if was not followed by a module specification that is valid.
					The correct syntax is <b>gridlabd --test <i>module_name</i></b>.
				*/
				return FAILED;
			}

		}
		else if (strcmp(*argv,"-D")==0 || strcmp(*argv,"--define")==0)
		{
			if (argc-1>0)
			{
				bool namestate = global_strictnames;
				global_strictnames = FALSE;
				if (global_setvar(*++argv,NULL)==SUCCESS){
					argc--;
				}
				global_strictnames = namestate;
			}
			else
			{
				output_fatal("definition is missing");
				/* TROUBLESHOOT
					The <b>-D</b> or <b>--define</b> command line parameters was given, but
					it was not followed by a variable definition.  The correct syntax
					<b>-D </i>variable</i>=<i>value</i></b> or
					<b>--define </i>variable</i>=<i>value</i></b>
				 */
				return FAILED;
			}
		}
		else if (strcmp(*argv,"--globals")==0)
		{
			char *list[65536];
			int i, n=0;
			GLOBALVAR *var = NULL;

			/* load the list into the array */
			while ((var=global_getnext(var))!=NULL)
			{
				if (n<sizeof(list)/sizeof(list[0]))
					list[n++] = var->prop->name;
				else
				{
					output_fatal("--globals has insufficient buffer space to sort globals list");
					return FAILED;
				}
			}

			/* sort the array */
			qsort(list,n,sizeof(list[0]),compare);

			/* output sorted array */
			for (i=0; i<n; i++)
			{
				char buffer[1024];
				var = global_find(list[i]);
				printf("%s=%s;",var->prop->name,global_getvar(var->prop->name,buffer,sizeof(buffer))?buffer:"(error)");
				if (var->prop->description || var->prop->flags&PF_DEPRECATED)
					printf(" // %s%s", (var->prop->flags&PF_DEPRECATED)?"DEPRECATED ":"", var->prop->description?var->prop->description:"");
				printf("\n");
			}
		}
		else if (strcmp(*argv,"--redirect")==0)
		{
			if (argc-1>0)
			{
				char buffer[1024]; char *p;
				strcpy(buffer,*++argv); argc--;
				if (strcmp(buffer,"all")==0)
				{
					if (output_redirect("output",NULL)==NULL ||
						output_redirect("error",NULL)==NULL ||
						output_redirect("warning",NULL)==NULL ||
						output_redirect("debug",NULL)==NULL ||
						output_redirect("verbose",NULL)==NULL ||
						output_redirect("profile",NULL)==NULL ||
						output_redirect("progress",NULL)==NULL)
					{
						output_fatal("redirection of all failed");
						/* TROUBLESHOOT
							An attempt to close all standard stream from the
							command line using <b>--redirect all</b> has failed.
							One of the streams cannot be closed.  Try redirecting
							each stream separately until the problem stream is
							identified and the correct the problem with that stream.
						 */
						return FAILED;
					}
				}
				else if ((p=strchr(buffer,':'))!=NULL)
				{
					*p++='\0';
					if (output_redirect(buffer,p)==NULL)
					{
						output_fatal("redirection of %s to '%s' failed: %s",buffer,p, strerror(errno));
						/*	TROUBLESHOOT
							An attempt to redirect a standard stream from the 
							command line using <b>--redirect <i>stream</i>:<i>destination</i></b>
							has failed.  The message should provide an indication of why the
							attempt failed. The remedy will depend on the nature of the problem.
						 */
						return FAILED;
					}
				}
				else if (output_redirect(buffer,NULL)==NULL)
				{
						output_fatal("default redirection of %s failed: %s",buffer, strerror(errno));
						/*	TROUBLESHOOT
							An attempt to close a standard stream from the 
							command line using <b>--redirect <i>stream</i></b>
							has failed.  The message should provide an indication of why the
							attempt failed. The remedy will depend on the nature of the problem.
							
						 */
						return FAILED;
				}
			}
			else
			{
				output_fatal("redirection is missing");
				/*	TROUBLESHOOT
					A <b>--redirect</b> directive on the command line is missing
					its redirection specification.  The correct syntax is
					<b>--redirect <i>stream</i>[:<i>destination</i>]</b>.
				 */
				return FAILED;
			}
		}
		else if (strcmp(*argv,"-L")==0 || strcmp(*argv,"--libinfo")==0)
		{
			if (argc-1>0)
			{	argc--;
				module_libinfo(*++argv);
				exit(0);
			}
			else
			{
				output_fatal("missing library name");
				/*	TROUBLESHOOT
					The <b>-L</b> or <b>--libinfo</b> command line directive
					was not followed by a module name.  The correct syntax is
					<b>-L <i>module_name</i></b> or <b>--libinfo <i>module_name</i></b>.
				 */
				return FAILED;
			}
		}
		else if (strcmp(*argv,"-T")==0 || strcmp(*argv,"--threadcount")==0)
		{
			if (argc-1>0)
				global_threadcount = (argc--,atoi(*++argv));
			else
			{
				output_fatal("missing thread count");
				/*	TROUBLESHOOT
					The <b>-T</b> or <b>--threadcount</b> command line directive
					was not followed by a valid number.  The correct syntax is
					<b>-T <i>number</i></b> or <b>--threadcount <i>number</i></b>.
				 */
				return FAILED;
			}
		}
		else if (strcmp(*argv,"-o")==0 || strcmp(*argv,"--output")==0)
		{
			if (argc-1>0)
				strcpy(global_savefile,(argc--,*++argv));
			else
			{
				output_fatal("missing output file");
				/* TROUBLESHOOT
					The <b>-o</b> or <b>--output</b> command line directive
					was not followed by a valid filename.  The correct syntax is
					<b>-o <i>file</i></b> or <b>--output <i>file</i></b>.
				 */
				return FAILED;
			}
		}
		else if (strcmp(*argv,"-e")==0 || strcmp(*argv,"--environment")==0)
		{
			if (argc-1>0)
				strcpy(global_environment,(argc--,*++argv));
			else
			{
				output_fatal("environment not specified");
				/*	TROUBLESHOOT
					The <b>-e</b> or <b>--environment</b> command line directive
					was not followed by a valid environment specification.  The
					correct syntax is <b>-e <i>keyword</i></b> or <b>--environment <i>keyword</i></b>.
				 */
				return FAILED;
			}
		}
		else if (strcmp(*argv,"--xmlencoding")==0)
		{
			if (argc-1>0)
			{
				global_xml_encoding = atoi(*++argv);
				argc--;
			}
			else
			{
				output_fatal("xml encoding not specified");
				/*	TROUBLESHOOT
					The <b>--xmlencoding</b> command line directive
					was not followed by a encoding specification.  The
					correct syntax is <b>--xmlencoding <i>keyword</i></b>.
				 */
				return FAILED;
			}
		}
		else if (strcmp(*argv,"--xsd")==0)
		{
			if (argc-1>0)
			{
				argc--;
				exit(output_xsd(*++argv));
			}
			else
			{
				MODULE *mod;
				for (mod=module_get_first(); mod!=NULL; mod=mod->next)
					output_xsd(mod->name);
				return SUCCESS;
			}
		}
		else if (strcmp(*argv,"--xsl")==0)
		{
			if (argc-1>0)
			{
				char fname[1024];
				char *p_arg = *++argv;
				char n_args=1;
				char **p_args;
				argc--;
				while (*p_arg++!='\0') if (*p_arg==',')	n_args++;
				p_args = (char**)malloc(sizeof(char*)*n_args);
				p_arg = strtok(*argv,",");
				n_args=0;
				while (p_arg!=NULL)
				{
					p_args[n_args++] = p_arg;
					p_arg = strtok(NULL,",");
				}
				sprintf(fname,"gridlabd-%d_%d.xsl",global_version_major,global_version_minor);
				exit(output_xsl(fname,n_args,p_args));
			}
			else
			{
				output_fatal("module list not specified");
				/*	TROUBLESHOOT
					The <b>--xsl</b> command line directive
					was not followed by a validlist of modules.  The
					correct syntax is <b>--xsl <i>module1</i>[,<i>module2</i>[,...]]</b>.
				 */
				return FAILED;
			}
		}
		else if (strcmp(*argv,"--stream")==0)
			global_streaming_io_enabled = !global_streaming_io_enabled;
		else if (strcmp(*argv,"--server")==0)
			strcpy(global_environment,"server");
		else if (strcmp(*argv,"-h")==0 || strcmp(*argv,"--help")==0)
		{
			printf("Syntax: gridlabd [OPTIONS ...] <file> ... \nOptions:\n"
				"  --avlbalance              toggles AVL tree balancing\n"
				"  -c|--check                toggles module checks after model loads\n"
				"  -D|--define <def>         defines a macro value\n"
				"  --debug                   toggles debug output (prints internal messages)\n"
				"  --debugger                toggles debugger mode (generates internal messages)\n"
				"  --dumpall                 toggles module data dump after run completes\n"
				"  -e|--environment <name>   specifies user environment (default none)\n"
				"  --license                 print license information\n"
				"  -L|--libinfo <module>     print module library information\n"
				"  -o|--output <file>        specifies model should be output after run\n"
				"  --profile                 toggles profilers\n"
				"  -q|--quiet                toggles quiet mode (suppresses startup banner)\n"
				"  --test                    toggles test mode (activate testing procedures)\n"
				"  -T|--threadcount <n>      specifies the number of processor threads to use\n"
				"  -v|--verbose              toggles verbose mode (active verbose messages)\n"
				"  -V|--version              prints the GridlabD version information\n"
				"  -w|--warn                 toggles warning mode (generates warning messages)\n"
				"  --xmlencoding <num>       set the XML encoding (8, 16, or 32)\n"
				"  --xmlstrict               toggles XML encoding to be strict\n"
				"  --xsd <module>[:<object>] prints the xsd of an object\n"
				"  --xsl <modlist>           prints the xsl for the modules listed\n"
				);
			exit(0);
		}
		else if (**argv!='-')
		{
			if (global_test_mode)
				output_warning("file '%s' ignored in test mode", *argv);
				/* TROUBLESHOOT
				   This warning is caused by an attempt to read an input file in self-test mode.  
				   The use of self-test model precludes reading model files.  Try running the system
				   in normal more or leaving off the model file name.
				 */
			else {
				if (!loadall(*argv))
					return FAILED;
				/* preserve name of first model only */
				if (strcmp(global_modelname,"")==0)
					strcpy(global_modelname,*argv);
			}
		}
		else
		{
			int n = module_cmdargs(argc,argv);
			if (n==0)
			{
				output_error("command line option '%s' is not recognized",*argv);
				/* TROUBLESHOOT
					The command line option given is not valid where it was found.
					Check the command line for correct syntax and order of options.
				 */
				return FAILED;
			}
		}
	}
	/*debug_traverse_tree(NULL);*/  /* for checking the name tree & getting a test file. -mh */
	return SUCCESS;
}
int enduse_publish(CLASS *oclass, PROPERTYADDR struct_address, char *prefix)
{
	enduse *this=NULL; // temporary enduse structure used for mapping variables
	int result = 0;
	struct s_map_enduse{
		PROPERTYTYPE type;
		char *name;
		char *addr;
		char *description;
		int flags;
	}*p, prop_list[]={
		{PT_complex, "energy[kVAh]", (char *)PADDR(energy), "the total energy consumed since the last meter reading"},
		{PT_complex, "power[kVA]", (char *)PADDR(total), "the total power consumption of the load"},
		{PT_complex, "peak_demand[kVA]", (char *)PADDR(demand), "the peak power consumption since the last meter reading"},
		{PT_double, "heatgain[Btu/h]", (char *)PADDR(heatgain), "the heat transferred from the enduse to the parent"},
		{PT_double, "heatgain_fraction[pu]", (char *)PADDR(heatgain_fraction), "the fraction of the heat that goes to the parent"},
		{PT_double, "current_fraction[pu]", (char *)PADDR(current_fraction),"the fraction of total power that is constant current"},
		{PT_double, "impedance_fraction[pu]", (char *)PADDR(impedance_fraction), "the fraction of total power that is constant impedance"},
		{PT_double, "power_fraction[pu]", (char *)PADDR(power_fraction), "the fraction of the total power that is constant power"},
		{PT_double, "power_factor", (char *)PADDR(power_factor), "the power factor of the load"},
		{PT_complex, "constant_power[kVA]", (char *)PADDR(power), "the constant power portion of the total load"},
		{PT_complex, "constant_current[kVA]", (char *)PADDR(current), "the constant current portion of the total load"},
		{PT_complex, "constant_admittance[kVA]", (char *)PADDR(admittance), "the constant admittance portion of the total load"},
		{PT_double, "voltage_factor[pu]", (char *)PADDR(voltage_factor), "the voltage change factor"},
		{PT_double, "breaker_amps[A]", (char *)PADDR(breaker_amps), "the rated breaker amperage"},
		{PT_set, "configuration", (char *)PADDR(config), "the load configuration options"},
			{PT_KEYWORD, "IS220", (set)EUC_IS220},
			//{PT_KEYWORD, "NONE",(set)0},
	}, *last=NULL;

	// publish the enduse load itself
	PROPERTY *prop = property_malloc(PT_enduse,oclass,strcmp(prefix,"")==0?"load":prefix,struct_address,NULL);
	prop->description = "the enduse load description";
	prop->flags = 0;
	class_add_property(oclass,prop);

	for (p=prop_list;p<prop_list+sizeof(prop_list)/sizeof(prop_list[0]);p++)
	{
		char name[256], lastname[256];

		if(prefix == NULL || strcmp(prefix,"")==0)
		{
			strcpy(name,p->name);
		}
		else
		{
			//strcpy(name,prefix);
			//strcat(name, ".");
			//strcat(name, p->name);
			sprintf(name,"%s.%s",prefix,p->name);
		}

		if (p->type<_PT_LAST)
		{
			prop = property_malloc(p->type,oclass,name,p->addr+(int64)struct_address,NULL);
			prop->description = p->description;
			prop->flags = p->flags;
			class_add_property(oclass,prop);
			result++;
		}
		else if (last==NULL)
		{
			output_error("PT_KEYWORD not allowed unless it follows another property specification");
			/* TROUBLESHOOT
				The enduse_publish structure is not defined correctly.  This is an internal error and cannot be corrected by
				users.  Contact technical support and report this problem.
			 */
			return -result;
		}
		else if (p->type==PT_KEYWORD) {
			switch (last->type) {
			case PT_enumeration:
				if (!class_define_enumeration_member(oclass,lastname,p->name,p->type))
				{
					output_error("unable to publish enumeration member '%s' of enduse '%s'", p->name,last->name);
					/* TROUBLESHOOT
					The enduse_publish structure is not defined correctly.  This is an internal error and cannot be corrected by
					users.  Contact technical support and report this problem.
					 */
					return -result;
				}
				break;
			case PT_set:
				if (!class_define_set_member(oclass,lastname,p->name,(int64)p->addr))
				{
					output_error("unable to publish set member '%s' of enduse '%s'", p->name,last->name);
					/* TROUBLESHOOT
					The enduse_publish structure is not defined correctly.  This is an internal error and cannot be corrected by
					users.  Contact technical support and report this problem.
					 */
					return -result;
				}
				break;
			default:
				output_error("PT_KEYWORD not supported after property '%s %s' in enduse_publish", class_get_property_typename(last->type), last->name);
				/* TROUBLESHOOT
				The enduse_publish structure is not defined correctly.  This is an internal error and cannot be corrected by
				users.  Contact technical support and report this problem.
				 */
				return -result;
			}
		}
		else
		{
			output_error("property type '%s' not recognized in enduse_publish", class_get_property_typename(last->type));
			/* TROUBLESHOOT
				The enduse_publish structure is not defined correctly.  This is an internal error and cannot be corrected by
				users.  Contact technical support and report this problem.
			*/
			return -result;
		}

		last = p;
		strcpy(lastname,name);
	}

	return result;
}
Example #8
0
/** Get a value (object, clock, or global)
	\verbatim gl('get',name) \endverbatim
 **/
void cmex_get(int nlhs, mxArray *plhs[], /**< {data} */
				int nrhs, const mxArray *prhs[] ) /**< (name) */
{
	if (nrhs>0)
	{
		char name[1024];
		OBJECT *obj=NULL;
		if (!mxIsChar(prhs[0]))
			output_error("entity name (arg 1) is not a string");
		else if (nlhs>1)
			output_error("only one return value is possible");
		else if (mxGetString(prhs[0],name,sizeof(name))!=0)
			output_error("object name too long");
		else if (strcmp(name,"clock")==0)
		{
			char *fnames[] = {"timestamp","timestring","timezone"};
			char buffer[256];
			mxArray *pTimestamp = mxCreateDoubleMatrix(1,1,mxREAL);
			mxArray *pTimestring = mxCreateString(convert_from_timestamp(global_clock,buffer,sizeof(buffer))?buffer:"(error)");
			mxArray *pTimezone = mxCreateString(timestamp_current_timezone());

			*(double*)mxGetPr(pTimestamp) = ((double)global_clock)/TS_SECOND;
			plhs[0] = mxCreateStructMatrix(1,1,sizeof(fnames)/sizeof(fnames[0]),fnames);
			mxSetFieldByNumber(plhs[0],0,0,pTimestamp);
			mxSetFieldByNumber(plhs[0],0,1,pTimestring);
			mxSetFieldByNumber(plhs[0],0,2,pTimezone);
		}
		else if (strcmp(name,"property")==0 && nrhs>1)
		{
			if (mxGetString(prhs[1],name,sizeof(name))!=0)
				output_error("missing property name");
			else
			{
				char classname[256];
				char propname[256];
				if (sscanf(name,"%[^.].%s",classname,propname)==2)
				{
					CLASS *pClass = class_get_class_from_classname(classname);
					if (pClass)
					{
						PROPERTY *pProp = class_find_property(pClass,propname);
						if (pProp)
						{
							char *fields[] = {"class","name","type","size","access","unit","delegation","keywords"};
							int fn = 0;
							mxArray *oclass = mxCreateString(classname);
							mxArray *prop = mxCreateString(pProp->name);
							mxArray *type = mxCreateString(class_get_property_typename(pProp->ptype));
							mxArray *size = mxCreateDoubleMatrix(1,1,mxREAL); 
							mxArray *access = mxCreateString("(na)"); /** @todo implement get_property access info (ticket #187) */
							mxArray *unit = mxCreateString(pProp->unit->name);
							mxArray *delegation = mxCreateString(pProp->delegation?pProp->delegation->oclass->name:"(none)");
							mxArray *keywords = mxCreateString("(na)"); /** @todo implement get_property keywords (ticket #188) */
							*(mxGetPr(size)) = pProp->size==0?1:pProp->size;
							plhs[0] = mxCreateStructMatrix(1,1,sizeof(fields)/sizeof(fields[0]),fields);
							mxSetFieldByNumber(plhs[0],0,fn++,oclass);
							mxSetFieldByNumber(plhs[0],0,fn++,prop);
							mxSetFieldByNumber(plhs[0],0,fn++,type);
							mxSetFieldByNumber(plhs[0],0,fn++,size);
							mxSetFieldByNumber(plhs[0],0,fn++,access);
							mxSetFieldByNumber(plhs[0],0,fn++,unit);
							mxSetFieldByNumber(plhs[0],0,fn++,delegation);
							mxSetFieldByNumber(plhs[0],0,fn++,keywords);
						}
						else
							output_error("property %s is not found in class %s", propname,classname);
					}
					else
						output_error("class %s is not found");
				}
				else
					output_error("property name not in class.name format");
			}
		}
		else if ((convert_to_object(name,&obj,NULL))==0)
		{
			GLOBALVAR *var = global_find(name);
			if (var==NULL)
				output_error("entity '%s' not found", name);
			else if (var->prop->ptype==PT_double)
			{
				size_t size = var->prop->size?var->prop->size:1;
				plhs[0] = mxCreateDoubleMatrix(size,1,mxREAL);
				memcpy(mxGetPr(plhs[0]),(void*)var->prop->addr,sizeof(double)*size);
			}
			else if (var->prop->ptype==PT_int32)
			{
				size_t size = var->prop->size?var->prop->size:1;
				plhs[0] = mxCreateDoubleMatrix(size,1,mxREAL);

				memcpy(mxGetPr(plhs[0]),(void*)var->prop->addr,sizeof(double)*size);
			}
			else if (var->prop->ptype!=PT_double)
				output_error("cannot retrieve globals that are of type %s",class_get_property_typename(var->prop->ptype));
		}
		else if ((plhs[0]=get_object_data(obj))==NULL)
			output_error("unable to extract %s data", name);
	}
	else
		output_error("object not specified");
	return;
}