<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 OPeNDAP, Inc.
// Author: <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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.

// (c) COPYRIGHT URI/MIT 1999
// Please read the full copyright statement in the file COPYRIGHT_URI.
//
// Authors:
//      jhrg,jimg       <NAME> <<EMAIL>>


// These functions are used by the CE evaluator
//
// 1/15/99 jhrg

#include "config.h"

static char rcsid[]not_used = { "$Id: ce_functions.cc 26039 2012-11-15 23:29:56Z jimg $" };

#include <limits.h>

#include <cstdlib>      // used by strtod()
#include <cerrno>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>

//#define DODS_DEBUG

#include "BaseType.h"
#include "Byte.h"
#include "Int16.h"
#include "UInt16.h"
#include "Int32.h"
#include "UInt32.h"
#include "Float32.h"
#include "Float64.h"
#include "Str.h"
#include "Url.h"
#include "Array.h"
#include "Structure.h"
#include "Sequence.h"
#include "Grid.h"

#include "Error.h"
#include "debug.h"

#include "reproj_functions.h"

//  We wrapped VC++ 6.x strtod() to account for a short coming
//  in that function in regards to "NaN".  I don't know if this
//  still applies in more recent versions of that product.
//  ROM - 12/2007
#ifdef WIN32
#include <limits>
double w32strtod(const char *, char **);
#endif

using namespace std;


namespace libdap {

void function_swath2grid(int argc, BaseType * argv[], DDS &, BaseType **btpp)
{

}

#if 0
/** The grid function uses a set of relational expressions to form a selection
 within a Grid variable based on the values in the Grid's map vectors.
 Thus, if a Grid has a 'temperature' map which ranges from 0.0 to 32.0
 degrees, it's possible to request the values of the Grid that fall between
 10.5 and 12.5 degrees without knowing to which array indexes those values
 correspond. The function takes one or more arguments:<ul>
 <li>The name of a Grid.</li>
 <li>Zero or more strings which hold relational expressions of the form:<ul><commit_msg>checkpoint for swath2grid...<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 OPeNDAP, Inc.
// Author: <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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.

// (c) COPYRIGHT URI/MIT 1999
// Please read the full copyright statement in the file COPYRIGHT_URI.
//
// Authors:
//      jhrg,jimg       <NAME> <<EMAIL>>


// These functions are used by the CE evaluator
//
// 1/15/99 jhrg

#include "config.h"

static char rcsid[]not_used = { "$Id: ce_functions.cc 26039 2012-11-15 23:29:56Z jimg $" };

#include <limits.h>

#if 0
#include <cstdlib>      // used by strtod()
#include <cerrno>
#include <cmath>
#endif
#include <iostream>
#if 0
#include <vector>
#include <algorithm>
#endif

#include <gdal.h>
// #include <gdal_priv.h>

//#define DODS_DEBUG

#include "BaseType.h"
#if 0
#include "Byte.h"
#include "Int16.h"
#include "UInt16.h"
#include "Int32.h"
#include "UInt32.h"
#include "Float32.h"
#include "Float64.h"
#include "Str.h"
#include "Url.h"
#endif
#include "Array.h"
#if 0
#include "Structure.h"
#include "Sequence.h"
#endif
#include "Grid.h"

#include "Error.h"
#include "debug.h"

#include "reproj_functions.h"

//  We wrapped VC++ 6.x strtod() to account for a short coming
//  in that function in regards to "NaN".  I don't know if this
//  still applies in more recent versions of that product.
//  ROM - 12/2007
#ifdef WIN32
#include <limits>
double w32strtod(const char *, char **);
#endif

using namespace std;


namespace libdap {

void function_swath2grid(int argc, BaseType * argv[], DDS &, BaseType **btpp)
{
    DBG(cerr << "Entering function_swath2grid..." << endl);

    string info = string("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
    		+ "<function name=\"swath2grid\" version=\"1.0\" href=\"http://docs.opendap.org/index.php/Server_Side_Processing_Functions#swath2grid\">\n"
            + "</function>\n";

    if (argc == 0) {
        Str *response = new Str("info");
        response->set_value(info);
        *btpp = response;
        return;
    }

    // TODO Add optional fourth arg that lets the caller say which datum to use;
    // default to WGS84
    if (argc != 3)
    	throw Error("The function swath2grid() requires three arguments. See http://docs.opendap.org/index.php/Server_Side_Processing_Functions#swath2grid");

    Array *src = dymanic_cast<Array*>(argv[0]);
    if (!src)
    	throw Error("The first argument to swath2grid() must be a data array. See http://docs.opendap.org/index.php/Server_Side_Processing_Functions#swath2grid");

    Array *lat = dymanic_cast<Array*>(argv[1]);
    if (!lat)
    	throw Error("The second argument to swath2grid() must be a latitude array. See http://docs.opendap.org/index.php/Server_Side_Processing_Functions#swath2grid");

    Array *lon = dymanic_cast<Array*>(argv[2]);
    if (!lon)
    	throw Error("The first argument to swath2grid() must be a longitude array. See http://docs.opendap.org/index.php/Server_Side_Processing_Functions#swath2grid");

    DAP_Dataset ds(src, lat, lon);

    GDALDataset *reproj = ds.maptr_DS.get();

    // Now build a libdap::Grid to return as the response

    // There should be just one band
    if (reproj->GetRasterCount() != 1)
    	throw Error("In function swath2grid(), expected a single raster band.");

    // Get the x and y dimensions of the raster band
    int x = reproj->GetRasterXSize();
    int y = reproj->GetRasterYSize();
    GDALRasterBand *rb = reproj->GetRasterBand(1);
    if (!rb)
    	throw Error("In function swath2grid(), could not access the raster data.");
    string projection_info = reproj->GetProjectionRef();
    double geo_transform_coef[6];
    if (CPL_None != reproj->GetGeoTransform (geo_transform_coef))
        throw Error("In function swath2grid(), could not access the geo transform data.");

    string gcp_projection_info = reporj->GetGCPProjection();

    // Since the DAP_Dataset code works with all data values as doubles,
    // Assume the raster band has GDAL type GDT_Float64, but test anyway
 	if (GDT_Float64 != reproj->GetRasterDataType())
 	    throw Error("In function swath2grid(), expected raster data to be of type double.");

 	/* RasterIO	(	GDALRWFlag 	eRWFlag,
 	int 	nXOff,
 	int 	nYOff,
 	int 	nXSize,
 	int 	nYSize,
 	void * 	pData,
 	int 	nBufXSize,
 	int 	nBufYSize,
 	GDALDataType 	eBufType,
 	int 	nPixelSpace,
 	int 	nLineSpace
 	) */
    double *data;

}

#if 0
/** The grid function uses a set of relational expressions to form a selection
 within a Grid variable based on the values in the Grid's map vectors.
 Thus, if a Grid has a 'temperature' map which ranges from 0.0 to 32.0
 degrees, it's possible to request the values of the Grid that fall between
 10.5 and 12.5 degrees without knowing to which array indexes those values
 correspond. The function takes one or more arguments:<ul>
 <li>The name of a Grid.</li>
 <li>Zero or more strings which hold relational expressions of the form:<ul>
{'fraction_non_alphanumeric': 0.11813471502590674, 'fraction_numerical': 0.027748992515831895, 'mean_word_length': 3.5286757038581857, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 1, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '1982947', 'n_tokens_mistral': 2978, 'n_tokens_neox': 2772, 'n_words': 1063}