From abeb369252ba9e71fc7664ac4509fb1604262452 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 10 Apr 2013 16:46:41 +0100 Subject: [PATCH] Cmake merge --- CMakeLists.txt | 119 ++++++++---- examples/C/CMakeLists.txt | 11 ++ examples/C/new_sample.c | 386 ++++++++++++++++++++++++++++++++++++++ examples/CMakeLists.txt | 1 + fortran/CMakeLists.txt | 50 ++++- grib_api_config.h.in | 73 ++++++- python/CMakeLists.txt | 133 +++++++------ src/CMakeLists.txt | 12 +- tests/ls.sh | 2 +- tools/CMakeLists.txt | 4 +- 10 files changed, 673 insertions(+), 118 deletions(-) create mode 100644 examples/C/CMakeLists.txt create mode 100644 examples/C/new_sample.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e813e463..a92408b48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,8 +7,6 @@ # -DCMAKE_MODULE_PATH=/path/to/ecbuild/cmake # TODO: -# * support for jpg and png -# * build fortran bindings # * build python bindings cmake_minimum_required( VERSION 2.8.4 FATAL_ERROR ) @@ -17,6 +15,8 @@ project( grib_api C ) set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH} ) +set( GRIB_API_INSTALL_INCLUDE_DIR include CACHE PATH "GRIB_API override installation directory for header files") + include( ecbuild_system ) ############################################################################### @@ -27,35 +27,42 @@ ecbuild_declare_project() ############################################################################### # some variables/options of this project -option( GRIB_API_JPG "try to add support for JPG encoding" ON ) -option( GRIB_API_PNG "try to add support for PNG encoding" ON ) -option( GRIB_API_NETCDF "try to add support for NetCDF" ON ) -option( GRIB_API_SZIP "try to add support for SZip encoding" ON ) -option( GRIB_API_PYTHON "try to build the GRIB_API Python interface" ON ) -option( GRIB_API_FORTRAN "try to build the GRIB_API Fortran interface" OFF ) +option( GRIB_API_JPG "try to add support for JPG encoding" ON ) +option( GRIB_API_PNG "try to add support for PNG encoding" ON ) +option( GRIB_API_NETCDF "try to add support for NetCDF" ON ) +option( GRIB_API_SZIP "try to add support for SZip encoding" ON ) +option( GRIB_API_PYTHON "try to build the GRIB_API Python interface" ON ) +option( GRIB_API_FORTRAN "try to build the GRIB_API Fortran interface" ON ) + +option( GRIB_API_MEMORY_MANAGEMENT "enable memory management" OFF ) +option( GRIB_API_ALIGN_MEMORY "enable memory alignment" OFF ) + +option( GRIB_TIMER "enable timer" OFF ) +option( GRIB_THREADS "enable threads" OFF ) ############################################################################### # macro processing -find_package( CMath ) +set( GRIB_API_EXTRA_LIBRARIES "" ) +set( GRIB_API_EXTRA_INCLUDE_DIRS "" ) +set( GRIB_API_EXTRA_DEFINITIONS "" ) -find_package( SWIG ) -if( SWIG_FOUND ) - include( ${SWIG_USE_FILE} ) -endif() +find_package( CMath ) ### SZIP support +set( HAVE_LIBSZIP 0 ) if( GRIB_API_SZIP ) find_package( SZip ) - set( HAVE_LIBSZIP ${SZIP_FOUND} ) + if( SZIP_FOUND ) + set( HAVE_LIBSZIP 1 ) + list( APPEND GRIB_API_EXTRA_LIBRARIES ${SZIP_LIBRARIES} ) + list( APPEND GRIB_API_EXTRA_INCLUDE_DIRS ${SZIP_INCLUDE_DIRS} ) + endif() endif() ### JPG support -set( GRIB_API_JPG_LIBRARIES "" ) -set( GRIB_API_JPG_INCLUDE_DIRS "" ) - set( HAVE_JPEG 0 ) set( HAVE_LIBJASPER 0 ) set( HAVE_LIBOPENJPEG 0 ) @@ -66,47 +73,41 @@ if( GRIB_API_JPG ) find_package( OpenJPEG ) if( JASPER_FOUND ) - list( APPEND GRIB_API_JPG_LIBRARIES ${JASPER_LIBRARIES} ) - list( APPEND GRIB_API_JPG_INCLUDE_DIRS ${JASPER_INCLUDE_DIR} ) set( HAVE_JPEG 1 ) set( HAVE_LIBJASPER 1 ) + list( APPEND GRIB_API_EXTRA_LIBRARIES ${JASPER_LIBRARIES} ) + list( APPEND GRIB_API_EXTRA_INCLUDE_DIRS ${JASPER_INCLUDE_DIR} ) endif() if( OpenJPEG_FOUND ) - list( APPEND GRIB_API_JPG_LIBRARIES ${OPENJPEG_LIBRARIES} ) - list( APPEND GRIB_API_JPG_INCLUDE_DIRS ${OPENJPEG_INCLUDE_DIR} ) set( HAVE_JPEG 1 ) set( HAVE_LIBOPENJPEG 1 ) + list( APPEND GRIB_API_EXTRA_LIBRARIES ${OPENJPEG_LIBRARIES} ) + list( APPEND GRIB_API_EXTRA_INCLUDE_DIRS ${OPENJPEG_INCLUDE_DIR} ) endif() endif() ### PNG support -set( GRIB_API_PNG_LIBRARIES "" ) -set( GRIB_API_PNG_INCLUDE_DIRS "" ) - set( HAVE_LIBPNG 0 ) -if( GRIB_API_JPG ) +if( GRIB_API_PNG ) find_package( PNG ) if( PNG_FOUND ) - list( APPEND GRIB_API_PNG_LIBRARIES ${PNG_LIBRARIES} ) - list( APPEND GRIB_API_PNG_INCLUDE_DIRS ${PNG_INCLUDE_DIR} ) - list( APPEND GRIB_API_PNG_DEFINITIONS ${PNG_DEFINITIONS} ) - add_definitions( ${PNG_DEFINITIONS} ) set( HAVE_LIBPNG 1 ) + list( APPEND GRIB_API_EXTRA_LIBRARIES ${PNG_LIBRARIES} ) + list( APPEND GRIB_API_EXTRA_INCLUDE_DIRS ${PNG_INCLUDE_DIR} ) + list( APPEND GRIB_API_EXTRA_DEFINITIONS ${PNG_DEFINITIONS} ) + add_definitions( ${PNG_DEFINITIONS} ) endif() endif() ### NetCDF support -set( GRIB_API_NETCDF_LIBRARIES "" ) -set( GRIB_API_NETCDF_INCLUDE_DIRS "" ) - set( HAVE_NETCDF 0 ) if( GRIB_API_NETCDF ) @@ -114,13 +115,47 @@ if( GRIB_API_NETCDF ) find_package( NetCDF ) if( NETCDF_FOUND ) - list( APPEND GRIB_API_NETCDF_LIBRARIES ${NETCDF_LIBRARIES} ) - list( APPEND GRIB_API_NETCDF_INCLUDE_DIRS ${NETCDF_INCLUDE_DIR} ) set( HAVE_NETCDF 1 ) + list( APPEND GRIB_API_EXTRA_LIBRARIES ${NETCDF_LIBRARIES} ) + list( APPEND GRIB_API_EXTRA_INCLUDE_DIRS ${NETCDF_INCLUDE_DIR} ) endif() endif() +# other options + +if( GRIB_TIMER ) + set( GRIB_TIMER 1 ) +else() + set( GRIB_TIMER 0 ) +endif() + +set( IS_BIG_ENDIAN 0 ) +if( EC_BIG_ENDIAN ) + set( IS_BIG_ENDIAN 1 ) +endif() + +set( MANAGE_MEM 0 ) +if( GRIB_API_MEMORY_MANAGEMENT ) + set( MANAGE_MEM 1 ) +endif() + +set( GRIB_PTHREADS 0 ) +set( GRIB_LINUX_PTHREADS 0 ) +if( GRIB_THREADS AND CMAKE_THREAD_LIBS_INIT ) + if( CMAKE_USE_PTHREADS_INIT ) + set( GRIB_PTHREADS 1 ) + if( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" ) + set( GRIB_LINUX_PTHREADS 1 ) + endif() + endif() +endif() + +set( GRIB_MEM_ALIGN 0 ) +if( GRIB_API_ALIGN_MEMORY ) + set( GRIB_MEM_ALIGN 1 ) +endif() + ############################################################################### # contents @@ -135,15 +170,19 @@ endif() configure_file( grib_api_config.h.in grib_api_config.h ) -install( FILES ${CMAKE_BINARY_DIR}/grib_api_config.h DESTINATION include/${PROJECT_NAME} ) +add_definitions( -DHAVE_GRIB_API_CONFIG_H ) + +install( FILES ${CMAKE_CURRENT_BINARY_DIR}/grib_api_config.h DESTINATION ${INSTALL_INCLUDE_DIR} ) + +if( CMAKE_COMPILER_IS_GNUCC ) + cmake_add_c_flags("-pedantic") +endif() ### include directories include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src ) -add_definitions( -DHAVE_GRIB_API_CONFIG_H ) - add_subdirectory( src ) add_subdirectory( tools ) add_subdirectory( fortran ) @@ -162,9 +201,9 @@ add_subdirectory( ifs_samples ) # must come after samples # export to other projects if( NOT ${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME} ) - set( GRIB_API_DEFINITIONS ${GRIB_API_PNG_DEFINITIONS} PARENT_SCOPE ) - set( GRIB_API_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src ${NETCDF_INCLUDE_DIR} ${GRIB_API_JPG_INCLUDE_DIRS} ${GRIB_API_PNG_INCLUDE_DIRS} PARENT_SCOPE ) - set( GRIB_API_LIBRARIES grib_api ${NETCDF_LIBRARIES} ${GRIB_API_JPG_LIBRARIES} ${GRIB_API_PNG_LIBRARIES} ${CMATH_LIBRARIES} PARENT_SCOPE ) + set( GRIB_API_DEFINITIONS ${GRIB_API_EXTRA_DEFINITIONS} PARENT_SCOPE ) + set( GRIB_API_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src ${GRIB_API_EXTRA_INCLUDE_DIRS} PARENT_SCOPE ) + set( GRIB_API_LIBRARIES grib_api ${GRIB_API_EXTRA_LIBRARIES} ${CMATH_LIBRARIES} PARENT_SCOPE ) set( GRIB_API_FOUND TRUE PARENT_SCOPE ) endif() diff --git a/examples/C/CMakeLists.txt b/examples/C/CMakeLists.txt new file mode 100644 index 000000000..f9591c58f --- /dev/null +++ b/examples/C/CMakeLists.txt @@ -0,0 +1,11 @@ +ecbuild_add_test( TARGET new_sample + SOURCES new_sample.c + LIBS grib_api + ARGS "out.grib" + ENVIRONMENT "GRIB_SAMPLES_PATH=${PROJECT_SOURCE_DIR}/samples" "GRIB_DEFINITION_PATH=${PROJECT_SOURCE_DIR}/definitions" ) + +#ecbuild_add_test( TARGET iterator +# SOURCES iterator.c +# LIBS grib_api +# ARGS "out.grib" +# ENVIRONMENT "GRIB_SAMPLES_PATH=${PROJECT_SOURCE_DIR}/samples" "GRIB_DEFINITION_PATH=${PROJECT_SOURCE_DIR}/definitions" ) diff --git a/examples/C/new_sample.c b/examples/C/new_sample.c new file mode 100644 index 000000000..bcd8eacd4 --- /dev/null +++ b/examples/C/new_sample.c @@ -0,0 +1,386 @@ +#include + +/* This code was generated automatically */ + + +int main(int argc,const char** argv) +{ + grib_handle *h = NULL; + size_t size = 0; + double* vdouble = NULL; + long* vlong = NULL; + FILE* f = NULL; + const char* p = NULL; + const void* buffer = NULL; + + if(argc != 2) { + fprintf(stderr,"usage: %s out\n",argv[0]); + exit(1); + } + + h = grib_handle_new_from_samples(NULL,"GRIB2"); + if(!h) { + fprintf(stderr,"Cannot create grib handle\n"); + exit(1); + } + + GRIB_CHECK(grib_set_long(h,"parametersVersion",1),0); + GRIB_CHECK(grib_set_long(h,"truncateLaplacian",0),0); + GRIB_CHECK(grib_set_long(h,"truncateDegrees",0),0); + GRIB_CHECK(grib_set_long(h,"dummy",1),0); + GRIB_CHECK(grib_set_long(h,"changingPrecision",0),0); + GRIB_CHECK(grib_set_long(h,"unitsFactor",1),0); + GRIB_CHECK(grib_set_long(h,"unitsBias",0),0); + GRIB_CHECK(grib_set_long(h,"timeRangeIndicatorFromStepRange",-1),0); + GRIB_CHECK(grib_set_long(h,"missingValue",9999),0); + + /* 0 = Meteorological products (grib2/tables/4/0.0.table) */ + GRIB_CHECK(grib_set_long(h,"discipline",0),0); + + GRIB_CHECK(grib_set_long(h,"editionNumber",2),0); + + /* 98 = European Center for Medium-Range Weather Forecasts (grib1/0.table) */ + GRIB_CHECK(grib_set_long(h,"centre",98),0); + + GRIB_CHECK(grib_set_long(h,"subCentre",0),0); + + /* 4 = Version implemented on 7 November 2007 (grib2/tables/1.0.table) */ + GRIB_CHECK(grib_set_long(h,"tablesVersion",4),0); + + + /* 0 = Local tables not used (grib2/tables/4/1.1.table) */ + GRIB_CHECK(grib_set_long(h,"localTablesVersion",0),0); + + + /* 1 = Start of forecast (grib2/tables/4/1.2.table) */ + GRIB_CHECK(grib_set_long(h,"significanceOfReferenceTime",1),0); + + GRIB_CHECK(grib_set_long(h,"year",2007),0); + GRIB_CHECK(grib_set_long(h,"month",3),0); + GRIB_CHECK(grib_set_long(h,"day",23),0); + GRIB_CHECK(grib_set_long(h,"hour",12),0); + GRIB_CHECK(grib_set_long(h,"minute",0),0); + GRIB_CHECK(grib_set_long(h,"second",0),0); + GRIB_CHECK(grib_set_long(h,"dataDate",20070323),0); + GRIB_CHECK(grib_set_long(h,"dataTime",1200),0); + + /* 0 = Operational products (grib2/tables/4/1.3.table) */ + GRIB_CHECK(grib_set_long(h,"productionStatusOfProcessedData",0),0); + + + /* 2 = Analysis and forecast products (grib2/tables/4/1.4.table) */ + GRIB_CHECK(grib_set_long(h,"typeOfProcessedData",2),0); + + GRIB_CHECK(grib_set_long(h,"selectStepTemplateInterval",1),0); + GRIB_CHECK(grib_set_long(h,"selectStepTemplateInstant",1),0); + GRIB_CHECK(grib_set_long(h,"grib2LocalSectionPresent",0),0); + + /* 0 = Specified in Code table 3.1 (grib2/tables/4/3.0.table) */ + GRIB_CHECK(grib_set_long(h,"sourceOfGridDefinition",0),0); + + GRIB_CHECK(grib_set_long(h,"numberOfDataPoints",496),0); + GRIB_CHECK(grib_set_long(h,"numberOfOctectsForNumberOfPoints",0),0); + + /* 0 = There is no appended list (grib2/tables/4/3.11.table) */ + GRIB_CHECK(grib_set_long(h,"interpretationOfNumberOfPoints",0),0); + + GRIB_CHECK(grib_set_long(h,"PLPresent",0),0); + + /* 0 = Latitude/longitude. Also called equidistant cylindrical, or Plate Carree (grib2/tables/4/3.1.table) */ + GRIB_CHECK(grib_set_long(h,"gridDefinitionTemplateNumber",0),0); + + + /* 0 = Earth assumed spherical with radius = 6,367,470.0 m (grib2/tables/4/3.2.table) */ + GRIB_CHECK(grib_set_long(h,"shapeOfTheEarth",0),0); + + GRIB_CHECK(grib_set_missing(h,"scaleFactorOfRadiusOfSphericalEarth"),0); + GRIB_CHECK(grib_set_missing(h,"scaledValueOfRadiusOfSphericalEarth"),0); + GRIB_CHECK(grib_set_missing(h,"scaleFactorOfEarthMajorAxis"),0); + GRIB_CHECK(grib_set_missing(h,"scaledValueOfEarthMajorAxis"),0); + GRIB_CHECK(grib_set_missing(h,"scaleFactorOfEarthMinorAxis"),0); + GRIB_CHECK(grib_set_missing(h,"scaledValueOfEarthMinorAxis"),0); + GRIB_CHECK(grib_set_long(h,"radius",6367470),0); + GRIB_CHECK(grib_set_long(h,"Ni",16),0); + GRIB_CHECK(grib_set_long(h,"Nj",31),0); + GRIB_CHECK(grib_set_long(h,"basicAngleOfTheInitialProductionDomain",0),0); + GRIB_CHECK(grib_set_long(h,"mBasicAngle",0),0); + GRIB_CHECK(grib_set_long(h,"angleMultiplier",1),0); + GRIB_CHECK(grib_set_long(h,"mAngleMultiplier",1000000),0); + GRIB_CHECK(grib_set_missing(h,"subdivisionsOfBasicAngle"),0); + GRIB_CHECK(grib_set_long(h,"angleDivisor",1000000),0); + GRIB_CHECK(grib_set_long(h,"latitudeOfFirstGridPoint",60000000),0); + GRIB_CHECK(grib_set_long(h,"longitudeOfFirstGridPoint",0),0); + + /* 48 = 00110000 + (3=1) i direction increments given + (4=1) j direction increments given + (5=0) Resolved u- and v- components of vector quantities relative to easterly and northerly directions + See grib2/tables/[tablesVersion]/3.3.table */ + GRIB_CHECK(grib_set_long(h,"resolutionAndComponentFlags",48),0); + + GRIB_CHECK(grib_set_long(h,"iDirectionIncrementGiven",1),0); + GRIB_CHECK(grib_set_long(h,"jDirectionIncrementGiven",1),0); + GRIB_CHECK(grib_set_long(h,"uvRelativeToGrid",0),0); + GRIB_CHECK(grib_set_long(h,"latitudeOfLastGridPoint",0),0); + GRIB_CHECK(grib_set_long(h,"longitudeOfLastGridPoint",30000000),0); + GRIB_CHECK(grib_set_long(h,"iDirectionIncrement",2000000),0); + GRIB_CHECK(grib_set_long(h,"jDirectionIncrement",2000000),0); + + /* 0 = 00000000 + (1=0) Points of first row or column scan in the +i (+x) direction + (2=0) Points of first row or column scan in the -j (-y) direction + (3=0) Adjacent points in i (x) direction are consecutive + (4=0) All rows scan in the same direction + See grib2/tables/[tablesVersion]/3.4.table */ + GRIB_CHECK(grib_set_long(h,"scanningMode",0),0); + + GRIB_CHECK(grib_set_long(h,"iScansNegatively",0),0); + GRIB_CHECK(grib_set_long(h,"jScansPositively",0),0); + GRIB_CHECK(grib_set_long(h,"jPointsAreConsecutive",0),0); + GRIB_CHECK(grib_set_long(h,"alternativeRowScanning",0),0); + GRIB_CHECK(grib_set_long(h,"iScansPositively",1),0); + + /* ITERATOR */ + + + /* NEAREST */ + + GRIB_CHECK(grib_set_long(h,"timeRangeIndicator",0),0); + GRIB_CHECK(grib_set_long(h,"NV",0),0); + GRIB_CHECK(grib_set_long(h,"neitherPresent",0),0); + + /* 0 = Analysis or forecast at a horizontal level or in a horizontal layer at a point in time (grib2/tables/4/4.0.table) */ + GRIB_CHECK(grib_set_long(h,"productDefinitionTemplateNumber",0),0); + + + /* Parameter information */ + + + /* 0 = Temperature (grib2/tables/4/4.1.0.table) */ + GRIB_CHECK(grib_set_long(h,"parameterCategory",0),0); + + + /* 0 = Temperature (K) (grib2/tables/4/4.2.0.0.table) */ + GRIB_CHECK(grib_set_long(h,"parameterNumber",0),0); + + + /* 0 = Analysis (grib2/tables/4/4.3.table) */ + GRIB_CHECK(grib_set_long(h,"typeOfGeneratingProcess",0),0); + + GRIB_CHECK(grib_set_long(h,"backgroundProcess",255),0); + GRIB_CHECK(grib_set_long(h,"generatingProcessIdentifier",128),0); + GRIB_CHECK(grib_set_long(h,"hoursAfterDataCutoff",0),0); + GRIB_CHECK(grib_set_long(h,"minutesAfterDataCutoff",0),0); + + /* 1 = Hour (grib2/tables/4/4.4.table) */ + GRIB_CHECK(grib_set_long(h,"indicatorOfUnitOfTimeRange",1),0); + + + /* 1 = Hour (stepUnits.table) */ + GRIB_CHECK(grib_set_long(h,"stepUnits",1),0); + + GRIB_CHECK(grib_set_long(h,"forecastTime",0),0); + + /* 1 = Ground or water surface (grib2/tables/4/4.5.table) */ + GRIB_CHECK(grib_set_long(h,"typeOfFirstFixedSurface",1),0); + + GRIB_CHECK(grib_set_missing(h,"scaleFactorOfFirstFixedSurface"),0); + GRIB_CHECK(grib_set_missing(h,"scaledValueOfFirstFixedSurface"),0); + + /* 255 = Missing (grib2/tables/4/4.5.table) */ + GRIB_CHECK(grib_set_long(h,"typeOfSecondFixedSurface",255),0); + + GRIB_CHECK(grib_set_missing(h,"scaleFactorOfSecondFixedSurface"),0); + GRIB_CHECK(grib_set_missing(h,"scaledValueOfSecondFixedSurface"),0); + GRIB_CHECK(grib_set_long(h,"level",0),0); + GRIB_CHECK(grib_set_long(h,"bottomLevel",0),0); + GRIB_CHECK(grib_set_long(h,"topLevel",0),0); + GRIB_CHECK(grib_set_long(h,"dummyc",0),0); + GRIB_CHECK(grib_set_long(h,"PVPresent",0),0); + + /* grib 2 Section 5 DATA REPRESENTATION SECTION */ + + GRIB_CHECK(grib_set_long(h,"numberOfValues",496),0); + + /* 0 = Grid point data - simple packing (grib2/tables/4/5.0.table) */ + GRIB_CHECK(grib_set_long(h,"dataRepresentationTemplateNumber",0),0); + + GRIB_CHECK(grib_set_long(h,"decimalScaleFactor",0),0); + GRIB_CHECK(grib_set_long(h,"bitsPerValue",0),0); + + /* 0 = Floating point (grib2/tables/4/5.1.table) */ + GRIB_CHECK(grib_set_long(h,"typeOfOriginalFieldValues",0),0); + + GRIB_CHECK(grib_set_long(h,"representationMode",0),0); + + /* grib 2 Section 6 BIT-MAP SECTION */ + + + /* 255 = A bit map does not apply to this product (grib2/tables/4/6.0.table) */ + GRIB_CHECK(grib_set_long(h,"bitMapIndicator",255),0); + + GRIB_CHECK(grib_set_long(h,"bitmapPresent",0),0); + + /* grib 2 Section 7 data */ + + size = 496; + vdouble = (double*)calloc(size,sizeof(double)); + if(!vdouble) { + fprintf(stderr,"failed to allocate %d bytes\n",size*sizeof(double)); + exit(1); + } + + vdouble[ 0] = 1; vdouble[ 1] = 1; vdouble[ 2] = 1; vdouble[ 3] = 1; + vdouble[ 4] = 1; vdouble[ 5] = 1; vdouble[ 6] = 1; vdouble[ 7] = 1; + vdouble[ 8] = 1; vdouble[ 9] = 1; vdouble[ 10] = 1; vdouble[ 11] = 1; + vdouble[ 12] = 1; vdouble[ 13] = 1; vdouble[ 14] = 1; vdouble[ 15] = 1; + vdouble[ 16] = 1; vdouble[ 17] = 1; vdouble[ 18] = 1; vdouble[ 19] = 1; + vdouble[ 20] = 1; vdouble[ 21] = 1; vdouble[ 22] = 1; vdouble[ 23] = 1; + vdouble[ 24] = 1; vdouble[ 25] = 1; vdouble[ 26] = 1; vdouble[ 27] = 1; + vdouble[ 28] = 1; vdouble[ 29] = 1; vdouble[ 30] = 1; vdouble[ 31] = 1; + vdouble[ 32] = 1; vdouble[ 33] = 1; vdouble[ 34] = 1; vdouble[ 35] = 1; + vdouble[ 36] = 1; vdouble[ 37] = 1; vdouble[ 38] = 1; vdouble[ 39] = 1; + vdouble[ 40] = 1; vdouble[ 41] = 1; vdouble[ 42] = 1; vdouble[ 43] = 1; + vdouble[ 44] = 1; vdouble[ 45] = 1; vdouble[ 46] = 1; vdouble[ 47] = 1; + vdouble[ 48] = 1; vdouble[ 49] = 1; vdouble[ 50] = 1; vdouble[ 51] = 1; + vdouble[ 52] = 1; vdouble[ 53] = 1; vdouble[ 54] = 1; vdouble[ 55] = 1; + vdouble[ 56] = 1; vdouble[ 57] = 1; vdouble[ 58] = 1; vdouble[ 59] = 1; + vdouble[ 60] = 1; vdouble[ 61] = 1; vdouble[ 62] = 1; vdouble[ 63] = 1; + vdouble[ 64] = 1; vdouble[ 65] = 1; vdouble[ 66] = 1; vdouble[ 67] = 1; + vdouble[ 68] = 1; vdouble[ 69] = 1; vdouble[ 70] = 1; vdouble[ 71] = 1; + vdouble[ 72] = 1; vdouble[ 73] = 1; vdouble[ 74] = 1; vdouble[ 75] = 1; + vdouble[ 76] = 1; vdouble[ 77] = 1; vdouble[ 78] = 1; vdouble[ 79] = 1; + vdouble[ 80] = 1; vdouble[ 81] = 1; vdouble[ 82] = 1; vdouble[ 83] = 1; + vdouble[ 84] = 1; vdouble[ 85] = 1; vdouble[ 86] = 1; vdouble[ 87] = 1; + vdouble[ 88] = 1; vdouble[ 89] = 1; vdouble[ 90] = 1; vdouble[ 91] = 1; + vdouble[ 92] = 1; vdouble[ 93] = 1; vdouble[ 94] = 1; vdouble[ 95] = 1; + vdouble[ 96] = 1; vdouble[ 97] = 1; vdouble[ 98] = 1; vdouble[ 99] = 1; + vdouble[ 100] = 1; vdouble[ 101] = 1; vdouble[ 102] = 1; vdouble[ 103] = 1; + vdouble[ 104] = 1; vdouble[ 105] = 1; vdouble[ 106] = 1; vdouble[ 107] = 1; + vdouble[ 108] = 1; vdouble[ 109] = 1; vdouble[ 110] = 1; vdouble[ 111] = 1; + vdouble[ 112] = 1; vdouble[ 113] = 1; vdouble[ 114] = 1; vdouble[ 115] = 1; + vdouble[ 116] = 1; vdouble[ 117] = 1; vdouble[ 118] = 1; vdouble[ 119] = 1; + vdouble[ 120] = 1; vdouble[ 121] = 1; vdouble[ 122] = 1; vdouble[ 123] = 1; + vdouble[ 124] = 1; vdouble[ 125] = 1; vdouble[ 126] = 1; vdouble[ 127] = 1; + vdouble[ 128] = 1; vdouble[ 129] = 1; vdouble[ 130] = 1; vdouble[ 131] = 1; + vdouble[ 132] = 1; vdouble[ 133] = 1; vdouble[ 134] = 1; vdouble[ 135] = 1; + vdouble[ 136] = 1; vdouble[ 137] = 1; vdouble[ 138] = 1; vdouble[ 139] = 1; + vdouble[ 140] = 1; vdouble[ 141] = 1; vdouble[ 142] = 1; vdouble[ 143] = 1; + vdouble[ 144] = 1; vdouble[ 145] = 1; vdouble[ 146] = 1; vdouble[ 147] = 1; + vdouble[ 148] = 1; vdouble[ 149] = 1; vdouble[ 150] = 1; vdouble[ 151] = 1; + vdouble[ 152] = 1; vdouble[ 153] = 1; vdouble[ 154] = 1; vdouble[ 155] = 1; + vdouble[ 156] = 1; vdouble[ 157] = 1; vdouble[ 158] = 1; vdouble[ 159] = 1; + vdouble[ 160] = 1; vdouble[ 161] = 1; vdouble[ 162] = 1; vdouble[ 163] = 1; + vdouble[ 164] = 1; vdouble[ 165] = 1; vdouble[ 166] = 1; vdouble[ 167] = 1; + vdouble[ 168] = 1; vdouble[ 169] = 1; vdouble[ 170] = 1; vdouble[ 171] = 1; + vdouble[ 172] = 1; vdouble[ 173] = 1; vdouble[ 174] = 1; vdouble[ 175] = 1; + vdouble[ 176] = 1; vdouble[ 177] = 1; vdouble[ 178] = 1; vdouble[ 179] = 1; + vdouble[ 180] = 1; vdouble[ 181] = 1; vdouble[ 182] = 1; vdouble[ 183] = 1; + vdouble[ 184] = 1; vdouble[ 185] = 1; vdouble[ 186] = 1; vdouble[ 187] = 1; + vdouble[ 188] = 1; vdouble[ 189] = 1; vdouble[ 190] = 1; vdouble[ 191] = 1; + vdouble[ 192] = 1; vdouble[ 193] = 1; vdouble[ 194] = 1; vdouble[ 195] = 1; + vdouble[ 196] = 1; vdouble[ 197] = 1; vdouble[ 198] = 1; vdouble[ 199] = 1; + vdouble[ 200] = 1; vdouble[ 201] = 1; vdouble[ 202] = 1; vdouble[ 203] = 1; + vdouble[ 204] = 1; vdouble[ 205] = 1; vdouble[ 206] = 1; vdouble[ 207] = 1; + vdouble[ 208] = 1; vdouble[ 209] = 1; vdouble[ 210] = 1; vdouble[ 211] = 1; + vdouble[ 212] = 1; vdouble[ 213] = 1; vdouble[ 214] = 1; vdouble[ 215] = 1; + vdouble[ 216] = 1; vdouble[ 217] = 1; vdouble[ 218] = 1; vdouble[ 219] = 1; + vdouble[ 220] = 1; vdouble[ 221] = 1; vdouble[ 222] = 1; vdouble[ 223] = 1; + vdouble[ 224] = 1; vdouble[ 225] = 1; vdouble[ 226] = 1; vdouble[ 227] = 1; + vdouble[ 228] = 1; vdouble[ 229] = 1; vdouble[ 230] = 1; vdouble[ 231] = 1; + vdouble[ 232] = 1; vdouble[ 233] = 1; vdouble[ 234] = 1; vdouble[ 235] = 1; + vdouble[ 236] = 1; vdouble[ 237] = 1; vdouble[ 238] = 1; vdouble[ 239] = 1; + vdouble[ 240] = 1; vdouble[ 241] = 1; vdouble[ 242] = 1; vdouble[ 243] = 1; + vdouble[ 244] = 1; vdouble[ 245] = 1; vdouble[ 246] = 1; vdouble[ 247] = 1; + vdouble[ 248] = 1; vdouble[ 249] = 1; vdouble[ 250] = 1; vdouble[ 251] = 1; + vdouble[ 252] = 1; vdouble[ 253] = 1; vdouble[ 254] = 1; vdouble[ 255] = 1; + vdouble[ 256] = 1; vdouble[ 257] = 1; vdouble[ 258] = 1; vdouble[ 259] = 1; + vdouble[ 260] = 1; vdouble[ 261] = 1; vdouble[ 262] = 1; vdouble[ 263] = 1; + vdouble[ 264] = 1; vdouble[ 265] = 1; vdouble[ 266] = 1; vdouble[ 267] = 1; + vdouble[ 268] = 1; vdouble[ 269] = 1; vdouble[ 270] = 1; vdouble[ 271] = 1; + vdouble[ 272] = 1; vdouble[ 273] = 1; vdouble[ 274] = 1; vdouble[ 275] = 1; + vdouble[ 276] = 1; vdouble[ 277] = 1; vdouble[ 278] = 1; vdouble[ 279] = 1; + vdouble[ 280] = 1; vdouble[ 281] = 1; vdouble[ 282] = 1; vdouble[ 283] = 1; + vdouble[ 284] = 1; vdouble[ 285] = 1; vdouble[ 286] = 1; vdouble[ 287] = 1; + vdouble[ 288] = 1; vdouble[ 289] = 1; vdouble[ 290] = 1; vdouble[ 291] = 1; + vdouble[ 292] = 1; vdouble[ 293] = 1; vdouble[ 294] = 1; vdouble[ 295] = 1; + vdouble[ 296] = 1; vdouble[ 297] = 1; vdouble[ 298] = 1; vdouble[ 299] = 1; + vdouble[ 300] = 1; vdouble[ 301] = 1; vdouble[ 302] = 1; vdouble[ 303] = 1; + vdouble[ 304] = 1; vdouble[ 305] = 1; vdouble[ 306] = 1; vdouble[ 307] = 1; + vdouble[ 308] = 1; vdouble[ 309] = 1; vdouble[ 310] = 1; vdouble[ 311] = 1; + vdouble[ 312] = 1; vdouble[ 313] = 1; vdouble[ 314] = 1; vdouble[ 315] = 1; + vdouble[ 316] = 1; vdouble[ 317] = 1; vdouble[ 318] = 1; vdouble[ 319] = 1; + vdouble[ 320] = 1; vdouble[ 321] = 1; vdouble[ 322] = 1; vdouble[ 323] = 1; + vdouble[ 324] = 1; vdouble[ 325] = 1; vdouble[ 326] = 1; vdouble[ 327] = 1; + vdouble[ 328] = 1; vdouble[ 329] = 1; vdouble[ 330] = 1; vdouble[ 331] = 1; + vdouble[ 332] = 1; vdouble[ 333] = 1; vdouble[ 334] = 1; vdouble[ 335] = 1; + vdouble[ 336] = 1; vdouble[ 337] = 1; vdouble[ 338] = 1; vdouble[ 339] = 1; + vdouble[ 340] = 1; vdouble[ 341] = 1; vdouble[ 342] = 1; vdouble[ 343] = 1; + vdouble[ 344] = 1; vdouble[ 345] = 1; vdouble[ 346] = 1; vdouble[ 347] = 1; + vdouble[ 348] = 1; vdouble[ 349] = 1; vdouble[ 350] = 1; vdouble[ 351] = 1; + vdouble[ 352] = 1; vdouble[ 353] = 1; vdouble[ 354] = 1; vdouble[ 355] = 1; + vdouble[ 356] = 1; vdouble[ 357] = 1; vdouble[ 358] = 1; vdouble[ 359] = 1; + vdouble[ 360] = 1; vdouble[ 361] = 1; vdouble[ 362] = 1; vdouble[ 363] = 1; + vdouble[ 364] = 1; vdouble[ 365] = 1; vdouble[ 366] = 1; vdouble[ 367] = 1; + vdouble[ 368] = 1; vdouble[ 369] = 1; vdouble[ 370] = 1; vdouble[ 371] = 1; + vdouble[ 372] = 1; vdouble[ 373] = 1; vdouble[ 374] = 1; vdouble[ 375] = 1; + vdouble[ 376] = 1; vdouble[ 377] = 1; vdouble[ 378] = 1; vdouble[ 379] = 1; + vdouble[ 380] = 1; vdouble[ 381] = 1; vdouble[ 382] = 1; vdouble[ 383] = 1; + vdouble[ 384] = 1; vdouble[ 385] = 1; vdouble[ 386] = 1; vdouble[ 387] = 1; + vdouble[ 388] = 1; vdouble[ 389] = 1; vdouble[ 390] = 1; vdouble[ 391] = 1; + vdouble[ 392] = 1; vdouble[ 393] = 1; vdouble[ 394] = 1; vdouble[ 395] = 1; + vdouble[ 396] = 1; vdouble[ 397] = 1; vdouble[ 398] = 1; vdouble[ 399] = 1; + vdouble[ 400] = 1; vdouble[ 401] = 1; vdouble[ 402] = 1; vdouble[ 403] = 1; + vdouble[ 404] = 1; vdouble[ 405] = 1; vdouble[ 406] = 1; vdouble[ 407] = 1; + vdouble[ 408] = 1; vdouble[ 409] = 1; vdouble[ 410] = 1; vdouble[ 411] = 1; + vdouble[ 412] = 1; vdouble[ 413] = 1; vdouble[ 414] = 1; vdouble[ 415] = 1; + vdouble[ 416] = 1; vdouble[ 417] = 1; vdouble[ 418] = 1; vdouble[ 419] = 1; + vdouble[ 420] = 1; vdouble[ 421] = 1; vdouble[ 422] = 1; vdouble[ 423] = 1; + vdouble[ 424] = 1; vdouble[ 425] = 1; vdouble[ 426] = 1; vdouble[ 427] = 1; + vdouble[ 428] = 1; vdouble[ 429] = 1; vdouble[ 430] = 1; vdouble[ 431] = 1; + vdouble[ 432] = 1; vdouble[ 433] = 1; vdouble[ 434] = 1; vdouble[ 435] = 1; + vdouble[ 436] = 1; vdouble[ 437] = 1; vdouble[ 438] = 1; vdouble[ 439] = 1; + vdouble[ 440] = 1; vdouble[ 441] = 1; vdouble[ 442] = 1; vdouble[ 443] = 1; + vdouble[ 444] = 1; vdouble[ 445] = 1; vdouble[ 446] = 1; vdouble[ 447] = 1; + vdouble[ 448] = 1; vdouble[ 449] = 1; vdouble[ 450] = 1; vdouble[ 451] = 1; + vdouble[ 452] = 1; vdouble[ 453] = 1; vdouble[ 454] = 1; vdouble[ 455] = 1; + vdouble[ 456] = 1; vdouble[ 457] = 1; vdouble[ 458] = 1; vdouble[ 459] = 1; + vdouble[ 460] = 1; vdouble[ 461] = 1; vdouble[ 462] = 1; vdouble[ 463] = 1; + vdouble[ 464] = 1; vdouble[ 465] = 1; vdouble[ 466] = 1; vdouble[ 467] = 1; + vdouble[ 468] = 1; vdouble[ 469] = 1; vdouble[ 470] = 1; vdouble[ 471] = 1; + vdouble[ 472] = 1; vdouble[ 473] = 1; vdouble[ 474] = 1; vdouble[ 475] = 1; + vdouble[ 476] = 1; vdouble[ 477] = 1; vdouble[ 478] = 1; vdouble[ 479] = 1; + vdouble[ 480] = 1; vdouble[ 481] = 1; vdouble[ 482] = 1; vdouble[ 483] = 1; + vdouble[ 484] = 1; vdouble[ 485] = 1; vdouble[ 486] = 1; vdouble[ 487] = 1; + vdouble[ 488] = 1; vdouble[ 489] = 1; vdouble[ 490] = 1; vdouble[ 491] = 1; + vdouble[ 492] = 1; vdouble[ 493] = 1; vdouble[ 494] = 1; vdouble[ 495] = 1; + + GRIB_CHECK(grib_set_double_array(h,"values",vdouble,size),0); + free(vdouble); + GRIB_CHECK(grib_set_long(h,"dirty_statistics",1),0); + GRIB_CHECK(grib_set_long(h,"changeDecimalPrecision",0),0); + GRIB_CHECK(grib_set_long(h,"decimalPrecision",0),0); + GRIB_CHECK(grib_set_long(h,"setBitsPerValue",0),0); +/* Save the message */ + + f = fopen(argv[1],"w"); + if(!f) { + perror(argv[1]); + exit(1); + } + + GRIB_CHECK(grib_get_message(h,&buffer,&size),0); + + if(fwrite(buffer,1,size,f) != size) { + perror(argv[1]); + exit(1); + } + + if(fclose(f)) { + perror(argv[1]); + exit(1); + } + + grib_handle_delete(h); + return 0; +} diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e69de29bb..5446ca349 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(C) diff --git a/fortran/CMakeLists.txt b/fortran/CMakeLists.txt index 18ebae00a..092f4e85e 100644 --- a/fortran/CMakeLists.txt +++ b/fortran/CMakeLists.txt @@ -1,11 +1,51 @@ -if( GRB_API_FORTRAN ) +if( GRIB_API_FORTRAN ) - message( WARNING "GRIB_API Fortran bindings still not supported with CMake builds" ) + ecbuild_enable_fortran( REQUIRED ) - ecbuild_enable_fortran( REQUIRED ) + set( CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/fortran/modules ) - # add here the building of fortran bindings + set( srcdir ${CMAKE_CURRENT_SOURCE_DIR} ) + set( bindir ${CMAKE_CURRENT_BINARY_DIR} ) - install( FILES grib_api_F77.h DESTINATION include/${PROJECT_NAME} ) + include_directories( ${srcdir} ${bindir} ${CMAKE_Fortran_MODULE_DIRECTORY} ) + + ecbuild_add_executable( TARGET grib_types + NOINSTALL + SOURCES grib_types.f90 grib_fortran_kinds.c ) + + add_custom_command( OUTPUT grib_kinds.h + COMMAND grib_types > grib_kinds.h + DEPENDS grib_types ) + + if( ${EC_SIZEOF_INT} EQUAL ${EC_SIZEOF_LONG} ) + set( _long_int_interface grib_f90_int.f90 ) + else() + set( _long_int_interface grib_f90_long_int.f90 ) + endif() + + add_custom_command( OUTPUT grib_f90.f90 + COMMAND cat ${srcdir}/grib_f90.f90.head ${srcdir}/${_long_int_interface} ${srcdir}/grib_f90.f90.tail > grib_f90.f90 + DEPENDS grib_f90.f90.head grib_f90.f90.tail grib_kinds.h ${_long_int_interface} ) + + ecbuild_add_library( TARGET grib_api_f77 + SOURCES grib_fortran.c grib_f77.c + LIBS grib_api ) + + ecbuild_add_library( TARGET grib_api_f90 + SOURCES grib_fortran.c grib_f90.f90 grib_kinds.h + GENERATED grib_f90.f90 + LIBS grib_api ) + + ecbuild_add_resources( TARGET fortran_resources + PACK + grib_fortran_prototypes.h grib_api_constants.h grib_api_externals.h + grib_api_visibility.h grib_types.f90 create_grib_f90.sh + grib_f90.f90.head grib_f90.f90.tail grib_f90_int.f90 grib_f90_long_int.f90 + same_int_long.f90 grib_fortran_kinds.c ) + + install( FILES grib_api_f77.h DESTINATION ${INSTALL_INCLUDE_DIR} ) + + install( CODE "EXECUTE_PROCESS (COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_Fortran_MODULE_DIRECTORY}/${CMAKE_CFG_INTDIR} ${CMAKE_INSTALL_PREFIX}/${INSTALL_INCLUDE_DIR})" ) endif() + diff --git a/grib_api_config.h.in b/grib_api_config.h.in index 71bf4b6b4..72958e52b 100644 --- a/grib_api_config.h.in +++ b/grib_api_config.h.in @@ -1,3 +1,13 @@ +/* + * Copyright 2005-2012 ECMWF. + * + * This software is licensed under the terms of the Apache Licence Version 2.0 + * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. + * + * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by + * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. + */ + #ifndef grib_api_config_h #define grib_api_config_h @@ -10,18 +20,79 @@ #define GRIB_API_REVISION_VERSION @GRIB_API_PATCH_VERSION@ #define GRIB_DEFINITION_PATH "@GRIB_API_DEFINITION_PATH@" + +#ifdef EC_HAVE_C_INLINE +#define GRIB_INLINE inline +#endif + +#define GRIB_LINUX_PTHREADS @GRIB_LINUX_PTHREADS@ + +#define GRIB_MEM_ALIGN @GRIB_MEM_ALIGN@ + +#define GRIB_PTHREADS @GRIB_PTHREADS@ + #define GRIB_SAMPLES_PATH "@GRIB_API_SAMPLES_PATH@" +#define GRIB_TEMPLATES_PATH "@GRIB_API_SAMPLES_PATH@" + +#define GRIB_TIMER @GRIB_TIMER@ + +/* headers */ + +#ifdef EC_HAVE_ASSERT_H +#define HAVE_ASSERT_H 1 +#endif + +#ifdef EC_HAVE_STRING_H +#define HAVE_STRING_H 1 +#endif + +#ifdef EC_HAVE_FSEEKO +#define HAVE_FSEEKO 1 +#endif + +#ifdef EC_HAVE_SYS_TYPES_H +#define HAVE_SYS_TYPES_H 1 +#endif + +#ifdef EC_HAVE_SYS_STAT_H +#define HAVE_SYS_STAT_H 1 +#endif + +#ifdef EC_HAVE_FCNTL_H +#define HAVE_FCNTL_H 1 +#endif + +#ifdef EC_HAVE_UNISTD_H +#define HAVE_UNISTD_H 1 +#endif + +#ifdef EC_HAVE_POSIX_MEMALIGN +#define POSIX_MEMALIGN 1 +#endif + +/* other */ + #define IEEE_BE @IEEE_BE@ + #define IEEE_LE @IEEE_LE@ +#define IS_BIG_ENDIAN @IS_BIG_ENDIAN@ + +#define MANAGE_MEM @MANAGE_MEM@ + +/* packages */ + #define HAVE_JPEG @HAVE_JPEG@ + #define HAVE_LIBJASPER @HAVE_LIBJASPER@ + #define HAVE_LIBOPENJPEG @HAVE_LIBOPENJPEG@ #define HAVE_LIBPNG @HAVE_LIBPNG@ #cmakedefine HAVE_LIBSZIP + #cmakedefine HAVE_NETCDF -#endif //grib_api_config_h +#endif /* grib_api_config_h */ diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index a9dce9e08..5a3686eeb 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,69 +1,82 @@ -### WARNING - support for Python with CMake still not ready +if( GRIB_API_PYTHON ) -# check for Numpy + message( WARNING "support for Python with CMake needs testing" ) -if(PYTHON_EXECUTABLE) + ecbuild_find_python( VERSION 2.5 ) + + find_package( SWIG ) + if( SWIG_FOUND ) + include( ${SWIG_USE_FILE} ) + endif() + + # check for Numpy + + if(PYTHON_EXECUTABLE) + + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/numpy_path.py "try: import numpy; print numpy.get_include()\nexcept: pass\n") + exec_program( ${PYTHON_EXECUTABLE} + ARGS "\"${CMAKE_CURRENT_BINARY_DIR}/determineNumpyPath.py\"" + OUTPUT_VARIABLE NUMPY_PATH ) + endif() + + find_path( PYTHON_NUMPY_INCLUDE_DIR arrayobject.h + "${NUMPY_PATH}/numpy/" + "${PYTHON_INCLUDE_PATH}/numpy/" + /usr/include/python2.6/numpy/ + /usr/include/python2.5/numpy/ + /usr/include/python2.4/numpy/ + /usr/include/python2.3/numpy/ + DOC "Directory where the arrayobject.h header file can be found. This file is part of the numpy package" ) + + if( PYTHON_NUMPY_INCLUDE_DIR ) + set(PYTHON_NUMPY_FOUND 1 CACHE INTERNAL "Python numpy development package is available") + endif() + + ############################################################################### + # swig python interface + + if( GRIB_API_PYTHON AND SWIG_FOUND AND PYTHONLIBS_FOUND ) + + # preparing for generating setup.py -- this may not be needed as cmake can do the swig + shared libs without libtool + + if( PYTHON_NUMPY_FOUND ) + set( DATA_HANDLER "numpy" ) + else() + set( DATA_HANDLER "array" ) + endif() - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/numpy_path.py "try: import numpy; print numpy.get_include()\nexcept: pass\n") - exec_program( ${PYTHON_EXECUTABLE} - ARGS "\"${CMAKE_CURRENT_BINARY_DIR}/determineNumpyPath.py\"" - OUTPUT_VARIABLE NUMPY_PATH - ) -endif() + set( BUILD_DIR "${PROJECT_SOURCE_DIR}" ) # setup.py assumes build_dir is same as source_dir -- not true for cmake builds + + set( LIB_PNG "${HAVE_LIBPNG}" ) -find_path( PYTHON_NUMPY_INCLUDE_DIR arrayobject.h - "${NUMPY_PATH}/numpy/" - "${PYTHON_INCLUDE_PATH}/numpy/" - /usr/include/python2.6/numpy/ - /usr/include/python2.5/numpy/ - /usr/include/python2.4/numpy/ - /usr/include/python2.3/numpy/ - DOC "Directory where the arrayobject.h header file can be found. This file is part of the numpy package" -) + set( LIB_JASPER ${HAVE_LIBJASPER} ) + get_filename_component(JASPER_DIR ${JASPER_INCLUDE_DIR} PATH ) + + set( LIB_OPENJPEG ${HAVE_LIBOPENJPEG} ) + get_filename_component(OPENJPEG_DIR ${OPENJPEG_INCLUDE_DIR} PATH ) + + include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) + + configure_file( setup.py.in setup.py ) -if( PYTHON_NUMPY_INCLUDE_DIR ) - set(PYTHON_NUMPY_FOUND 1 CACHE INTERNAL "Python numpy development package is available") -endif() + # compile swig interface -############################################################################### -# swig python interface - -if( GRIB_API_PYTHON AND SWIG_FOUND AND PYTHONLIBS_FOUND ) - - message( WARNING "Support for Python with CMake still not ready" ) - - # preparing for generating setup.py - - if( PYTHON_NUMPY_FOUND ) - set( DATA_HANDLER "numpy" ) - else() - set( DATA_HANDLER "array" ) + set(CMAKE_SWIG_FLAGS "") + + include_directories( ${PYTHON_INCLUDE_PATH} ) + + set_source_files_properties( gribapi_swig.i PROPERTIES C ON ) + + swig_add_module( gribapi_swig python gribapi_swig.i ) + + swig_link_libraries( gribapi_swig grib_api ${PYTHON_LIBRARIES} ) + + set(PYTHON_DEST "lib/python${PYTHON_VERSION}/site-packages" ) + + install(TARGETS _gribapi_swig DESTINATION ${PYTHON_DEST} ) + + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gribapi_swig.py DESTINATION ${PYTHON_DEST}) + endif() - if( PNG_LIBRARIES ) - set( LIB_PNG "${PNG_LIBRARIES}" ) - else() - set( LIB_PNG "" ) - endif() - - include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) - - # do the smae for JASPER and OPENJPEG - - configure_file( setup.py.in setup.py ) - - set(CMAKE_SWIG_FLAGS "") - - include_directories( ${PYTHON_INCLUDE_PATH} ) - - set_source_files_properties( gribapi_swig.i PROPERTIES C ON ) - - swig_add_module( gribapi_swig python gribapi_swig.i ) - - swig_link_libraries( gribapi_swig grib_api ${PYTHON_LIBRARIES} ) - - set(PYTHON_DEST "lib/python${PYTHON_VERSION}/site-packages" ) - install(TARGETS _gribapi_swig DESTINATION ${PYTHON_DEST} ) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gribapi_swig.py DESTINATION ${PYTHON_DEST}) - endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9ea69f86b..54f72d210 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -316,18 +316,12 @@ ecbuild_add_library( TARGET grib_api ${grib_api_extra_srcs} ${grib_api_srcs} INCLUDES - ${SZIP_INCLUDE_DIRS} - ${GRIB_API_NETCDF_LIBRARIES} - ${GRIB_API_JPG_INCLUDE_DIRS} - ${GRIB_API_PNG_INCLUDE_DIRS} + ${GRIB_API_EXTRA_INCLUDE_DIRS} LIBS - ${SZIP_LIBRARY} - ${GRIB_API_NETCDF_LIBRARIES} - ${GRIB_API_JPG_LIBRARIES} - ${GRIB_API_PNG_LIBRARIES} + ${GRIB_API_EXTRA_LIBRARIES} ${CMATH_LIBRARIES} ) # TODO: add support for jpg and png -install( FILES grib_api.h DESTINATION include/${PROJECT_NAME} ) +install( FILES grib_api.h DESTINATION include ) diff --git a/tests/ls.sh b/tests/ls.sh index d9a641226..9adf870e1 100755 --- a/tests/ls.sh +++ b/tests/ls.sh @@ -52,7 +52,7 @@ regular_latlon_surface.grib2 for file in $files do - [ -f $file ] + [ -f "$file" ] echo $file >> log ${tools_dir}grib_ls -l 40,28 $file | grep index | awk '{print $4;}' >> log done diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index c53a4c887..59b632970 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -2,6 +2,7 @@ ecbuild_add_library( TARGET grib_tools TYPE STATIC + NOINSTALL SOURCES grib_tools.c grib_options.c grib_tools.h LIBS grib_api ) @@ -20,6 +21,7 @@ foreach( tool ${grib_tools_bins} ) # here we use the fact that each tool has only one C file that matches its name ecbuild_add_executable( TARGET ${tool} SOURCES ${tool}.c + INCLUDES ${GRIB_API_EXTRA_INCLUDE_DIRS} LIBS grib_tools ) endforeach() @@ -28,8 +30,6 @@ endforeach() SOURCES list_keys.c LIBS grib_tools ) - # missing noinst_PROGRAMS # missing grib1to2 -