<commit_before>// -*- mode: c++; c-basic-offset:4 -*-

// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.

// Copyright (c) 2002,2003,2011,2012 OPeNDAP, Inc.
// Authors: <NAME> <<EMAIL>>
//          <NAME> <<EMAIL>>
//          <NAME> <<EMAIL>>
//          <NAME> <<EMAIL>>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.

// NOTE: This file is built only when the gridfields library is linked with
// the netcdf_handler (i.e., the handler's build is configured using the
// --with-gridfields=... option to the 'configure' script).

#include "config.h"

#include <limits.h>

#include <cstdlib>      // used by strtod()
#include <cerrno>
#include <cmath>
#include <iostream>
#include <sstream>
//#include <cxxabi.h>

#include <curl/curl.h>

#define DODS_DEBUG

#include "BaseType.h"
#include "Int32.h"
#include "Str.h"
#include "Array.h"
#include "Structure.h"
#include "Error.h"

#include "BESDebug.h"
#include "util.h"

#include "ugrid_utils.h"
#include "MeshDataVariable.h"
#include "TwoDMeshTopology.h"
#include "NDimensionalArray.h"

#include "ugr5.h"


using namespace std;
using namespace libdap;

namespace ugrid {

/**
 * Function syntax
 */
static string ugrSyntax =
		"ugr5(dim:int32, rangeVariable:string, [rangeVariable:string, ... ] condition:string)";

/**
 * Function Arguments
 */
struct UgridRestrictArgs {
	locationType dimension;
	vector<libdap::Array *> rangeVars;
	string filterExpression;
};


/**
 * Evaluates the rangeVar and determines which meshTopology it is associated with. If one hasn't been found
 * a new mesh topology is created. Once the associated mesh topology had been found (or created), the rangeVar
 * is added to the vector of rangeVars held by the mesh topology for later evaluation.
 */
static void addRangeVar(DDS *dds, libdap::Array *rangeVar, map<string, vector<MeshDataVariable *> *> *rangeVariables) {

	MeshDataVariable *mdv = new MeshDataVariable();
	mdv->init(rangeVar);
	string meshVarName = mdv->getMeshName();

    BaseType *meshVar = dds->var(meshVarName);

    if(meshVar == 0){
        string msg = "The range variable '"+mdv->getName()+"' references the mesh variable '"+meshVarName+
                "' which cannot be located in this dataset.";
        BESDEBUG("ugrid", "addRangeVar() - " << msg  << endl);
        throw new Error(no_such_variable,msg);
    }


	// Get the rangeVariable vector for this mesh name from the map.
	vector<MeshDataVariable *> *requestedRangeVarsForMesh;
	map<string, vector<MeshDataVariable *> *>::iterator mit = rangeVariables->find(meshVarName);
	if(mit == rangeVariables->end()){
		// Not there? Make a new one.
		BESDEBUG("ugrid", "addRangeVar() - MeshTopology object for '" << meshVarName <<"' does NOT exist. Getting a 'new' one... "  << endl);

		requestedRangeVarsForMesh =  new vector<MeshDataVariable *>();
		(*rangeVariables)[meshVarName] = requestedRangeVarsForMesh;
	}
	else {
		// Sweet! Found it....
		BESDEBUG("ugrid", "addRangeVar() - MeshTopology object for '" << meshVarName <<"' exists. Retrieving... "  << endl);
		requestedRangeVarsForMesh = mit->second;
	}<commit_msg>Fixed bad pattern of 'throw new Error/Exception' - a byproduct of thinking in Java and not C++<commit_after>// -*- mode: c++; c-basic-offset:4 -*-

// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.

// Copyright (c) 2002,2003,2011,2012 OPeNDAP, Inc.
// Authors: <NAME> <<EMAIL>>
//          <NAME> <<EMAIL>>
//          <NAME> <<EMAIL>>
//          <NAME> <<EMAIL>>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.

// NOTE: This file is built only when the gridfields library is linked with
// the netcdf_handler (i.e., the handler's build is configured using the
// --with-gridfields=... option to the 'configure' script).

#include "config.h"

#include <limits.h>

#include <cstdlib>      // used by strtod()
#include <cerrno>
#include <cmath>
#include <iostream>
#include <sstream>
//#include <cxxabi.h>

#include <curl/curl.h>

#define DODS_DEBUG

#include "BaseType.h"
#include "Int32.h"
#include "Str.h"
#include "Array.h"
#include "Structure.h"
#include "Error.h"

#include "BESDebug.h"
#include "util.h"

#include "ugrid_utils.h"
#include "MeshDataVariable.h"
#include "TwoDMeshTopology.h"
#include "NDimensionalArray.h"

#include "ugr5.h"


using namespace std;
using namespace libdap;

namespace ugrid {

/**
 * Function syntax
 */
static string ugrSyntax =
		"ugr5(dim:int32, rangeVariable:string, [rangeVariable:string, ... ] condition:string)";

/**
 * Function Arguments
 */
struct UgridRestrictArgs {
	locationType dimension;
	vector<libdap::Array *> rangeVars;
	string filterExpression;
};


/**
 * Evaluates the rangeVar and determines which meshTopology it is associated with. If one hasn't been found
 * a new mesh topology is created. Once the associated mesh topology had been found (or created), the rangeVar
 * is added to the vector of rangeVars held by the mesh topology for later evaluation.
 */
static void addRangeVar(DDS *dds, libdap::Array *rangeVar, map<string, vector<MeshDataVariable *> *> *rangeVariables) {

	MeshDataVariable *mdv = new MeshDataVariable();
	mdv->init(rangeVar);
	string meshVarName = mdv->getMeshName();

    BaseType *meshVar = dds->var(meshVarName);

    if(meshVar == 0){
        string msg = "The range variable '"+mdv->getName()+"' references the mesh variable '"+meshVarName+
                "' which cannot be located in this dataset.";
        BESDEBUG("ugrid", "addRangeVar() - " << msg  << endl);
        throw Error(no_such_variable,msg);
    }


	// Get the rangeVariable vector for this mesh name from the map.
	vector<MeshDataVariable *> *requestedRangeVarsForMesh;
	map<string, vector<MeshDataVariable *> *>::iterator mit = rangeVariables->find(meshVarName);
	if(mit == rangeVariables->end()){
		// Not there? Make a new one.
		BESDEBUG("ugrid", "addRangeVar() - MeshTopology object for '" << meshVarName <<"' does NOT exist. Getting a 'new' one... "  << endl);

		requestedRangeVarsForMesh =  new vector<MeshDataVariable *>();
		(*rangeVariables)[meshVarName] = requestedRangeVarsForMesh;
	}
	else {
		// Sweet! Found it....
		BESDEBUG("ugrid", "addRangeVar() - MeshTopology object for '" << meshVarName <<"' exists. Retrieving... "  << endl);
		requestedRangeVarsForMesh = mit->second;
	}
{'fraction_non_alphanumeric': 0.1284753078583217, 'fraction_numerical': 0.012441284753078583, 'mean_word_length': 3.821297429620563, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4677117', 'n_tokens_mistral': 2516, 'n_tokens_neox': 2406, 'n_words': 860}