From 25fdfa07ae493ba82ef145d9c8acb694854809c8 Mon Sep 17 00:00:00 2001
From: Uwe Schulzweida <uwe.schulzweida@mpimet.mpg.de>
Date: Wed, 29 Jan 2025 11:00:10 +0100
Subject: [PATCH] Added CDI_KEY_CHUNKSIZE_DIMT

---
 ChangeLog       | 4 ++++
 src/cdf_write.c | 5 ++++-
 src/cdi.h       | 1 +
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index de8024bd8..a4e64a7f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,10 @@
 
 	* Version 2.5.1 released
 
+2025-01-29  Uwe Schulzweida
+
+	* Added CDI_KEY_CHUNKSIZE_DIMT
+
 2025-01-14  Uwe Schulzweida
 
 	* NetCDF: Fix error in scanning coordinates attribute
diff --git a/src/cdf_write.c b/src/cdf_write.c
index 709a6b07e..9fc92f4a5 100644
--- a/src/cdf_write.c
+++ b/src/cdf_write.c
@@ -764,10 +764,13 @@ cdfDefineDimsAndChunks(const stream_t *streamptr, int varID, int xid, int yid, i
   int timetype = vlistInqVarTimetype(vlistID, varID);
   if (vlistHasTime(vlistID) && timetype != TIME_CONSTANT)
     {
+      int chunkSize = 0;
+      cdiInqKeyInt(vlistID, CDI_GLOBAL, CDI_KEY_CHUNKSIZE_DIMT, &chunkSize);
+      printf("chunkSize %d\n", chunkSize);
       int tid = streamptr->basetime.ncdimid;
       if (tid == CDI_UNDEFID) Error("Internal problem, time undefined!");
       axis[iax++] = 'T';
-      chunks[ndims] = 1;
+      chunks[ndims] = (chunkSize > 0) ? chunkSize : 1;
       dims[ndims] = tid;
       ndims++;
     }
diff --git a/src/cdi.h b/src/cdi.h
index 3b9777d12..8f62f5859 100644
--- a/src/cdi.h
+++ b/src/cdi.h
@@ -846,6 +846,7 @@ SizeType gridInqYCvals(int gridID, char *ycvals[]);
 #define  CDI_KEY_NLEV                          964  // GRIB2 nlev
 #define  CDI_KEY_CHUNKTYPE                     965  // ChunkType: CDI_CHUNK_AUTO/CDI_CHUNK_GRID/CDI_CHUNK_LINES
 #define  CDI_KEY_CHUNKSIZE                     966  // ChunkSize
+#define  CDI_KEY_CHUNKSIZE_DIMT                967  // ChunkSize time dimension
 
 // Floating point keys
 #define  CDI_KEY_MISSVAL                       701  // Missing value
-- 
GitLab