Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ option (PIO_USE_MPIIO "Enable support for MPI-IO auto detect" ON)
option (PIO_USE_MPISERIAL "Enable mpi-serial support (instead of MPI)" OFF)
option (PIO_USE_PNETCDF_VARD "Use pnetcdf put_vard " OFF)
option (WITH_PNETCDF "Require the use of PnetCDF" ON)
option (PIO_USE_GDAL "Enable support for Geospatial Data Abstraction Library ON")
option (BUILD_SHARED_LIBS "Build shared libraries" OFF)

if(APPLE)
Expand All @@ -110,6 +111,14 @@ else()
set(USE_VARD 0)
endif()

# Set a variable that appears in the config.h.in file.
if(PIO_USE_GDAL)
set(USE_GDAL 1)
else()
set(USE_GDAL 0)
endif()


# Set a variable that appears in the config.h.in file.
if(PIO_ENABLE_LOGGING)
set(ENABLE_LOGGING 1)
Expand Down
2 changes: 2 additions & 0 deletions cmake_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@
/* Does PIO support using pnetcdf for I/O? */
#cmakedefine _PNETCDF

#cmakedefine USE_GDAL

#endif /* _PIO_CONFIG_ */
12 changes: 12 additions & 0 deletions src/clib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ set (src topology.c pio_file.c pioc_support.c pio_lists.c
if (NETCDF_INTEGRATION)
set (src ${src} ../ncint/nc_get_vard.c ../ncint/ncintdispatch.c ../ncint/ncint_pio.c ../ncint/nc_put_vard.c)
endif ()
# This needs to be in an IF statement. using GDAL_INTEGRATION. But haven't figured that out yet.
if (USE_GDAL)
set (src ${src} pio_gdal.c)
endif()

add_library (pioc ${src})

Expand Down Expand Up @@ -173,6 +177,14 @@ if (PIO_USE_MPISERIAL)
endif ()
endif ()

#===== GDAL ===== <M.Long>
if (USE_GDAL)
target_include_directories (pioc
PUBLIC ${GDAL_INCLUDE_DIR})
target_link_libraries (pioc
PUBLIC "-L${GDAL_LIBRARY_PATH} -lgdal")
endif ()

include(CheckTypeSize)
check_type_size("size_t" SIZEOF_SIZE_T)
CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
Expand Down
23 changes: 22 additions & 1 deletion src/clib/pio.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <netcdf.h>
#include <netcdf_meta.h>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also include an #ifdef here.

#include <gdal.h>

#define NETCDF_VERSION_LE(Maj, Min, Pat) \
(((NC_VERSION_MAJOR == Maj) && (NC_VERSION_MINOR == Min) && (NC_VERSION_PATCH <= Pat)) || \
((NC_VERSION_MAJOR == Maj) && (NC_VERSION_MINOR < Min)) || (NC_VERSION_MAJOR < Maj))
Expand Down Expand Up @@ -606,6 +608,13 @@ typedef struct file_desc_t
* feature. One consequence is that PIO_IOTYPE_NETCDF4C files will
* not have deflate automatically turned on for each var. */
int ncint_file;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#ifdef here too

/** GDAL specific vars - M.Long */
GDALDatasetH *hDS;
int dateVarID; // Index of field with type OFTDate
int timeVarID; // Index of field with type OFTTime
int datetimeVarID; // Index of field with type OFTDatetime

} file_desc_t;

/**
Expand All @@ -624,7 +633,10 @@ enum PIO_IOTYPE
PIO_IOTYPE_NETCDF4C = 3,

/** NetCDF4 (HDF5) parallel */
PIO_IOTYPE_NETCDF4P = 4
PIO_IOTYPE_NETCDF4P = 4,

/** GDAL (serial only) */
PIO_IOTYPE_GDAL = 5
};

/**
Expand Down Expand Up @@ -1357,6 +1369,15 @@ extern "C" {
int nc_put_vard_ulonglong(int ncid, int varid, int decompid, const size_t recnum,
const unsigned long long *op);

/* These functions are for the GDAL integration layer. MSL - 9/7/2023 */
int GDALc_inq_fieldid(int fileid, const char *name, int *varidp);
int GDALc_inq_timeid(int fileid, int *timeid); // Is there a field of type OFTDate, OFTTime, or OFTDateTime?
int GDALc_openfile(int iosysid, int *fileIDp, GDALDatasetH *hDSp, int *iotype, const char *fname, bool mode);
int GDALc_sync(int fileid);
int GDALc_shp_get_int_field(int fileid);
int GDALc_shp_get_float_field(int fileid, int varid, const size_t *startp, const size_t *countp, float *ip);
int GDALc_shp_get_double_field(int fileid, int varid, const size_t *startp, const size_t *countp, double *ip);

#if defined(__cplusplus)
}
#endif
Expand Down
8 changes: 7 additions & 1 deletion src/clib/pio_darray.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ PIOc_write_darray_multi(int ncid, const int *varids, int ioid, int nvars,

/* Run these on all tasks if async is not in use, but only on
* non-IO tasks if async is in use. */
if (!ios->async || !ios->ioproc)
if ((!ios->async || !ios->ioproc) && (file->iotype != PIO_IOTYPE_GDAL))
{
/* Get the number of dims for this var. */
PLOG((3, "about to call PIOc_inq_varndims varids[0] = %d", varids[0]));
Expand Down Expand Up @@ -949,6 +949,12 @@ PIOc_read_darray(int ncid, int varid, int ioid, PIO_Offset arraylen,
if ((ierr = pio_read_darray_nc(file, iodesc, varid, iobuf)))
return pio_err(ios, file, ierr, __FILE__, __LINE__);
break;
#ifdef USE_GDAL
case PIO_IOTYPE_GDAL:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need #ifdef

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey. Yeah. I tried to set up an #ifdef. It's on the list of to-do

if ((ierr = pio_read_darray_shp(file, iodesc, varid, iobuf)))
return pio_err(ios, file, ierr, __FILE__, __LINE__);
break;
#endif
default:
return pio_err(NULL, NULL, PIO_EBADIOTYPE, __FILE__, __LINE__);
}
Expand Down
6 changes: 6 additions & 0 deletions src/clib/pio_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ PIOc_closefile(int ncid)
ierr = ncmpi_close(file->fh);
break;
#endif
case PIO_IOTYPE_GDAL:
if (ios->io_rank == 0) {
ierr = GDALClose((void*)file->hDS);
printf("GDALClose ierr: %d\n",ierr);
}
break;
default:
return pio_err(ios, file, PIO_EBADIOTYPE, __FILE__, __LINE__);
}
Expand Down
Loading
Loading