- vector<SGMetarCloud>::const_iterator cloud;
-
- const char *cl = "/environment/clouds/layer[%i]";
- for (i = 0, cloud = cv.begin(); cloud != cv.end(); cloud++, i++) {
- const char *coverage_string[5] =
- { "clear", "few", "scattered", "broken", "overcast" };
- const double thickness[5] = { 0, 65, 600,750, 1000};
- int q;
-
- snprintf(s, 128, cl, i);
- strncat(s, "/coverage", 128);
- q = cloud->getCoverage();
- fgSetString(s, coverage_string[q] );
-
- snprintf(s, 128, cl, i);
- strncat(s, "/elevation-ft", 128);
- fgSetDouble(s, cloud->getAltitude_ft() + station_elevation_ft);
-
- snprintf(s, 128, cl, i);
- strncat(s, "/thickness-ft", 128);
- fgSetDouble(s, thickness[q]);
-
- snprintf(s, 128, cl, i);
- strncat(s, "/span-m", 128);
- fgSetDouble(s, 40000.0);
- }
-
- for (; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
- snprintf(s, 128, cl, i);
- strncat(s, "/coverage", 128);
- fgSetString(s, "clear");
-
- snprintf(s, 128, cl, i);
- strncat(s, "/elevation-ft", 128);
- fgSetDouble(s, -9999);
-
- snprintf(s, 128, cl, i);
- strncat(s, "/thickness-ft", 128);
- fgSetDouble(s, 0);
-
- snprintf(s, 128, cl, i);
- strncat(s, "/span-m", 128);
- fgSetDouble(s, 40000.0);
+ vector<SGMetarCloud>::const_iterator cloud, cloud_end = cv.end();
+
+ // Load into both the METAR and environment properties to stop interpolation
+ SGPropertyNode *metar_clouds = fgGetNode("/environment/metar/clouds", true);
+ SGPropertyNode *clouds = fgGetNode("/environment/clouds", true);
+
+ for (i = 0, cloud = cv.begin(); i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
+ const char *coverage_string[5] = { "clear", "few", "scattered", "broken", "overcast" };
+ const double thickness_value[5] = { 0, 65, 600, 750, 1000 };
+
+ const char *coverage = "clear";
+ double elevation = -9999.0;
+ double thickness = 0.0;
+ const double span = 40000.0;
+
+ if (cloud != cloud_end) {
+ int c = cloud->getCoverage();
+ coverage = coverage_string[c];
+ elevation = cloud->getAltitude_ft() + station_elevation_ft;
+ thickness = thickness_value[c];
+ ++cloud;
+ }
+
+ SGPropertyNode *layer;
+ layer = metar_clouds->getChild("layer", i, true);
+ layer->setStringValue("coverage", coverage);
+ layer->setDoubleValue("elevation-ft", elevation);
+ layer->setDoubleValue("thickness-ft", thickness);
+ layer->setDoubleValue("span-m", span);
+
+ layer = clouds->getChild("layer", i, true);
+ layer->setStringValue("coverage", coverage);
+ layer->setDoubleValue("elevation-ft", elevation);
+ layer->setDoubleValue("thickness-ft", thickness);
+ layer->setDoubleValue("span-m", span);