NetCDF CF reader creates duplicate latitude/longitude bands (latitude_, longitude_)

When opening a CF NetCDF file in SNAP that already contains latitude and longitude variables, SNAP creates duplicate bands named latitude_ and longitude_.
This appears to happen in the NetCDF CF reader path (org.esa.snap.dataio.netcdf.metadata.profiles.cf.CfBandPart).

Observed behavior
For a dataset with only coordinate raster variables latitude and longitude, band list contains:

  • latitude
  • longitude
  • latitude_
  • longitude_

Expected behavior
latitude and longitude should appear only once (no suffixed duplicates).

Suspected root cause
In CfBandPart:

  1. preDecode(…) adds latitude/longitude bands explicitly if both exist:
    • addBand(ctx, p, longitude, new int[0], longitude.getShortName())
    • addBand(ctx, p, latitude, new int[0], latitude.getShortName()) (around lines 408–410)
  2. decode(…) then iterates all raster variables and adds rank-2 variables again (including lat/lon):
    • if (rank == 2) { addBand(…) } (around line 424)
  3. On name collision, addBand(…) falls back to:
    • bandBasename + “_” + variable.getParentGroup().getShortName() (around lines 161–162)

For root-group vars this can result in trailing underscore names, hence latitude_ / longitude_.

Possible fix directions

  • Skip lat/lon in decode(…) if already added in preDecode(…), or
  • Stop adding them in preDecode(…) and handle consistently in one place, or
  • Guard against empty group short name in collision fallback to avoid trailing _ names.

Jira ticket SNAP-4201 created