Skip to content

Commit e2202ec

Browse files
authored
Merge pull request #254 from xylar/build_with_cmake
Several small fixes to support conda-forge When I tried to build the `mpas_tools` package on conda-forge, I ran into 3 issues: * compilers (g++ for linux and clang for OSX) don't work well with our simple make file * in clang, there is a conflict between `std::merge` and the local definition of `merge` in the cell culler (and probably the same issue in g++ but not a fatal error). * The test for the python interface to the mesh conversion tools needs to use the 'Agg' backend for matplotlib because CI doesn't have a display. This merge adds support for a cmake build of `mesh_conversion_tools` and fixes the other two issues above in the hopes of making another minor release that will work without patching on conda-forge.
2 parents 8948389 + 9c1e553 commit e2202ec

File tree

7 files changed

+70
-52
lines changed

7 files changed

+70
-52
lines changed

conda_package/docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363
# built documents.
6464
#
6565
# The short X.Y version.
66-
version = u'0.0.1'
66+
version = u'0.0.2'
6767
# The full version, including alpha/beta/rc tags.
68-
release = u'0.0.1'
68+
release = u'0.0.2'
6969

7070
# The language for content autogenerated by Sphinx. Refer to documentation
7171
# for a list of supported languages.

conda_package/mpas_tools/tests/test_conversion.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from mpas_tools.conversion import convert, cull, mask
44
from mpas_tools.io import write_netcdf
5+
import matplotlib
6+
matplotlib.use('Agg')
57
from geometric_features import read_feature_collection
68
import xarray
79

conda_package/recipe/build.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@ ${PYTHON} -m pip install . --no-deps -vv
1010

1111
cd mesh_tools/mesh_conversion_tools
1212

13-
export CXX=${GXX}
14-
export CFLAGS="-O3 -std=c++0x -fopenmp -lstdc++"
15-
13+
# build and install JIGSAW
14+
mkdir build
15+
cd build
16+
cmake -DCMAKE_INSTALL_PREFIX=${PREFIX} -DCMAKE_BUILD_TYPE=Release ..
1617
make
17-
18-
install -d ${PREFIX}/bin/
19-
for exec in MpasMeshConverter.x MpasCellCuller.x MpasMaskCreator.x
20-
do
21-
install -m 755 ${exec} ${PREFIX}/bin/
22-
done
18+
make install
2319

conda_package/recipe/meta.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% set name = "mpas_tools" %}
2-
{% set version = "0.0.1" %}
2+
{% set version = "0.0.2" %}
33

44
package:
55
name: '{{ name|lower }}'
@@ -17,6 +17,7 @@ build:
1717
requirements:
1818
build:
1919
- {{ compiler('cxx') }}
20+
- cmake
2021
host:
2122
- python
2223
- hdf5

conda_package/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from setuptools import setup, find_packages
44

5-
version = '0.0.1'
5+
version = '0.0.2'
66

77
setup(name='mpas_tools',
88
version=version,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cmake_minimum_required (VERSION 3.0.2)
2+
project (mesh_conversion_tools)
3+
4+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
5+
6+
include_directories (netcdf-cxx-4.2 .)
7+
8+
set(SOURCES netcdf_utils.cpp netcdf-cxx-4.2/ncvalues.cpp netcdf-cxx-4.2/netcdf.cpp)
9+
10+
add_executable (MpasMeshConverter.x mpas_mesh_converter.cpp ${SOURCES})
11+
target_link_libraries (MpasMeshConverter.x netcdf)
12+
13+
add_executable (MpasCellCuller.x mpas_cell_culler.cpp ${SOURCES})
14+
target_link_libraries (MpasCellCuller.x netcdf)
15+
16+
add_executable (MpasMaskCreator.x mpas_mask_creator.cpp jsoncpp.cpp ${SOURCES})
17+
target_link_libraries (MpasMaskCreator.x netcdf)
18+
19+
install (TARGETS MpasMeshConverter.x MpasCellCuller.x MpasMaskCreator.x DESTINATION bin)

mesh_tools/mesh_conversion_tools/mpas_cell_culler.cpp

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
using namespace std;
1818

19-
enum { merge, invert, preserve };
19+
enum { mergeOp, invertOp, preserveOp };
2020

2121
int nCells, nVertices, nEdges, vertexDegree, maxEdges;
2222
bool spherical, periodic;
@@ -155,13 +155,13 @@ int main ( int argc, char *argv[] ) {
155155
for ( int i = 3; i < argc; i+=2 ) {
156156
foundOperation = false;
157157
if (strcmp(argv[i], "-m") == 0 ) {
158-
mask_ops.push_back(static_cast<int>(merge));
158+
mask_ops.push_back(static_cast<int>(mergeOp));
159159
foundOperation = true;
160160
} else if ( strcmp(argv[i], "-i") == 0 ){
161-
mask_ops.push_back(static_cast<int>(invert));
161+
mask_ops.push_back(static_cast<int>(invertOp));
162162
foundOperation = true;
163163
} else if ( strcmp(argv[i], "-p") == 0 ){
164-
mask_ops.push_back(static_cast<int>(preserve));
164+
mask_ops.push_back(static_cast<int>(preserveOp));
165165
foundOperation = true;
166166
} else if ( strcmp(argv[i], "-c") == 0 ){
167167
outputMap = true;
@@ -471,8 +471,8 @@ int mergeCellMasks(const string masksFilename, const int maskOp){/*{{{*/
471471
}
472472
}
473473

474-
if ( maskOp == invert || maskOp == merge ) {
475-
if ( maskOp == invert ) {
474+
if ( maskOp == invertOp || maskOp == mergeOp ) {
475+
if ( maskOp == invertOp ) {
476476
for (i = 0; i < nCells; i++){
477477
flattenedMask[i] = (flattenedMask[i] + 1) % 2;
478478
}
@@ -481,7 +481,7 @@ int mergeCellMasks(const string masksFilename, const int maskOp){/*{{{*/
481481
for ( i = 0; i < nCells; i++ ){
482482
cullCell[i] = max(cullCell[i], flattenedMask[i]);
483483
}
484-
} else if ( maskOp == preserve ) {
484+
} else if ( maskOp == preserveOp ) {
485485
for ( i = 0; i < nCells; i++ ) {
486486
if ( flattenedMask[i] && cullCell[i] ) {
487487
cullCell[i] = 0;
@@ -614,21 +614,21 @@ int outputGridDimensions( const string outputFilename ){/*{{{*/
614614
int nCellsNew, nEdgesNew, nVerticesNew;
615615
// Return this code to the OS in case of failure.
616616
static const int NC_ERR = 2;
617-
617+
618618
// set error behaviour (matches fortran behaviour)
619619
NcError err(NcError::verbose_nonfatal);
620-
620+
621621
// open the scvtmesh file
622622
NcFile grid(outputFilename.c_str(), NcFile::Replace, NULL, 0, NcFile::Offset64Bits);
623623

624624
/*
625625
for(vec_int_itr = edgesOnCell.begin(); vec_int_itr != edgesOnCell.end(); ++vec_int_itr){
626-
maxEdges = std::max(maxEdges, (int)(*vec_int_itr).size());
626+
maxEdges = std::max(maxEdges, (int)(*vec_int_itr).size());
627627
}*/
628-
628+
629629
// check to see if the file was opened
630630
if(!grid.is_valid()) return NC_ERR;
631-
631+
632632
// define dimensions
633633
NcDim *nCellsDim;
634634
NcDim *nEdgesDim;
@@ -652,7 +652,7 @@ int outputGridDimensions( const string outputFilename ){/*{{{*/
652652
for(int iEdge = 0; iEdge < nEdges; iEdge++){
653653
nEdgesNew += (edgeMap.at(iEdge) != -1);
654654
}
655-
655+
656656
// write dimensions
657657
if (!(nCellsDim = grid.add_dim( "nCells", nCellsNew) )) return NC_ERR;
658658
if (!(nEdgesDim = grid.add_dim( "nEdges", nEdgesNew) )) return NC_ERR;
@@ -662,7 +662,7 @@ int outputGridDimensions( const string outputFilename ){/*{{{*/
662662
if (!(timeDim = grid.add_dim( "Time") )) return NC_ERR;
663663

664664
grid.close();
665-
665+
666666
// file closed when file obj goes out of scope
667667
return 0;
668668
}/*}}}*/
@@ -675,10 +675,10 @@ int outputGridAttributes( const string inputFilename, const string outputFilenam
675675
* **********************************************************************/
676676
// Return this code to the OS in case of failure.
677677
static const int NC_ERR = 2;
678-
678+
679679
// set error behaviour (matches fortran behaviour)
680680
NcError err(NcError::verbose_nonfatal);
681-
681+
682682
// open the scvtmesh file
683683
NcFile grid(outputFilename.c_str(), NcFile::Write);
684684

@@ -689,7 +689,7 @@ int outputGridAttributes( const string inputFilename, const string outputFilenam
689689
string history_str = "";
690690
string id_str = "";
691691
string parent_str = "";
692-
692+
693693
// write attributes
694694
if(!spherical){
695695
if (!(sphereAtt = grid.add_att( "on_a_sphere", "NO\0"))) return NC_ERR;
@@ -734,7 +734,7 @@ int outputGridAttributes( const string inputFilename, const string outputFilenam
734734
if (!(id = grid.add_att( "file_id", id_str.c_str() ))) return NC_ERR;
735735

736736
grid.close();
737-
737+
738738
// file closed when file obj goes out of scope
739739
return 0;
740740
}/*}}}*/
@@ -749,16 +749,16 @@ int mapAndOutputGridCoordinates( const string inputFilename, const string output
749749
* **********************************************************************/
750750
// Return this code to the OS in case of failure.
751751
static const int NC_ERR = 2;
752-
752+
753753
// set error behaviour (matches fortran behaviour)
754754
NcError err(NcError::verbose_nonfatal);
755-
755+
756756
// open the scvtmesh file
757757
NcFile grid(outputFilename.c_str(), NcFile::Write);
758-
758+
759759
// check to see if the file was opened
760760
if(!grid.is_valid()) return NC_ERR;
761-
761+
762762
// fetch dimensions
763763
NcDim *nCellsDim = grid.get_dim( "nCells" );
764764
NcDim *nEdgesDim = grid.get_dim( "nEdges" );
@@ -774,7 +774,7 @@ int mapAndOutputGridCoordinates( const string inputFilename, const string output
774774
NcVar *idx2cellVar, *idx2edgeVar, *idx2vertexVar;
775775

776776
int i, idx_map;
777-
777+
778778
double *xOld, *yOld, *zOld, *latOld, *lonOld;
779779
double *xNew, *yNew, *zNew, *latNew, *lonNew;
780780
int *idxToNew;
@@ -833,7 +833,7 @@ int mapAndOutputGridCoordinates( const string inputFilename, const string output
833833
delete[] latNew;
834834
delete[] lonNew;
835835
delete[] idxToNew;
836-
836+
837837
//Build and write edge coordinate arrays
838838
xOld = new double[nEdges];
839839
yOld = new double[nEdges];
@@ -964,16 +964,16 @@ int mapAndOutputCellFields( const string inputFilename, const string outputFilen
964964
* ***************************************************************/
965965
// Return this code to the OS in case of failure.
966966
static const int NC_ERR = 2;
967-
967+
968968
// set error behaviour (matches fortran behaviour)
969969
NcError err(NcError::verbose_nonfatal);
970-
970+
971971
// open the scvtmesh file
972972
NcFile grid(outputFilename.c_str(), NcFile::Write);
973-
973+
974974
// check to see if the file was opened
975975
if(!grid.is_valid()) return NC_ERR;
976-
976+
977977
// fetch dimensions
978978
NcDim *nCellsDim = grid.get_dim( "nCells" );
979979
NcDim *nEdgesDim = grid.get_dim( "nEdges" );
@@ -993,7 +993,7 @@ int mapAndOutputCellFields( const string inputFilename, const string outputFilen
993993
double *areaCellNew;
994994
int *tmp_arr_old, *nEdgesOnCellOld, *nEdgesOnCellNew;
995995
int *tmp_arr_new;
996-
996+
997997
tmp_arr_old = new int[nCells*maxEdges];
998998
nEdgesOnCellOld = new int[nCells];
999999
nEdgesOnCellNew = new int[nCellsNew];
@@ -1106,7 +1106,7 @@ int mapAndOutputCellFields( const string inputFilename, const string outputFilen
11061106
delete[] tmp_arr_new;
11071107

11081108
// Map areaCell
1109-
areaCellNew = new double[nCellsNew];
1109+
areaCellNew = new double[nCellsNew];
11101110

11111111
for(int iCell = 0; iCell < nCells; iCell++){
11121112
if(cellMap.at(iCell) != -1){
@@ -1154,16 +1154,16 @@ int mapAndOutputEdgeFields( const string inputFilename, const string outputFilen
11541154
* ***************************************************************/
11551155
// Return this code to the OS in case of failure.
11561156
static const int NC_ERR = 2;
1157-
1157+
11581158
// set error behaviour (matches fortran behaviour)
11591159
NcError err(NcError::verbose_nonfatal);
1160-
1160+
11611161
// open the scvtmesh file
11621162
NcFile grid(outputFilename.c_str(), NcFile::Write);
1163-
1163+
11641164
// check to see if the file was opened
11651165
if(!grid.is_valid()) return NC_ERR;
1166-
1166+
11671167
// fetch dimensions
11681168
NcDim *nEdgesDim = grid.get_dim( "nEdges" );
11691169
NcDim *maxEdges2Dim = grid.get_dim( "maxEdges2" );
@@ -1265,7 +1265,7 @@ int mapAndOutputEdgeFields( const string inputFilename, const string outputFilen
12651265
#endif
12661266
}
12671267
}
1268-
1268+
12691269
if (!(voeVar = grid.add_var("verticesOnEdge", ncInt, nEdgesDim, twoDim))) return NC_ERR;
12701270
if (!voeVar->put(verticesOnEdgeNew,nEdgesNew,2)) return NC_ERR;
12711271
if (!(coeVar = grid.add_var("cellsOnEdge", ncInt, nEdgesDim, twoDim))) return NC_ERR;
@@ -1394,16 +1394,16 @@ int mapAndOutputVertexFields( const string inputFilename, const string outputFil
13941394
* ***************************************************************/
13951395
// Return this code to the OS in case of failure.
13961396
static const int NC_ERR = 2;
1397-
1397+
13981398
// set error behaviour (matches fortran behaviour)
13991399
NcError err(NcError::verbose_nonfatal);
1400-
1400+
14011401
// open the scvtmesh file
14021402
NcFile grid(outputFilename.c_str(), NcFile::Write);
1403-
1403+
14041404
// check to see if the file was opened
14051405
if(!grid.is_valid()) return NC_ERR;
1406-
1406+
14071407
// fetch dimensions
14081408
NcDim *nVerticesDim = grid.get_dim( "nVertices" );
14091409
NcDim *vertexDegreeDim = grid.get_dim( "vertexDegree" );

0 commit comments

Comments
 (0)