Skip to content

Commit 9a56514

Browse files
committed
bring up to latest main, still debugging
1 parent 5ccfb3f commit 9a56514

12 files changed

Lines changed: 55 additions & 33 deletions

CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This is the CMake build file for the main directory.
44
# Jim Edwards
55

6-
cmake_minimum_required(VERSION 3.10)
6+
cmake_minimum_required(VERSION 3.18)
77
project(PIO LANGUAGES C)
88

99
# The project version number (modern style)
@@ -141,9 +141,12 @@ endif()
141141

142142
# Set a variable that appears in the config.h.in file.
143143
if(PIO_USE_GDAL)
144-
set(USE_GDAL 1)
144+
find_package(GDAL REQUIRED)
145+
if(GDAL_FOUND)
146+
set(PIO_ENABLE_GDAL 1)
147+
endif()
145148
else()
146-
set(USE_GDAL 0)
149+
set(PIO_ENABLE_GDAL 0)
147150
endif()
148151

149152

cmake_config.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@
4646
/* Does PIO support using pnetcdf for I/O? */
4747
#cmakedefine _PNETCDF
4848

49-
#cmakedefine USE_GDAL
49+
#cmakedefine PIO_ENABLE_GDAL
5050

5151
#endif /* _PIO_CONFIG_ */

src/clib/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if (NETCDF_INTEGRATION)
2929
set (src ${src} ../ncint/nc_get_vard.c ../ncint/ncintdispatch.c ../ncint/ncint_pio.c ../ncint/nc_put_vard.c)
3030
endif ()
3131
# This needs to be in an IF statement. using GDAL_INTEGRATION. But haven't figured that out yet.
32-
if (USE_GDAL)
32+
if (PIO_USE_GDAL)
3333
set (src ${src} pio_gdal.c)
3434
endif()
3535

@@ -193,11 +193,11 @@ endif()
193193

194194

195195
#===== GDAL ===== <M.Long>
196-
if (USE_GDAL)
196+
if (PIO_USE_GDAL)
197197
target_include_directories (pioc
198-
PUBLIC ${GDAL_INCLUDE_DIR})
198+
PUBLIC ${GDAL_INCLUDE_DIRS})
199199
target_link_libraries (pioc
200-
PUBLIC "-L${GDAL_LIBRARY_PATH} -lgdal")
200+
PUBLIC ${GDAL_LIBRARIES})
201201
endif ()
202202

203203
include(CheckTypeSize)

src/clib/pio.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
#include <netcdf.h>
2020
#include <netcdf_meta.h>
21-
21+
#ifdef PIO_ENABLE_GDAL
2222
#include <gdal.h>
23-
23+
#endif
2424
#define NETCDF_VERSION_LE(Maj, Min, Pat) \
2525
(((NC_VERSION_MAJOR == Maj) && (NC_VERSION_MINOR == Min) && (NC_VERSION_PATCH <= Pat)) || \
2626
((NC_VERSION_MAJOR == Maj) && (NC_VERSION_MINOR < Min)) || (NC_VERSION_MAJOR < Maj))
@@ -611,12 +611,13 @@ typedef struct file_desc_t
611611
* feature. One consequence is that PIO_IOTYPE_NETCDF4C files will
612612
* not have deflate automatically turned on for each var. */
613613
int ncint_file;
614-
614+
#ifdef PIO_ENABLE_GDAL
615615
/** GDAL specific vars - M.Long */
616616
GDALDatasetH *hDS;
617617
int dateVarID; // Index of field with type OFTDate
618618
int timeVarID; // Index of field with type OFTTime
619619
int datetimeVarID; // Index of field with type OFTDatetime
620+
#endif
620621

621622
} file_desc_t;
622623

@@ -640,6 +641,7 @@ enum PIO_IOTYPE
640641

641642
/** GDAL (serial only) */
642643
PIO_IOTYPE_GDAL = 5
644+
643645
};
644646

645647
/**
@@ -1371,7 +1373,7 @@ extern "C" {
13711373
const long long *op);
13721374
int nc_put_vard_ulonglong(int ncid, int varid, int decompid, const size_t recnum,
13731375
const unsigned long long *op);
1374-
1376+
#ifdef PIO_ENABLE_GDAL
13751377
/* These functions are for the GDAL integration layer. MSL - 9/7/2023 */
13761378
int GDALc_inq_fieldid(int fileid, const char *name, int *varidp);
13771379
int GDALc_inq_timeid(int fileid, int *timeid); // Is there a field of type OFTDate, OFTTime, or OFTDateTime?
@@ -1385,7 +1387,7 @@ extern "C" {
13851387
int pio_read_darray_shp(file_desc_t *file, io_desc_t *iodesc, int vid, void *iobuf);
13861388
int pio_gdal_read_features_par(int fileid, int varid, io_desc_t *ddesc, float *ip);
13871389
int pio_read_darray_shp_par(file_desc_t *file, io_desc_t *iodesc, int vid, void *iobuf);
1388-
1390+
#endif
13891391
#if defined(__cplusplus)
13901392
}
13911393
#endif

src/clib/pio_darray.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ PIOc_write_darray_multi(int ncid, const int *varids, int ioid, int nvars,
197197

198198
}
199199

200-
if ((!ios->async || !ios->ioproc) && (file->iotype = PIO_IOTYPE_GDAL))
200+
if ((!ios->async || !ios->ioproc) && (file->iotype == PIO_IOTYPE_GDAL))
201201
{
202202
// Do we even need to sort out fndims here? (MSL<<>>)
203203
fndims = 1;
@@ -961,7 +961,7 @@ PIOc_read_darray(int ncid, int varid, int ioid, PIO_Offset arraylen,
961961
if ((ierr = pio_read_darray_nc(file, iodesc, varid, iobuf)))
962962
return pio_err(ios, file, ierr, __FILE__, __LINE__);
963963
break;
964-
#ifdef USE_GDAL
964+
#ifdef PIO_ENABLE_GDAL
965965
case PIO_IOTYPE_GDAL:
966966
if ((ierr = pio_read_darray_shp_par(file, iodesc, varid, iobuf)))
967967
return pio_err(ios, file, ierr, __FILE__, __LINE__);

src/clib/pio_darray_int.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,11 +996,13 @@ recv_and_write_data(file_desc_t *file, const int *varids, const int *frame,
996996

997997
/* Call the netCDF functions to write the data. */
998998
if (needtowrite) {
999+
#ifdef PIO_ENABLE_GDAL
1000+
if (file->iotype == PIO_IOTYPE_GDAL)
1001+
ierr = GDALc_shp_write_float_field(file->pio_ncid, varids[nv], start, count, bufptr);
1002+
#endif
9991003
if (file->iotype == PIO_IOTYPE_NETCDF)
10001004
if ((ierr = nc_put_vara(file->fh, varids[nv], start, count, bufptr)))
10011005
return check_netcdf2(ios, NULL, ierr, __FILE__, __LINE__);
1002-
if (file->iotype == PIO_IOTYPE_GDAL)
1003-
ierr = GDALc_shp_write_float_field(file->pio_ncid, varids[nv], start, count, bufptr);
10041006
}
10051007

10061008
} /* next var */

src/clib/pio_file.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,14 @@ PIOc_closefile(int ncid)
283283
ierr = ncmpi_close(file->fh);
284284
break;
285285
#endif
286+
#ifdef PIO_ENABLE_GDAL
286287
case PIO_IOTYPE_GDAL:
287288
if (ios->io_rank == 0) {
288289
GDALClose((void*)file->hDS);
289290
printf("GDALClose ierr: %d\n",ierr);
290291
}
291292
break;
293+
#endif
292294
default:
293295
return pio_err(ios, file, PIO_EBADIOTYPE, __FILE__, __LINE__);
294296
}
@@ -477,8 +479,10 @@ PIOc_sync(int ncid)
477479
flush_output_buffer(file, true, 0);
478480
break;
479481
#endif
482+
#ifdef PIO_ENABLE_GDAL
480483
case PIO_IOTYPE_GDAL:
481484
break;
485+
#endif
482486
default:
483487
return pio_err(ios, file, PIO_EBADIOTYPE, __FILE__, __LINE__);
484488
}

src/clib/pio_gdal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <config.h>
22
#include <pio.h>
33
#include <pio_internal.h>
4-
#ifdef USE_GDAL
4+
#ifdef PIO_ENABLE_GDAL
55
#include <ogr_api.h>
66

77
/**

src/clib/pio_internal.h

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

9292
#define PIO_DATATYPE_NULL MPI_CHAR
9393

94-
#ifdef USE_GDAL
94+
#ifdef PIO_ENABLE_GDAL
9595
int
9696
pio_read_darray_shp(file_desc_t *file, io_desc_t *iodesc, int vid,
9797
void *iobuf);

src/clib/pioc_support.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,10 +3137,10 @@ iotype_is_valid(int iotype)
31373137
if (iotype == PIO_IOTYPE_PNETCDF)
31383138
ret++;
31393139
#endif /* _PNETCDF */
3140-
3140+
#ifdef PIO_ENABLE_GDAL
31413141
if (iotype == PIO_IOTYPE_GDAL)
31423142
ret++;
3143-
3143+
#endif
31443144
return ret;
31453145
}
31463146

0 commit comments

Comments
 (0)