Skip to content
Closed
10 changes: 10 additions & 0 deletions src/clib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ 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.
set (src ${src} pio_gdal.c)

add_library (pioc ${src})

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

#===== GDAL ===== <M.Long>
#if (GDAL_Found)
target_include_directories (pioc
PUBLIC ${GDAL_INCLUDE_DIR})
target_link_libraries (pioc
PUBLIC ${GDAL_LIBRARY})
#endif ()

include(CheckTypeSize)
check_type_size("size_t" SIZEOF_SIZE_T)
CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
Expand Down
22 changes: 21 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
Copy Markdown
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
Copy Markdown
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,14 @@ 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_double_field(int fileid, int varid, const size_t *startp, const size_t *countp, double *ip);

#if defined(__cplusplus)
}
#endif
Expand Down
6 changes: 5 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,10 @@ 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;
case PIO_IOTYPE_GDAL:
Copy link
Copy Markdown
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
Copy Markdown
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;
default:
return pio_err(NULL, NULL, PIO_EBADIOTYPE, __FILE__, __LINE__);
}
Expand Down
4 changes: 4 additions & 0 deletions src/clib/pio_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ PIOc_closefile(int ncid)
ierr = ncmpi_close(file->fh);
break;
#endif
case PIO_IOTYPE_GDAL:
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