11#include " gdal_timesnap.h"
22#include < boost/filesystem.hpp>
3+ #include " util/concat.h"
4+ #include " util/log.h"
35
46constexpr int MAX_FILE_NAME_LENGTH = 255 ;
57
@@ -110,14 +112,24 @@ GDALTimesnap::GDALDataLoadingInfo GDALTimesnap::getDataLoadingInfo(Json::Value d
110112{
111113 // get parameters
112114 Json::Value channelJson = datasetJson[" channels" ][channel];
113-
115+
116+ // get parameters
114117 std::string time_format = channelJson.get (" time_format" , datasetJson.get (" time_format" , " " )).asString ();
115118 std::string time_start = channelJson.get (" time_start" , datasetJson.get (" time_start" , " " )).asString ();
116119 std::string time_end = channelJson.get (" time_end" , datasetJson.get (" time_end" , " " )).asString ();
117120
118121 std::string path = channelJson.get (" path" , datasetJson.get (" path" , " " )).asString ();
119122 std::string fileName = channelJson.get (" file_name" , datasetJson.get (" file_name" , " " )).asString ();
120123
124+ Log::debug (
125+ concat (" getDataLoadingInfo: time_format: " , time_format,
126+ " , time_start: " , time_start,
127+ " , time_end: " , time_end,
128+ " , path: " , path,
129+ " , fileName: " , fileName
130+ )
131+ );
132+
121133 channel = channelJson.get (" channel" , channel).asInt ();
122134
123135 // resolve time
@@ -200,6 +212,8 @@ GDALTimesnap::GDALDataLoadingInfo GDALTimesnap::getDataLoadingInfo(Json::Value d
200212 size_t placeholderPos = fileName.find (placeholder);
201213
202214 fileName = fileName.replace (placeholderPos, placeholder.length (), snappedTimeString);
215+ Log::debug (concat (" getDataLoadingInfo: resulting time fileName: " , fileName.c_str ()));
216+
203217 }
204218
205219
@@ -220,7 +234,17 @@ GDALTimesnap::GDALDataLoadingInfo GDALTimesnap::getDataLoadingInfo(Json::Value d
220234
221235 boost::filesystem::path file_path (path);
222236 file_path /= fileName;
223- return GDALDataLoadingInfo (file_path.string (), channel,
237+ std::string dataset_file_path = file_path.string ();
238+ Log::debug (concat (" getDataLoadingInfo: file_path: " , file_path));
239+
240+ // Handle NetCDF subdatasets
241+ if (channelJson.isMember (" netcdf_subdataset" ) || datasetJson.isMember (" netcdf_subdataset" )) {
242+ std::string netcdf_subdataset = channelJson.get (" netcdf_subdataset" , datasetJson.get (" netcdf_subdataset" , " " )).asString ();
243+ dataset_file_path = concat (" NETCDF:" , dataset_file_path, " :" , netcdf_subdataset);
244+ Log::debug (concat (" getDataLoadingInfo: found NETCDF subdataset: " , netcdf_subdataset, " . Resulting path: " , dataset_file_path));
245+ }
246+
247+ return GDALDataLoadingInfo (dataset_file_path, channel,
224248 TemporalReference (TIMETYPE_UNIX, time_start_mapping, time_end_mapping),
225249 crsId, nodata, unit);
226250}
0 commit comments