Exemple #1
0
// Retrieve the value of the given built-in enum attribute.
// If the value is missing, this is marked in the ValueStatus
// and the corresponding default is returned.
// Returns -1 or a globally unique id for the value such that
// enuNames[id] is the string representation of the enum value. 
Enu getEnumValue(void* element, Att a, ValueStatus* vs) {
    const char* value = getString(element, a);
    Enu id = valueDefined;
    if (!value) { 
        *vs = valueMissing;
        switch (a) {
            case att_variableNamingConvention: return enu_flat;
            case att_variability: return enu_continuous;
            case att_causality: return enu_internal;
            case att_alias: return enu_noAlias;
            default: return -1;
        }
    }
    id = checkEnumValue(value);
    if (id==-1) *vs = valueIllegal; 
    return id;
}
////////////////////////////////////////////////////////////////////////////////////
/// Generate idf file for EnergyPlus
///
///\param md The model description
////////////////////////////////////////////////////////////////////////////////////
void printidf(const char* fmuFilNam, ModelDescription* md)
{
	FILE *fp;

  char type[12];
	int i, j, varname, vardes=-1;
	void **list;
	ScalarVariable* se;
	Element* ee;

	fp = fopen("tmp.idf", "w");

	if (fp == NULL) {
	  printf("Can't create temporary idf file!\n");
	  exit(42);  // STL error code: File not open.
	}

	/////////////////////////////////////////////////////////////////////////////
	// Define ExternalInterface
	fprintf(fp, "ExternalInterface,\n");
	fprintf(fp, "  FunctionalMockupUnit;\t\t!- Name of External Interface\n");

	////////////////////////////////////////////////////////////////////////////
  // Define ExternalInterface:FunctionalMockupUnit
	fprintf(fp, "\nExternalInterface:FunctionalMockupUnit,\n");

	fprintf(fp, "  %s,\t\t!- FMU Filename\n", fmuFilNam);
  //fprintf(fp, "   ,\t\t!- FMU Model Name\n");
  fprintf(fp, "   ;\t\t!- FMU Timeout in milli-seconds\n");
  //fprintf(fp, "   ,\t\t!- FMU Visible Value\n");
  //fprintf(fp, "   ,\t\t!- FMU Interactive Value\n");
  //fprintf(fp, "   ;\t\t!- FMU LoggingOn Value\n");

	list = (void **)md->modelVariables;
	if (list)
		for(j=0; list[j]; j++)
		{
			Element* e = (Element*)list[j];
			Enu val = enu_none;

			for(i=0; i<e->n; i+=2)
			{
				if(!strcmp(e->attributes[i], "name"))
					varname = i+1;
				else if(!strcmp(e->attributes[i], "causality"))
					val = checkEnumValue(e->attributes[i+1]);
				else if(!strcmp(e->attributes[i], "description"))
					vardes = i+1;
			}

      /////////////////////////////////////////////////////////////////////////////////////
      // Define ExternalInterface:FunctionalMockupUnit:From:Variable
      // Define part of ExternalInterface:FunctionalMockupUnit:To      
			if(val == enu_input || val == enu_output)
			{
				switch (val)
				{
					case enu_input:
						fprintf(fp, "\nExternalInterface:FunctionalMockupUnit:From:Variable,\n");
            fprintf(fp, "   ,\t\t!- EnergyPlus Key Value\n");          
						break;
					case enu_output:
            // User should manually define the To type: Schedule, Actuator, Variable
						fprintf(fp, "\nExternalInterface:FunctionalMockupUnit:To:\n");
						break;
					default:
						break;
				}
  

        fprintf(fp, "   ,\t\t!- Energyplus Variable Name\n");
	      fprintf(fp, "   %s,\t\t!- FMU Filename\n", fmuFilNam);
				fprintf(fp, "   ,\t\t!- FMU Instance Name\n");
				switch (val)
				{
          case enu_input:
            fprintf(fp, "   %s;\t\t!- FMU Variable Name\n", e->attributes[varname]);
            break;
					case enu_output:
            fprintf(fp, "   %s,\t\t!- FMU Variable Name\n", e->attributes[varname]);				   
            break;
        }

        // Get the type of FMU variable 
				/*se = (ScalarVariable*)list[j];
				ee = se->typeSpec;
				switch(ee->type)
				{
					case elm_Integer:
						strcpy(type, "Integer");	break;
					case elm_Real:
						strcpy(type, "Real"); 		break;
					case elm_Boolean:
						strcpy(type, "Boolean"); 	break;
					case elm_String:
						strcpy(type, "String"); 	break;
					case elm_Enumeration:
						strcpy(type, "Enumeration"); break;
					default:
						break;
				}
        if(vardes != -1) fprintf(fp, ", %s", e->attributes[vardes]);
				fprintf(fp, ", %s\n", type); //Type of variable*/
			}

      if(val==enu_output) fprintf(fp, "   ;\t\t!- Initial Value\n");


    }
	fclose(fp);
}