11/*
2- * Copyright (c) 1998-2018 John Caron and University Corporation for Atmospheric Research/Unidata
2+ * Copyright (c) 1998-2025 John Caron and University Corporation for Atmospheric Research/Unidata
33 * See LICENSE for license information.
44 */
55package ucar .nc2 .dataset ;
@@ -494,9 +494,28 @@ protected Array _read(Section section) throws IOException, InvalidRangeException
494494 // do not call directly
495495 @ Override
496496 public Array reallyRead (Variable client , CancelTask cancelTask ) throws IOException {
497- if (orgVar == null )
497+ if (orgVar == null ) {
498+ // possible aggregation
499+ if (this .proxyReader != null && this .proxyReader instanceof ucar .nc2 .ncml .Aggregation ) {
500+ return this .proxyReader .reallyRead (client , cancelTask );
501+ }
498502 return getMissingDataArray (shape );
503+ }
499504
505+ if (client instanceof CoordinateAxis ) {
506+ // If orgVar is a VariableDS (orgVar of a CoordinateAxis using the non-builder
507+ // API, for example), call reallyRead on it, otherwise, enhancements will get
508+ // applied twice in a second _read() call triggered by calling read() on the
509+ // VariableDS.
510+ if (orgVar instanceof VariableDS && !orgVar .hasCachedData ()) {
511+ return orgVar .reallyRead (client , cancelTask );
512+ }
513+ // Some aggregations use a DatasetProxyReader for reading a coordinate axis
514+ // variable, so check to see if that's what we have and, if so, use it.
515+ if (ucar .nc2 .ncml .Aggregation .instanceOfDatasetProxyReader (this .proxyReader )) {
516+ return this .proxyReader .reallyRead (client , cancelTask );
517+ }
518+ }
500519 return orgVar .read ();
501520 }
502521
@@ -508,9 +527,28 @@ public Array reallyRead(Variable client, Section section, CancelTask cancelTask)
508527 if ((null == section ) || section .computeSize () == getSize ())
509528 return reallyRead (client , cancelTask );
510529
511- if (orgVar == null )
512- return getMissingDataArray (section .getShape ());
530+ if (orgVar == null ) {
531+ // possible aggregation
532+ if (this .proxyReader != null && this .proxyReader instanceof ucar .nc2 .ncml .Aggregation ) {
533+ return this .proxyReader .reallyRead (client , section , cancelTask );
534+ }
535+ return getMissingDataArray (shape );
536+ }
513537
538+ if (client instanceof CoordinateAxis ) {
539+ // If orgVar is a VariableDS (orgVar of a CoordinateAxis using the non-builder
540+ // API, for example), call reallyRead on it, otherwise, enhancements will get
541+ // applied twice in a second _read() call triggered by calling read() on the
542+ // VariableDS.
543+ if (orgVar instanceof VariableDS && !orgVar .hasCachedData ()) {
544+ return orgVar .reallyRead (client , section , cancelTask );
545+ }
546+ // Some aggregations use a DatasetProxyReader for reading a coordinate axis
547+ // variable, so check to see if that's what we have and, if so, use it.
548+ if (ucar .nc2 .ncml .Aggregation .instanceOfDatasetProxyReader (this .proxyReader )) {
549+ return this .proxyReader .reallyRead (client , section , cancelTask );
550+ }
551+ }
514552 return orgVar .read (section );
515553 }
516554
0 commit comments