Skip to content

Commit

Permalink
Try compiling C example for netcdf
Browse files Browse the repository at this point in the history
  • Loading branch information
djhoese committed Jul 20, 2023
1 parent cc69b75 commit 4ad0b53
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ jobs:
run: |
python -m pip install --no-deps -e .
# - name: Run test_write_netcdf
# shell: cmd
# run: |
# cl test_write_netcdf.c /out:test_write_netcdf.exe
# test_write_netcdf.exe
- name: Run test_write_netcdf
shell: bash -l {0}
run: |
gcc -o test_write_netcdf -L "${CONDA_PREFIX}/lib" -I "${CONDA_PREFIX}/include" -lnetcdf test_write_netcdf.c
./test_write_netcdf
- name: Run test_netcdf manually - netcdf4 python close
shell: bash -l {0}
run: |
Expand Down
2 changes: 2 additions & 0 deletions continuous_integration/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ dependencies:
# PNetCDF (build 109)
# - libnetcdf
- netcdf4
# - vc # [win]
- gcc
22 changes: 22 additions & 0 deletions test_write_netcdf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <netcdf.h>
#include <stdio.h>
#include <string.h>

/* This macro handles errors by outputting a message to stdout and
then exiting. */
#define NC_EXAMPLE_ERROR 2 /* This is the exit code for failure. */
#define BAIL(e) do { \
printf("Bailing out in file %s, line %d, error:%s.\n", \
__FILE__, __LINE__, nc_strerror(e)); \
return NC_EXAMPLE_ERROR; \
} while (0)

int main() {
int res, ncid;
res = nc_create("test_netcdf_c.nc", NC_CLOBBER, &ncid);
if (res) {
BAIL(res);
}
printf("SUCCESS!\n");
return 0;
}

0 comments on commit 4ad0b53

Please sign in to comment.