Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4.8.0 ncgen not handling path names correctly on Windows #1988

Closed
openSourcerer9000 opened this issue Apr 21, 2021 · 4 comments
Closed

v4.8.0 ncgen not handling path names correctly on Windows #1988

openSourcerer9000 opened this issue Apr 21, 2021 · 4 comments

Comments

@openSourcerer9000
Copy link

I'll keep this short since the symptom is pretty simple. Basically ncgen -o output option is taking an absolute path argument and converting it into one long file name. This is a regression from version 4.7. This unexpected behavior only happens on Windows, on Linux it still generates the file in the correct location.

  • How to reproduce:
    On windows:

Using version 4.7:
$ ncgen -o C:\Users\you\Desktop\temp\fourpointseven.nc C:\Users\you\Desktop\temp\test_cdl.cdl
<generates the .nc to the path C:\Users\you\Desktop\temp\fourpointseven.nc>

Using version 4.8.0:
$ ncgen -o C:\Users\you\Desktop\temp\fourpointeight.nc C:\Users\you\Desktop\temp\test_cdl.cdl
<generates the .nc to a file named UsersyouDesktoptempfourpointeight.nc in wherever CD is>

Any .cdl will work for the test, I'm using this one:

netcdf timeseries {
dimensions:
    time = 2;
variables:
    double time(time);
        time:standard_name = "time";
        time:long_name = "Time";
        time:axis = "T";
        time:units = "seconds since 1970-01-01T00:00:00Z";
    float lat;
        lat:standard_name = "latitude";
        lat:units = "degrees_north";
        lat:axis = "Y";
        lat:long_name = "Latitude";
    float lon;
        lon:standard_name = "longitude";
        lon:units = "degrees_east";
        lon:axis = "X";
        lon:long_name = "Longitude";
    float z;
        z:standard_name = "depth";
        z:positive = "down";
        z:units = "m";
        z:long_name = "Depth below surface";

    float temperature(time);
        temperature:standard_name = "sea_water_temperature";
        temperature:units = "deg_C";
        temperature:long_name = "Seawater Temperature";
        temperature:coordinates = "time lat lon z";

}


  • environmental information (i.e. Operating System, compiler info, java version, python version, etc.)
    I am using libnetcdf with python, I've tested this with python 3.7,3.8,3.9.
@DennisHeimbigner
Copy link
Collaborator

I am curious; how does python come in to play here. Are you calling ncgen using python?
In any case, I will investigate.

@openSourcerer9000
Copy link
Author

openSourcerer9000 commented Apr 21, 2021

I wouldn't think it affects anything, that's just my exposure to this library, from a python background. It should be reproducible from the CLI only.

@DennisHeimbigner
Copy link
Collaborator

I found the problem. There was an issue with certain shell programs (bash notably).
For certain platforms and when given a url that had an escaped '#' character (e.g. #)
bash would not remove the backslash. So I had to add a hack for this. Unfortunately
I overdid it and it removed all '' characters. This is ok for non-windows platforms,
but obviously fails for windows.
I am preparing a fix now, but if you need it in a hurry, the general solution is this:

  1. In netcdf-c/ncgen/main.c replace all occurrences of NC_backslashUnescape(XXX) with strdup(XXX).
  2. Similarly for netcdf-c/ncdump/ncdump.c
  3. Similarly for netcdf-c/ncdump/nccopy.c

DennisHeimbigner added a commit to DennisHeimbigner/netcdf-c that referenced this issue Apr 21, 2021
re: Unidata#1988

There was an issue with certain shell programs (bash notably).
For certain platforms and when given a url that had an escaped
'#' character (e.g. \\#) bash would not remove the backslash. So I
had to add a hack for this. Unfortunately I overdid it and it
removed all '' characters. This is ok for non-windows platforms,
but obviously fails for windows.

The fix is this.

1. In a utility program (ncgen, ncdump, nccopy, etc) there is probably a call (or calls) to NC_backslashUnescape(xxx) where xxx is a path argument from the command line.
2. Replace each such call with NC_shellUnescape(xxx).

The NC_shellUnescape function was added and searched only for occurrences of "\#" and replaces them with "#".
@DennisHeimbigner
Copy link
Collaborator

Fixed (I hope) by PR #1989

@WardF WardF closed this as completed Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants