void ComplexXMLParser10x::parseRMCRFromXML(const XMLElem rmcrElem, 
                                           RMCR* rmcr) const
{
    common().parseVector3D(getFirstAndOnly(rmcrElem, "PosRef"), rmcr->refPos);
    common().parseVector3D(getFirstAndOnly(rmcrElem, "VelRef"), rmcr->refVel);
    parseDouble(getFirstAndOnly(rmcrElem, "DopConeAngRef"), rmcr->dopConeAngleRef);
}
void ComplexXMLParser10x::parseSCPCOAFromXML(
        const XMLElem scpcoaXML, SCPCOA* scpcoa) const
{
    ComplexXMLParser::parseSCPCOAFromXML(scpcoaXML, scpcoa);

    //! Added in 1.0.0
    parseDouble(getFirstAndOnly(scpcoaXML, "AzimAng"), scpcoa->azimAngle);
    parseDouble(getFirstAndOnly(scpcoaXML, "LayoverAng"), scpcoa->layoverAngle);
}
void ComplexXMLParser10x::parseAntennaParamArrayFromXML(
    const XMLElem antennaParamsXML, 
    six::sicd::AntennaParameters* params) const
{
    //! this field is mandatory in 1.0.0
    XMLElem arrayElem = getFirstAndOnly(antennaParamsXML, "Array");
    params->array.reset(new GainAndPhasePolys());
    common().parsePoly2D(getFirstAndOnly(arrayElem, "GainPoly"),
                params->array->gainPoly);
    common().parsePoly2D(getFirstAndOnly(arrayElem, "PhasePoly"),
                params->array->phasePoly);
}
void ComplexXMLParser10x::parsePolarizationCalibrationFromXML(
    const XMLElem polCalXML,
    six::sicd::PolarizationCalibration* obj) const
{
    // HVAngleCompApplied no longer exists in 1.0.0
    parseBooleanType(getFirstAndOnly(polCalXML, "DistortCorrectionApplied"),
                     obj->distortionCorrectionApplied);
}
void ComplexXMLParser10x::parseTxRcvPolFromXML(
    const XMLElem parent,
    six::DualPolarizationType& txRcvPol) const
{
    //! Required field
    txRcvPol = six::toType<
        DualPolarizationType>(
            getFirstAndOnly(parent, "TxRcvPolarizationProc")->
                getCharacterData());
}
void ComplexXMLParser040::parseRMATFromXML(const XMLElem rmatElem,
        RMAT* rmat) const
{
    parseDouble(getFirstAndOnly(rmatElem, "RMRefTime"), rmat->refTime);
    common().parseVector3D(getFirstAndOnly(rmatElem, "RMPosRef"), rmat->refPos);
    common().parseVector3D(getFirstAndOnly(rmatElem, "RMVelRef"), rmat->refVel);
    common().parsePoly2D(getFirstAndOnly(rmatElem, "CosDCACOAPoly"),
                         rmat->cosDCACOAPoly);
    parseDouble(getFirstAndOnly(rmatElem, "Kx1"), rmat->kx1);
    parseDouble(getFirstAndOnly(rmatElem, "Kx2"), rmat->kx2);
    parseDouble(getFirstAndOnly(rmatElem, "Ky1"), rmat->ky1);
    parseDouble(getFirstAndOnly(rmatElem, "Ky2"), rmat->ky2);
}
void ComplexXMLParser040::parseDRateSFPolyFromXML(
    const XMLElem incaElem, INCA* inca) const
{
    //! Poly1D in 0.4.0
    Poly1D dRateSFPoly;
    common().parsePoly1D(getFirstAndOnly(incaElem, "DRateSFPoly"),
                         dRateSFPoly);

    // set x order -> 0, y order -> oldPoly
    inca->dopplerRateScaleFactorPoly = Poly2D(0, dRateSFPoly.order());
    inca->dopplerRateScaleFactorPoly.set(0, dRateSFPoly);
}
void ComplexXMLParser10x::parseWeightTypeFromXML(
    const XMLElem gridRowColXML,
    mem::ScopedCopyablePtr<WeightType>& obj) const
{
    const XMLElem weightType = getOptional(gridRowColXML, "WgtType");
    if (weightType)
    {
        obj.reset(new WeightType());
        parseString(getFirstAndOnly(weightType, "WindowName"),
                    obj->windowName);
        common().parseParameters(weightType, "Parameter", obj->parameters);
    }
    else
    {
        obj.reset();
    }
}
void ComplexXMLParser10x::parseRadarCollectionFromXML(
        const XMLElem radarCollectionXML,
        RadarCollection* radarCollection) const
{
    XMLElem tmpElem = getFirstAndOnly(radarCollectionXML, "TxFrequency");
    parseDouble(getFirstAndOnly(tmpElem, "Min"),
                radarCollection->txFrequencyMin);
    parseDouble(getFirstAndOnly(tmpElem, "Max"),
                radarCollection->txFrequencyMax);

    tmpElem = getOptional(radarCollectionXML, "RefFreqIndex");
    if (tmpElem)
    {
        //optional
        parseInt(tmpElem, radarCollection->refFrequencyIndex);
    }

    tmpElem = getOptional(radarCollectionXML, "Waveform");
    if (tmpElem)
    {
        //optional
        parseWaveformFromXML(tmpElem, radarCollection->waveform);
    }

    tmpElem = getFirstAndOnly(radarCollectionXML, "TxPolarization");
    radarCollection->txPolarization = six::toType<PolarizationSequenceType>(
            tmpElem->getCharacterData());

    tmpElem = getOptional(radarCollectionXML, "TxSequence");
    if (tmpElem)
    {
        //optional
        parseTxSequenceFromXML(tmpElem, radarCollection->txSequence);
    }

    tmpElem = getFirstAndOnly(radarCollectionXML, "RcvChannels");

    std::vector<XMLElem> channelsXML;
    tmpElem->getElementsByTagName("ChanParameters", channelsXML);
    if (channelsXML.empty())
    {
        throw except::Exception(Ctxt(
                "Expected at least one ChanParameters element"));
    }

    for (std::vector<XMLElem>::const_iterator it = channelsXML.begin();
         it != channelsXML.end();
         ++it)
    {
        radarCollection->rcvChannels.resize(
                radarCollection->rcvChannels.size() + 1);
        mem::ScopedCloneablePtr<ChannelParameters>& chanParams =
                radarCollection->rcvChannels.back();
        chanParams.reset(new ChannelParameters());

        XMLElem childXML = getFirstAndOnly(*it, "TxRcvPolarization");
        chanParams->txRcvPolarization = six::toType<DualPolarizationType>(
                childXML->getCharacterData());

        childXML = getOptional(*it, "RcvAPCIndex");
        if (childXML)
        {
            parseInt(childXML, chanParams->rcvAPCIndex);
        }
    }

    XMLElem areaXML = getOptional(radarCollectionXML, "Area");
    if (areaXML)
    {
        //optional
        parseAreaFromXML(areaXML, true, false, radarCollection->area);
    }

    common().parseParameters(radarCollectionXML, "Parameter",
                    radarCollection->parameters);
}
void ComplexXMLParser10x::parseMatchInformationFromXML(
    const XMLElem matchInfoXML, 
    MatchInformation* matchInfo) const
{
    int numMatchTypes = 0;
    parseInt(getFirstAndOnly(matchInfoXML, "NumMatchTypes"), numMatchTypes);

    //TODO make sure there is at least one
    std::vector < XMLElem > typesXML;
    matchInfoXML->getElementsByTagName("MatchType", typesXML);

    //! validate the numMatchTypes
    if (typesXML.size() != (size_t)numMatchTypes)
    {
        throw except::Exception(
            Ctxt("NumMatchTypes does not match number of MatchType fields"));
    }

    for (size_t i = 0; i < typesXML.size(); i++)
    {
        // The MatchInformation object was given a MatchType when
        // it was instantiated.  The first time through, just populate it.
        if (i != 0)
        {
            matchInfo->types.push_back(
                mem::ScopedCopyablePtr<MatchType>(new MatchType()));
        }
        MatchType* type = matchInfo->types[i].get();

        parseString(getFirstAndOnly(typesXML[i], "TypeID"), type->typeID);

        XMLElem curIndexElem = getOptional(typesXML[i], "CurrentIndex");
        if (curIndexElem)
        {
            //optional
            parseInt(curIndexElem, type->currentIndex);
        }

        int numMatchCollections = 0;
        parseInt(getFirstAndOnly(typesXML[i], "NumMatchCollections"), 
                 numMatchCollections);

        std::vector < XMLElem > matchCollectionsXML;
        typesXML[i]->getElementsByTagName("MatchCollection", matchCollectionsXML);

        //! validate the numMatchTypes
        if (matchCollectionsXML.size() !=
            static_cast<size_t>(numMatchCollections))
        {
            throw except::Exception(
                Ctxt("NumMatchCollections does not match number of " \
                     "MatchCollect fields"));
        }

        // Need to make sure this is resized properly - at MatchType
        // construction time, matchCollects is initialized to size 1, but in
        // SICD 1.1 this entire block may be missing.
        type->matchCollects.resize(matchCollectionsXML.size());
        for (size_t jj = 0; jj < matchCollectionsXML.size(); jj++)
        {
            MatchCollect& collect(type->matchCollects[jj]);

            parseString(getFirstAndOnly(
                matchCollectionsXML[jj], "CoreName"), collect.coreName);

            XMLElem matchIndexXML = 
                getOptional(matchCollectionsXML[jj], "MatchIndex");
            if (matchIndexXML)
            {
                parseInt(matchIndexXML, collect.matchIndex);
            }

            common().parseParameters(
                matchCollectionsXML[jj], "Parameter", collect.parameters);
        }
    }
}