void
ProgrammableOpAttributes::AddFunction(const std::string& name, const stringVector& atts)
{
    JSONNode vars = JSONNode::JSONArray();
    for(int i = 0; i < atts.size(); ++i)
        vars.Append(atts[i]);

    JSONNode node;
    node["vars"] = vars;

    std::string argstring = "";
    for(size_t i = 0; i < atts.size(); ++i)
        argstring += atts[i] + (i == atts.size()-1 ? "" : ",");

   // char buf[1024];
   // sprintf(buf,"import visit_internal_funcs\nsetout(visit_internal_funcs.%s(%s))",name.c_str(),argstring.c_str());

    std::ostringstream ostr;

    ostr << "import visit_internal_funcs\n"
         << "setout(visit_internal_funcs." << name << "(" << argstring << "))" << std::endl;

    std::string escapedCode = ostr.str();
    //std::cout << escapedCode << std::endl;
    replace(escapedCode, "\n", "\\n");

    node["source"] = escapedCode;

    script["scripts"][name] = node;

    //update scriptmap
    scriptMap = script.ToString();
    Select(ID_scriptMap, (void *)&scriptMap);
}
Пример #2
0
void 
XMLNode::GetAttributeNames(stringVector &result) const
{
    result.clear();
    map<string,string>::const_iterator itr;
    for(itr =attributes.begin(); itr != attributes.end();++itr)
        result.push_back(itr->first);
}
// ****************************************************************************
// Method: QvisScatterPlotWizardPage::GetSelectedVars()
//
// Purpose: Returns the names of the selected variables.
//
// Programmer: Cyrus Harrison
// Creation:  Wed Aug 18 15:26:15 PDT 2010
//
//
// Modifications:
//
// ****************************************************************************
void
QvisScatterPlotWizardPage::GetSelectedVars(stringVector &res) const
{
    res.clear();
    res.push_back(xVarName);
    res.push_back(yVarName);
    res.push_back(zVarName);
    res.push_back(colorVarName);
}
Пример #4
0
void
NameSimplifier::GetSimplifiedNames(stringVector &n) const
{
    n.clear();

    for (size_t i=0; i<names.size(); i++)
    {
        n.push_back(names[i].GetAsString());
    }
}
void
ViewerDatabaseCorrelationMethods::DeclineCorrelationCreation(const stringVector &dbs)
{
    if(dbs.size() > 0)
    {
        for(size_t i = 0; i < dbs.size(); ++i)
            declinedFiles.push_back(dbs[i]);
        declinedFilesLength.push_back((int)dbs.size());
    }
}
bool
GetStringVectorFromPyObject(PyObject *obj, stringVector &vec)
{
    bool retval = true;

    if(obj == 0)
    {
        retval = false;
    }
    else if(PyTuple_Check(obj))
    {
        // Extract arguments from the tuple.
        for(int i = 0; i < PyTuple_Size(obj); ++i)
        {
            PyObject *item = PyTuple_GET_ITEM(obj, i);
            if(PyString_Check(item))
                vec.push_back(PyString_AS_STRING(item));
            else
            {
                VisItErrorFunc("The tuple must contain all strings.");
                retval = false;
                break;
            }
        }
    }
    else if(PyList_Check(obj))
    {
        // Extract arguments from the list.
        for(int i = 0; i < PyList_Size(obj); ++i)
        {
            PyObject *item = PyList_GET_ITEM(obj, i);
            if(PyString_Check(item))
                vec.push_back(PyString_AS_STRING(item));
            else
            {
                VisItErrorFunc("The list must contain all strings.");
                retval = false;
                break;
            }
        }
    }
    else if(PyString_Check(obj))
    {
        vec.push_back(PyString_AS_STRING(obj));
    }
    else
    {
        retval = false;
        VisItErrorFunc("The object could not be converted to a "
                       "vector of strings.");
    }

    return retval;
}
Пример #7
0
// ****************************************************************************
// Method:  FileOpenOptions::AddFallbackFormatsToPreferred
//
// Purpose:
//   Adds any given formats to the *end* of the preferred list, moving
//   their position to the back if they were already in the list.
//
// Arguments:
//   given    the list of formats labeled as "fallback"
//
// Programmer:  Jeremy Meredith
// Creation:    March 26, 2010
//
// ****************************************************************************
void
FileOpenOptions::AddFallbackFormatsToPreferred(const stringVector &given)
{
    // for each format, append it
    for (size_t i=0; i<given.size(); i++)
    {
        // get its actual ID
        std::string id = "";
        for (size_t j=0; j<typeIDs.size(); j++)
        {
            if (given[i] == typeIDs[j] ||
                given[i] == typeNames[j])
            {
                id = typeIDs[j];
                break;
            }
        }
        // if no id, we don't have that plugin, so skip this one
        if (id == "")
            continue;

        // make a new list with this given one at the back
        stringVector newPreferredIDs;
        for (size_t j=0; j<preferredIDs.size(); j++)
        {
            if (preferredIDs[j] != id)
                newPreferredIDs.push_back(preferredIDs[j]);
        }
        newPreferredIDs.push_back(id);
        preferredIDs = newPreferredIDs;
    }
    SelectPreferredIDs();
}
void 
ProgrammableOpAttributes::AddPythonScript(const std::string& name, const stringVector& atts, const std::string& code)
{
    JSONNode vars = JSONNode::JSONArray();
    for(int i = 0; i < atts.size(); ++i)
        vars.Append(atts[i]);

    JSONNode node;
    node["vars"] = vars;

    std::ostringstream pwrapper;

    pwrapper << "from visit_internal_funcs import *\n"
             << code
             << "\n";
    std::string escapedCode = pwrapper.str();
    replace(escapedCode, "\n", "\\n");

    node["source"] = escapedCode;

    script["scripts"][name] = node;

    //update scriptmap
    scriptMap = script.ToString();
    Select(ID_scriptMap, (void *)&scriptMap);
}
Пример #9
0
// ****************************************************************************
// Method:  FileOpenOptions::AddAssumedFormatsToPreferred
//
// Purpose:
//   Adds any given formats to the *beginning* of the preferred list, moving
//   their position to the front if they were already in the list.
//
// Arguments:
//   given    the list of formats labeled as "assumed"
//
// Programmer:  Jeremy Meredith
// Creation:    March 26, 2010
//
// ****************************************************************************
void
FileOpenOptions::AddAssumedFormatsToPreferred(const stringVector &given)
{
    // for each format, prepend it; visit them in reverse order
    // so the first one given winds up first in the new list
    for (int i=(int)given.size()-1; i>=0; i--)
    {
        // get its actual ID
        std::string id = "";
        for (size_t j=0; j<typeIDs.size(); j++)
        {
            if (given[i] == typeIDs[j] ||
                given[i] == typeNames[j])
            {
                id = typeIDs[j];
                break;
            }
        }
        // if no id, we don't have that plugin, so skip this one
        if (id == "")
            continue;

        // make a new list with this given one at the front
        stringVector newPreferredIDs;
        newPreferredIDs.push_back(id);
        for (size_t j=0; j<preferredIDs.size(); j++)
        {
            if (preferredIDs[j] != id)
                newPreferredIDs.push_back(preferredIDs[j]);
        }
        preferredIDs = newPreferredIDs;
    }
    SelectPreferredIDs();
}
void
ProgrammableOpAttributes::AddRScript(const std::string& name, const stringVector& atts, const std::string& code)
{
    JSONNode vars = JSONNode::JSONArray();
    for(int i = 0; i < atts.size(); ++i)
        vars.Append(atts[i]);

    JSONNode node;
    node["vars"] = vars;

    std::string argstring = "";
    for(size_t i = 0; i < atts.size(); ++i)
        argstring += atts[i] + (i == atts.size()-1 ? "" : ",");

    std::ostringstream rwrapper;

    rwrapper << "import rpy2,numpy\n"
             << "import rpy2.robjects as robjects\n"
             << "import rpy2.robjects.numpy2ri\n"
             << "rpy2.robjects.numpy2ri.activate()\n"
             << "_r_output = None\n"
             << "def _r_setout(out):\n"
             << "  global _r_output\n"
             << "  _r_output = out\n"
             << "r_setout = rpy2.rinterface.rternalize(_r_setout)\n"
             << "rpy2.robjects.globalenv['setout'] = r_setout\n"
             << "r_f = robjects.r('''\n"
             << "(function(" + argstring + ") { \n"
             << code
             << "})\n"
             << "''')\n"
             << "r=r_f("+ argstring + ")\n"
             << "setout(numpy.asarray(_r_output))\n";

    std::string escapedCode = rwrapper.str();
    replace(escapedCode, "\n", "\\n");

    node["source"] = escapedCode;

    script["scripts"][name] = node;

    //update scriptmap
    scriptMap = script.ToString();
    Select(ID_scriptMap, (void *)&scriptMap);
}
ProgrammableOperation::ResponseType
avtProgrammableOperation::avtVisItForEachLocation::getSignature(std::string& name,
                          stringVector& argnames,
                          std::vector<ScriptType>& argtypes)
{
    name = "visit_foreach_location";
    argnames.push_back("window");
    argtypes.push_back(ProgrammableOperation::INT_VECTOR_TYPE);

    argnames.push_back("variableName");
    argtypes.push_back(ProgrammableOperation::VTK_DATA_ARRAY_TYPE);

    argnames.push_back("kernelLanguage");
    argtypes.push_back(ProgrammableOperation::STRING_TYPE);

    argnames.push_back("kernel");
    argtypes.push_back(ProgrammableOperation::STRING_TYPE);

    argnames.push_back("kernelName");
    argtypes.push_back(ProgrammableOperation::STRING_TYPE);

    argnames.push_back("primaryVariable");
    argtypes.push_back(ProgrammableOperation::STRING_TYPE);

    argnames.push_back("kernelArgs");
    argtypes.push_back(ProgrammableOperation::VARIANT_VECTOR_TYPE);
    return ProgrammableOperation::VTK_MULTI_DIMENSIONAL_DATA_ARRAY;
}
Пример #12
0
void
CallbackManager::GetCallbackNames(stringVector &names) const
{
    for(SubjectCallbackDataMap::const_iterator it = callbacks.begin();
        it != callbacks.end(); ++it)
    {
        if(it->second.handler != 0 && it->second.name.size() > 0)
            names.push_back(it->second.name);
    }
}
Пример #13
0
void
Dyna3DFile::GetMaterials(intVector &matnos, stringVector &matnames, doubleVector &matdens)
{
    for(int i = 0; i < materialCards.size(); ++i)
    {
        matnos.push_back(materialCards[i].materialNumber);
        matnames.push_back(materialCards[i].materialName);
        matdens.push_back(materialCards[i].density);
    }
}
ProgrammableOperation::ResponseType
avtProgrammableOperation::avtVisItMaxAcrossTime::getSignature(std::string& name,
                    stringVector& argnames,
                        std::vector<ProgrammableOperation::ScriptType>& argtypes)
{
    name = "visit_max_across_time";

    argnames.push_back("variable");
    argtypes.push_back(ProgrammableOperation::VTK_DATA_ARRAY_TYPE);
    
    return ProgrammableOperation::VTK_DATA_ARRAY;
}
ProgrammableOperation::ResponseType
avtProgrammableOperation::avtVisItGetVarInfo::getSignature(std::string& name,
                          stringVector& argnames,
                          std::vector<ScriptType>& argtypes)
{
    name = "visit_get_var_info";

    argnames.push_back("variableName");
    argtypes.push_back(ProgrammableOperation::STRING_TYPE);

    return ProgrammableOperation::CONSTANT;
}
bool
ViewerDatabaseCorrelationMethods::PreviouslyDeclinedCorrelationCreation(
    const stringVector &dbs) const
{
    int index = 0;
    for(size_t fileSet = 0; fileSet < declinedFilesLength.size();
        ++fileSet)
    {
        if(declinedFilesLength[fileSet] == (int)dbs.size())
        {
            bool same = true;
            for(int i = 0; i < declinedFilesLength[fileSet] && same; ++i, ++index)
                same &= (std::find(dbs.begin(), dbs.end(), declinedFiles[index])
                         != dbs.end());

            if(same)
                return true;
        }
    }

    return false;
}
Пример #17
0
void loadDirRange(std::string &dir, std::string &firstDir, std::string &lastDir, stringVector &tables)
	throw (std::invalid_argument)
{
	/* remove slash, if any */
	if (firstDir[firstDir.length()-1] == '/') {
		firstDir.resize(firstDir.length()-1);
	}
	if (lastDir[lastDir.length()-1] == '/') {
		lastDir.resize(lastDir.length()-1);
	}

	/* check that first dir comes before last dir */
	if (strverscmp(firstDir.c_str(), lastDir.c_str()) > 0) {
		throw std::invalid_argument(lastDir + " comes before " + firstDir);
	}

	struct dirent **namelist;
	int dirs_counter;

	/* scan for subdirectories */
	dirs_counter = scandir(dir.c_str(), &namelist, NULL, versionsort);
	if (dirs_counter < 0) {
#ifdef DEBUG
		std::cerr << "Cannot scan directory " << dir << ": " << strerror(errno) << std::endl;
#endif
		return;
	}
	/*
	 * namelist now contains dirent structure for every entry in directory.
	 * the structures are sorted according to versionsort, which is ok for most cases
	 */

	int counter = 0;
	struct dirent *dent;

	while(dirs_counter--) {
		dent = namelist[counter++];

		/* Check that the directory is in range and not '.' or '..' */
		if (dent->d_type == DT_DIR && strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..") &&
			strverscmp(dent->d_name, firstDir.c_str()) >= 0 && strverscmp(dent->d_name, lastDir.c_str()) <= 0) {

			std::string tableDir = dir + dent->d_name;
			Utils::sanitizePath(tableDir);
			tables.push_back(std::string(tableDir));
		}

		free(namelist[counter-1]);
	}
	free(namelist);
}
ProgrammableOperation::ResponseType
avtProgrammableOperation::avtVisItWriteData::getSignature(std::string& name,
                          stringVector& argnames,
                          std::vector<ProgrammableOperation::ScriptType>& argtypes)
{
    name = "visit_write";

    argnames.push_back("filename");
    argtypes.push_back(ProgrammableOperation::STRING_TYPE);

    argnames.push_back("format");
    argtypes.push_back(ProgrammableOperation::STRING_TYPE);

    argnames.push_back("local_or_global");
    argtypes.push_back(ProgrammableOperation::STRING_TYPE);

    argnames.push_back("dimension_names");
    argtypes.push_back(ProgrammableOperation::STRING_VECTOR_TYPE);

    argnames.push_back("dimension_X");
    argtypes.push_back(ProgrammableOperation::DOUBLE_VECTOR_TYPE);
    argnames.push_back("dimension_Y");
    argtypes.push_back(ProgrammableOperation::DOUBLE_VECTOR_TYPE);
    argnames.push_back("dimension_Z");
    argtypes.push_back(ProgrammableOperation::DOUBLE_VECTOR_TYPE);


    argnames.push_back("variable");
    argtypes.push_back(ProgrammableOperation::VTK_DATA_ARRAY_TYPE);

    argnames.push_back("varnames");
    argtypes.push_back(ProgrammableOperation::STRING_VECTOR_TYPE);

    argnames.push_back("indices");
    argtypes.push_back(ProgrammableOperation::INT_VECTOR_TYPE);

    return ProgrammableOperation::CONSTANT;
}
Пример #19
0
void
ConfigManager::RemoveLeadAndTailQuotes(stringVector &sv)
{
    for(size_t i = 0; i < sv.size(); ++i)
    {
        std::string &s = sv[i];
        if(s.size() > 0)
        {
            int head = (s[0] == '"') ? 1 : 0;
            int tail = (s[s.size()-1] == '"') ? 1 : 0;
            sv[i] = s.substr(head, s.size() - head - tail);
        }
    }
}
Пример #20
0
void
PluginManagerAttributes::UniqueCategories(const std::string &t, stringVector &c) const
{
    c.clear();
    for(size_t i = 0; i < type.size(); ++i)
    {
        if(type[i] == t)
        {
            if(i < category.size() &&
                    category[i] != "?" &&
                    std::find(c.begin(), c.end(), category[i]) == c.end())
                c.push_back(category[i]);
        }
    }
    std::sort(c.begin(), c.end());
}
bool
QvisPlotListBox::NeedsToBeRegenerated(const PlotList *pl,
    const stringVector &prefixes, const stringVector &createdSelections) const
{
    bool retval = true;

    if(pl->GetNumPlots() == count() && prefixes.size() == (size_t)count())
    {
        for(int i = 0; i < pl->GetNumPlots(); ++i)
        {
            QvisPlotListBoxItem *lbi = (QvisPlotListBoxItem *)item(i);
            const Plot &newPlot = pl->operator[](i);
            const Plot &currentPlot = lbi->GetPlot();

            // See if the prefixes are different.
            if(prefixes[i] != std::string(lbi->GetPrefix().toStdString()))
                 return true;

            // See if the createdSelections are different.
            if(createdSelections[i] != std::string(lbi->GetSelectionName().toStdString()))
                 return true;

            // See if the plots are different
            bool nu = newPlot.GetStateType() != currentPlot.GetStateType() ||
                   newPlot.GetPlotType() != currentPlot.GetPlotType() ||
                   newPlot.GetHiddenFlag() != currentPlot.GetHiddenFlag() ||
                   newPlot.GetExpandedFlag() != currentPlot.GetExpandedFlag() ||
                   newPlot.GetActiveOperator() != currentPlot.GetActiveOperator() ||
                   newPlot.GetPlotVar() != currentPlot.GetPlotVar() ||
                   newPlot.GetDatabaseName() != currentPlot.GetDatabaseName() ||
                   newPlot.GetOperators() != currentPlot.GetOperators() ||
                   newPlot.GetDescription() != currentPlot.GetDescription() ||
                   newPlot.GetSelection() != currentPlot.GetSelection() ||
                   newPlot.GetFollowsTime() != currentPlot.GetFollowsTime();

            if(nu) return true;
        }
        return false;
    }

    return retval;
}
Пример #22
0
avtCentering
avtMissingDataFilter::MissingDataCentering(const stringVector &vars) const
{
    bool mixed = false;
    avtCentering c0 = AVT_ZONECENT;
    for(size_t i = 0; i < vars.size(); ++i)
    {
        const avtScalarMetaData *scalar = metadata.GetScalar(vars[i]);
        if(scalar != NULL)
        {
            avtCentering thisC = scalar->centering;
            if(i == 0)
                c0 = thisC;
            if(thisC != c0)
            {
                mixed = true;
                break;
            }
        }
    }

    return mixed ? AVT_ZONECENT : c0;
}
Пример #23
0
void loadDirsTree(std::string basedir, std::string first, std::string last, stringVector &tables)
{
	struct dirent **namelist;
	int dirs_counter;

	sanitizePath(basedir);
	
	/* Find root directories */
	std::string root_first = rootDir(first);
	std::string root_last = rootDir(last);

	/* scan for subdirs */
	dirs_counter = scandir(basedir.c_str(), &namelist, NULL, versionsort);
	if (dirs_counter < 0) {
#ifdef DEBUG
		std::cerr << "Cannot stat directory " << basedir << ": " << strerror(errno) << std::endl;
#endif
		return;
	}

	/* Add all directories into vector */
	for (int i = 0; i < dirs_counter; ++i) {
		std::string entry_name = namelist[i]->d_name;

		/* Ignore . and .. */
		if (entry_name == "." || entry_name == "..") {
			continue;
		}

		/* If first dir was given, ignore entries before it */
		if (!root_first.empty() && strverscmp(entry_name.c_str(), root_first.c_str()) < 0) {
			continue;
		} else if (strverscmp(entry_name.c_str(), root_first.c_str()) == 0) {
			if (root_first == first.substr(0, first.length() - 1)) {
				/* Found first folder */
				std::string tableDir = basedir + entry_name;
				sanitizePath(tableDir);
				tables.push_back(tableDir);
			} else {
				/* Go deeper and find first folder */
				std::string new_basedir = basedir + entry_name;
				std::string new_first = first.substr(root_first.length() + 1);
				loadDirsTree(new_basedir, new_first, "", tables);
			}
		} else if (root_last.empty() || strverscmp(entry_name.c_str(), root_last.c_str()) < 0) {
			/* Entry is between first and last */
			std::string tableDir = basedir + entry_name;
			sanitizePath(tableDir);
			tables.push_back(tableDir);
		} else if (strverscmp(entry_name.c_str(), root_last.c_str()) == 0){
			/* Entry == root_last */
			if (root_last == last.substr(0, last.length() - 1)) {
				/* We're on last level, add last directory to vector */
				std::string tableDir = basedir + entry_name;
				sanitizePath(tableDir);
				tables.push_back(tableDir);
			} else {
				/* Goo deeper */
				std::string new_basedir = basedir + entry_name;
				std::string new_last = last.substr(root_last.length() + 1);
				loadDirsTree(new_basedir, "", new_last, tables);
			}
		}
	}

}
bool
ProgrammableOpAttributes::SetupPipeline(const JSONNode& atts, stringVector& args, const std::string& parent)
{
    if(atts.GetType() != JSONNode::JSONARRAY)
        return false;

    const JSONNode::JSONArray& array = atts.GetArray();

    for(int i = 0; i < array.size(); ++i)
    {
        /// need key, value pair
        /// this can be in the form of a dictionary, "a = b", pair tuple (a,b), or a pair array [a,b]
        JSONNode node = array[i];
        JSONNode key,value;
        if(node.GetType() == JSONNode::JSONARRAY)
        {
            if(node.GetArray().size() != 2) continue;

            key = node.GetArray()[0];
            value = node.GetArray()[1];
        }
        else if(node.GetType() == JSONNode::JSONOBJECT)
        {
            /// parse through dictionary and compute arguments from names..
            const JSONNode::JSONObject& obj = node.GetJsonObject();
            if(obj.size() != 1) continue;

            const JSONNode::JSONObject::const_iterator itr = obj.begin();
            key = itr->first;
            value = itr->second;
        }
        else if(node.GetType() == JSONNode::JSONSTRING)
        {
            std::string pair = node.GetString();
            int index = pair.find("=");
            if(index == std::string::npos) continue;
            key = pair.substr(0,index);

            value = trim(pair.substr(index+1));
         }

        if(key.GetType() != JSONNode::JSONSTRING) continue;

        std::string keystr = trim(key.GetString());

        std::ostringstream str;
        str << "import json\n";
        if(value.GetType() == JSONNode::JSONSTRING)
        {
            std::string v = trim(value.GetString());

            ///character at 0 and has :
            if(v.find(":") != std::string::npos && v.find(":") == 0)
            {
                /// optionally handle whether it can be as_vtkarray, as_ndarray, or as_rarray

                size_t index = v.find(":as_ndarray");

                if(index == std::string::npos)
                    index = v.find(":as_rarray");

                if(index != std::string::npos)
                {
                    std::string newName = getNextName();
                    v = v.substr(0,index);
                    AddNode(newName, "as_ndarray");
                    AddConnection(v, newName, "in");
                    AddConnection(newName,parent,keystr);
                }
                else
                {
                    index = v.find(":as_vtkarray");
                    if(index != std::string::npos)
                        v = v.substr(0,index);
                    AddConnection(v,parent,keystr);
                }
            }
            else
            {
                std::string escapedCode = trim(value.GetString());
                replace(escapedCode,"\n","\\\n");
                replace(escapedCode,"'","\"");
                escapedCode = "'" + escapedCode + "'";

                str << "try:\n"
                    << " a = json.loads(" << escapedCode << ")\n"
                    << "except:\n"
                    << " a = " << escapedCode << "\n"
                    << "setout(a)\n";

                AddPythonScript(keystr,stringVector(),str.str());
                AddNode(keystr,keystr);
                AddConnection(keystr,parent,keystr);
            }
        }
        else
        {
            str << "setout(json.loads('" << trim(value.ToString()) << "'))\n";

            AddPythonScript(keystr,stringVector(),str.str());
            AddNode(keystr,keystr);
            AddConnection(keystr,parent,keystr);
        }
        args.push_back(keystr);
    }
    return true;
}
Пример #25
0
bool
avtMissingDataFilter::TagMissingData(vtkDataSet *in_ds, vtkDataArray *missingData, 
    const stringVector &varsMissingData, avtCentering centering) const
{
    bool missing = false;
    unsigned char *mdptr = (unsigned char *)missingData->GetVoidPointer(0);

    // Go through each variable and populate the avtMissingData array.
    for(size_t i = 0; i < varsMissingData.size(); ++i)
    {
        const avtScalarMetaData *scalar = metadata.GetScalar(varsMissingData[i]);
        if(scalar != NULL)
        {
            // Try checking the current variable against the cell data.
            vtkDataArray *arr = in_ds->GetCellData()->GetArray(varsMissingData[i].c_str());
            if(arr != 0)
            {
                debug5 << "\tApplying rule for cell data \"" << varsMissingData[i]
                       << "\" to avtMissingData" << endl;
                vtkIdType nCells = in_ds->GetNumberOfCells();

                switch(scalar->GetMissingDataType())
                {
                case avtScalarMetaData::MissingData_Value:
                    { // new scope
                    double missingValue = scalar->GetMissingData()[0];
                    for(vtkIdType cellid = 0; cellid < nCells; ++cellid)
                    {
                        if(arr->GetTuple1(cellid) == missingValue)
                        {
                            mdptr[cellid] = 1;
                            missing = true;
                        }
                    }
                    }
                    break;
                case avtScalarMetaData::MissingData_Valid_Min:
                    { // new scope
                    double minValue = scalar->GetMissingData()[0];
                    for(vtkIdType cellid = 0; cellid < nCells; ++cellid)
                    {
                        if(arr->GetTuple1(cellid) < minValue)
                        {
                            mdptr[cellid] = 1;
                            missing = true;
                        }
                    }
                    }
                    break;
                case avtScalarMetaData::MissingData_Valid_Max:
                    { // new scope
                    double maxValue = scalar->GetMissingData()[0];
                    for(vtkIdType cellid = 0; cellid < nCells; ++cellid)
                    {
                        if(arr->GetTuple1(cellid) > maxValue)
                        {
                            mdptr[cellid] = 1;
                            missing = true;
                        }
                    }
                    }
                    break;
                case avtScalarMetaData::MissingData_Valid_Range:
                    { // new scope
                    double minValue = scalar->GetMissingData()[0];
                    double maxValue = scalar->GetMissingData()[1];
                    for(vtkIdType cellid = 0; cellid < nCells; ++cellid)
                    {
                        double val = arr->GetTuple1(cellid);
                        if(val < minValue || val > maxValue)
                        {
                            mdptr[cellid] = 1;
                            missing = true;
                        }
                    }
                    }
                    break;
                default:
                    break;
                }
            }

            // Try checking the current variable against the point data.
            arr = in_ds->GetPointData()->GetArray(varsMissingData[i].c_str());
            if(arr != 0)
            {
                debug5 << "\tApplying rule for point data \"" << varsMissingData[i]
                       << "\" to avtMissingData. Storing values as "
                       << (centering==AVT_ZONECENT?"cells":"points") << endl;

                vtkIdType nPoints = in_ds->GetNumberOfPoints();
                vtkIdList *idList = vtkIdList::New();
                switch(scalar->GetMissingDataType())
                {
                case avtScalarMetaData::MissingData_Value:
                    { // new scope
                    double missingValue = scalar->GetMissingData()[0];
                    if(centering == AVT_NODECENT)
                    {
                        for(vtkIdType ptid = 0; ptid < nPoints; ++ptid)
                            if(arr->GetTuple1(ptid) == missingValue)
                            {
                                missing = true;
                                mdptr[ptid] = 1;
                            }
                    }
                    else
                    {
                        for(vtkIdType ptid = 0; ptid < nPoints; ++ptid)
                            if(arr->GetTuple1(ptid) == missingValue)
                            {
                                missing = true;
                                in_ds->GetPointCells(ptid, idList);
                                for(vtkIdType i = 0; i < idList->GetNumberOfIds(); ++i)
                                    mdptr[idList->GetId(i)] = 1;
                            }
                    }
                    }
                    break;
                case avtScalarMetaData::MissingData_Valid_Min:
                    { // new scope
                    double minValue = scalar->GetMissingData()[0];
                    if(centering == AVT_NODECENT)
                    {
                        for(vtkIdType ptid = 0; ptid < nPoints; ++ptid)
                            if(arr->GetTuple1(ptid) < minValue)
                            {
                                missing = true;
                                mdptr[ptid] = 1;
                            }
                    }
                    else
                    {
                        for(vtkIdType ptid = 0; ptid < nPoints; ++ptid)
                            if(arr->GetTuple1(ptid) < minValue)
                            {
                                missing = true;
                                in_ds->GetPointCells(ptid, idList);
                                for(vtkIdType i = 0; i < idList->GetNumberOfIds(); ++i)
                                    mdptr[idList->GetId(i)] = 1;
                            }
                    }
                    }
                    break;
                case avtScalarMetaData::MissingData_Valid_Max:
                    { // new scope
                    double maxValue = scalar->GetMissingData()[0];
                    if(centering == AVT_NODECENT)
                    {
                        for(vtkIdType ptid = 0; ptid < nPoints; ++ptid)
                            if(arr->GetTuple1(ptid) > maxValue)
                            {
                                missing = true;
                                mdptr[ptid] = 1;
                            }
                    }
                    else
                    {
                        for(vtkIdType ptid = 0; ptid < nPoints; ++ptid)
                            if(arr->GetTuple1(ptid) > maxValue)
                            {
                                missing = true;
                                in_ds->GetPointCells(ptid, idList);
                                for(vtkIdType i = 0; i < idList->GetNumberOfIds(); ++i)
                                    mdptr[idList->GetId(i)] = 1;
                            }
                    }
                    }
                    break;
                case avtScalarMetaData::MissingData_Valid_Range:
                    { // new scope
                    double minValue = scalar->GetMissingData()[0];
                    double maxValue = scalar->GetMissingData()[1];
                    if(centering == AVT_NODECENT)
                    {
                        for(vtkIdType ptid = 0; ptid < nPoints; ++ptid)
                        {
                            double val = arr->GetTuple1(ptid);
                            if(val < minValue || val > maxValue)
                            {
                                missing = true;
                                mdptr[ptid] = 1;
                            }
                        }
                    }
                    else
                    {
                        for(vtkIdType ptid = 0; ptid < nPoints; ++ptid)
                        {
                            double val = arr->GetTuple1(ptid);
                            if(val < minValue || val > maxValue)
                            {
                                missing = true;
                                in_ds->GetPointCells(ptid, idList);
                                for(vtkIdType i = 0; i < idList->GetNumberOfIds(); ++i)
                                    mdptr[idList->GetId(i)] = 1;
                            }
                        }
                    }
                    }
                    break;
                default:
                    break;
                }
                idList->Delete();
            }
        }
        else
        {
            debug5 << "\tCould not get metadata for " << varsMissingData[i] << endl;
        }
    }

    return missing;
}
Пример #26
0
avtContract_p
avtModelFitFilter::ModifyContract(avtContract_p in_spec){
    std::string db = GetInput()->GetInfo().GetAttributes().GetFullDBName();
    ref_ptr<avtDatabase> dbp = avtCallback::GetDatabase(db, 0, NULL);
    avtDatabaseMetaData *md = dbp->GetMetaData(0);

    numTimesteps = (int)md->GetTimes().size();
    activeTs = in_spec->GetDataRequest()->GetTimestep();

    std::string meshName = GetInput()->GetInfo().GetAttributes().GetMeshname();

    pipelineVar = in_spec->GetDataRequest()->GetVariable();
    new_pipelineVar = strdup(pipelineVar);

    const stringVector curListedVars = atts.GetVars();

    if(!curListedVars.size())
    return in_spec;
  
    if((!strcmp(pipelineVar, "operators/ModelFit/model")) || 
       (!strcmp(pipelineVar, "operators/ModelFit/distance")))
        for(int i = 0; ; i++)
          if((strcmp(curListedVars[i].c_str(), "operators/ModelFit/model")) && 
             (strcmp(curListedVars[i].c_str(), "operators/ModelFit/distance")))
            {
                strcpy(new_pipelineVar, curListedVars[i].c_str());
                break;
            }

    avtDataRequest_p aDR  = new avtDataRequest(in_spec->GetDataRequest(), new_pipelineVar);
    aDR->SetOriginalVariable(pipelineVar);
    avtContract_p outSpec = new avtContract(in_spec, aDR);

    const char *curListedVar;
    std::vector<CharStrRef> curSecondaryVars = outSpec->GetDataRequest()->GetSecondaryVariables();
    size_t listedVarNum, secVarNum;
    char secVarName[1024];

    for(listedVarNum = 0; listedVarNum < curListedVars.size(); listedVarNum++){
        curListedVar = curListedVars[listedVarNum].c_str();
    
        if(strcmp(curListedVar, pipelineVar)){
            for(secVarNum = 0; secVarNum < curSecondaryVars.size(); secVarNum++)
                if(!strcmp(*curSecondaryVars[secVarNum], curListedVar))
                    break;
            if(secVarNum >= curSecondaryVars.size())
                outSpec->GetDataRequest()->AddSecondaryVariable(curListedVar);
            sprintf(secVarName, "%s", curListedVar);
        }
        curSecondaryVars = outSpec->GetDataRequest()->GetSecondaryVariables();
    }
    
    curSecondaryVars = outSpec->GetDataRequest()->GetSecondaryVariables();
    for(secVarNum = 0; secVarNum < curSecondaryVars.size(); secVarNum++){
        if(!strcmp(*curSecondaryVars[secVarNum], "operators/ModelFit/distance"))
            outSpec->GetDataRequest()->RemoveSecondaryVariable("operators/ModelFit/distance");

        if(!strcmp(*curSecondaryVars[secVarNum], "operators/ModelFit/model"))
            outSpec->GetDataRequest()->RemoveSecondaryVariable("operators/ModelFit/model");
    }
    return outSpec;
}
Пример #27
0
std::string 
GetVisItEnvironment(stringVector &env, bool useShortFileName, bool addPluginVars, bool &usingdev)
{
    char *tmp, *visitpath = NULL;
    char *visitdevdir = NULL;
    char tmpdir[512];
    bool haveVISITHOME = false;
    usingdev = false;
    bool freeVisItPath = true;
    string config;

    tmp = (char *)malloc(10000);

    /*
     * Determine visit path
     */
    haveVISITHOME = ReadKey("VISITHOME", &visitpath);

    if (!haveVISITHOME)
    {
        free(visitpath);
        visitpath = NULL;
        if ((visitpath = getenv("VISITHOME")) != NULL)
        {
            haveVISITHOME = true;
            freeVisItPath = false;
        }
    }

    /*
     * We could not get the value associated with the key. It may mean
     * that VisIt was not installed properly. Use a default value.
     */
    if(!haveVISITHOME)
    {
        char tmpdir[MAX_PATH];
        if (GetModuleFileName(NULL, tmpdir, MAX_PATH) != 0)
        {
            size_t pos = 0;
            size_t len = strlen(tmpdir);
            for (pos = len; tmpdir[pos] != '\\' && pos >=0; pos--)
            {
                continue;
            }
            if (pos <= 0)
                pos = len;

            visitpath = (char*)malloc(pos +1);
            strncpy(visitpath, tmpdir, pos);
            visitpath[pos] = '\0';
         }
    }
    /*
     * Determine if this is dev version
     */
    {
        string vp(visitpath);
        string tp = vp + "\\..\\" + "ThirdParty";
        struct _stat fs;
        if (_stat(tp.c_str(), &fs) == 0)
        {
            usingdev = 1;
            size_t pos;
            size_t len = strlen(visitpath);
            for (pos = len; visitpath[pos] != '\\' && pos >=0; pos--)
            {
                continue;
            }
            if (pos <= 0)
                pos = len;

            visitdevdir = (char*)malloc(pos + 14);
            strncpy(visitdevdir, visitpath, pos);
            visitdevdir[pos] = '\0';
            strncat(visitdevdir, "\\ThirdParty", 14);
            if (len != pos)
                config = vp.substr(pos+1);
        }
    }
 
    /*
     * Determine visit user path (Path to My Documents).
     */
    {
        char visituserpath[MAX_PATH], expvisituserpath[MAX_PATH];
        bool haveVISITUSERHOME=0;
        TCHAR szPath[MAX_PATH];
        struct _stat fs;
        if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 
                                 SHGFP_TYPE_CURRENT, szPath))) 
        {
            SNPRINTF(visituserpath, 512, "%s\\VisIt", szPath);
            haveVISITUSERHOME = true;
        }

        if (haveVISITUSERHOME)
        {
            ExpandEnvironmentStrings(visituserpath,expvisituserpath,512);
            if (_stat(expvisituserpath, &fs) == -1)
            {
                _mkdir(expvisituserpath);
            }
        }
        else
        {
            strcpy(expvisituserpath, visitpath);
        }
        sprintf(tmpdir, "%s\\My images", expvisituserpath);
        if (_stat(tmpdir, &fs) == -1)
        {
            _mkdir(tmpdir);
        }
        sprintf(tmp, "VISITUSERHOME=%s", expvisituserpath);
        env.push_back(tmp);
    }

    /* 
     * Turn the long VisIt path into the shortened system path.
     */
    if(useShortFileName)
    {
        char *vp2 = (char *)malloc(512);
        GetShortPathName(visitpath, vp2, 512);
        if (freeVisItPath)
            free(visitpath);
        visitpath = vp2;
        freeVisItPath = true;
    }
    string vp(visitpath);

    /*
     * Add VisIt's home directory to the path.
     */
    env.push_back(AddPath(tmp, visitpath, visitdevdir));

    /*
     * Set the VisIt home dir.
     */
    sprintf(tmp, "VISITHOME=%s", visitpath);
    env.push_back(tmp);

    if (visitdevdir != 0)
        free(visitdevdir);

    /*
     * Set the plugin dir.
     */
    { 
        char appData[MAX_PATH];
        if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL,
                                          SHGFP_TYPE_CURRENT, appData)))
        {
            PathAppend(appData, "LLNL");
            PathAppend(appData, "VisIt");
            sprintf(tmp, "VISITPLUGINDIR=%s;%s", appData, visitpath);
            env.push_back(tmp);
            if (addPluginVars)
            {
                sprintf(tmp, "VISITPLUGININSTPRI=%s", appData);
                env.push_back(tmp);
            }
        }
        else
        {
            sprintf(tmp, "VISITPLUGINDIR=%s", visitpath);
            env.push_back(tmp);
        }
    }

    if (addPluginVars)
    {
        sprintf(tmp, "VISITPLUGININSTPUB=%s", visitpath);
        env.push_back(tmp);
        sprintf(tmp, "VISITARCHHOME=%s", visitpath);
        env.push_back(tmp);
    }

    /*
     * Set the ultrawrapper dir.
     */
    if (!usingdev)
    {
        sprintf(tmp, "VISITULTRAHOME=%s\\ultrawrapper", visitpath);
        env.push_back(tmp);
    }
    else
    {
        sprintf(tmp, "VISITULTRAHOME=%s\\..\\ultrawrapper", visitpath);
        env.push_back(tmp);
    }

    /*
     * Set PYTHONPATH
     */
    if (!usingdev)
    {
        sprintf(tmp, "PYTHONPATH=%s\\lib;%s\\lib\\Python\\lib", 
                visitpath, visitpath);
        env.push_back(tmp);
        sprintf(tmp, "PYTHONHOME=%s",visitpath);
        env.push_back(tmp);
    }
    else 
    {
        string vp(visitpath);
        size_t pos = vp.find_last_of("\\");
        pos = vp.find_last_of("\\", pos-1);
        string svp = vp.substr(0, pos);
        if (config.length() > 0)
        {
            sprintf(tmp, "PYTHONPATH=%s\\lib\\%s;%s\\lib\\%s\\Python\\Lib", svp.c_str(), config.c_str(), svp.c_str(), config.c_str());
        }
        else
        {
            sprintf(tmp, "PYTHONPATH=%s\\lib;%s\\lib\\Python\\Lib", svp.c_str(), svp.c_str());
        }
        env.push_back(tmp);
    }

    /*
     * Set the SSH program.
     */
    { 
        char *ssh = NULL, *sshargs = NULL;
        int haveSSH = 0, haveSSHARGS = 0, freeSSH = 0, freeSSHARGS = 0;
        
        if((ssh = getenv("VISITSSH")) == NULL)
        {
            haveSSH = ReadKey("SSH", &ssh);
            if(haveSSH)
            {
                sprintf(tmp, "VISITSSH=%s", ssh);
                env.push_back(tmp);
            }
            free(ssh);
        }

        /*
         * Set the SSH arguments.
         */
        if((sshargs = getenv("VISITSSHARGS")) == NULL)
        {
            haveSSHARGS = ReadKey("SSHARGS", &sshargs);
            if(haveSSHARGS)
            {
                sprintf(tmp, "VISITSSHARGS=%s", sshargs);
                env.push_back(tmp);
            }
            free(sshargs);
        }
    }

    free(tmp);
    if (freeVisItPath)
        free(visitpath);
    return vp;
}
Пример #28
0
void
ViewerRPCCallbacks::GetCallbackNames(stringVector &names)
{
    for(int r = 0; r < (int)ViewerRPC::MaxRPC; ++r)
        names.push_back(ViewerRPC::ViewerRPCType_ToString((ViewerRPC::ViewerRPCType)r));
}
bool
LaunchService::SetupGatewaySocketBridgeIfNeeded(stringVector &launchArgs)
{
    const char *mName="LaunchService::SetupGatewaySocketBridgeIfNeeded: ";

    // Get the port and host.
    int  oldlocalport       = -1;
    int  portargument       = -1;
    int  hostargument       = -1;
    for (size_t i=0; i<launchArgs.size(); i++)
    {
        if (i<launchArgs.size()-1 && launchArgs[i] == "-port")
        {
            oldlocalport = atoi(launchArgs[i+1].c_str());
            portargument = i+1;
        }
        else if (i<launchArgs.size()-1 && launchArgs[i] == "-host")
        {
            hostargument = i+1;
        }
    }

    bool setupBridge = (portargument != -1 && hostargument != -1);
    if(setupBridge)
    {
        debug5 << mName << "Setting up gateway port bridge.\n";
        // find a new local port
        int lowerRemotePort = 10000;
        int upperRemotePort = 40000;
        int remotePortRange = 1+upperRemotePort-lowerRemotePort;

#if defined(_WIN32)
        srand((unsigned)time(0));
        int newlocalport = lowerRemotePort+(rand()%remotePortRange);
#else
        srand48(long(time(0)));
        int newlocalport = lowerRemotePort+(lrand48()%remotePortRange);
#endif
        debug5 << mName << "Bridging new port INADDR_ANY/" << newlocalport
               << " to tunneled port localhost/" << oldlocalport << endl;

        // replace the host with my host name
        char hostname[1024];
        gethostname(hostname,1024);
        launchArgs[hostargument] = hostname;

        // replace the launch argument port number
        char newportstr[10];
        sprintf(newportstr,"%d",newlocalport);
        launchArgs[portargument] = newportstr;

        // fork and start the socket bridge
        int *ports = new int[2];
        ports[0] = newlocalport;
        ports[1] = oldlocalport;
#ifdef _WIN32
        _beginthread(CreateSocketBridge, 0, (void*)ports);
#else
        switch (fork())
        {
          case -1:
            // Could not fork.
            exit(-1); // HOOKS_IGNORE
            break;
          case 0:
              {
                  // The child process will start the bridge
                  // Close stdin and any other file descriptors.
                  fclose(stdin);
                  for (int k = 3 ; k < 32 ; ++k)
                  {
                      close(k);
                  }
                  CreateSocketBridge((void*)ports);
                  exit(0); // HOOKS_IGNORE
                  break;
              }
          default:
            // Parent process continues on as normal
            // Caution: there is a slight race condition here, though
            // it would require the engine to launch and try to connect
            // back before the child process got the bridge set up.
            // The odds of this happening are low, but it should be fixed.
            break;
        }
#endif
    }
    else
    {
        debug5 << mName << "Required -host or -port argument not found" << endl;
    }

    return setupBridge;
}
Пример #30
0
void
SetVisItEnvironment(const stringVector &env)
{
    for(size_t i = 0; i < env.size(); ++i)
        _putenv(env[i].c_str());
}