Issue #197 - merging gridslice changes into git thinclient branch.

Former-commit-id: ae1bd95af06f6413ff17b73b290fda3ab8a13b29
This commit is contained in:
Bryan Kowal 2012-01-23 13:40:59 -06:00
parent cf4d56d0a0
commit a48a3094f0
8 changed files with 637 additions and 341 deletions

View file

@ -1,341 +1,365 @@
/***************************************************************************************** /*****************************************************************************************
* COPYRIGHT (c), 2009, RAYTHEON COMPANY * COPYRIGHT (c), 2009, RAYTHEON COMPANY
* ALL RIGHTS RESERVED, An Unpublished Work * ALL RIGHTS RESERVED, An Unpublished Work
* *
* RAYTHEON PROPRIETARY * RAYTHEON PROPRIETARY
* If the end user is not the U.S. Government or any agency thereof, use * If the end user is not the U.S. Government or any agency thereof, use
* or disclosure of data contained in this source code file is subject to * or disclosure of data contained in this source code file is subject to
* the proprietary restrictions set forth in the Master Rights File. * the proprietary restrictions set forth in the Master Rights File.
* *
* U.S. GOVERNMENT PURPOSE RIGHTS NOTICE * U.S. GOVERNMENT PURPOSE RIGHTS NOTICE
* If the end user is the U.S. Government or any agency thereof, this source * If the end user is the U.S. Government or any agency thereof, this source
* code is provided to the U.S. Government with Government Purpose Rights. * code is provided to the U.S. Government with Government Purpose Rights.
* Use or disclosure of data contained in this source code file is subject to * Use or disclosure of data contained in this source code file is subject to
* the "Government Purpose Rights" restriction in the Master Rights File. * the "Government Purpose Rights" restriction in the Master Rights File.
* *
* U.S. EXPORT CONTROLLED TECHNICAL DATA * U.S. EXPORT CONTROLLED TECHNICAL DATA
* Use or disclosure of data contained in this source code file is subject to * Use or disclosure of data contained in this source code file is subject to
* the export restrictions set forth in the Master Rights File. * the export restrictions set forth in the Master Rights File.
******************************************************************************************/ ******************************************************************************************/
/* /*
* Python module that utilizes the AWIPSI sliceConvert functions to offer * Python module that utilizes the AWIPSI sliceConvert functions to offer
* slicing capability to numpy arrays. * slicing capability to numpy arrays.
* *
* <pre> * <pre>
* *
* SOFTWARE HISTORY * SOFTWARE HISTORY
* *
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* 11/17/09 3580 brockwoo Initial Creation * 11/17/09 3580 brockwoo Initial Creation
* *
* </pre> * </pre>
* *
* @author brockwoo * @author brockwoo
* @version 1 * @version 1
*/ */
#include <Python.h> #include <Python.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "numpy/arrayobject.h" #include "numpy/arrayobject.h"
#include "sliceConvert.h" #include "sliceConvert.h"
static PyObject *GridSliceError; static PyObject *GridSliceError;
static int dimensions(PyObject * array) { static int dimensions(PyObject * array) {
int returnValue = 0; int returnValue = 0;
int aDim = PyArray_NDIM(array); int aDim = PyArray_NDIM(array);
if (aDim == 3) { if (aDim == 3) {
returnValue |= 4; // 2d arrays returnValue |= 4; // 2d arrays
} else if (aDim == 2) { } else if (aDim == 2) {
npy_intp * aDimList = PyArray_DIMS(array); npy_int * aDimList = PyArray_DIMS(array);
if (aDimList[0] == 1) { if (aDimList[0] == 1) {
returnValue |= 1; //linear array returnValue |= 1; //linear array
} }
} else { } else {
returnValue |= 8; // Unsupported returnValue |= 8; // Unsupported
} }
return returnValue; return returnValue;
} }
static PyObject * defineNumpySlice(PyObject *self, PyObject* args) static PyObject * defineNumpySlice(PyObject *self, PyObject* args)
/* float ** vc3d, float ** param3d, int mnx, /* float ** vc3d, float ** param3d, int mnx,
int nx, int ny, int nz, float param, int sense, float * vc2d) */{ int nx, int ny, int nz, float param, int sense, float * vc2d) */{
PyObject * vc; PyObject * vc;
PyObject * param; PyObject * param;
//int mx = 0; //int mx = 0;
int nx = 0; int nx = 0;
int ny = 0; int ny = 0;
int nz = 0; int nz = 0;
float targetLevel; float targetLevel;
int sense; int sense;
if (!PyArg_ParseTuple(args, "OOfi", &vc, &param, &targetLevel, &sense)) { int vu, pu, uniformity;
return NULL; float * vc2d;
} float ** vc3d;
int * vc3dDim;
int vu = dimensions(vc); float ** param3d;
int pu = dimensions(param); int * param3dDim;
int uniformity = (vu | pu); int levelCount;
int vnz, pnz, vny , pny , vnx , pnx;
if ((uniformity >> 3) == 1) { int dimSize[2];
PyErr_SetString(GridSliceError, npy_int * vdimList;
"One of the numpy arrays passed cannot be used for slicing."); npy_int * pdimList;
return NULL;
} if (!PyArg_ParseTuple(args, "OOfi", &vc, &param, &targetLevel, &sense)) {
return NULL;
npy_intp * vdimList = PyArray_DIMS(vc); }
npy_intp * pdimList = PyArray_DIMS(param);
float * vc2d = 0; vu = dimensions(vc);
if (uniformity == 4) { // two cubes pu = dimensions(param);
if (vdimList[0] != pdimList[0] || vdimList[1] != pdimList[1] uniformity = (vu | pu);
|| vdimList[2] != pdimList[2]) {
PyErr_SetString(GridSliceError, if ((uniformity >> 3) == 1) {
"Dimensions are different between cubes. Calculation cannot be done."); PyErr_SetString(GridSliceError,
return NULL; "One of the numpy arrays passed cannot be used for slicing.");
} return NULL;
nz = vdimList[0]; }
ny = vdimList[1];
nx = vdimList[2]; vdimList = PyArray_DIMS(vc);
float ** vc3d = (float**) malloc(nz * sizeof(float*)); pdimList = PyArray_DIMS(param);
float ** param3d = (float**) malloc(nz * sizeof(float*)); vc2d = 0;
vc2d = (float*) malloc(nx * ny * sizeof(float)); if (uniformity == 4) { // two cubes
int levelCount = 0; if (vdimList[0] != pdimList[0] || vdimList[1] != pdimList[1]
for (levelCount = 0; levelCount < nz; levelCount++) { || vdimList[2] != pdimList[2]) {
vc3d[levelCount] = (float *) PyArray_GETPTR1(vc, levelCount); PyErr_SetString(GridSliceError,
param3d[levelCount] = (float *) PyArray_GETPTR1(param, levelCount); "Dimensions are different between cubes. Calculation cannot be done.");
} return NULL;
}
defineSlice(vc3d, param3d, nx, nx, ny, nz, targetLevel, sense, vc2d); nz = vdimList[0];
free(vc3d); ny = vdimList[1];
free(param3d); nx = vdimList[2];
} else if (uniformity < 4 || uniformity == 5) { // one cube and one constant or two constants vc3d = (float**) malloc(nz * sizeof(float*));
int vnz = (vu == 4) ? vdimList[0] : vdimList[1]; param3d = (float**) malloc(nz * sizeof(float*));
int pnz = (pu == 4) ? pdimList[0] : pdimList[1]; vc2d = (float*) malloc(nx * ny * sizeof(float));
int vny = (vu == 4) ? vdimList[1] : 0; levelCount = 0;
int pny = (pu == 4) ? pdimList[1] : 0; for (levelCount = 0; levelCount < nz; levelCount++) {
int vnx = (vu == 4) ? vdimList[2] : 0; vc3d[levelCount] = (float *) PyArray_GETPTR1(vc, levelCount);
int pnx = (pu == 4) ? pdimList[2] : 0; param3d[levelCount] = (float *) PyArray_GETPTR1(param, levelCount);
if (vnz != pnz) { }
PyErr_SetString(GridSliceError,
"Dimensions are different between the arrays. Calculation cannot be done."); defineSlice(vc3d, param3d, nx, nx, ny, nz, targetLevel, sense, vc2d);
return NULL; free(vc3d);
} free(param3d);
nz = vnz; } else if (uniformity < 4 || uniformity == 5) { // one cube and one constant or two constants
ny = vny >= pny ? vny : pny; vnz = (vu == 4) ? vdimList[0] : vdimList[1];
nx = vnx >= pnx ? vnx : pnx; pnz = (pu == 4) ? pdimList[0] : pdimList[1];
float ** vc3d = (float**) malloc(nz * sizeof(float*)); vny = (vu == 4) ? vdimList[1] : 0;
float ** param3d = (float**) malloc(nz * sizeof(float*)); pny = (pu == 4) ? pdimList[1] : 0;
vc2d = (float*) malloc(nx * ny * sizeof(float)); vnx = (vu == 4) ? vdimList[2] : 0;
int * vc3dDim = (int*) malloc(nz * sizeof(int)); pnx = (pu == 4) ? pdimList[2] : 0;
int * param3dDim = (int*) malloc(nz * sizeof(int)); if (vnz != pnz) {
PyErr_SetString(GridSliceError,
int levelCount = 0; "Dimensions are different between the arrays. Calculation cannot be done.");
for (levelCount = 0; levelCount < nz; levelCount++) { return NULL;
if (vu == 4) { }
vc3d[levelCount] = (float *) PyArray_GETPTR1(vc, levelCount); nz = vnz;
vc3dDim[levelCount] = 2; ny = vny >= pny ? vny : pny;
} else { nx = vnx >= pnx ? vnx : pnx;
vc3d[levelCount] = (float *) PyArray_GETPTR2(vc, 0, levelCount); vc3d = (float**) malloc(nz * sizeof(float*));
vc3dDim[levelCount] = 0; param3d = (float**) malloc(nz * sizeof(float*));
} vc2d = (float*) malloc(nx * ny * sizeof(float));
if (pu == 4) { vc3dDim = (int*) malloc(nz * sizeof(int));
param3d[levelCount] param3dDim = (int*) malloc(nz * sizeof(int));
= (float *) PyArray_GETPTR1(param, levelCount);
param3dDim[levelCount] = 2; levelCount = 0;
} else { for (levelCount = 0; levelCount < nz; levelCount++) {
param3d[levelCount] if (vu == 4) {
= (float *) PyArray_GETPTR2(param, 0, levelCount); vc3d[levelCount] = (float *) PyArray_GETPTR1(vc, levelCount);
param3dDim[levelCount] = 0; vc3dDim[levelCount] = 2;
} } else {
vc3d[levelCount] = (float *) PyArray_GETPTR2(vc, 0, levelCount);
} vc3dDim[levelCount] = 0;
defineSliceD(vc3d, vc3dDim, param3d, param3dDim, nx, nx, ny, nz, }
targetLevel, sense, vc2d); if (pu == 4) {
free(vc3d); param3d[levelCount]
free(param3d); = (float *) PyArray_GETPTR1(param, levelCount);
free(vc3dDim); param3dDim[levelCount] = 2;
free(param3dDim); } else {
} param3d[levelCount]
= (float *) PyArray_GETPTR2(param, 0, levelCount);
if (vc2d) { param3dDim[levelCount] = 0;
PyObject * pyVc2d; }
npy_intp dimSize[2];
dimSize[0] = ny; }
dimSize[1] = nx; defineSliceD(vc3d, vc3dDim, param3d, param3dDim, nx, nx, ny, nz,
pyVc2d = PyArray_SimpleNew(2, dimSize, NPY_FLOAT); targetLevel, sense, vc2d);
memcpy(((PyArrayObject *) pyVc2d)->data, vc2d, nx * ny * sizeof(float)); free(vc3d);
free(vc2d); free(param3d);
return pyVc2d; free(vc3dDim);
} else { free(param3dDim);
PyErr_SetString( }
GridSliceError,
"The result grid returned was empty. Please check your initial data and try again."); if (vc2d) {
return NULL; PyObject * pyVc2d;
} dimSize[0] = ny;
} dimSize[1] = nx;
pyVc2d = PyArray_SimpleNew(2, dimSize, NPY_FLOAT);
static PyObject * createNumpySlice(PyObject *self, PyObject* args) memcpy(((PyArrayObject *) pyVc2d)->data, vc2d, nx * ny * sizeof(float));
/*float ** vc3d, float * vc2d, free(vc2d);
float ** slice3d, int mnx, int nx, int ny, int nz, int sense, return pyVc2d;
float * slice)*/{ } else {
PyErr_SetString(
PyObject * vc; GridSliceError,
PyObject * s3d; "The result grid returned was empty. Please check your initial data and try again.");
//int mx = 0; return NULL;
int nx = 0; }
int ny = 0; }
int nz = 0;
PyObject * targetLevel; static PyObject * createNumpySlice(PyObject *self, PyObject* args)
int sense; /*float ** vc3d, float * vc2d,
int hyb = DOINTERP; float ** slice3d, int mnx, int nx, int ny, int nz, int sense,
if (!PyArg_ParseTuple(args, "OOOi|i", &vc, &s3d, &targetLevel, &sense, &hyb)) { float * slice)*/{
return NULL;
} PyObject * vc;
PyObject * s3d;
int vu = dimensions(vc); //int mx = 0;
int su = dimensions(s3d); int nx = 0;
int uniformity = (vu | su); int ny = 0;
int nz = 0;
npy_intp * vdimList = PyArray_DIMS(vc); PyObject * targetLevel;
npy_intp * sdimList = PyArray_DIMS(s3d); int sense;
float * slice = 0; int hyb = DOINTERP;
if (uniformity == 4) { int vu;
if (vdimList[0] != sdimList[0] || vdimList[1] != sdimList[1] int su;
|| vdimList[2] != sdimList[2]) { int uniformity;
PyErr_SetString(GridSliceError, int vnz;
"Dimensions are different between cubes. Calculation cannot be done."); float * slice = 0;
return NULL; float ** vc3d ;
} float ** slice3d;
nz = vdimList[0]; int * vc3dDim ;
ny = vdimList[1]; int levelCount;
nx = vdimList[2]; float * vc2d ;
float ** vc3d = (float**) malloc(nz * sizeof(float*)); int dimSize[2];
float ** slice3d = (float**) malloc(nz * sizeof(float*)); npy_int * vdimList;
slice = (float*) malloc(nx * ny * sizeof(float)); npy_int * sdimList;
int levelCount = 0;
float * vc2d = (float *) PyArray_GETPTR1(targetLevel, 0); if (!PyArg_ParseTuple(args, "OOOi|i", &vc, &s3d, &targetLevel, &sense, &hyb)) {
for (levelCount = 0; levelCount < nz; levelCount++) { return NULL;
vc3d[levelCount] = (float *) PyArray_GETPTR1(vc, levelCount); }
slice3d[levelCount] = (float *) PyArray_GETPTR1(s3d, levelCount);
} vu = dimensions(vc);
if (hyb == DOINTERP) { su = dimensions(s3d);
createSlice(vc3d, vc2d, slice3d, nx, nx, ny, nz, sense, slice); uniformity = (vu | su);
} else {
sampleSlice(vc3d, vc2d, slice3d, nx, nx, ny, nz, sense, hyb, slice); vdimList = PyArray_DIMS(vc);
} sdimList = PyArray_DIMS(s3d);
free(vc3d); if (uniformity == 4) {
free(slice3d); if (vdimList[0] != sdimList[0] || vdimList[1] != sdimList[1]
} else if (vu < 4 && su == 4) { // one cube and one constant or two constants || vdimList[2] != sdimList[2]) {
int vnz = (vu == 4) ? vdimList[0] : vdimList[1]; PyErr_SetString(GridSliceError,
if (vnz != sdimList[0]) { "Dimensions are different between cubes. Calculation cannot be done.");
PyErr_SetString(GridSliceError, return NULL;
"Dimensions are different between the arrays. Calculation cannot be done."); }
return NULL; nz = vdimList[0];
} ny = vdimList[1];
nz = sdimList[0]; nx = vdimList[2];
ny = sdimList[1]; vc3d = (float**) malloc(nz * sizeof(float*));
nx = sdimList[2]; slice3d = (float**) malloc(nz * sizeof(float*));
float ** vc3d = (float**) malloc(nz * sizeof(float*)); slice = (float*) malloc(nx * ny * sizeof(float));
float ** slice3d = (float**) malloc(nz * sizeof(float*)); levelCount = 0;
int * vc3dDim = (int*) malloc(nz * sizeof(int)); vc2d = (float *) PyArray_GETPTR1(targetLevel, 0);
slice = (float*) malloc(nx * ny * sizeof(float)); for (levelCount = 0; levelCount < nz; levelCount++) {
int levelCount = 0; vc3d[levelCount] = (float *) PyArray_GETPTR1(vc, levelCount);
for (levelCount = 0; levelCount < nz; levelCount++) { slice3d[levelCount] = (float *) PyArray_GETPTR1(s3d, levelCount);
if (vu == 4) { }
vc3d[levelCount] = (float *) PyArray_GETPTR1(vc, levelCount); if (hyb == DOINTERP) {
vc3dDim[levelCount] = 2; createSlice(vc3d, vc2d, slice3d, nx, nx, ny, nz, sense, slice);
} else { } else {
vc3d[levelCount] = (float *) PyArray_GETPTR2(vc, 0, levelCount); sampleSlice(vc3d, vc2d, slice3d, nx, nx, ny, nz, sense, hyb, slice);
vc3dDim[levelCount] = 0; }
}
slice3d[levelCount] = (float *) PyArray_GETPTR1(s3d, levelCount); free(vc3d);
} free(slice3d);
float * vc2d = (float *) PyArray_GETPTR1(targetLevel, 0); } else if (vu < 4 && su == 4) { // one cube and one constant or two constants
if (hyb == DOINTERP) { vnz = (vu == 4) ? vdimList[0] : vdimList[1];
createSliceD(vc3d, vc3dDim, vc2d, 2, slice3d, nx, nx, ny, nz, sense, slice); if (vnz != sdimList[0]) {
} else { PyErr_SetString(GridSliceError,
sampleSliceD(vc3d, vc3dDim, vc2d, 2, slice3d, nx, nx, ny, nz, sense, hyb, slice); "Dimensions are different between the arrays. Calculation cannot be done.");
} return NULL;
free(vc3d); }
free(slice3d); nz = sdimList[0];
free(vc3dDim); ny = sdimList[1];
} nx = sdimList[2];
vc3d = (float**) malloc(nz * sizeof(float*));
if (slice) { slice3d = (float**) malloc(nz * sizeof(float*));
PyObject * pyVc2d; vc3dDim = (int*) malloc(nz * sizeof(int));
npy_intp dimSize[2]; slice = (float*) malloc(nx * ny * sizeof(float));
dimSize[0] = ny; levelCount = 0;
dimSize[1] = nx; for (levelCount = 0; levelCount < nz; levelCount++) {
pyVc2d = PyArray_SimpleNew(2, dimSize, NPY_FLOAT); if (vu == 4) {
memcpy(((PyArrayObject *) pyVc2d)->data, slice, nx * ny * sizeof(float)); vc3d[levelCount] = (float *) PyArray_GETPTR1(vc, levelCount);
free(slice); vc3dDim[levelCount] = 2;
return pyVc2d; } else {
} else { vc3d[levelCount] = (float *) PyArray_GETPTR2(vc, 0, levelCount);
PyErr_SetString( vc3dDim[levelCount] = 0;
GridSliceError, }
"The result grid returned was empty. Please check your initial data and try again."); slice3d[levelCount] = (float *) PyArray_GETPTR1(s3d, levelCount);
return NULL; }
} vc2d = (float *) PyArray_GETPTR1(targetLevel, 0);
if (hyb == DOINTERP) {
return NULL; createSliceD(vc3d, vc3dDim, vc2d, 2, slice3d, nx, nx, ny, nz, sense, slice);
} } else {
sampleSliceD(vc3d, vc3dDim, vc2d, 2, slice3d, nx, nx, ny, nz, sense, hyb, slice);
static PyObject * createNumpySliceD(PyObject *self, PyObject* args) }
/*float ** vc3d, int * dim3, float * vc2d, free(vc3d);
int dim2, float ** slice3d, int mnx, int nx, int ny, int nz, int sense, free(slice3d);
float * slice)*/{ free(vc3dDim);
return NULL; }
}
if (slice) {
static PyObject * sampleNumpySlice(PyObject *self, PyObject* args) PyObject * pyVc2d;
/*float ** vc3d, float * vc2d, dimSize[0] = ny;
float ** slice3d, int mnx, int nx, int ny, int nz, int sense, int hyb, dimSize[1] = nx;
float * slice)*/{ pyVc2d = PyArray_SimpleNew(2, dimSize, NPY_FLOAT);
return NULL; memcpy(((PyArrayObject *) pyVc2d)->data, slice, nx * ny * sizeof(float));
} free(slice);
return pyVc2d;
static PyObject * sampleNumpySliceD(PyObject *self, PyObject* args) } else {
/*float ** vc3d, int * dim3, float * vc2d, PyErr_SetString(
int dim2, float ** slice3d, int mnx, int nx, int ny, int nz, int sense, GridSliceError,
int hyb, float * slice)*/{ "The result grid returned was empty. Please check your initial data and try again.");
return NULL; return NULL;
} }
static PyObject * defineNumpySlices(PyObject *self, PyObject* args) return NULL;
/*float * vc3d, int senseA, float * param3d, }
int senseB, int nx, int ny, int nz, float * paramC, int nc, float * vcC)*/{
return NULL; static PyObject * createNumpySliceD(PyObject *self, PyObject* args)
} /*float ** vc3d, int * dim3, float * vc2d,
int dim2, float ** slice3d, int mnx, int nx, int ny, int nz, int sense,
static PyObject * createNumpySlices(PyObject *self, PyObject* args) float * slice)*/{
/*float * vc3d, float * param3d, int sense, return NULL;
int nx, int ny, int nz, float * vcC, int nc, float * paramC)*/{ }
return NULL;
} static PyObject * sampleNumpySlice(PyObject *self, PyObject* args)
/*float ** vc3d, float * vc2d,
static PyMethodDef gridslice_methods[] = { { "defineNumpySlice", float ** slice3d, int mnx, int nx, int ny, int nz, int sense, int hyb,
defineNumpySlice, METH_VARARGS, "Description to be decided." }, { float * slice)*/{
"createNumpySlice", createNumpySlice, METH_VARARGS, return NULL;
"Description to be decided." }, { "createNumpySliceD", }
createNumpySliceD, METH_VARARGS, "Description to be decided." }, {
"sampleNumpySlice", sampleNumpySlice, METH_VARARGS, static PyObject * sampleNumpySliceD(PyObject *self, PyObject* args)
"Description to be decided." }, { "sampleNumpySliceD", /*float ** vc3d, int * dim3, float * vc2d,
sampleNumpySliceD, METH_VARARGS, "Description to be decided." }, { int dim2, float ** slice3d, int mnx, int nx, int ny, int nz, int sense,
"defineNumpySlices", defineNumpySlices, METH_VARARGS, int hyb, float * slice)*/{
"Description to be decided." }, { "createNumpySlices", return NULL;
createNumpySlices, METH_VARARGS, "Description to be decided." }, { }
NULL, NULL, 0, NULL } /* sentinel */
}; static PyObject * defineNumpySlices(PyObject *self, PyObject* args)
/*float * vc3d, int senseA, float * param3d,
void initgridslice(void) { int senseB, int nx, int ny, int nz, float * paramC, int nc, float * vcC)*/{
PyObject *m; return NULL;
import_array(); }
PyImport_AddModule("gridslice");
m = Py_InitModule("gridslice", gridslice_methods); static PyObject * createNumpySlices(PyObject *self, PyObject* args)
GridSliceError = PyErr_NewException("gridslice.error", NULL, NULL); /*float * vc3d, float * param3d, int sense,
Py_INCREF(GridSliceError); int nx, int ny, int nz, float * vcC, int nc, float * paramC)*/{
PyModule_AddObject(m, "error", GridSliceError); return NULL;
} }
static PyMethodDef gridslice_methods[] = { { "defineNumpySlice",
defineNumpySlice, METH_VARARGS, "Description to be decided." }, {
"createNumpySlice", createNumpySlice, METH_VARARGS,
"Description to be decided." }, { "createNumpySliceD",
createNumpySliceD, METH_VARARGS, "Description to be decided." }, {
"sampleNumpySlice", sampleNumpySlice, METH_VARARGS,
"Description to be decided." }, { "sampleNumpySliceD",
sampleNumpySliceD, METH_VARARGS, "Description to be decided." }, {
"defineNumpySlices", defineNumpySlices, METH_VARARGS,
"Description to be decided." }, { "createNumpySlices",
createNumpySlices, METH_VARARGS, "Description to be decided." }, {
NULL, NULL, 0, NULL } /* sentinel */
};
void initgridslice(void) {
PyObject *m;
import_array();
PyImport_AddModule("gridslice");
m = Py_InitModule("gridslice", gridslice_methods);
GridSliceError = PyErr_NewException("gridslice.error", NULL, NULL);
Py_INCREF(GridSliceError);
PyModule_AddObject(m, "error", GridSliceError);
}

View file

@ -0,0 +1,90 @@
@echo OFF
REM This script will compile a Windows version of the gridslice library.
REM In order to compile the gridslice library, you will need to have
REM Microsoft Visual C++ 2008 installed and the AWIPS II Runtime Environment.
REM This script assumes that Microsoft Visual Studio has been installed in the
REM standard location - in the Program Files directory.
REM
REM This script should work on both a 32-bit and a 64-bit Windows 7
REM installation.
SET CONTAINING_DIR=%~dp0
REM Determine what our architecture is.
SET REG_EXE=
SET PROGRAM_FILES_DIR=
IF "%PROCESSOR_ARCHITECTURE%" == "AMD64" (
GOTO OS_64_BIT
) ELSE (
IF "%PROCESSOR_ARCHITECTURE%" == "x86" (
GOTO OS_32_BIT
) ELSE (
echo "ERROR: Unrecognized Architecture."
PAUSE
)
)
REM Set the Program Files location based on the architecture.
:OS_32_BIT
SET PROGRAM_FILES_DIR=%ProgramFiles%
SET REG_EXE=C:\Windows\System32\reg.exe
GOTO ARCH_KNOWN
:OS_64_BIT
SET PROGRAM_FILES_DIR=%ProgramFiles(x86)%
SET REG_EXE=C:\Windows\SysWOW64\reg.exe
GOTO ARCH_KNOWN
:ARCH_KNOWN
REM Determine where AWIPS II Python has been installed.
SET A2_PYTHON_REG="HKLM\Software\Raytheon\Runtime Environment\AWIPS II Python"
%REG_EXE% QUERY %A2_PYTHON_REG% /v PythonInstallDirectory > NUL 2>&1
IF ERRORLEVEL 1 (
echo ENVIRONMENT ERROR - Unable to find AWIPS II Python.
PAUSE && EXIT 1
)
FOR /F "tokens=2* delims= " %%A IN (
'%REG_EXE% QUERY %A2_PYTHON_REG% /v PythonInstallDirectory'
) DO (
SET PythonInstallDirectory=%%B
)
REM Visual Studio 2008 is Version 9.0 of Microsoft Visual Studio.
SET MVS_VERSION=Microsoft Visual Studio 9.0
REM Use the MS Visual Studion vcvarsall.bat utility to prepare
REM the environment for this build.
REM Until further notice, we assume the build is 32-bit.
cd "%PROGRAM_FILES_DIR%\%MVS_VERSION%\VC"
CALL vcvarsall.bat x86
IF NOT ERRORLEVEL 0 (
echo ERROR: Unable to prepare the environment.
PAUSE && EXIT 1
)
cd "%CONTAINING_DIR%"
REM Compile gridslice
cl.exe /LD "%CONTAINING_DIR%..\sliceConvert.c" ^
"%CONTAINING_DIR%..\gridslice.c" ^
-I"%PythonInstallDirectory%\Lib\site-packages\numpy\core\include" ^
-I"%PythonInstallDirectory%\include" ^
"%PythonInstallDirectory%\libs\python27.lib" ^
/link/out:gridslice.pyd /EXPORT:initgridslice
if ERRORLEVEL 1 (
echo ERROR: The gridslice compile has failed.
PAUSE
)
REM Move the build artifacts to the build directory.
IF NOT EXIST "%CONTAINING_DIR%build" (
MKDIR "%CONTAINING_DIR%build"
)
MOVE /Y "%CONTAINING_DIR%sliceConvert*" ^
"%CONTAINING_DIR%build"
MOVE /Y "%CONTAINING_DIR%gridslice*" ^
"%CONTAINING_DIR%build"
echo.
echo.
echo The gridslice compile was successful.
PAUSE

Binary file not shown.

View file

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual C++ Express 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gridslice", "gridslice.vcproj", "{60589C73-F65B-44AE-8D8C-DE88B01E6ECE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{60589C73-F65B-44AE-8D8C-DE88B01E6ECE}.Debug|Win32.ActiveCfg = Debug|Win32
{60589C73-F65B-44AE-8D8C-DE88B01E6ECE}.Debug|Win32.Build.0 = Debug|Win32
{60589C73-F65B-44AE-8D8C-DE88B01E6ECE}.Release|Win32.ActiveCfg = Release|Win32
{60589C73-F65B-44AE-8D8C-DE88B01E6ECE}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Binary file not shown.

View file

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="gridslice"
ProjectGUID="{60589C73-F65B-44AE-8D8C-DE88B01E6ECE}"
RootNamespace="gridslice"
Keyword="MakeFileProj"
TargetFrameworkVersion="0"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="0"
>
<Tool
Name="VCNMakeTool"
BuildCommandLine="cd $(InputDir)..\&#x0D;&#x0A;CALL build.bat"
ReBuildCommandLine=""
CleanCommandLine="cd $(InputDir)..\&#x0D;&#x0A;IF EXIST build (&#x0D;&#x0A; DEL /Q build\*&#x0D;&#x0A; RMDIR build&#x0D;&#x0A;)"
Output=""
PreprocessorDefinitions="WIN32;_DEBUG;"
IncludeSearchPath=""
ForcedIncludes=""
AssemblySearchPath=""
ForcedUsingAssemblies=""
CompileAsManaged=""
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="0"
>
<Tool
Name="VCNMakeTool"
BuildCommandLine=""
ReBuildCommandLine=""
CleanCommandLine=""
Output=""
PreprocessorDefinitions="WIN32;NDEBUG;"
IncludeSearchPath=""
ForcedIncludes=""
AssemblySearchPath=""
ForcedUsingAssemblies=""
CompileAsManaged=""
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath="..\..\sliceConvert.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\..\gridslice.c"
>
</File>
<File
RelativePath="..\..\sliceConvert.c"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View file

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<VisualStudioUserFile
ProjectType="Visual C++"
Version="9.00"
ShowAllFiles="true"
>
<Configurations>
<Configuration
Name="Debug|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="ISFL017138"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
<Configuration
Name="Release|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="ISFL017138"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
</Configurations>
</VisualStudioUserFile>

View file

@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8"?><VisualStudioUserFile ProjectType="Visual C++" Version="9.00" ShowAllFiles="true"></VisualStudioUserFile>