@@ -6634,3 +6634,93 @@ def test_netcdf_var_with_geoloc_array_but_no_coordinates_attr():
6634
6634
got_md ["X_DATASET" ]
6635
6635
== 'NETCDF:"data/netcdf/var_with_geoloc_array_but_no_coordinates_attr.nc":lon'
6636
6636
)
6637
+
6638
+
6639
+ ###############################################################################
6640
+ # Test reporting of values of an extra dimension which is unlimited
6641
+
6642
+
6643
+ def test_netcdf_var_extra_dim_unlimited ():
6644
+
6645
+ ds = gdal .Open ("data/netcdf/extra_dim_unlimited.nc" )
6646
+ assert ds .GetMetadataItem ("NETCDF_DIM_time_VALUES" ) == "{17927,17955}"
6647
+
6648
+ with gdal .config_option ("GDAL_NETCDF_REPORT_EXTRA_DIM_VALUES" , "YES" ):
6649
+ ds = gdal .Open ("data/netcdf/extra_dim_unlimited.nc" )
6650
+ assert ds .GetMetadataItem ("NETCDF_DIM_time_VALUES" ) == "{17927,17955}"
6651
+
6652
+ with gdal .config_option ("GDAL_NETCDF_REPORT_EXTRA_DIM_VALUES" , "NO" ):
6653
+ ds = gdal .Open ("data/netcdf/extra_dim_unlimited.nc" )
6654
+ assert ds .GetMetadataItem ("NETCDF_DIM_time_VALUES" ) is None
6655
+
6656
+
6657
+ ###############################################################################
6658
+ # Test reporting of values of an extra dimension which is unlimited
6659
+
6660
+
6661
+ @pytest .mark .require_curl ()
6662
+ @pytest .mark .skipif (sys .platform != "linux" , reason = "Incorrect platform" )
6663
+ def test_netcdf_var_extra_dim_unlimited_network ():
6664
+
6665
+ import webserver
6666
+
6667
+ webserver_process = None
6668
+ webserver_port = 0
6669
+
6670
+ (webserver_process , webserver_port ) = webserver .launch (
6671
+ handler = webserver .DispatcherHttpHandler
6672
+ )
6673
+ if webserver_port == 0 :
6674
+ pytest .skip ()
6675
+
6676
+ filename = "data/netcdf/extra_dim_unlimited.nc"
6677
+
6678
+ gdal .VSICurlClearCache ()
6679
+
6680
+ try :
6681
+ filesize = gdal .VSIStatL (filename ).size
6682
+ handler = webserver .SequentialHandler ()
6683
+ handler .add ("HEAD" , "/test.nc" , 200 , {"Content-Length" : "%d" % filesize })
6684
+
6685
+ def method (request ):
6686
+ # sys.stderr.write('%s\n' % str(request.headers))
6687
+
6688
+ if request .headers ["Range" ].startswith ("bytes=" ):
6689
+ rng = request .headers ["Range" ][len ("bytes=" ) :]
6690
+ assert len (rng .split ("-" )) == 2
6691
+ start = int (rng .split ("-" )[0 ])
6692
+ end = int (rng .split ("-" )[1 ])
6693
+
6694
+ request .protocol_version = "HTTP/1.1"
6695
+ request .send_response (206 )
6696
+ request .send_header ("Content-type" , "application/octet-stream" )
6697
+ request .send_header (
6698
+ "Content-Range" , "bytes %d-%d/%d" % (start , end , filesize )
6699
+ )
6700
+ request .send_header ("Content-Length" , end - start + 1 )
6701
+ request .send_header ("Connection" , "close" )
6702
+ request .end_headers ()
6703
+ with open (filename , "rb" ) as f :
6704
+ f .seek (start , 0 )
6705
+ request .wfile .write (f .read (end - start + 1 ))
6706
+
6707
+ handler .add ("GET" , "/test.nc" , custom_method = method )
6708
+
6709
+ handler .add ("HEAD" , "/test.nc.aux.xml" , 404 )
6710
+ handler .add ("GET" , "/" , 404 )
6711
+ handler .add ("HEAD" , "/test.aux" , 404 )
6712
+ handler .add ("HEAD" , "/test.AUX" , 404 )
6713
+ handler .add ("HEAD" , "/test.nc.aux" , 404 )
6714
+ handler .add ("HEAD" , "/test.nc.AUX" , 404 )
6715
+
6716
+ with webserver .install_http_handler (handler ):
6717
+ with gdal .quiet_errors ():
6718
+ ds = gdal .Open ("/vsicurl/http://127.0.0.1:%d/test.nc" % webserver_port )
6719
+ if ds is None :
6720
+ pytest .skip ("cannot open /vsicurl/ netCDF file" )
6721
+ assert ds .GetMetadataItem ("NETCDF_DIM_time_VALUES" ) is None
6722
+
6723
+ finally :
6724
+ webserver .server_stop (webserver_process , webserver_port )
6725
+
6726
+ gdal .VSICurlClearCache ()
0 commit comments