netcdf-c: Unable to use absolute file path on mingw64 with NetCDF 4.8.1

  • the version of the software with which you are encountering an issue

NetCDF 4.8.1

  • environmental information (i.e. Operating System, compiler info, java version, python version, etc.) Window 10, mingw64 gcc (version 10.1.0)

  • a description of the issue with the steps needed to reproduce it

The C file below works with NetCDF 4.7.4 but it produces an error with Error: No such file or directory with NetCDF 4.8.1. I am debugging an issue for the Julia NetCDF package which today upgraded to 4.8.1. Linux and Mac OS X are fine. In Julia, all C packages are cross-compiled from a Linux host. I was able to reproduce the issue indepdently of Julia.

This file is the sample simple_xy_wr.c file with an adapted filename to show the error.

#include <stdlib.h>
#include <stdio.h>
#include <netcdf.h>

/* This is the name of the data file we will create. */
/* fails in 4.8.1; works in 4.7.4 */
#define FILE_NAME "C:\\Users\\ALEXAN~1\\AppData\\Local\\Temp\\foobar.nc"

/* works 4.8.1 */
/*#define FILE_NAME "..\\AppData\\Local\\Temp\\foobar.nc"*/

/* works 4.8.1 */
/*#define FILE_NAME "Test\\foobar.nc"*/

/* We are writing 2D data, a 6 x 12 grid. */
#define NDIMS 2
#define NX 6
#define NY 12

/* Handle errors by printing an error message and exiting with a
 * non-zero status. */
#define ERRCODE 2
#define ERR(e) {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);}

int
main()
{
   /* When we create netCDF variables and dimensions, we get back an
    * ID for each one. */
   int ncid, x_dimid, y_dimid, varid;
   int dimids[NDIMS];

   /* This is the data array we will write. It will just be filled
    * with a progression of numbers for this example. */
   int data_out[NX][NY];

   /* Loop indexes, and error handling. */
   int x, y, retval;

   /* Create some pretend data. If this wasn't an example program, we
    * would have some real data to write, for example, model
    * output. */
   for (x = 0; x < NX; x++)
      for (y = 0; y < NY; y++)
	 data_out[x][y] = x * NY + y;

   /* Always check the return code of every netCDF function call. In
    * this example program, any retval which is not equal to NC_NOERR
    * (0) will cause the program to print an error message and exit
    * with a non-zero return code. */

   /* Create the file. The NC_CLOBBER parameter tells netCDF to
    * overwrite this file, if it already exists.*/
   if ((retval = nc_create(FILE_NAME, NC_CLOBBER, &ncid)))
      ERR(retval);

   /* Define the dimensions. NetCDF will hand back an ID for each. */
   if ((retval = nc_def_dim(ncid, "x", NX, &x_dimid)))
      ERR(retval);
   if ((retval = nc_def_dim(ncid, "y", NY, &y_dimid)))
      ERR(retval);

   /* The dimids array is used to pass the IDs of the dimensions of
    * the variable. */
   dimids[0] = x_dimid;
   dimids[1] = y_dimid;

   /* Define the variable. The type of the variable in this case is
    * NC_INT (4-byte integer). */
   if ((retval = nc_def_var(ncid, "data", NC_INT, NDIMS, 
			    dimids, &varid)))
      ERR(retval);

   /* End define mode. This tells netCDF we are done defining
    * metadata. */
   if ((retval = nc_enddef(ncid)))
      ERR(retval);

   /* Write the pretend data to the file. Although netCDF supports
    * reading and writing subsets of data, in this case we write all
    * the data in one operation. */
   if ((retval = nc_put_var_int(ncid, varid, &data_out[0][0])))
      ERR(retval);

   /* Close the file. This frees up any internal netCDF resources
    * associated with the file, and flushes any buffers. */
   if ((retval = nc_close(ncid)))
      ERR(retval);

   printf("*** SUCCESS writing example file simple_xy.nc!\n");
   return 0;
}

The code is compiled in a MSYS2 shell as follows:

$ gcc -o simple_xy_wr_nc481 -I/c/Users/Alexander\ Barth/.julia/artifacts/ae78b073115f5cca9ab13a23994bdd930ecfe887/include/ simple_xy_wr2.c -L/c/Users/Alexander\ Barth/.julia/artifacts/ae78b073115f5cca9ab13a23994bdd930ecfe887/lib -lnetcdf

Alexander Barth@alex-laptop MINGW64 /c/Users/Alexander Barth/Downloads
$ ./simple_xy_wr_nc481.exe
Error: No such file or directory

The path /c/Users/Alexander Barth/.julia/artifacts/ae78b073115f5cca9ab13a23994bdd930ecfe887/ contains the NetCDF 4.8.1 library.

Prior to all tests, I checked that the file to be written does not exists (any more).

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 46 (21 by maintainers)

Commits related to this issue

Most upvoted comments

Well in this case GitHub actions supporting Windows means you can start up a VM, that happens to be pre-populated with a bunch of dev packages. You can of course install on top of that pretty much whatever you feel like.