--- gdal-3.9.1/frmts/netcdf/netcdfdataset.cpp.orig	2024-07-27 14:15:00.137501386 +0200
+++ gdal-3.9.1/frmts/netcdf/netcdfdataset.cpp	2024-07-27 14:17:44.537204901 +0200
@@ -451,11 +451,11 @@
     size_t attlen = 0;
     const char *pszNoValueName = nullptr;
 
-    // Find attribute name, either _FillValue or missing_value.
-    int status = nc_inq_att(cdfid, nZId, _FillValue, &atttype, &attlen);
+    // Find attribute name, either NC_FillValue or missing_value.
+    int status = nc_inq_att(cdfid, nZId, NC_FillValue, &atttype, &attlen);
     if (status == NC_NOERR)
     {
-        pszNoValueName = _FillValue;
+        pszNoValueName = NC_FillValue;
     }
     else
     {
@@ -1172,7 +1172,7 @@
 
         const char *const papszIgnoreBand[] = {
             CF_ADD_OFFSET, CF_SCALE_FACTOR, "valid_range", "_Unsigned",
-            _FillValue,    "coordinates",   nullptr};
+            NC_FillValue,    "coordinates",   nullptr};
         // Do not copy varname, stats, NETCDF_DIM_*, nodata
         // and items in papszIgnoreBand.
         if (STARTS_WITH(pszName, "NETCDF_VARNAME") ||
@@ -1462,7 +1462,7 @@
     // Write value if in update mode.
     if (poDS->GetAccess() == GA_Update)
     {
-        // netcdf-4 does not allow to set _FillValue after leaving define mode,
+        // netcdf-4 does not allow to set NC_FillValue after leaving define mode,
         // but it is ok if variable has not been written to, so only print
         // debug. See bug #4484.
         if (m_bNoDataSet &&
@@ -1490,33 +1490,33 @@
             if (bSignedData)
             {
                 signed char cNoDataValue = static_cast<signed char>(dfNoData);
-                status = nc_put_att_schar(cdfid, nZId, _FillValue, nc_datatype,
+                status = nc_put_att_schar(cdfid, nZId, NC_FillValue, nc_datatype,
                                           1, &cNoDataValue);
             }
             else
             {
                 const unsigned char ucNoDataValue =
                     static_cast<unsigned char>(dfNoData);
-                status = nc_put_att_uchar(cdfid, nZId, _FillValue, nc_datatype,
+                status = nc_put_att_uchar(cdfid, nZId, NC_FillValue, nc_datatype,
                                           1, &ucNoDataValue);
             }
         }
         else if (eDataType == GDT_Int16)
         {
             short nsNoDataValue = static_cast<short>(dfNoData);
-            status = nc_put_att_short(cdfid, nZId, _FillValue, nc_datatype, 1,
+            status = nc_put_att_short(cdfid, nZId, NC_FillValue, nc_datatype, 1,
                                       &nsNoDataValue);
         }
         else if (eDataType == GDT_Int32)
         {
             int nNoDataValue = static_cast<int>(dfNoData);
-            status = nc_put_att_int(cdfid, nZId, _FillValue, nc_datatype, 1,
+            status = nc_put_att_int(cdfid, nZId, NC_FillValue, nc_datatype, 1,
                                     &nNoDataValue);
         }
         else if (eDataType == GDT_Float32)
         {
             float fNoDataValue = static_cast<float>(dfNoData);
-            status = nc_put_att_float(cdfid, nZId, _FillValue, nc_datatype, 1,
+            status = nc_put_att_float(cdfid, nZId, NC_FillValue, nc_datatype, 1,
                                       &fNoDataValue);
         }
         else if (eDataType == GDT_UInt16 &&
@@ -1525,7 +1525,7 @@
         {
             unsigned short usNoDataValue =
                 static_cast<unsigned short>(dfNoData);
-            status = nc_put_att_ushort(cdfid, nZId, _FillValue, nc_datatype, 1,
+            status = nc_put_att_ushort(cdfid, nZId, NC_FillValue, nc_datatype, 1,
                                        &usNoDataValue);
         }
         else if (eDataType == GDT_UInt32 &&
@@ -1533,12 +1533,12 @@
                      NCDF_FORMAT_NC4)
         {
             unsigned int unNoDataValue = static_cast<unsigned int>(dfNoData);
-            status = nc_put_att_uint(cdfid, nZId, _FillValue, nc_datatype, 1,
+            status = nc_put_att_uint(cdfid, nZId, NC_FillValue, nc_datatype, 1,
                                      &unNoDataValue);
         }
         else
         {
-            status = nc_put_att_double(cdfid, nZId, _FillValue, nc_datatype, 1,
+            status = nc_put_att_double(cdfid, nZId, NC_FillValue, nc_datatype, 1,
                                        &dfNoData);
         }
 
@@ -1586,7 +1586,7 @@
     // Write value if in update mode.
     if (poDS->GetAccess() == GA_Update)
     {
-        // netcdf-4 does not allow to set _FillValue after leaving define mode,
+        // netcdf-4 does not allow to set NC_FillValue after leaving define mode,
         // but it is ok if variable has not been written to, so only print
         // debug. See bug #4484.
         if (m_bNoDataSetAsInt64 &&
@@ -1616,13 +1616,13 @@
             reinterpret_cast<netCDFDataset *>(poDS)->eFormat == NCDF_FORMAT_NC4)
         {
             long long tmp = static_cast<long long>(nNoData);
-            status = nc_put_att_longlong(cdfid, nZId, _FillValue, nc_datatype,
+            status = nc_put_att_longlong(cdfid, nZId, NC_FillValue, nc_datatype,
                                          1, &tmp);
         }
         else
         {
             double dfNoData = static_cast<double>(nNoData);
-            status = nc_put_att_double(cdfid, nZId, _FillValue, nc_datatype, 1,
+            status = nc_put_att_double(cdfid, nZId, NC_FillValue, nc_datatype, 1,
                                        &dfNoData);
         }
 
@@ -1670,7 +1670,7 @@
     // Write value if in update mode.
     if (poDS->GetAccess() == GA_Update)
     {
-        // netcdf-4 does not allow to set _FillValue after leaving define mode,
+        // netcdf-4 does not allow to set NC_FillValue after leaving define mode,
         // but it is ok if variable has not been written to, so only print
         // debug. See bug #4484.
         if (m_bNoDataSetAsUInt64 &&
@@ -1700,13 +1700,13 @@
             reinterpret_cast<netCDFDataset *>(poDS)->eFormat == NCDF_FORMAT_NC4)
         {
             unsigned long long tmp = static_cast<long long>(nNoData);
-            status = nc_put_att_ulonglong(cdfid, nZId, _FillValue, nc_datatype,
+            status = nc_put_att_ulonglong(cdfid, nZId, NC_FillValue, nc_datatype,
                                           1, &tmp);
         }
         else
         {
             double dfNoData = static_cast<double>(nNoData);
-            status = nc_put_att_double(cdfid, nZId, _FillValue, nc_datatype, 1,
+            status = nc_put_att_double(cdfid, nZId, NC_FillValue, nc_datatype, 1,
                                        &dfNoData);
         }
 
@@ -1757,7 +1757,7 @@
         // Make sure we are in define mode.
         static_cast<netCDFDataset *>(poDS)->SetDefineMode(true);
 
-        status = nc_del_att(cdfid, nZId, _FillValue);
+        status = nc_del_att(cdfid, nZId, NC_FillValue);
 
         NCDF_ERR(status);
 
@@ -7670,7 +7670,7 @@
                 status = NC_EBADTYPE;
                 if (*pszValue == '"')
                 {
-                    // For _FillValue, the attribute type should match
+                    // For NC_FillValue, the attribute type should match
                     // the variable type. Leaks memory with NC4 otherwise
                     if (osAttrName == "_FillValue")
                     {
@@ -8979,7 +8979,7 @@
     // Remove the following band meta but set them later from band data.
     const char *const papszIgnoreBand[] = {
         CF_ADD_OFFSET, CF_SCALE_FACTOR, "valid_range", "_Unsigned",
-        _FillValue,    "coordinates",   nullptr};
+        NC_FillValue,    "coordinates",   nullptr};
     const char *const papszIgnoreGlobal[] = {"NETCDF_DIM_EXTRA", nullptr};
 
     CSLConstList papszMetadata = nullptr;
--- gdal-3.9.1/frmts/netcdf/netcdflayer.cpp.orig	2024-07-27 14:35:23.240696146 +0200
+++ gdal-3.9.1/frmts/netcdf/netcdflayer.cpp	2024-07-27 14:35:37.071337316 +0200
@@ -647,14 +647,14 @@
 
 CPLErr netCDFLayer::GetFillValue(int nVarId, char **ppszValue)
 {
-    if (NCDFGetAttr(m_nLayerCDFId, nVarId, _FillValue, ppszValue) == CE_None)
+    if (NCDFGetAttr(m_nLayerCDFId, nVarId, NC_FillValue, ppszValue) == CE_None)
         return CE_None;
     return NCDFGetAttr(m_nLayerCDFId, nVarId, "missing_value", ppszValue);
 }
 
 CPLErr netCDFLayer::GetFillValue(int nVarId, double *pdfValue)
 {
-    if (NCDFGetAttr(m_nLayerCDFId, nVarId, _FillValue, pdfValue) == CE_None)
+    if (NCDFGetAttr(m_nLayerCDFId, nVarId, NC_FillValue, pdfValue) == CE_None)
         return CE_None;
     return NCDFGetAttr(m_nLayerCDFId, nVarId, "missing_value", pdfValue);
 }
--- gdal-3.9.1/frmts/netcdf/netcdfmultidim.cpp.orig	2024-07-27 14:45:05.323367506 +0200
+++ gdal-3.9.1/frmts/netcdf/netcdfmultidim.cpp	2024-07-27 14:46:24.763528778 +0200
@@ -3687,7 +3687,7 @@
 
     m_bGetRawNoDataValueHasRun = true;
 
-    const char *pszAttrName = _FillValue;
+    const char *pszAttrName = NC_FillValue;
     auto poAttr = GetAttribute(pszAttrName);
     if (!poAttr)
     {
@@ -3701,10 +3701,10 @@
         {
             // Round-trip attribute value to target data type and back
             // to attribute data type to ensure there is no loss
-            // Normally _FillValue data type should be the same
+            // Normally NC_FillValue data type should be the same
             // as the array one, but this is not always the case.
             // For example NASA GEDI L2B products have Float64
-            // _FillValue for Float32 variables.
+            // NC_FillValue for Float32 variables.
             m_abyNoData.resize(dt.GetSize());
             GDALExtendedDataType::CopyValue(oRawResult.data(),
                                             poAttr->GetDataType(),
@@ -3812,9 +3812,9 @@
         m_abyNoData.clear();
         nc_type atttype = NC_NAT;
         size_t attlen = 0;
-        if (nc_inq_att(m_gid, m_varid, _FillValue, &atttype, &attlen) ==
+        if (nc_inq_att(m_gid, m_varid, NC_FillValue, &atttype, &attlen) ==
             NC_NOERR)
-            ret = nc_del_att(m_gid, m_varid, _FillValue);
+            ret = nc_del_att(m_gid, m_varid, NC_FillValue);
         else
             ret = NC_NOERR;
         if (nc_inq_att(m_gid, m_varid, "missing_value", &atttype, &attlen) ==
@@ -3846,7 +3846,7 @@
         if (nc_inq_att(m_gid, m_varid, "missing_value", &atttype, &attlen) ==
             NC_NOERR)
         {
-            if (nc_inq_att(m_gid, m_varid, _FillValue, &atttype, &attlen) ==
+            if (nc_inq_att(m_gid, m_varid, NC_FillValue, &atttype, &attlen) ==
                 NC_NOERR)
             {
                 CPLError(CE_Failure, CPLE_NotSupported,
@@ -3859,7 +3859,7 @@
         }
         else
         {
-            ret = nc_put_att(m_gid, m_varid, _FillValue, m_nVarType, 1,
+            ret = nc_put_att(m_gid, m_varid, NC_FillValue, m_nVarType, 1,
                              &abyTmp[0]);
         }
     }
@@ -4010,7 +4010,7 @@
         char szAttrName[NC_MAX_NAME + 1];
         szAttrName[0] = 0;
         NCDF_ERR(nc_inq_attname(m_gid, m_varid, i, szAttrName));
-        if (bShowAll || (!EQUAL(szAttrName, _FillValue) &&
+        if (bShowAll || (!EQUAL(szAttrName, NC_FillValue) &&
                          !EQUAL(szAttrName, "missing_value") &&
                          !EQUAL(szAttrName, CF_UNITS) &&
                          !EQUAL(szAttrName, CF_SCALE_FACTOR) &&
