Commit b3e70ee2 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

configure: added support for --with-curl

parent f421a3e7
......@@ -148,6 +148,8 @@ CLDFLAGS = @CLDFLAGS@
CLIBS = @CLIBS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CURL_INCLUDE = @CURL_INCLUDE@
CURL_LDFLAGS = @CURL_LDFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
......
......@@ -42,6 +42,7 @@ case "${HOSTNAME}" in
--with-szlib=$HOME/local \
--with-udunits2=$HOME/local/udunits-2.1.24 \
--with-proj=/opt/local \
--with-curl=/opt/local \
--with-libxml2=/usr \
--with-magics=/Users/m214003/local/magics-2.14.9 \
CC=gcc CFLAGS="-g -pipe -D_REENTRANT -Wall -W -Wfloat-equal -pedantic -O3 -march=native -fopenmp -DHAVE_LIBYAC -I/Users/m214003/cdt/work/YAC/src" \
......
......@@ -635,6 +635,8 @@ MAGICS_ROOT
MAGICS_LIBS
UDUNITS_INCLUDE
UDUNITS_LDFLAGS
CURL_INCLUDE
CURL_LDFLAGS
PROJ_INCLUDE
PROJ_LDFLAGS
ENABLE_IEG
......@@ -810,6 +812,7 @@ enable_extra
enable_ieg
with_fftw3
with_proj
with_curl
with_udunits2
with_magics
with_libxml2
......@@ -1499,6 +1502,7 @@ Optional Packages:
--without-fftw3 disable support for fftw3
--with-proj=<directory> Specify location of PROJ library for cartographic
projections.
--with-curl=<directory> Specify location of CURL library.
--with-udunits2=<directory>
Specify location of UDUNITS2 library.
--with-magics=<yes|no|directory>
......@@ -18605,6 +18609,188 @@ $as_echo_n "checking for the PROJ library... " >&6; }
$as_echo "suppressed" >&6; }
fi
 
# ----------------------------------------------------------------------
# Checks for CURL library
# Check whether --with-curl was given.
if test "${with_curl+set}" = set; then :
withval=$with_curl; case "$with_curl" in #(
no) :
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for curl library" >&5
$as_echo_n "checking for curl library... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: suppressed" >&5
$as_echo "suppressed" >&6; } ;; #(
yes) :
for ac_header in curl/curl.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "curl/curl.h" "ac_cv_header_curl_curl_h" "$ac_includes_default"
if test "x$ac_cv_header_curl_curl_h" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_CURL_CURL_H 1
_ACEOF
fi
done
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing curl_global_init" >&5
$as_echo_n "checking for library containing curl_global_init... " >&6; }
if ${ac_cv_search_curl_global_init+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_func_search_save_LIBS=$LIBS
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char curl_global_init ();
int
main ()
{
return curl_global_init ();
;
return 0;
}
_ACEOF
for ac_lib in '' curl; do
if test -z "$ac_lib"; then
ac_res="none required"
else
ac_res=-l$ac_lib
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
fi
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_search_curl_global_init=$ac_res
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext
if ${ac_cv_search_curl_global_init+:} false; then :
break
fi
done
if ${ac_cv_search_curl_global_init+:} false; then :
else
ac_cv_search_curl_global_init=no
fi
rm conftest.$ac_ext
LIBS=$ac_func_search_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_curl_global_init" >&5
$as_echo "$ac_cv_search_curl_global_init" >&6; }
ac_res=$ac_cv_search_curl_global_init
if test "$ac_res" != no; then :
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
$as_echo "#define HAVE_LIBCURL 1" >>confdefs.h
else
as_fn_error $? "Could not link to CURL library!" "$LINENO" 5
fi
CURL_LDFLAGS=" -lcurl"
CURL_INCLUDE=""
;; #(
*) :
CURL_ROOT=$with_curl
if test -d "$CURL_ROOT"; then :
LDFLAGS="-L$CURL_ROOT/lib $LDFLAGS"
CPPFLAGS="-I$CURL_ROOT/include $CPPFLAGS"
for ac_header in curl/curl.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "curl/curl.h" "ac_cv_header_curl_curl_h" "$ac_includes_default"
if test "x$ac_cv_header_curl_curl_h" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_CURL_CURL_H 1
_ACEOF
fi
done
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing curl_global_init" >&5
$as_echo_n "checking for library containing curl_global_init... " >&6; }
if ${ac_cv_search_curl_global_init+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_func_search_save_LIBS=$LIBS
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char curl_global_init ();
int
main ()
{
return curl_global_init ();
;
return 0;
}
_ACEOF
for ac_lib in '' curl; do
if test -z "$ac_lib"; then
ac_res="none required"
else
ac_res=-l$ac_lib
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
fi
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_search_curl_global_init=$ac_res
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext
if ${ac_cv_search_curl_global_init+:} false; then :
break
fi
done
if ${ac_cv_search_curl_global_init+:} false; then :
else
ac_cv_search_curl_global_init=no
fi
rm conftest.$ac_ext
LIBS=$ac_func_search_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_curl_global_init" >&5
$as_echo "$ac_cv_search_curl_global_init" >&6; }
ac_res=$ac_cv_search_curl_global_init
if test "$ac_res" != no; then :
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
$as_echo "#define HAVE_LIBCURL 1" >>confdefs.h
else
as_fn_error $? "Could not link to CURL library!" "$LINENO" 5
fi
CURL_LDFLAGS=" -L$CURL_ROOT/lib -lcurl"
CURL_INCLUDE=" -I$CURL_ROOT/include"
else
as_fn_error $? "$CURL_ROOT is not a directory! CURL suppressed" "$LINENO" 5
fi ;; #(
*) :
;;
esac
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for the CURL library" >&5
$as_echo_n "checking for the CURL library... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: suppressed" >&5
$as_echo "suppressed" >&6; }
fi
# ----------------------------------------------------------------------
# Link application with UDUNITS2 library
 
......
......@@ -88,6 +88,8 @@ CLDFLAGS = @CLDFLAGS@
CLIBS = @CLIBS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CURL_INCLUDE = @CURL_INCLUDE@
CURL_LDFLAGS = @CURL_LDFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
......
......@@ -354,6 +354,33 @@ AC_ARG_WITH([proj],
[AC_MSG_CHECKING([for the PROJ library])
AC_MSG_RESULT([suppressed])])
# ----------------------------------------------------------------------
# Checks for CURL library
AC_ARG_WITH([curl],
[AS_HELP_STRING([--with-curl=<directory>],
[Specify location of CURL library.])],
[AS_CASE(["$with_curl"],
[no],[AC_MSG_CHECKING([for curl library])
AC_MSG_RESULT([suppressed])],
[yes],[AC_CHECK_HEADERS([curl/curl.h])
AC_SEARCH_LIBS([curl_global_init],[curl],[AC_DEFINE([HAVE_LIBCURL],[1],[Define to 1 for CURL support])],
[AC_MSG_ERROR([Could not link to CURL library!])])
AC_SUBST([CURL_LDFLAGS],[" -lcurl"])
AC_SUBST([CURL_INCLUDE],[""])],
[*],[CURL_ROOT=$with_curl
AS_IF([test -d "$CURL_ROOT"],
[LDFLAGS="-L$CURL_ROOT/lib $LDFLAGS"
CPPFLAGS="-I$CURL_ROOT/include $CPPFLAGS"
AC_CHECK_HEADERS([curl/curl.h])
AC_SEARCH_LIBS([curl_global_init],
[curl],
[AC_DEFINE([HAVE_LIBCURL],[1],[Define to 1 for CURL support])],
[AC_MSG_ERROR([Could not link to CURL library!])])
AC_SUBST([CURL_LDFLAGS],[" -L$CURL_ROOT/lib -lcurl"])
AC_SUBST([CURL_INCLUDE],[" -I$CURL_ROOT/include"])],
[AC_MSG_ERROR([$CURL_ROOT is not a directory! CURL suppressed])])])],
[AC_MSG_CHECKING([for the CURL library])
AC_MSG_RESULT([suppressed])])
# ----------------------------------------------------------------------
# Link application with UDUNITS2 library
AC_ARG_WITH([udunits2],
[AS_HELP_STRING([--with-udunits2=<directory>],
......
......@@ -306,6 +306,8 @@ CLDFLAGS = @CLDFLAGS@
CLIBS = @CLIBS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CURL_INCLUDE = @CURL_INCLUDE@
CURL_LDFLAGS = @CURL_LDFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
......
......@@ -69,6 +69,7 @@ char *Progname;
int ompNumThreads = 1;
char *cdoGridSearchDir = NULL;
int cdoDefaultFileType = CDI_UNDEFID;
int cdoDefaultDataType = CDI_UNDEFID;
int cdoDefaultTimeType = CDI_UNDEFID;
......@@ -797,6 +798,23 @@ void get_env_vars(void)
{
char *envstr;
envstr = getenv("CDO_GRID_SEARCH_DIR");
if ( envstr )
{
size_t len = strlen(envstr);
if ( len > 0 )
{
len += 2;
cdoGridSearchDir = (char *) malloc(len);
memcpy(cdoGridSearchDir, envstr, len-1);
if ( cdoGridSearchDir[len-3] != '/' )
{
cdoGridSearchDir[len-2] = '/';
cdoGridSearchDir[len-1] = 0;
}
}
}
envstr = getenv("CDO_LOG_OFF");
if ( envstr )
{
......@@ -1273,5 +1291,7 @@ int main(int argc, char *argv[])
/* malloc_stats(); */
if ( cdoGridSearchDir ) free(cdoGridSearchDir);
return (status);
}
......@@ -9,6 +9,9 @@
/* Define to 1 for DATA support */
#undef ENABLE_DATA
/* Define to 1 if you have the <curl/curl.h> header file. */
#undef HAVE_CURL_CURL_H
/* Define to 1 if you have the declaration of `isnan', and to 0 if you don't.
*/
#undef HAVE_DECL_ISNAN
......@@ -46,6 +49,9 @@
/* Define to 1 for GRIB1 decoding/encoding with cgribex */
#undef HAVE_LIBCGRIBEX
/* Define to 1 for CURL support */
#undef HAVE_LIBCURL
/* Define to 1 for EXTRA interface */
#undef HAVE_LIBEXTRA
......
......@@ -1420,52 +1420,232 @@ int gridCurvilinearToRegular(int gridID1)
return (gridID2);
}
#include <sys/stat.h>
/*
* Search for filename.
*/
int search_file(const char *restrict directory, const char *restrict filename)
{
struct stat buf;
int status;
status = stat(directory, &buf);
if ( status == 0 )
{
status = stat(filename, &buf);
if ( status == 0 ) return 0;
}
else
{
perror(directory);
}
return 1;
}
#if defined (HAVE_LIBCURL)
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#include <errno.h>
#endif
/*
* callback function for curl for writing the network retrieved grid file
*/
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written;
written = fwrite(ptr, size, nmemb, stream);
return written;
}
/* code from grid_tools.2 */
int download_gridfile(const char *restrict uri, const char *restrict basename)
{
#if defined (HAVE_LIBCURL)
// As curl_easy_init calls non-thread safe curl_global_init the libcurl developer advice
// to call curl_global_init first and before potential thread spawning.
CURLcode ret;
CURL *hd;
double length;
int status;
int curlflags = CURL_GLOBAL_DEFAULT;
#if defined (CURL_GLOBAL_ACK_EINTR)
curlflags |= CURL_GLOBAL_ACK_EINTR;
#endif
ret = curl_global_init(curlflags);
if(ret != 0)
{
fprintf(stderr, "ERROR: %s!\n", curl_easy_strerror(ret));
return -1;
}
hd = curl_easy_init();
if (hd == NULL)
{
fprintf(stderr, "ERROR: could not get curl handler.\n");
return -1;
}
else
{
FILE *fp;
fp = fopen(basename, "w");
if (fp == NULL)
{
fprintf(stderr, "ERROR: could not open local output file %s. %s.\n", basename, strerror(errno));
return -1;
}
curl_easy_setopt(hd, CURLOPT_URL, uri);
curl_easy_setopt(hd, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(hd, CURLOPT_WRITEDATA, fp);
ret = curl_easy_perform(hd);
if (ret == 0)
{
fclose(fp);
curl_easy_getinfo(hd, CURLINFO_SIZE_DOWNLOAD, &length);
if ( cdoVerbose ) cdoPrint("File %s downloaded - size: %.0lf byte", basename, length);
curl_easy_cleanup(hd);
return 0;
}
else
{
fclose(fp);
status = remove(basename);
if (status == -1) perror(basename);
fprintf(stderr, "ERROR: %s. Download %s failed.\n\n", curl_easy_strerror(ret), basename);
curl_easy_cleanup(hd);
}
}
#else
cdoWarning("CURL support not compiled in!");
#endif
return 1;
}
int referenceToGrid(int gridID1)
{
int gridID2 = -1;
int gridtype, gridsize;
int offset = 7;
char griduri[8912];
char gridpath[8912];
gridsize = gridInqSize(gridID1);
griduri[0] = 0;
gridpath[0] = 0;
if ( gridInqReference(gridID1, NULL) ) gridInqReference(gridID1, griduri);
if ( gridInqReference(gridID1, NULL) )
if ( griduri[0] == 0 )
{
cdoWarning("Reference to grid not available!");
}
else
{
int status;
int streamID;
int number, position;
char gridfile[8912];
number = gridInqNumber(gridID1);
position = gridInqPosition(gridID1);
gridInqReference(gridID1, gridfile);
char *basename = strrchr(griduri, '/') + 1;
strcpy(gridpath, "./");
strcat(gridpath, basename);
if ( cdoVerbose ) cdoPrint("Search for horizontal grid file \"%s\"", gridpath);
/* scan local directory for file */
status = search_file("./", gridpath);
if ( status != 0 )
{
extern char *cdoGridSearchDir;
if ( cdoGridSearchDir != NULL)
{
strcpy(gridpath, cdoGridSearchDir);
strcat(gridpath, basename);
if ( cdoVerbose ) cdoPrint("Search for horizontal grid file \"%s\"", gridpath);
/* scan directory given by environment variable */
status = search_file(cdoGridSearchDir, gridpath);
}
if ( gridfile[offset] != '/' ) offset--;
streamID = streamOpenRead(&gridfile[offset]);
if ( streamID >= 0 )
if ( status != 0 )
{
//strcpy(griduri, "http://icon-downloads.mpimet.mpg.de:/grids/public/edzw/icon_grid_0001_R02B05_R.nc");
//char *basename = strrchr(griduri, '/') + 1;
if ( cdoVerbose ) cdoPrint("Download horizontal grid file %s to %s", griduri, basename);
status = download_gridfile(griduri, basename);
}
}
if ( status == 0 )
{
int vlistID, gridID = -1;
int ngrids;
vlistID = streamInqVlist(streamID);
ngrids = vlistNgrids(vlistID);
if ( position > 0 && position <= ngrids )
if ( cdoVerbose ) cdoPrint("Horizontal grid file used: %s", gridpath);
gridsize = gridInqSize(gridID1);
number = gridInqNumber(gridID1);
position = gridInqPosition(gridID1);
streamID = streamOpenRead(gridpath);
if ( streamID >= 0 )
{
gridID = vlistGrid(vlistID, position-1);
if ( gridInqSize(gridID) == gridsize )
gridID2 = gridDuplicate(gridID);
int vlistID, gridID = -1;
int ngrids;
vlistID = streamInqVlist(streamID);
ngrids = vlistNgrids(vlistID);
if ( position > 0 && position <= ngrids )
{
gridID = vlistGrid(vlistID, position-1);
if ( gridInqSize(gridID) == gridsize )
gridID2 = gridDuplicate(gridID);
else
cdoWarning("Grid size %d on position %d do not match! Reference=%s", gridsize, position, gridpath);
}
else if ( position == 0 )
{
for ( int grididx = 0; grididx < ngrids; ++grididx )
{
gridID = vlistGrid(vlistID, grididx);
if ( gridInqSize(gridID) == gridsize )
{
gridID2 = gridDuplicate(gridID);
break;
}
}
}
else
cdoWarning("Grid size %d on position %d do not match! Reference=%s", gridsize, position, gridfile);
cdoWarning("Grid position %d not available! Reference=%s", position, gridpath);
streamClose(streamID);
}
else
cdoWarning("Grid position %d not available! Reference=%s", position, gridfile);
cdiError(streamID, "Open failed on horizontal grid file >%s<", gridpath);
}
streamClose(streamID);
if ( gridID2 != -1 )
{
char uuidOfHGrid1[16];
char uuidOfHGrid2[16];
memset(uuidOfHGrid1, 0, 16);
memset(uuidOfHGrid2, 0, 16);
gridInqUUID(gridID1, uuidOfHGrid1);
gridInqUUID(gridID2, uuidOfHGrid2);
if ( uuidOfHGrid1[0] != 0 && uuidOfHGrid1[0] != 0 && memcmp(uuidOfHGrid1, uuidOfHGrid2, 16) != 0 )
cdoWarning("UUID of horizontal grids differ!");
int number1 = gridInqNumber(gridID1);
int number2 = gridInqNumber(gridID2);
if ( number1 > 0 && number2 > 0 && number1 != number2 )
cdoWarning("Number of grid used of horizontal grids differ!");
}
else
cdoWarning("Reference to grid not found! Path=%s", gridfile);
}
else
{
cdoWarning("No reference to grid found!");
}
return (gridID2);
......
......@@ -89,6 +89,8 @@ CLDFLAGS = @CLDFLAGS@
CLIBS = @CLIBS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CURL_INCLUDE = @CURL_INCLUDE@
CURL_LDFLAGS = @CURL_LDFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment