@@ -349,13 +349,13 @@ namespace fmu4cpp {
349349 }();
350350
351351 auto type = [](const VariableBase *v) {
352- if (auto i = dynamic_cast <const IntVariable *>(v)) {
352+ if (dynamic_cast <const IntVariable *>(v)) {
353353 return " Int32" ;
354- } else if (auto r = dynamic_cast <const RealVariable *>(v)) {
354+ } else if (dynamic_cast <const RealVariable *>(v)) {
355355 return " Float64" ;
356- } else if (auto s = dynamic_cast <const StringVariable *>(v)) {
356+ } else if (dynamic_cast <const StringVariable *>(v)) {
357357 return " String" ;
358- } else if (auto b = dynamic_cast <const BoolVariable *>(v)) {
358+ } else if (dynamic_cast <const BoolVariable *>(v)) {
359359 return " Boolean" ;
360360 }
361361 throw std::runtime_error (" Unknown variable type" );
@@ -376,12 +376,13 @@ namespace fmu4cpp {
376376 if (initial) {
377377 ss << " initial=\" " << to_string (*initial) << " \" " ;
378378 }
379+ bool with_start = requires_start (*v);
379380 if (auto i = dynamic_cast <const IntVariable *>(v)) {
380- if (requires_start (*v) ) {
381+ if (with_start ) {
381382 ss << " start=\" " << i->get () << " \" " ;
382383 }
383384 } else if (auto r = dynamic_cast <const RealVariable *>(v)) {
384- if (requires_start (*v) ) {
385+ if (with_start ) {
385386 ss << " start=\" " << r->get () << " \" " ;
386387 }
387388 const auto min = r->getMin ();
@@ -390,15 +391,22 @@ namespace fmu4cpp {
390391 ss << " min=\" " << *min << " \" max=\" " << *max << " \" " ;
391392 }
392393 } else if (auto s = dynamic_cast <const StringVariable *>(v)) {
393- if (requires_start (*v)) {
394- ss << " start=\" " << s->get () << " \" " ;
394+ if (with_start) {
395+ ss << " >\n " ;
396+ ss << " \t\t\t <Dimension start=\" 1\" />\n " ;
397+ ss << " \t\t\t <Start value=\" " << s->get () << " \" />\n " ;
395398 }
396399 } else if (auto b = dynamic_cast <const BoolVariable *>(v)) {
397- if (requires_start (*v) ) {
400+ if (with_start ) {
398401 ss << " start=\" " << b->get () << " \" " ;
399402 }
400403 }
401- ss << " />\n " ;
404+ if (with_start && dynamic_cast <const StringVariable *>(v)) {
405+ ss << " \t\t </String>\n " ;
406+ } else {
407+ ss << " />\n " ;
408+ }
409+
402410 if (!annotations.empty ()) {
403411 ss << " \t\t\t <Annotations>\n " ;
404412 for (const auto &annotation: annotations) {
@@ -420,31 +428,29 @@ namespace fmu4cpp {
420428 if (!unknowns.empty ()) {
421429 for (const auto &v: unknowns) {
422430 ss << " \t\t\t <Output valueReference=\" " << v->value_reference () << " \" " ;
423- const auto deps = v->getDependencies ();
431+ const auto deps = v->getDependencies (); // indices
424432 if (!deps.empty ()) {
425433 ss << " dependencies=\" " ;
426434 for (unsigned i = 0 ; i < deps.size (); i++) {
427- ss << deps[i];
435+ ss << deps[i]- 1 ; // valueRef is index -1
428436 if (i != deps.size () - 1 ) {
429437 ss << " " ;
430438 }
431439 }
432440 ss << " \" " ;
433441 }
442+ ss << " />\n " ;
434443 }
435- ss << " />\n " ;
436444 }
437445
438446 const auto initialUnknowns = collect (integers_, reals_, booleans_, strings_, [](auto &v) {
439447 return (v.causality () == causality_t ::OUTPUT && v.initial () == initial_t ::APPROX || v.initial () == initial_t ::CALCULATED ) || v.causality () == causality_t ::CALCULATED_PARAMETER ;
440448 });
441449 if (!initialUnknowns.empty ()) {
442- ss << " \t\t <InitialUnknowns>\n " ;
443450 for (const auto &v: initialUnknowns) {
444- ss << " \t\t\t <Unknown index =\" " << v->index () << " \" " ;
451+ ss << " \t\t\t <InitialUnknown valueReference =\" " << v->index ()- 1 << " \" " ;
445452 ss << " />\n " ;
446453 }
447- ss << " \t\t </InitialUnknowns>\n " ;
448454 }
449455
450456 ss << " \t </ModelStructure>\n " ;
0 commit comments