From 9039e225796df50937cf31f57968eb0222cbcfaf Mon Sep 17 00:00:00 2001 From: Bertrand Zhang Date: Thu, 1 Aug 2024 13:55:41 -0400 Subject: [PATCH 1/9] six update --- .../c++/cphd/include/cphd/CPHDWriter.h | 7 +- .../c++/cphd/include/cphd/SupportArray.h | 8 +- six/modules/c++/cphd/source/CPHDWriter.cpp | 74 ++++++++++++++++++- six/modules/c++/cphd/source/CPHDXMLParser.cpp | 21 ++++-- six/modules/c++/cphd/source/FileHeader.cpp | 18 ++--- six/modules/c++/cphd/source/SupportArray.cpp | 29 ++++++-- .../cphd/unittests/test_cphd_xml_optional.cpp | 4 +- .../six.sidd/source/DerivedXMLParser200.cpp | 6 +- .../c++/six/include/six/ErrorStatistics.h | 2 +- .../c++/six/include/six/SICommonXMLParser.h | 2 +- six/modules/c++/six/include/six/XMLParser.h | 2 + six/modules/c++/six/include/six/XmlLite.h | 2 + .../c++/six/source/SICommonXMLParser.cpp | 29 ++++++-- six/modules/c++/six/source/XMLParser.cpp | 9 +++ six/modules/c++/six/source/XmlLite.cpp | 10 +++ .../cphd/source/generated/cphd_wrap.cxx | 24 +++--- 16 files changed, 193 insertions(+), 54 deletions(-) diff --git a/six/modules/c++/cphd/include/cphd/CPHDWriter.h b/six/modules/c++/cphd/include/cphd/CPHDWriter.h index 4a5f9ea7a..800f91e91 100644 --- a/six/modules/c++/cphd/include/cphd/CPHDWriter.h +++ b/six/modules/c++/cphd/include/cphd/CPHDWriter.h @@ -202,9 +202,11 @@ struct SIX_CPHD_API CPHDWriter final void writeSupportData(io::OutputStream& stream, const T* data_, const std::string& id) { - const auto size = mMetadata.data.getSupportArrayById(id).size_bytes(); + const auto &dataArray = mMetadata.data.getSupportArrayById(id); + + const auto size = dataArray.size_bytes(); const auto data = sys::make_span(data_, size); - writeSupportDataImpl(stream, data, mMetadata.data.getSupportArrayById(id).bytesPerElement); + writeSupportDataImpl(stream, data, getSupportDataBytesPerSwap(dataArray)); } template void writeSupportData(const T* data, const std::string& id) @@ -221,6 +223,7 @@ struct SIX_CPHD_API CPHDWriter final * \param data A pointer to the start of the support array data block */ sys::Off_T getSupportBlockByteOffset(const Data::SupportArray&) const; + size_t getSupportDataBytesPerSwap(const Data::SupportArray& dataArray) const; void writeSupportDataArray(io::SeekableOutputStream&, DataWriter&, std::span, const Data::SupportArray&); void writeSupportDataArray(io::SeekableOutputStream&, std::span, const Data::SupportArray&); diff --git a/six/modules/c++/cphd/include/cphd/SupportArray.h b/six/modules/c++/cphd/include/cphd/SupportArray.h index 464fe91b9..d4352f0e1 100644 --- a/six/modules/c++/cphd/include/cphd/SupportArray.h +++ b/six/modules/c++/cphd/include/cphd/SupportArray.h @@ -65,7 +65,7 @@ struct SupportArrayParameter * \param ySS_in Col coordinate (Y) sample spacing */ SupportArrayParameter( - const std::string& format, size_t id, + const std::string& format, std::string id, double x0_in, double y0_in, double xSS_in, double ySS_in); @@ -83,13 +83,13 @@ struct SupportArrayParameter } //! Set unique identifier - void setIdentifier(size_t identifierIn) + void setIdentifier(std::string identifierIn) { identifier = identifierIn; } //! Get unique identifier - inline size_t getIdentifier() const + inline std::string getIdentifier() const { return identifier; } @@ -112,7 +112,7 @@ struct SupportArrayParameter protected: void initializeParams(); private: - size_t identifier; + std::string identifier; }; /*! diff --git a/six/modules/c++/cphd/source/CPHDWriter.cpp b/six/modules/c++/cphd/source/CPHDWriter.cpp index 60d0d5f7f..24331fc6f 100644 --- a/six/modules/c++/cphd/source/CPHDWriter.cpp +++ b/six/modules/c++/cphd/source/CPHDWriter.cpp @@ -162,13 +162,85 @@ sys::Off_T CPHDWriter::getSupportBlockByteOffset(const Data::SupportArray& dataA const auto supportBlockByteOffset = mHeader.getSupportBlockByteOffset(); return supportBlockByteOffset + dataArray.arrayByteOffset; } +size_t CPHDWriter::getSupportDataBytesPerSwap(const Data::SupportArray& dataArray) const +{ + const auto &id = dataArray.identifier; + std::string elemFmt; + const auto &sas = *mMetadata.supportArray; + // Unfortunately, need to search each vector/map of support arrays + if(elemFmt.empty()) + { + for(size_t ii = 0; ii < sas.iazArray.size(); ++ii) + { + if (sas.iazArray[ii].getIdentifier() == id) + { + // found correct id, so get element format + elemFmt = sas.iazArray[ii].elementFormat; + break; + } + } + } + + if(elemFmt.empty()) + { + for(size_t ii = 0; ii < sas.antGainPhase.size(); ++ii) + { + if (sas.antGainPhase[ii].getIdentifier() == id) + { + // found correct id, so get element format + elemFmt = sas.antGainPhase[ii].elementFormat; + break; + } + } + } + + if(elemFmt.empty()) + { + for(size_t ii = 0; ii < sas.dwellTimeArray.size(); ++ii) + { + if (sas.dwellTimeArray[ii].getIdentifier() == id) + { + // found correct id, so get element format + elemFmt = sas.dwellTimeArray[ii].elementFormat; + break; + } + } + } + + if(elemFmt.empty()) + { + if (sas.addedSupportArray.count(id) > 0) + { + // found correct id, so get element format + elemFmt = sas.addedSupportArray.find(id)->second.elementFormat; + } + } + + if(elemFmt.empty()) + { + std::ostringstream oss; + oss << "SA_ID was not found" << (id); + throw except::Exception(Ctxt(oss.str())); + } + + //Assuming homogeneous component types + //TODO: Test for validity of this assumption? + auto eqLoc = elemFmt.find("="); + auto numPerElement = str::split(elemFmt, ";").size(); + if (elemFmt[eqLoc + 1] == 'C') + { + //Byteswap complex components individually too + numPerElement *= 2; + } + return dataArray.bytesPerElement / numPerElement; +} void CPHDWriter::writeSupportDataArray(io::SeekableOutputStream& stream, DataWriter& dataWriter, std::span data, const Data::SupportArray& dataArray) { // Move inputstream head to offset of particular support array stream.seek(getSupportBlockByteOffset(dataArray), io::SeekableOutputStream::START); - dataWriter(make_span(data, dataArray), dataArray.bytesPerElement); + dataWriter(make_span(data, dataArray), getSupportDataBytesPerSwap(dataArray)); } void CPHDWriter::writeSupportDataArray(io::SeekableOutputStream& stream, std::span data, const Data::SupportArray& dataArray) diff --git a/six/modules/c++/cphd/source/CPHDXMLParser.cpp b/six/modules/c++/cphd/source/CPHDXMLParser.cpp index 8cd76a2e8..20ad15ad4 100644 --- a/six/modules/c++/cphd/source/CPHDXMLParser.cpp +++ b/six/modules/c++/cphd/source/CPHDXMLParser.cpp @@ -79,13 +79,15 @@ std::unique_ptr CPHDXMLParser::toXML( toXML(metadata.data, root); toXML(metadata.channel, root); toXML(metadata.pvp, root); - toXML(metadata.dwell, root); - toXML(metadata.referenceGeometry, root); if (metadata.supportArray.get()) { toXML(*(metadata.supportArray), root); } + + toXML(metadata.dwell, root); + toXML(metadata.referenceGeometry, root); + if (metadata.antenna.get()) { toXML(*(metadata.antenna), root); @@ -320,8 +322,15 @@ XMLElem CPHDXMLParser::toXML(const Data& data, XMLElem parent) createString("Identifier", data.channels[ii].identifier, channelXML); createInt("NumVectors", data.channels[ii].numVectors, channelXML); createInt("NumSamples", data.channels[ii].numSamples, channelXML); +#if 0 createInt("SignalArrayByteOffset", data.channels[ii].signalArrayByteOffset, channelXML); createInt("PVPArrayByteOffset", data.channels[ii].pvpArrayByteOffset, channelXML); +#else + std::string lTmpStr1 = std::to_string(data.channels[ii].signalArrayByteOffset); + std::string lTmpStr2 = std::to_string(data.channels[ii].pvpArrayByteOffset); + createString("SignalArrayByteOffset", lTmpStr1, channelXML); + createString("PVPArrayByteOffset", lTmpStr2, channelXML); +#endif if(!six::Init::isUndefined(data.channels[ii].compressedSignalSize)) { createInt("CompressedSignalSize", data.channels[ii].compressedSignalSize, channelXML); @@ -581,13 +590,12 @@ void CPHDXMLParser::createSupportArray(const std::vector& for (auto&& param : supportArray) { XMLElem pXML = newElement(tag, &parent); - createInt("Identifier", param.getIdentifier(), pXML); + createString("Identifier", param.getIdentifier(), pXML); createString("ElementFormat", param.elementFormat, pXML); createDouble("X0", param.x0, pXML); createDouble("Y0", param.y0, pXML); createDouble("XSS", param.xSS, pXML); createDouble("YSS", param.ySS, pXML); - } } @@ -1757,6 +1765,7 @@ void CPHDXMLParser::fromXML(const xml::lite::Element* antennaXML, Antenna& anten XMLElem arrayXML = getFirstAndOnly(antPatternXMLVec[ii], "Array"); mCommon.parsePoly2D(getFirstAndOnly(arrayXML, "GainPoly"), antenna.antPattern[ii].array.gainPoly); mCommon.parsePoly2D(getFirstAndOnly(arrayXML, "PhasePoly"), antenna.antPattern[ii].array.phasePoly); + std::ignore = six::parse(parser(), *arrayXML, antenna.antPattern[ii].array.antGPId) // Parse Element XMLElem elementXML = getFirstAndOnly(antPatternXMLVec[ii], "Element"); @@ -2413,8 +2422,8 @@ void CPHDXMLParser::parseSupportArrayParameter(const xml::lite::Element* paramXM { if(!additionalFlag) { - size_t identifierVal; - parseUInt(getFirstAndOnly(paramXML, "Identifier"), identifierVal); + std::string identifierVal; + parseString(getFirstAndOnly(paramXML, "Identifier"), identifierVal); param.setIdentifier(identifierVal); } parseString(getFirstAndOnly(paramXML, "ElementFormat"), param.elementFormat); diff --git a/six/modules/c++/cphd/source/FileHeader.cpp b/six/modules/c++/cphd/source/FileHeader.cpp index 933ebcebb..0d8cc321a 100644 --- a/six/modules/c++/cphd/source/FileHeader.cpp +++ b/six/modules/c++/cphd/source/FileHeader.cpp @@ -303,15 +303,15 @@ int64_t FileHeader::getPvpPadBytes() const std::ostream& operator<< (std::ostream& os, const FileHeader& fh) { os << "FileHeader::\n" - << " mVersion : " << to_string(fh.mVersion) << "\n" - << " mXmlBlockSize : " << fh.mXmlBlockSize << "\n" - << " mXmlBlockByteOffset : " << fh.mXmlBlockByteOffset << "\n" - << " mSupportBlockSize : " << fh.mSupportBlockSize << "\n" - << " mSupportBlockSize : " << fh.mSupportBlockByteOffset << "\n" - << " mPvpBlockByteOffset : " << fh.mPvpBlockSize << "\n" - << " mPvpBlockByteOffset : " << fh.mPvpBlockByteOffset << "\n" - << " mSignalBlockSize : " << fh.mSignalBlockSize << "\n" - << " mSignalBlockByteOffset : " << fh.mSignalBlockByteOffset << "\n" + << " mVersion : " << to_string(fh.mVersion) << "\n" + << " mXmlBlockSize : " << fh.mXmlBlockSize << "\n" + << " mXmlBlockByteOffset : " << fh.mXmlBlockByteOffset << "\n" + << " mSupportBlockSize : " << fh.mSupportBlockSize << "\n" + << " mSupportBlockSize : " << fh.mSupportBlockByteOffset << "\n" + << " mPvpBlockByteOffset : " << fh.mPvpBlockSize << "\n" + << " mPvpBlockByteOffset : " << fh.mPvpBlockByteOffset << "\n" + << " mSignalBlockSize : " << fh.mSignalBlockSize << "\n" + << " mSignalBlockByteOffset : " << fh.mSignalBlockByteOffset << "\n" << " mClassification: " << fh.mClassification << "\n" << " mReleaseInfo : " << fh.mReleaseInfo << "\n"; return os; diff --git a/six/modules/c++/cphd/source/SupportArray.cpp b/six/modules/c++/cphd/source/SupportArray.cpp index aaa66eb63..329500b5b 100644 --- a/six/modules/c++/cphd/source/SupportArray.cpp +++ b/six/modules/c++/cphd/source/SupportArray.cpp @@ -33,13 +33,13 @@ SupportArrayParameter::SupportArrayParameter() : y0(six::Init::undefined()), xSS(six::Init::undefined()), ySS(six::Init::undefined()), - identifier(six::Init::undefined()) + identifier(six::Init::undefined()) { } SupportArrayParameter::SupportArrayParameter( const std::string& format, - size_t id, + std::string id, double x0_in, double y0_in, double xSS_in, @@ -83,14 +83,33 @@ AdditionalSupportArray::AdditionalSupportArray( static SupportArrayParameter getSupportArray(const std::vector& params, const std::string& key) { - size_t keyNum = str::toType(key); - if (params.size() <= keyNum) + std::vector valid_keys; + for(size_t ii = 0; ii < params.size(); ++ii) + { + if (params[ii].getIdentifier()==key) + { + // found correct key. so add to valid_keys + valid_keys.push_back(ii); + } + } + + if(!valid_keys.size()) { std::ostringstream oss; oss << "SA_ID was not found " << (key); throw except::Exception(Ctxt(oss)); } - return params[keyNum]; + else if (valid_keys.size()>1) + { + std::ostringstream oss; + oss << "Found multiple support arrays with same SA_ID: " << (key); + throw except::Exception(Ctxt(oss)); + } + else + { + // if valid key is length 1, return that SupportArrayParameter + return params[valid_keys[0]]; + } } SupportArrayParameter SupportArray::getIAZSupportArray(const std::string& key) const diff --git a/six/modules/c++/cphd/unittests/test_cphd_xml_optional.cpp b/six/modules/c++/cphd/unittests/test_cphd_xml_optional.cpp index ebc55372f..ba2c89df4 100644 --- a/six/modules/c++/cphd/unittests/test_cphd_xml_optional.cpp +++ b/six/modules/c++/cphd/unittests/test_cphd_xml_optional.cpp @@ -893,7 +893,7 @@ TEST_CASE(testOptional) const cphd::SupportArray& supportArray = *(metadata->supportArray); TEST_ASSERT_EQ(supportArray.iazArray.size(), static_cast(1)); - TEST_ASSERT_EQ(supportArray.iazArray[0].getIdentifier(), static_cast(1)); + TEST_ASSERT_EQ(supportArray.iazArray[0].getIdentifier(), static_cast("1")); TEST_ASSERT_EQ(supportArray.iazArray[0].elementFormat, "IAZ=F4;"); TEST_ASSERT_EQ(supportArray.iazArray[0].x0, 0.0); TEST_ASSERT_EQ(supportArray.iazArray[0].y0, 0.0); @@ -901,7 +901,7 @@ TEST_CASE(testOptional) TEST_ASSERT_EQ(supportArray.iazArray[0].ySS, 5.0); TEST_ASSERT_EQ(supportArray.antGainPhase.size(), static_cast(1)); - TEST_ASSERT_EQ(supportArray.antGainPhase[0].getIdentifier(), static_cast(2)); + TEST_ASSERT_EQ(supportArray.antGainPhase[0].getIdentifier(), static_cast("2")); TEST_ASSERT_EQ(supportArray.antGainPhase[0].elementFormat, "Gain=F4;Phase=F4;"); TEST_ASSERT_EQ(supportArray.antGainPhase[0].x0, 0.0); TEST_ASSERT_EQ(supportArray.antGainPhase[0].y0, 0.0); diff --git a/six/modules/c++/six.sidd/source/DerivedXMLParser200.cpp b/six/modules/c++/six.sidd/source/DerivedXMLParser200.cpp index 48c3cc418..315897165 100644 --- a/six/modules/c++/six.sidd/source/DerivedXMLParser200.cpp +++ b/six/modules/c++/six.sidd/source/DerivedXMLParser200.cpp @@ -1288,7 +1288,7 @@ xml::lite::Element& DerivedXMLParser200::convertInteractiveProcessingToXML(const { auto& paramElem = parser.newElement("DRAParameters", adjustElem); parser.createDouble("Pmin", adjust.draParameters->pMin, paramElem); - parser.createDouble("Pmax", adjust.draParameters->pMax, paramElem); + parser.createFloat("Pmax", static_cast(adjust.draParameters->pMax), paramElem); parser.createDouble("EminModifier", adjust.draParameters->eMinModifier, paramElem); parser.createDouble("EmaxModifier", adjust.draParameters->eMinModifier, paramElem); } @@ -1380,8 +1380,8 @@ xml::lite::Element& DerivedXMLParser200::convertKernelToXML(const DerivedXMLPars { for (ptrdiff_t col = 0; col < kernel.custom->size.col; ++col, ++idx) { - auto& coefElem = parser.createDouble("Coef", kernel.custom->filterCoef[static_cast(idx)], - filterCoef); + //Anti-aliasing filter coefficients should be single precision + auto& coefElem = parser.createFloat("Coef", static_cast(kernel.custom->filterCoef[static_cast(idx)]), filterCoef); setAttribute(coefElem, "row", static_cast(row)); setAttribute(coefElem, "col", static_cast(col)); } diff --git a/six/modules/c++/six/include/six/ErrorStatistics.h b/six/modules/c++/six/include/six/ErrorStatistics.h index 712881401..d96ef07ca 100644 --- a/six/modules/c++/six/include/six/ErrorStatistics.h +++ b/six/modules/c++/six/include/six/ErrorStatistics.h @@ -137,7 +137,7 @@ struct SIX_SIX_API RadarSensor * (Optional) Transmit frequency scale factor * standard deviation. */ - double transmitFreqSF = 0.0; // From Bill: "No mention of the TransmitFreqSF in volume 3 ... would still recommend setting to 0." + double transmitFreqSF = Init::undefined(); // From Bill: "No mention of the TransmitFreqSF in volume 3 ... would still recommend setting to 0." /*! * (Optional) Range bias decorrelated rate diff --git a/six/modules/c++/six/include/six/SICommonXMLParser.h b/six/modules/c++/six/include/six/SICommonXMLParser.h index a52a91686..6182ac3d8 100644 --- a/six/modules/c++/six/include/six/SICommonXMLParser.h +++ b/six/modules/c++/six/include/six/SICommonXMLParser.h @@ -93,7 +93,7 @@ struct SIX_SIX_API SICommonXMLParser : public XMLParser XMLElem createLatLon(const std::string& name, const LatLon& value, XMLElem parent = nullptr) const; XMLElem createLatLon(const std::string& name, const std::string& uri, - const LatLon& value, XMLElem parent = nullptr) const; + const LatLon& value, XMLElem parent = nullptr, bool singlePrecision = false) const; XMLElem createLatLonAlt(const std::string& name, const LatLonAlt& value, XMLElem parent = nullptr) const; diff --git a/six/modules/c++/six/include/six/XMLParser.h b/six/modules/c++/six/include/six/XMLParser.h index 48a7df861..b653dee4a 100644 --- a/six/modules/c++/six/include/six/XMLParser.h +++ b/six/modules/c++/six/include/six/XMLParser.h @@ -86,6 +86,8 @@ struct SIX_SIX_API XMLParser return mXmlLite.createInt(name, p, parent); } + xml::lite::Element& createFloat(const std::string& name, float p, xml::lite::Element& parent) const; + XMLElem createFloat(const std::string& name, const std::string& uri, float p = 0, XMLElem parent = nullptr) const; xml::lite::Element& createDouble(const std::string& name, double p, xml::lite::Element& parent) const; XMLElem createDouble(const std::string& name, const std::string& uri, double p = 0, XMLElem parent = nullptr) const; diff --git a/six/modules/c++/six/include/six/XmlLite.h b/six/modules/c++/six/include/six/XmlLite.h index c3fec1687..14ce76ed7 100644 --- a/six/modules/c++/six/include/six/XmlLite.h +++ b/six/modules/c++/six/include/six/XmlLite.h @@ -158,6 +158,7 @@ struct SIX_SIX_API XmlLite final xml::lite::Element& createInt(const xml::lite::QName& name, int p, xml::lite::Element& parent) const; xml::lite::Element& createDouble(const xml::lite::QName&, double p, xml::lite::Element& parent) const; xml::lite::Element& createDouble(const xml::lite::QName&, const std::optional& p, xml::lite::Element& parent) const; + xml::lite::Element& createFloat(const xml::lite::QName&, float p, xml::lite::Element& parent) const; xml::lite::Element* createOptionalDouble(const xml::lite::QName&, double p, xml::lite::Element& parent) const; xml::lite::Element* createOptionalDouble(const xml::lite::QName&, const std::optional& p, xml::lite::Element& parent) const; xml::lite::Element* createBooleanType(const xml::lite::QName&, BooleanType b, xml::lite::Element& parent) const; @@ -199,6 +200,7 @@ struct SIX_SIX_API XmlLite final } xml::lite::Element& createDouble(const std::string& name, double p, xml::lite::Element& parent ) const; xml::lite::Element& createDouble(const std::string& name, const std::optional& p, xml::lite::Element& parent) const; + xml::lite::Element& createFloat(const std::string& name, float p, xml::lite::Element& parent ) const; xml::lite::Element* createOptionalDouble(const std::string& name, double p, xml::lite::Element& parent) const; xml::lite::Element* createOptionalDouble(const std::string& name, const std::optional& p, xml::lite::Element& parent) const; xml::lite::Element* createBooleanType(const std::string& name, BooleanType b, xml::lite::Element&parent ) const; diff --git a/six/modules/c++/six/source/SICommonXMLParser.cpp b/six/modules/c++/six/source/SICommonXMLParser.cpp index cf38b8eb9..8196f7074 100644 --- a/six/modules/c++/six/source/SICommonXMLParser.cpp +++ b/six/modules/c++/six/source/SICommonXMLParser.cpp @@ -231,7 +231,7 @@ XMLElem SICommonXMLParser::convertGeoInfoToXML(const GeoInfo& geoInfo, const size_t numLatLons = geoInfo.geometryLatLon.size(); if (numLatLons == 1) { - createLatLon("Point", uri, geoInfo.geometryLatLon[0], geoInfoXML); + createLatLon("Point", uri, geoInfo.geometryLatLon[0], geoInfoXML, true); } else if (numLatLons >= 2) { @@ -246,7 +246,8 @@ XMLElem SICommonXMLParser::convertGeoInfoToXML(const GeoInfo& geoInfo, numLatLons == 2 ? "Endpoint" : "Vertex", uri, geoInfo.geometryLatLon[ii], - linePolyXML); + linePolyXML, + true); setAttribute(v, "index", ii + 1); } @@ -516,11 +517,20 @@ XMLElem SICommonXMLParser::createLatLon( const std::string& name, const std::string& uri, const LatLon& value, - XMLElem parent) const + XMLElem parent, + bool singlePrecision) const { XMLElem e = newElement(name, uri, parent); - createDouble("Lat", getSICommonURI(), value.getLat(), e); - createDouble("Lon", getSICommonURI(), value.getLon(), e); + if (!singlePrecision) + { + createDouble("Lat", getSICommonURI(), value.getLat(), e); + createDouble("Lon", getSICommonURI(), value.getLon(), e); + } + else + { + createFloat("Lat", getSICommonURI(), value.getLat(), e); + createFloat("Lon", getSICommonURI(), value.getLon(), e); + } return e; } @@ -912,8 +922,11 @@ XMLElem SICommonXMLParser::convertErrorStatisticsToXML( createOptionalDouble("ClockFreqSF", getSICommonURI(), radarSensor->clockFreqSF, radarSensorXML); - createOptionalDouble("TransmitFreqSF", getSICommonURI(), - radarSensor->transmitFreqSF, radarSensorXML); + if(!Init::isUndefined(radarSensor->transmitFreqSF)) + { + createOptionalDouble("TransmitFreqSF", getSICommonURI(), + radarSensor->transmitFreqSF, radarSensorXML); + } addDecorrType("RangeBiasDecorr", getSICommonURI(), radarSensor->rangeBiasDecorr, radarSensorXML); @@ -1292,7 +1305,7 @@ void SICommonXMLParser::parseCollectionInformationFromXML( const auto& classificationXML = getFirstAndOnly(*collectionInfoXML, "Classification"); // For "new" XML processing (storing the encoding) we'll have a UTF-8 value. - // This is important as it could be French "NON CLASSIFIÉ / UNCLASSIFIED" + // This is important as it could be French "NON CLASSIFI� / UNCLASSIFIED" std::u8string classification_u8; if (parseString(classificationXML, classification_u8)) { diff --git a/six/modules/c++/six/source/XMLParser.cpp b/six/modules/c++/six/source/XMLParser.cpp index 5cf83dbff..adcf66e50 100644 --- a/six/modules/c++/six/source/XMLParser.cpp +++ b/six/modules/c++/six/source/XMLParser.cpp @@ -105,6 +105,15 @@ XMLElem XMLParser::createDouble(const std::string& name, const std::string& uri, assert(parent != nullptr); return &mXmlLite.createDouble(xml::lite::QName(xml::lite::Uri(uri), name), p, *parent); } +XMLElem XMLParser::createFloat(const std::string& name, const std::string& uri, float p, XMLElem parent) const +{ + assert(parent != nullptr); + return &mXmlLite.createFloat(xml::lite::QName(xml::lite::Uri(uri), name), p, *parent); +} +xml::lite::Element& XMLParser::createFloat(const std::string& name, float p, xml::lite::Element& parent) const +{ + return mXmlLite.createFloat(name, p, parent); +} xml::lite::Element& XMLParser::createDouble(const std::string& name, double p, xml::lite::Element& parent) const { return mXmlLite.createDouble(name, p, parent); diff --git a/six/modules/c++/six/source/XmlLite.cpp b/six/modules/c++/six/source/XmlLite.cpp index 250ff7b9c..a4b2a2a3e 100644 --- a/six/modules/c++/six/source/XmlLite.cpp +++ b/six/modules/c++/six/source/XmlLite.cpp @@ -254,6 +254,12 @@ xml::lite::Element& XmlLite::createInt_(const std::string& name, int p, xml::lit return createInt(makeQName(name), p, parent); } +xml::lite::Element& XmlLite::createFloat(const xml::lite::QName& name, float p, xml::lite::Element& parent) const +{ + p = value(p); // be sure this is initialized; throws if not + return createValue(name, p, parent, mAddClassAttributes, "xs:double", getDefaultURI()); +} + xml::lite::Element& XmlLite::createDouble(const xml::lite::QName& name, double p, xml::lite::Element& parent) const { p = value(p); // be sure this is initialized; throws if not @@ -263,6 +269,10 @@ xml::lite::Element& XmlLite::createDouble(const xml::lite::QName& name, const st { return createDouble(name, p.value(), parent); } +xml::lite::Element& XmlLite::createFloat(const std::string& name, float p, xml::lite::Element& parent) const +{ + return createFloat(makeQName(name), p, parent); +} xml::lite::Element& XmlLite::createDouble(const std::string& name, double p, xml::lite::Element& parent) const { return createDouble(makeQName(name), p, parent); diff --git a/six/modules/python/cphd/source/generated/cphd_wrap.cxx b/six/modules/python/cphd/source/generated/cphd_wrap.cxx index 80f6d72d6..91cb15bb4 100644 --- a/six/modules/python/cphd/source/generated/cphd_wrap.cxx +++ b/six/modules/python/cphd/source/generated/cphd_wrap.cxx @@ -36444,13 +36444,13 @@ SWIGINTERN PyObject *_wrap_new_SupportArrayParameter__SWIG_0(PyObject *SWIGUNUSE SWIGINTERN PyObject *_wrap_new_SupportArrayParameter__SWIG_1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; std::string *arg1 = 0 ; - size_t arg2 ; + std::string arg2 ; double arg3 ; double arg4 ; double arg5 ; double arg6 ; int res1 = SWIG_OLDOBJ ; - size_t val2 ; + std::string val2 ; int ecode2 = 0 ; double val3 ; int ecode3 = 0 ; @@ -36480,11 +36480,11 @@ SWIGINTERN PyObject *_wrap_new_SupportArrayParameter__SWIG_1(PyObject *SWIGUNUSE } arg1 = ptr; } - ecode2 = SWIG_AsVal_size_t(obj1, &val2); + ecode2 = SWIG_AsVal_std_string(obj1, &val2); if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "new_SupportArrayParameter" "', argument " "2"" of type '" "size_t""'"); + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "new_SupportArrayParameter" "', argument " "2"" of type '" "std::string""'"); } - arg2 = static_cast< size_t >(val2); + arg2 = static_cast< std::string >(val2); ecode3 = SWIG_AsVal_double(obj2, &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "new_SupportArrayParameter" "', argument " "3"" of type '" "double""'"); @@ -36739,10 +36739,10 @@ SWIGINTERN PyObject *_wrap_SupportArrayParameter___ne__(PyObject *SWIGUNUSEDPARM SWIGINTERN PyObject *_wrap_SupportArrayParameter_setIdentifier(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; cphd::SupportArrayParameter *arg1 = (cphd::SupportArrayParameter *) 0 ; - size_t arg2 ; + std::string arg2 ; void *argp1 = 0 ; int res1 = 0 ; - size_t val2 ; + std::string val2 ; int ecode2 = 0 ; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; @@ -36753,11 +36753,11 @@ SWIGINTERN PyObject *_wrap_SupportArrayParameter_setIdentifier(PyObject *SWIGUNU SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SupportArrayParameter_setIdentifier" "', argument " "1"" of type '" "cphd::SupportArrayParameter *""'"); } arg1 = reinterpret_cast< cphd::SupportArrayParameter * >(argp1); - ecode2 = SWIG_AsVal_size_t(obj1, &val2); + ecode2 = SWIG_AsVal_std_string(obj1, &val2); if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "SupportArrayParameter_setIdentifier" "', argument " "2"" of type '" "size_t""'"); + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "SupportArrayParameter_setIdentifier" "', argument " "2"" of type '" "std::string""'"); } - arg2 = static_cast< size_t >(val2); + arg2 = static_cast< std::string >(val2); { try { @@ -36802,7 +36802,7 @@ SWIGINTERN PyObject *_wrap_SupportArrayParameter_getIdentifier(PyObject *SWIGUNU void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; - size_t result; + std::string result; if (!PyArg_ParseTuple(args,(char *)"O:SupportArrayParameter_getIdentifier",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_cphd__SupportArrayParameter, 0 | 0 ); @@ -36841,7 +36841,7 @@ SWIGINTERN PyObject *_wrap_SupportArrayParameter_getIdentifier(PyObject *SWIGUNU SWIG_fail; } } - resultobj = SWIG_From_size_t(static_cast< size_t >(result)); + resultobj = SWIG_From_std_string(static_cast< std::string >(result)); return resultobj; fail: return NULL; From 946bbee4462b55565620d113321d4639b92fa546 Mon Sep 17 00:00:00 2001 From: Bertrand Zhang Date: Thu, 1 Aug 2024 14:11:00 -0400 Subject: [PATCH 2/9] coda-oss changes --- externals/coda-oss/modules/c++/str/source/Convert.cpp | 2 +- externals/coda-oss/modules/c++/types/include/types/RowCol.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/externals/coda-oss/modules/c++/str/source/Convert.cpp b/externals/coda-oss/modules/c++/str/source/Convert.cpp index b8a2bc741..fcb4e8a6b 100644 --- a/externals/coda-oss/modules/c++/str/source/Convert.cpp +++ b/externals/coda-oss/modules/c++/str/source/Convert.cpp @@ -83,7 +83,7 @@ unsigned long long str::strtoull(const char *str, char **endptr, int base) template<> CODA_OSS_API int str::getPrecision(const float&) { - return std::numeric_limits::max_digits10; + return std::numeric_limits::digits10; } template<> CODA_OSS_API int str::getPrecision(const double& ) { diff --git a/externals/coda-oss/modules/c++/types/include/types/RowCol.h b/externals/coda-oss/modules/c++/types/include/types/RowCol.h index 846280aaa..213933b1a 100644 --- a/externals/coda-oss/modules/c++/types/include/types/RowCol.h +++ b/externals/coda-oss/modules/c++/types/include/types/RowCol.h @@ -61,7 +61,7 @@ template class RowCol T col{}; // Try to protect us from the unfortunate and probably - // unintendet case where row gets set and col doesnt, especially + // unintended case where row gets set and col doesn't, especially // when doing scalar operations that might otherwise create // ambiguities RowCol() {} // = default; // error w/ICC and "const" member data From 322a99f9dae4511a071b527f70ce4445baaaf39a Mon Sep 17 00:00:00 2001 From: Bertrand Zhang Date: Thu, 1 Aug 2024 16:10:06 -0400 Subject: [PATCH 3/9] make error fixed --- six/modules/c++/cphd/source/CPHDXMLParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/six/modules/c++/cphd/source/CPHDXMLParser.cpp b/six/modules/c++/cphd/source/CPHDXMLParser.cpp index 20ad15ad4..ef1d4dc41 100644 --- a/six/modules/c++/cphd/source/CPHDXMLParser.cpp +++ b/six/modules/c++/cphd/source/CPHDXMLParser.cpp @@ -1765,7 +1765,7 @@ void CPHDXMLParser::fromXML(const xml::lite::Element* antennaXML, Antenna& anten XMLElem arrayXML = getFirstAndOnly(antPatternXMLVec[ii], "Array"); mCommon.parsePoly2D(getFirstAndOnly(arrayXML, "GainPoly"), antenna.antPattern[ii].array.gainPoly); mCommon.parsePoly2D(getFirstAndOnly(arrayXML, "PhasePoly"), antenna.antPattern[ii].array.phasePoly); - std::ignore = six::parse(parser(), *arrayXML, antenna.antPattern[ii].array.antGPId) + std::ignore = six::parse(parser(), *arrayXML, antenna.antPattern[ii].array.antGPId); // Parse Element XMLElem elementXML = getFirstAndOnly(antPatternXMLVec[ii], "Element"); From 7c49b048a77c53dfe4eb82f6b3c522aef29a2ef0 Mon Sep 17 00:00:00 2001 From: Bertrand Zhang Date: Thu, 1 Aug 2024 17:06:11 -0400 Subject: [PATCH 4/9] fixed errors in supportarray --- six/modules/c++/cphd/source/SupportArray.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/six/modules/c++/cphd/source/SupportArray.cpp b/six/modules/c++/cphd/source/SupportArray.cpp index 329500b5b..6d516f0b8 100644 --- a/six/modules/c++/cphd/source/SupportArray.cpp +++ b/six/modules/c++/cphd/source/SupportArray.cpp @@ -97,13 +97,13 @@ static SupportArrayParameter getSupportArray(const std::vector1) { std::ostringstream oss; oss << "Found multiple support arrays with same SA_ID: " << (key); - throw except::Exception(Ctxt(oss)); + throw except::Exception(Ctxt(oss.str())); } else { From ed23657c5e0c497c7d5238ab3346440e9e2c788d Mon Sep 17 00:00:00 2001 From: Bertrand Zhang Date: Fri, 2 Aug 2024 14:18:25 -0400 Subject: [PATCH 5/9] sync fixes --- six/modules/c++/cphd/source/FileHeader.cpp | 4 ++-- six/modules/c++/cphd/source/SupportArray.cpp | 2 ++ six/modules/c++/six/source/SICommonXMLParser.cpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/six/modules/c++/cphd/source/FileHeader.cpp b/six/modules/c++/cphd/source/FileHeader.cpp index 0d8cc321a..d89fe6b63 100644 --- a/six/modules/c++/cphd/source/FileHeader.cpp +++ b/six/modules/c++/cphd/source/FileHeader.cpp @@ -307,8 +307,8 @@ std::ostream& operator<< (std::ostream& os, const FileHeader& fh) << " mXmlBlockSize : " << fh.mXmlBlockSize << "\n" << " mXmlBlockByteOffset : " << fh.mXmlBlockByteOffset << "\n" << " mSupportBlockSize : " << fh.mSupportBlockSize << "\n" - << " mSupportBlockSize : " << fh.mSupportBlockByteOffset << "\n" - << " mPvpBlockByteOffset : " << fh.mPvpBlockSize << "\n" + << " mSupportBlockByteOffset : " << fh.mSupportBlockByteOffset << "\n" + << " mPvpBlockSize : " << fh.mPvpBlockSize << "\n" << " mPvpBlockByteOffset : " << fh.mPvpBlockByteOffset << "\n" << " mSignalBlockSize : " << fh.mSignalBlockSize << "\n" << " mSignalBlockByteOffset : " << fh.mSignalBlockByteOffset << "\n" diff --git a/six/modules/c++/cphd/source/SupportArray.cpp b/six/modules/c++/cphd/source/SupportArray.cpp index 6d516f0b8..3f36c1db4 100644 --- a/six/modules/c++/cphd/source/SupportArray.cpp +++ b/six/modules/c++/cphd/source/SupportArray.cpp @@ -95,12 +95,14 @@ static SupportArrayParameter getSupportArray(const std::vector1) { + // if find repeated key, throw an exception std::ostringstream oss; oss << "Found multiple support arrays with same SA_ID: " << (key); throw except::Exception(Ctxt(oss.str())); diff --git a/six/modules/c++/six/source/SICommonXMLParser.cpp b/six/modules/c++/six/source/SICommonXMLParser.cpp index 8196f7074..48ea212c4 100644 --- a/six/modules/c++/six/source/SICommonXMLParser.cpp +++ b/six/modules/c++/six/source/SICommonXMLParser.cpp @@ -925,7 +925,7 @@ XMLElem SICommonXMLParser::convertErrorStatisticsToXML( if(!Init::isUndefined(radarSensor->transmitFreqSF)) { createOptionalDouble("TransmitFreqSF", getSICommonURI(), - radarSensor->transmitFreqSF, radarSensorXML); + radarSensor->transmitFreqSF, radarSensorXML); } addDecorrType("RangeBiasDecorr", getSICommonURI(), From c5a92e2ff231602c2311e0e8a68340cabaa8d696 Mon Sep 17 00:00:00 2001 From: Bertrand Zhang Date: Mon, 19 Aug 2024 15:38:00 -0400 Subject: [PATCH 6/9] addressed PR comments --- six/modules/c++/cphd/include/cphd/SupportArray.h | 4 ++-- six/modules/c++/cphd/source/SupportArray.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/six/modules/c++/cphd/include/cphd/SupportArray.h b/six/modules/c++/cphd/include/cphd/SupportArray.h index d4352f0e1..911fc5099 100644 --- a/six/modules/c++/cphd/include/cphd/SupportArray.h +++ b/six/modules/c++/cphd/include/cphd/SupportArray.h @@ -65,7 +65,7 @@ struct SupportArrayParameter * \param ySS_in Col coordinate (Y) sample spacing */ SupportArrayParameter( - const std::string& format, std::string id, + const std::string& format, const std::string& id, double x0_in, double y0_in, double xSS_in, double ySS_in); @@ -83,7 +83,7 @@ struct SupportArrayParameter } //! Set unique identifier - void setIdentifier(std::string identifierIn) + void setIdentifier(const std::string& identifierIn) { identifier = identifierIn; } diff --git a/six/modules/c++/cphd/source/SupportArray.cpp b/six/modules/c++/cphd/source/SupportArray.cpp index 3f36c1db4..98df99eeb 100644 --- a/six/modules/c++/cphd/source/SupportArray.cpp +++ b/six/modules/c++/cphd/source/SupportArray.cpp @@ -39,7 +39,7 @@ SupportArrayParameter::SupportArrayParameter() : SupportArrayParameter::SupportArrayParameter( const std::string& format, - std::string id, + const std::string& id, double x0_in, double y0_in, double xSS_in, From 8fa1fc3616adb243aea13af7be5b57d5c62f1e2e Mon Sep 17 00:00:00 2001 From: Bertrand Zhang Date: Thu, 29 Aug 2024 15:05:36 -0400 Subject: [PATCH 7/9] revert changes related to removal of XML digits --- .../modules/c++/str/source/Convert.cpp | 2 +- .../six.sidd/source/DerivedXMLParser200.cpp | 5 ++--- .../c++/six/include/six/SICommonXMLParser.h | 2 +- six/modules/c++/six/include/six/XMLParser.h | 2 -- six/modules/c++/six/include/six/XmlLite.h | 2 -- .../c++/six/source/SICommonXMLParser.cpp | 21 ++++++------------- six/modules/c++/six/source/XMLParser.cpp | 9 -------- six/modules/c++/six/source/XmlLite.cpp | 11 ---------- 8 files changed, 10 insertions(+), 44 deletions(-) diff --git a/externals/coda-oss/modules/c++/str/source/Convert.cpp b/externals/coda-oss/modules/c++/str/source/Convert.cpp index fcb4e8a6b..b8a2bc741 100644 --- a/externals/coda-oss/modules/c++/str/source/Convert.cpp +++ b/externals/coda-oss/modules/c++/str/source/Convert.cpp @@ -83,7 +83,7 @@ unsigned long long str::strtoull(const char *str, char **endptr, int base) template<> CODA_OSS_API int str::getPrecision(const float&) { - return std::numeric_limits::digits10; + return std::numeric_limits::max_digits10; } template<> CODA_OSS_API int str::getPrecision(const double& ) { diff --git a/six/modules/c++/six.sidd/source/DerivedXMLParser200.cpp b/six/modules/c++/six.sidd/source/DerivedXMLParser200.cpp index 315897165..e8cd00e5b 100644 --- a/six/modules/c++/six.sidd/source/DerivedXMLParser200.cpp +++ b/six/modules/c++/six.sidd/source/DerivedXMLParser200.cpp @@ -1288,7 +1288,7 @@ xml::lite::Element& DerivedXMLParser200::convertInteractiveProcessingToXML(const { auto& paramElem = parser.newElement("DRAParameters", adjustElem); parser.createDouble("Pmin", adjust.draParameters->pMin, paramElem); - parser.createFloat("Pmax", static_cast(adjust.draParameters->pMax), paramElem); + parser.createDouble("Pmax", adjust.draParameters->pMax, paramElem); parser.createDouble("EminModifier", adjust.draParameters->eMinModifier, paramElem); parser.createDouble("EmaxModifier", adjust.draParameters->eMinModifier, paramElem); } @@ -1380,8 +1380,7 @@ xml::lite::Element& DerivedXMLParser200::convertKernelToXML(const DerivedXMLPars { for (ptrdiff_t col = 0; col < kernel.custom->size.col; ++col, ++idx) { - //Anti-aliasing filter coefficients should be single precision - auto& coefElem = parser.createFloat("Coef", static_cast(kernel.custom->filterCoef[static_cast(idx)]), filterCoef); + auto& coefElem = parser.createDouble("Coef", kernel.custom->filterCoef[static_cast(idx)], filterCoef); setAttribute(coefElem, "row", static_cast(row)); setAttribute(coefElem, "col", static_cast(col)); } diff --git a/six/modules/c++/six/include/six/SICommonXMLParser.h b/six/modules/c++/six/include/six/SICommonXMLParser.h index 6182ac3d8..a52a91686 100644 --- a/six/modules/c++/six/include/six/SICommonXMLParser.h +++ b/six/modules/c++/six/include/six/SICommonXMLParser.h @@ -93,7 +93,7 @@ struct SIX_SIX_API SICommonXMLParser : public XMLParser XMLElem createLatLon(const std::string& name, const LatLon& value, XMLElem parent = nullptr) const; XMLElem createLatLon(const std::string& name, const std::string& uri, - const LatLon& value, XMLElem parent = nullptr, bool singlePrecision = false) const; + const LatLon& value, XMLElem parent = nullptr) const; XMLElem createLatLonAlt(const std::string& name, const LatLonAlt& value, XMLElem parent = nullptr) const; diff --git a/six/modules/c++/six/include/six/XMLParser.h b/six/modules/c++/six/include/six/XMLParser.h index b653dee4a..48a7df861 100644 --- a/six/modules/c++/six/include/six/XMLParser.h +++ b/six/modules/c++/six/include/six/XMLParser.h @@ -86,8 +86,6 @@ struct SIX_SIX_API XMLParser return mXmlLite.createInt(name, p, parent); } - xml::lite::Element& createFloat(const std::string& name, float p, xml::lite::Element& parent) const; - XMLElem createFloat(const std::string& name, const std::string& uri, float p = 0, XMLElem parent = nullptr) const; xml::lite::Element& createDouble(const std::string& name, double p, xml::lite::Element& parent) const; XMLElem createDouble(const std::string& name, const std::string& uri, double p = 0, XMLElem parent = nullptr) const; diff --git a/six/modules/c++/six/include/six/XmlLite.h b/six/modules/c++/six/include/six/XmlLite.h index 14ce76ed7..c3fec1687 100644 --- a/six/modules/c++/six/include/six/XmlLite.h +++ b/six/modules/c++/six/include/six/XmlLite.h @@ -158,7 +158,6 @@ struct SIX_SIX_API XmlLite final xml::lite::Element& createInt(const xml::lite::QName& name, int p, xml::lite::Element& parent) const; xml::lite::Element& createDouble(const xml::lite::QName&, double p, xml::lite::Element& parent) const; xml::lite::Element& createDouble(const xml::lite::QName&, const std::optional& p, xml::lite::Element& parent) const; - xml::lite::Element& createFloat(const xml::lite::QName&, float p, xml::lite::Element& parent) const; xml::lite::Element* createOptionalDouble(const xml::lite::QName&, double p, xml::lite::Element& parent) const; xml::lite::Element* createOptionalDouble(const xml::lite::QName&, const std::optional& p, xml::lite::Element& parent) const; xml::lite::Element* createBooleanType(const xml::lite::QName&, BooleanType b, xml::lite::Element& parent) const; @@ -200,7 +199,6 @@ struct SIX_SIX_API XmlLite final } xml::lite::Element& createDouble(const std::string& name, double p, xml::lite::Element& parent ) const; xml::lite::Element& createDouble(const std::string& name, const std::optional& p, xml::lite::Element& parent) const; - xml::lite::Element& createFloat(const std::string& name, float p, xml::lite::Element& parent ) const; xml::lite::Element* createOptionalDouble(const std::string& name, double p, xml::lite::Element& parent) const; xml::lite::Element* createOptionalDouble(const std::string& name, const std::optional& p, xml::lite::Element& parent) const; xml::lite::Element* createBooleanType(const std::string& name, BooleanType b, xml::lite::Element&parent ) const; diff --git a/six/modules/c++/six/source/SICommonXMLParser.cpp b/six/modules/c++/six/source/SICommonXMLParser.cpp index 48ea212c4..9f2577f52 100644 --- a/six/modules/c++/six/source/SICommonXMLParser.cpp +++ b/six/modules/c++/six/source/SICommonXMLParser.cpp @@ -231,7 +231,7 @@ XMLElem SICommonXMLParser::convertGeoInfoToXML(const GeoInfo& geoInfo, const size_t numLatLons = geoInfo.geometryLatLon.size(); if (numLatLons == 1) { - createLatLon("Point", uri, geoInfo.geometryLatLon[0], geoInfoXML, true); + createLatLon("Point", uri, geoInfo.geometryLatLon[0], geoInfoXML); } else if (numLatLons >= 2) { @@ -246,8 +246,7 @@ XMLElem SICommonXMLParser::convertGeoInfoToXML(const GeoInfo& geoInfo, numLatLons == 2 ? "Endpoint" : "Vertex", uri, geoInfo.geometryLatLon[ii], - linePolyXML, - true); + linePolyXML); setAttribute(v, "index", ii + 1); } @@ -517,20 +516,12 @@ XMLElem SICommonXMLParser::createLatLon( const std::string& name, const std::string& uri, const LatLon& value, - XMLElem parent, - bool singlePrecision) const + XMLElem parent) const { XMLElem e = newElement(name, uri, parent); - if (!singlePrecision) - { - createDouble("Lat", getSICommonURI(), value.getLat(), e); - createDouble("Lon", getSICommonURI(), value.getLon(), e); - } - else - { - createFloat("Lat", getSICommonURI(), value.getLat(), e); - createFloat("Lon", getSICommonURI(), value.getLon(), e); - } + createDouble("Lat", getSICommonURI(), value.getLat(), e); + createDouble("Lon", getSICommonURI(), value.getLon(), e); + return e; } diff --git a/six/modules/c++/six/source/XMLParser.cpp b/six/modules/c++/six/source/XMLParser.cpp index adcf66e50..5cf83dbff 100644 --- a/six/modules/c++/six/source/XMLParser.cpp +++ b/six/modules/c++/six/source/XMLParser.cpp @@ -105,15 +105,6 @@ XMLElem XMLParser::createDouble(const std::string& name, const std::string& uri, assert(parent != nullptr); return &mXmlLite.createDouble(xml::lite::QName(xml::lite::Uri(uri), name), p, *parent); } -XMLElem XMLParser::createFloat(const std::string& name, const std::string& uri, float p, XMLElem parent) const -{ - assert(parent != nullptr); - return &mXmlLite.createFloat(xml::lite::QName(xml::lite::Uri(uri), name), p, *parent); -} -xml::lite::Element& XMLParser::createFloat(const std::string& name, float p, xml::lite::Element& parent) const -{ - return mXmlLite.createFloat(name, p, parent); -} xml::lite::Element& XMLParser::createDouble(const std::string& name, double p, xml::lite::Element& parent) const { return mXmlLite.createDouble(name, p, parent); diff --git a/six/modules/c++/six/source/XmlLite.cpp b/six/modules/c++/six/source/XmlLite.cpp index a4b2a2a3e..f1c92063c 100644 --- a/six/modules/c++/six/source/XmlLite.cpp +++ b/six/modules/c++/six/source/XmlLite.cpp @@ -253,13 +253,6 @@ xml::lite::Element& XmlLite::createInt_(const std::string& name, int p, xml::lit { return createInt(makeQName(name), p, parent); } - -xml::lite::Element& XmlLite::createFloat(const xml::lite::QName& name, float p, xml::lite::Element& parent) const -{ - p = value(p); // be sure this is initialized; throws if not - return createValue(name, p, parent, mAddClassAttributes, "xs:double", getDefaultURI()); -} - xml::lite::Element& XmlLite::createDouble(const xml::lite::QName& name, double p, xml::lite::Element& parent) const { p = value(p); // be sure this is initialized; throws if not @@ -269,10 +262,6 @@ xml::lite::Element& XmlLite::createDouble(const xml::lite::QName& name, const st { return createDouble(name, p.value(), parent); } -xml::lite::Element& XmlLite::createFloat(const std::string& name, float p, xml::lite::Element& parent) const -{ - return createFloat(makeQName(name), p, parent); -} xml::lite::Element& XmlLite::createDouble(const std::string& name, double p, xml::lite::Element& parent) const { return createDouble(makeQName(name), p, parent); From 06357cdc0cc22d4b4b1524ffc0125530faf4f2e2 Mon Sep 17 00:00:00 2001 From: Bertrand Zhang Date: Tue, 3 Sep 2024 16:12:06 -0400 Subject: [PATCH 8/9] fixed unit test --- .../c++/cphd/include/cphd/SupportArray.h | 3 + .../c++/cphd/include/cphd/SupportBlock.h | 10 ++- six/modules/c++/cphd/source/CPHDReader.cpp | 5 +- six/modules/c++/cphd/source/CPHDWriter.cpp | 69 ++---------------- six/modules/c++/cphd/source/SupportArray.cpp | 72 +++++++++++++++++++ six/modules/c++/cphd/source/SupportBlock.cpp | 35 ++++++--- .../unittests/test_support_block_round.cpp | 58 ++++++++++++--- 7 files changed, 168 insertions(+), 84 deletions(-) diff --git a/six/modules/c++/cphd/include/cphd/SupportArray.h b/six/modules/c++/cphd/include/cphd/SupportArray.h index 911fc5099..41cf8dfa4 100644 --- a/six/modules/c++/cphd/include/cphd/SupportArray.h +++ b/six/modules/c++/cphd/include/cphd/SupportArray.h @@ -229,6 +229,9 @@ struct SupportArray final //! Get AGP support array by unique id AdditionalSupportArray getAddedSupportArray(const std::string& key) const; + //!Get bytes per swap for suppor array data by unique id + size_t getSupportDataBytesPerSwap(const std::string& key, size_t bytesPerElement) const; + //! Vector of IAZ type arrays std::vector iazArray; diff --git a/six/modules/c++/cphd/include/cphd/SupportBlock.h b/six/modules/c++/cphd/include/cphd/SupportBlock.h index e1b7b8115..ab0c4c440 100644 --- a/six/modules/c++/cphd/include/cphd/SupportBlock.h +++ b/six/modules/c++/cphd/include/cphd/SupportBlock.h @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -59,11 +60,13 @@ struct SIX_CPHD_API SupportBlock final * \brief Constructor initializes book keeping information * * \param pathname Input CPHD pathname to initialize a file input stream + * \param supportArray SupportArray section for cphd::Metadata * \param data Data section from CPHD * \param startSupport CPHD header keyword "SUPPORT_BLOCK_BYTE_OFFSET" * \param sizeSupport CPHD header keyword "SUPPORT_BLOCK_SIZE" */ SupportBlock(const std::string& pathname, + const mem::ScopedCopyablePtr supportArray, const cphd::Data& data, int64_t startSupport, int64_t sizeSupport); @@ -74,16 +77,20 @@ struct SIX_CPHD_API SupportBlock final * \brief Constructor initializes book keeping information * * \param inStream Input stream to an already opened CPHD file + * \param supportArray SupportArray section for cphd::Metadata * \param data Data section from CPHD * \param startSupport CPHD header keyword "SUPPORT_BLOCK_BYTE_OFFSET" * \param sizeSupport CPHD header keyword "SUPPORT_BLOCK_SIZE" */ SupportBlock(std::shared_ptr inStream, + const mem::ScopedCopyablePtr supportArray, const cphd::Data& data, int64_t startSupport, int64_t sizeSupport); SupportBlock(std::shared_ptr inStream, - const cphd::Data& data, const FileHeader&); + const mem::ScopedCopyablePtr supportArray, + const cphd::Data& data, + const FileHeader&); // Noncopyable SupportBlock(const SupportBlock&) = delete; @@ -154,6 +161,7 @@ struct SIX_CPHD_API SupportBlock final private: const std::shared_ptr mInStream; + const mem::ScopedCopyablePtr mSupportArray; cphd::Data mData; const int64_t mSupportOffset; // offset in bytes to start of SupportBlock const size_t mSupportSize; // total size in bytes of SupportBlock diff --git a/six/modules/c++/cphd/source/CPHDReader.cpp b/six/modules/c++/cphd/source/CPHDReader.cpp index 8cb31fbb9..83f369890 100644 --- a/six/modules/c++/cphd/source/CPHDReader.cpp +++ b/six/modules/c++/cphd/source/CPHDReader.cpp @@ -71,7 +71,10 @@ cphd::CPHDReader::CPHDReader(std::shared_ptr inStream, : mFileHeader(cphd::FileHeader::read(*inStream)), mMetadata(fromXML(*inStream, schemaPaths_, logger, mFileHeader)) { - mSupportBlock = std::make_unique(inStream, mMetadata.data, mFileHeader); + mSupportBlock = std::make_unique(inStream, + mMetadata.supportArray, + mMetadata.data, + mFileHeader); // Load the PVPBlock into memory mPVPBlock = PVPBlock(mMetadata); diff --git a/six/modules/c++/cphd/source/CPHDWriter.cpp b/six/modules/c++/cphd/source/CPHDWriter.cpp index 24331fc6f..e913d2757 100644 --- a/six/modules/c++/cphd/source/CPHDWriter.cpp +++ b/six/modules/c++/cphd/source/CPHDWriter.cpp @@ -164,76 +164,15 @@ sys::Off_T CPHDWriter::getSupportBlockByteOffset(const Data::SupportArray& dataA } size_t CPHDWriter::getSupportDataBytesPerSwap(const Data::SupportArray& dataArray) const { - const auto &id = dataArray.identifier; - - std::string elemFmt; - const auto &sas = *mMetadata.supportArray; - // Unfortunately, need to search each vector/map of support arrays - if(elemFmt.empty()) - { - for(size_t ii = 0; ii < sas.iazArray.size(); ++ii) - { - if (sas.iazArray[ii].getIdentifier() == id) - { - // found correct id, so get element format - elemFmt = sas.iazArray[ii].elementFormat; - break; - } - } - } - - if(elemFmt.empty()) - { - for(size_t ii = 0; ii < sas.antGainPhase.size(); ++ii) - { - if (sas.antGainPhase[ii].getIdentifier() == id) - { - // found correct id, so get element format - elemFmt = sas.antGainPhase[ii].elementFormat; - break; - } - } - } - - if(elemFmt.empty()) - { - for(size_t ii = 0; ii < sas.dwellTimeArray.size(); ++ii) - { - if (sas.dwellTimeArray[ii].getIdentifier() == id) - { - // found correct id, so get element format - elemFmt = sas.dwellTimeArray[ii].elementFormat; - break; - } - } - } - - if(elemFmt.empty()) - { - if (sas.addedSupportArray.count(id) > 0) - { - // found correct id, so get element format - elemFmt = sas.addedSupportArray.find(id)->second.elementFormat; - } - } - - if(elemFmt.empty()) + if(mMetadata.supportArray.get() == nullptr) { std::ostringstream oss; - oss << "SA_ID was not found" << (id); + oss << "mMetadata.supportArray was not populated"; throw except::Exception(Ctxt(oss.str())); } - //Assuming homogeneous component types - //TODO: Test for validity of this assumption? - auto eqLoc = elemFmt.find("="); - auto numPerElement = str::split(elemFmt, ";").size(); - if (elemFmt[eqLoc + 1] == 'C') - { - //Byteswap complex components individually too - numPerElement *= 2; - } - return dataArray.bytesPerElement / numPerElement; + return mMetadata.supportArray->getSupportDataBytesPerSwap(dataArray.identifier, + dataArray.bytesPerElement); } void CPHDWriter::writeSupportDataArray(io::SeekableOutputStream& stream, DataWriter& dataWriter, std::span data, const Data::SupportArray& dataArray) diff --git a/six/modules/c++/cphd/source/SupportArray.cpp b/six/modules/c++/cphd/source/SupportArray.cpp index 98df99eeb..2b2b50058 100644 --- a/six/modules/c++/cphd/source/SupportArray.cpp +++ b/six/modules/c++/cphd/source/SupportArray.cpp @@ -140,6 +140,78 @@ AdditionalSupportArray SupportArray::getAddedSupportArray(const std::string& key return addedSupportArray.find(key)->second; } +size_t SupportArray::getSupportDataBytesPerSwap(const std::string& key, + size_t bytesPerElement) const +{ + std::string elemFmt; + // Unfortunately, need to search each vector/map of support arrays + if(elemFmt.empty()) + { + for(size_t ii = 0; ii < iazArray.size(); ++ii) + { + if (iazArray[ii].getIdentifier() == key) + { + // found correct id, so get element format + elemFmt = iazArray[ii].elementFormat; + break; + } + } + } + + if(elemFmt.empty()) + { + for(size_t ii = 0; ii < antGainPhase.size(); ++ii) + { + if (antGainPhase[ii].getIdentifier() == key) + { + // found correct id, so get element format + elemFmt = antGainPhase[ii].elementFormat; + break; + } + } + } + + if(elemFmt.empty()) + { + for(size_t ii = 0; ii < dwellTimeArray.size(); ++ii) + { + if (dwellTimeArray[ii].getIdentifier() == key) + { + // found correct id, so get element format + elemFmt = dwellTimeArray[ii].elementFormat; + break; + } + } + } + + if(elemFmt.empty()) + { + if (addedSupportArray.count(key) > 0) + { + // found correct id, so get element format + elemFmt = addedSupportArray.find(key)->second.elementFormat; + } + } + + if(elemFmt.empty()) + { + std::ostringstream oss; + oss << "SA_ID was not found" << (key); + throw except::Exception(Ctxt(oss.str())); + } + + //Assuming homogeneous component types + //TODO: Test for validity of this assumption? + auto eqLoc = elemFmt.find("="); + auto numSwapsPerElement = str::split(elemFmt, ";").size(); + if (elemFmt[eqLoc + 1] == 'C') + { + //Byteswap complex components individually too + numSwapsPerElement *= 2; + } + return bytesPerElement / numSwapsPerElement; +} + std::ostream& operator<< (std::ostream& os, const SupportArrayParameter& s) { if (!six::Init::isUndefined(s.getIdentifier())) diff --git a/six/modules/c++/cphd/source/SupportBlock.cpp b/six/modules/c++/cphd/source/SupportBlock.cpp index 6825ca288..59979c6af 100644 --- a/six/modules/c++/cphd/source/SupportBlock.cpp +++ b/six/modules/c++/cphd/source/SupportBlock.cpp @@ -39,17 +39,24 @@ namespace cphd { SupportBlock::SupportBlock(const std::string& pathname, + const mem::ScopedCopyablePtr supportArray, const cphd::Data& data, int64_t startSupport, int64_t sizeSupport) : - SupportBlock(std::make_shared(pathname), data, startSupport, sizeSupport) + SupportBlock(std::make_shared(pathname), + supportArray, + data, + startSupport, + sizeSupport) { } SupportBlock::SupportBlock(std::shared_ptr inStream, + const mem::ScopedCopyablePtr supportArray, const cphd::Data& data, int64_t startSupport, int64_t sizeSupport) : mInStream(inStream), + mSupportArray(supportArray), mData(data), mSupportOffset(startSupport), mSupportSize(sizeSupport) @@ -62,9 +69,14 @@ SupportBlock::SupportBlock(std::shared_ptr inStream, } } SupportBlock::SupportBlock(std::shared_ptr inStream, - const cphd::Data& data, const cphd::FileHeader& fileHeader): - SupportBlock(inStream, data, - fileHeader.getSupportBlockByteOffset(), fileHeader.getSupportBlockSize()) + const mem::ScopedCopyablePtr supportArray, + const cphd::Data& data, + const cphd::FileHeader& fileHeader): + SupportBlock(inStream, + supportArray, + data, + fileHeader.getSupportBlockByteOffset(), + fileHeader.getSupportBlockSize()) { } @@ -105,11 +117,18 @@ void SupportBlock::read(const std::string& id, size_t numThreads, std::spanread(dataPtr, bytes); - if ((std::endian::native == std::endian::little) && mData.getElementSize(id) > 1) + const size_t elemSize = mData.getElementSize(id); + if ((std::endian::native == std::endian::little) && elemSize > 1) { - cphd::byteSwap(dataPtr, mData.getElementSize(id), - mData.getSupportArrayById(id).size(), - numThreads); + if (mSupportArray.get() == nullptr) + { + std::ostringstream ostr; + ostr << "mSupportArray was not populated"; + throw except::Exception(Ctxt(ostr.str())); + } + + const size_t bytesPerSwap = mSupportArray->getSupportDataBytesPerSwap(id, elemSize); + cphd::byteSwap(dataPtr, bytesPerSwap, bytes / bytesPerSwap, numThreads); } } diff --git a/six/modules/c++/cphd/unittests/test_support_block_round.cpp b/six/modules/c++/cphd/unittests/test_support_block_round.cpp index 36899ec5e..c99228d83 100644 --- a/six/modules/c++/cphd/unittests/test_support_block_round.cpp +++ b/six/modules/c++/cphd/unittests/test_support_block_round.cpp @@ -43,7 +43,6 @@ #include #include -static constexpr size_t NUM_SUPPORT = 3; static constexpr size_t NUM_ROWS = 3; static constexpr size_t NUM_COLS = 4; @@ -60,11 +59,52 @@ std::vector generateSupportData(size_t length) } template -void setSupport(cphd::Data& d) +void setSupport(cphd::Metadata& md) { - d.setSupportArray("1.0", NUM_ROWS, NUM_COLS, sizeof(T), 0); - d.setSupportArray("2.0", NUM_ROWS, NUM_COLS, sizeof(T), NUM_ROWS*NUM_COLS*sizeof(T)); - d.setSupportArray("AddedSupport", NUM_ROWS, NUM_COLS, sizeof(T), 2*NUM_ROWS*NUM_COLS*sizeof(T)); + std::string tStr, ctStr; + const size_t sizeofT = sizeof(T); + switch (sizeofT) + { + case 4: + tStr = "I4;"; + ctStr = "CI8;"; + break; + case 8: + tStr = "F8;"; + ctStr = "CF16;"; + break; + } + + std::string id; + md.supportArray.reset(new cphd::SupportArray()); + + id = "IAZ"; + md.data.setSupportArray(id, NUM_ROWS, NUM_COLS, sizeof(T), 0); + md.supportArray->iazArray.push_back( + cphd::SupportArrayParameter("IAZ="+tStr, + id, 0.0, 0.0, 5.0, 5.0)); + + id = "AGP"; + md.data.setSupportArray(id, NUM_ROWS, NUM_COLS, 2*sizeof(T), + NUM_ROWS*NUM_COLS*sizeof(T)); + md.supportArray->antGainPhase.push_back( + cphd::SupportArrayParameter("Gain="+tStr+"Phase="+tStr, + id, 0.0, 0.0, 5.0, 5.0)); + + id = "DTA"; + md.data.setSupportArray(id, NUM_ROWS, NUM_COLS, 2*sizeof(T), + 3*NUM_ROWS*NUM_COLS*sizeof(T)); + md.supportArray->dwellTimeArray.push_back( + cphd::SupportArrayParameter("COD="+tStr+"DT="+tStr, + id, 0.0, 0.0, 5.0, 5.0)); + + id = "AddedSupport"; + md.data.setSupportArray(id, NUM_ROWS, NUM_COLS, 3*2*sizeof(T), + 5*NUM_ROWS*NUM_COLS*sizeof(T)); + md.supportArray->addedSupportArray[id] = cphd::AdditionalSupportArray( + "f000="+ctStr+"f001="+ctStr+"f002="+ctStr, + id, 0.0, 0.0, 5.0, 5.0, + "XUnits", "YUnits", "ZUnits"); } template @@ -133,12 +173,12 @@ bool runTest(const std::vector& writeData) io::TempFile tempfile; const size_t numThreads = 1; auto meta = cphd::setUpData(types::RowCol(128,256), std::vector()); - setSupport(meta.data); + setSupport(meta); cphd::setPVPXML(meta.pvp); cphd::PVPBlock pvpBlock(meta.pvp, meta.data); writeSupportData(tempfile.pathname(), numThreads, writeData, meta, pvpBlock); const std::vector readData = - checkSupportData(tempfile.pathname(), NUM_SUPPORT*NUM_ROWS*NUM_COLS*sizeof(T), numThreads); + checkSupportData(tempfile.pathname(), 11*NUM_ROWS*NUM_COLS*sizeof(T), numThreads); return compareVectors(readData, writeData.data(), writeData.size()); } @@ -147,7 +187,7 @@ TEST_CASE(testSupportsInt) { const types::RowCol dims(NUM_ROWS, NUM_COLS); const std::vector writeData = - generateSupportData(NUM_SUPPORT*dims.area()); + generateSupportData(11*dims.area()); TEST_ASSERT_TRUE(runTest(writeData)); } @@ -155,7 +195,7 @@ TEST_CASE(testSupportsDouble) { const types::RowCol dims(NUM_ROWS, NUM_COLS); const std::vector writeData = - generateSupportData(NUM_SUPPORT*dims.area()); + generateSupportData(11*dims.area()); TEST_ASSERT_TRUE(runTest(writeData)); } From 938798411129c6eaf32ffa451dd079cf1005e247 Mon Sep 17 00:00:00 2001 From: Bertrand Zhang Date: Wed, 4 Sep 2024 13:28:57 -0400 Subject: [PATCH 9/9] PR changes --- six/modules/c++/cphd/source/CPHDXMLParser.cpp | 6 +----- six/modules/c++/cphd/source/SupportArray.cpp | 17 +++++++---------- .../c++/six/include/six/ErrorStatistics.h | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/six/modules/c++/cphd/source/CPHDXMLParser.cpp b/six/modules/c++/cphd/source/CPHDXMLParser.cpp index ef1d4dc41..f655b7a9b 100644 --- a/six/modules/c++/cphd/source/CPHDXMLParser.cpp +++ b/six/modules/c++/cphd/source/CPHDXMLParser.cpp @@ -322,15 +322,11 @@ XMLElem CPHDXMLParser::toXML(const Data& data, XMLElem parent) createString("Identifier", data.channels[ii].identifier, channelXML); createInt("NumVectors", data.channels[ii].numVectors, channelXML); createInt("NumSamples", data.channels[ii].numSamples, channelXML); -#if 0 - createInt("SignalArrayByteOffset", data.channels[ii].signalArrayByteOffset, channelXML); - createInt("PVPArrayByteOffset", data.channels[ii].pvpArrayByteOffset, channelXML); -#else std::string lTmpStr1 = std::to_string(data.channels[ii].signalArrayByteOffset); std::string lTmpStr2 = std::to_string(data.channels[ii].pvpArrayByteOffset); createString("SignalArrayByteOffset", lTmpStr1, channelXML); createString("PVPArrayByteOffset", lTmpStr2, channelXML); -#endif + if(!six::Init::isUndefined(data.channels[ii].compressedSignalSize)) { createInt("CompressedSignalSize", data.channels[ii].compressedSignalSize, channelXML); diff --git a/six/modules/c++/cphd/source/SupportArray.cpp b/six/modules/c++/cphd/source/SupportArray.cpp index 2b2b50058..435de72bb 100644 --- a/six/modules/c++/cphd/source/SupportArray.cpp +++ b/six/modules/c++/cphd/source/SupportArray.cpp @@ -83,35 +83,32 @@ AdditionalSupportArray::AdditionalSupportArray( static SupportArrayParameter getSupportArray(const std::vector& params, const std::string& key) { - std::vector valid_keys; + std::vector validKeys; for(size_t ii = 0; ii < params.size(); ++ii) { if (params[ii].getIdentifier()==key) { - // found correct key. so add to valid_keys - valid_keys.push_back(ii); + // found correct key. so add to validKeys + validKeys.push_back(ii); } } - if(!valid_keys.size()) + if(validKeys.empty()) { // if no matching key found, throw an exception std::ostringstream oss; oss << "SA_ID was not found " << (key); throw except::Exception(Ctxt(oss.str())); } - else if (valid_keys.size()>1) + if (validKeys.size()>1) { // if find repeated key, throw an exception std::ostringstream oss; oss << "Found multiple support arrays with same SA_ID: " << (key); throw except::Exception(Ctxt(oss.str())); } - else - { - // if valid key is length 1, return that SupportArrayParameter - return params[valid_keys[0]]; - } + + return params[validKeys[0]]; } SupportArrayParameter SupportArray::getIAZSupportArray(const std::string& key) const diff --git a/six/modules/c++/six/include/six/ErrorStatistics.h b/six/modules/c++/six/include/six/ErrorStatistics.h index d96ef07ca..da1b2245e 100644 --- a/six/modules/c++/six/include/six/ErrorStatistics.h +++ b/six/modules/c++/six/include/six/ErrorStatistics.h @@ -137,7 +137,7 @@ struct SIX_SIX_API RadarSensor * (Optional) Transmit frequency scale factor * standard deviation. */ - double transmitFreqSF = Init::undefined(); // From Bill: "No mention of the TransmitFreqSF in volume 3 ... would still recommend setting to 0." + double transmitFreqSF = Init::undefined(); // Set to undefined so that it skips population instead of setting to 0 /*! * (Optional) Range bias decorrelated rate