当前位置: 首页>>代码示例>>C++>>正文


C++ GModelPar::unit方法代码示例

本文整理汇总了C++中GModelPar::unit方法的典型用法代码示例。如果您正苦于以下问题:C++ GModelPar::unit方法的具体用法?C++ GModelPar::unit怎么用?C++ GModelPar::unit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GModelPar的用法示例。


在下文中一共展示了GModelPar::unit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GCTAModelRadial

/***********************************************************************//**
 * @brief Constructor
 *
 * @param[in] coeffs Vector of polynomial coefficients.
 ***************************************************************************/
GCTAModelRadialPolynom::GCTAModelRadialPolynom(const std::vector<double>& coeffs)
                                                          : GCTAModelRadial()
{
    // Initialise members
    init_members();

    // Assign coefficients
    for (int i = 0; i < coeffs.size(); ++i) {

        // Allocate parameter
        GModelPar par;

        // Set value
        par.real_value(coeffs[i]);

        // Set other attributes
        std::string name = "coeff"+str(i);
        par.name(name);
        par.unit("");
        par.free();
        par.scale(1.0);
        par.gradient(0.0);
        par.hasgrad(true);

        // Push coefficient on list
        m_coeffs.push_back(par);

    } // endfor: looped over coefficients

    // Update parameter mapping
    update_pars();

    // Return
    return;
}
开发者ID:adonath,项目名称:gammalib,代码行数:40,代码来源:GCTAModelRadialPolynom.cpp

示例2: read

/***********************************************************************//**
 * @brief Read model from XML element
 *
 * @param[in] xml XML element.
 *
 * @exception GException::invalid_value
 *            Model definition requires at least one node.
 *
 * Read the COMPTEL DRB fitting model from an XML element.
 *
 * The model is composed of nodes that define the normalization value as
 * function of Phibar value. The following XML file syntax is expected:
 *
 *     <source name="Background" type="DRBFitting" instrument="COM">
 *       <node>
 *         <parameter name="Phibar"        .../>
 *         <parameter name="Normalization" .../>
 *       </node>
 *       ...
 *       <node>
 *         <parameter name="Phibar"        .../>
 *         <parameter name="Normalization" .../>
 *       </node>
 *     </source>
 ***************************************************************************/
void GCOMModelDRBFitting::read(const GXmlElement& xml)
{
    // Free space for nodes
    m_phibars.clear();
    m_values.clear();

    // Get number of nodes from XML file
    int nodes = xml.elements("node");

    // Throw an error if there are no nodes
    if (nodes < 1) {
        std::string msg = "DRB fitting model requires at least one Phibar "
                          "node. Please correct XML format.";
        throw GException::invalid_value(G_READ, msg);
    }

    // Loop over all nodes
    for (int i = 0; i < nodes; ++i) {

        // Allocate node parameters
        GModelPar phibar;
        GModelPar normalization;
            
        // Get node
        const GXmlElement* node = xml.element("node", i);

        // Read Phibar parameter
        const GXmlElement* par = gammalib::xml_get_par(G_READ, *node, "Phibar");
        phibar.read(*par);

        // Read Normalization parameter
        par = gammalib::xml_get_par(G_READ, *node, "Normalization");
        normalization.read(*par);

        // Set parameter names
        std::string phibar_name        = "Phibar layer "+gammalib::str(i);
        std::string normalization_name = "Scale factor "+gammalib::str(i);

        // Set Phibar attributes
        phibar.name(phibar_name);
        phibar.unit("deg");
        phibar.has_grad(false);

        // Set normalization attributes
        normalization.name(normalization_name);
        normalization.unit("");
        normalization.has_grad(true);

        // Push node parameters on list
        m_phibars.push_back(phibar);
        m_values.push_back(normalization);

    } // endfor: looped over nodes

    // Set model name
    name(xml.attribute("name"));

    // Set instruments
    instruments(xml.attribute("instrument"));

    // Set observation identifiers
    ids(xml.attribute("id"));

    // Check flag if TS value should be computed
    bool tscalc = (xml.attribute("tscalc") == "1") ? true : false;

    // Set flag if TS value should be computed
    this->tscalc(tscalc);

    // Set pointers
    set_pointers();

    // Set evluation cache
    set_cache();

//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例3: read


//.........这里部分代码省略.........
        }
        
        // Verify that parameter coefficient has index in valid range
        int index = -1;
        size_t nchars = par->attribute("name").length() - 5;
        if (nchars > 0) {
            index = toint(par->attribute("name").substr(5, nchars));
        }
        else {
            throw GException::model_invalid_parnames(G_READ, xml,
                  "Radial polynomial \"Coeff\" parameter has no index.");
        }
        if (index < 0) {
            throw GException::model_invalid_parnames(G_READ, xml,
                  "Radial polynomial \"Coeff\" parameter index < 0.");
        }
        if (index >= max_coeffs) {
            std::string message = "There are "+str(max_coeffs)+" parameters,"
                                  " hence polynomial coefficients are expected"
                                  " to run from 0 to "+str(max_coeffs-1)+", yet"
                                  " a coefficient with index "+str(index)+" was"
                                  " encountered.";
            throw GException::model_invalid_parnames(G_READ, xml, message);
        }

        // Increment parameter counter
        npar[index]++;
        
        // Update number of coefficients
        if (index+1 > ncoeffs) {
            ncoeffs = index + 1;
        }

    } // endfor: verified XML file consistency
    
    // Verify that the number of coefficients is between 1 and max_coeffs
    if (ncoeffs < 0 || ncoeffs > max_coeffs) {
        std::string message = "Radial polynomial model requires at between"
                              " 1 and "+str(max_coeffs)+" parameters.";
        throw GException::model_invalid_parnum(G_READ, xml, message);
    }

    // Verify that all parameters were found
    for (int i = 0; i < ncoeffs; ++i) {
        if (npar[i] == 0) {
            std::string message = "Parameter \"Coeff"+str(i)+"\" required,"
                                  " but not found in XML file.";
            throw GException::model_invalid_parnames(G_READ, xml, message);
        }
        else if (npar[i] > 1) {
            std::string message = "Multiple parameters \"Coeff"+str(i)+"\""
                                  " found in XML file.";
            throw GException::model_invalid_parnames(G_READ, xml, message);
        }
    }

    // Finally get all coefficients in order
    for (int i = 0; i < ncoeffs; ++i) {

        // Set parameter name
        std::string name = "Coeff"+str(i);

        // Get corresponding parameter element
        GXmlElement* par = NULL;
        for (int k = 0; k < ncoeffs; ++k) {
            GXmlElement* element = static_cast<GXmlElement*>(xml.element("parameter", k));
            if (element->attribute("name") == name) {
                par = element;
                break;
            }
        }

        // Make sure that we really have one (just a double check, this should
        // never fail)
        if (par == NULL) {
            std::string message = "Required parameter \""+name+"\" not found.";
            throw GException::model_invalid_parnames(G_READ, xml, message);
        }

        // Now read that parameter ...
        GModelPar coeff;
        coeff.read(*par);

        // ... set other attributes ...
        coeff.name(name);
        coeff.unit("");

        //TODO: Check parameter

        // ... and push it on the list
        m_coeffs.push_back(coeff);

    } // endfor: looped over all parameters

    // Update parameter mapping
    update_pars();

    // Return
    return;
}
开发者ID:adonath,项目名称:gammalib,代码行数:101,代码来源:GCTAModelRadialPolynom.cpp


注:本文中的GModelPar::unit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。