Skip to content

Commit 01e452f

Browse files
committed
Add CDM Section Specification documentation
Fixes #1528
1 parent 1ff0c95 commit 01e452f

3 files changed

Lines changed: 70 additions & 2 deletions

File tree

docs/src/site/_data/sidebars/netcdfJavaTutorial_sidebar.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ entries:
159159
url: /arraystructures_ref.html
160160
output: web, pdf
161161

162+
- title: CDM Section Specification
163+
url: /section_specification_ref.html
164+
output: web, pdf
165+
162166
- title: CDM Calendar Date Handling
163167
url: /cdm_calendar_date_time_ref.html
164168
output: web, pdf
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: Section Specification
3+
last_updated: 2026-06-23
4+
sidebar: netcdfJavaTutorial_sidebar
5+
toc: false
6+
permalink: section_specification_ref.html
7+
---
8+
## CDM Section Specification
9+
10+
### Syntax
11+
12+
Array sections can be specified with Fortran 90 array section syntax, using zero-based indexing. For example:
13+
14+
`/group1/group2/varName(12:22,0:100:2,:,17)`
15+
16+
specifies an array section for a four-dimensional variable:
17+
18+
1. `12:22` includes all the elements from 12 to 22 inclusive
19+
1. `0:100:2` includes the elements from 0 to 100 inclusive, with a stride of 2
20+
1. `:` includes all the elements
21+
1. `17` includes just the 18th element.
22+
23+
For structures, you can specify nested selectors, e.g. `record(12).wind(1:20,:,3)` does a selection on the `wind` member variable of the `record` structure at index 12.
24+
If you don’t specify a section, it means read the entire variable, e.g. `record.wind` means all the data in all the wind variables in all the record structures.
25+
26+
Formally:
27+
28+
```
29+
sectionSpec := selector | selector '.' selector
30+
selector := varName ['(' sectionSpec ')']
31+
varName := STRING
32+
sectionSpec := dim | dim ',' sectionSpec
33+
dim := ':' | slice | start ':' end | start ':' end ':' stride
34+
35+
36+
slice := INTEGER
37+
start := INTEGER
38+
stride := INTEGER
39+
end := INTEGER
40+
STRING := String with escaped chars = '.', '/', '(', and ')'
41+
```
42+
43+
where:
44+
45+
* Nonterminals are in lower case, terminals are in upper case, and literals are in single quotes.
46+
* Optional components are enclosed between square braces `[` and `]`.
47+
48+
TBD:
49+
50+
* escape mechanism is currently %xx , mostly following opendap
51+
* not sure if any other chars need to be escaped.
52+
53+
### Restrictions
54+
55+
A Sequence is a one-dimensional Structure with a variable length, it cannot be subsetted.
56+
57+
A variable long name must be used, that is with its group names: `/group1/group2/varName`
58+
59+
### Use
60+
61+
`public Array NetcdfFile.readSection(String variableSection);`

docs/src/site/pages/netcdfJava_tutorial/cdmdatasets/readingcdm.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Note that you can edit the `Variable`'s ranges (`T(0:30:10, 1, 0:3)` in this exa
5454
These are expressed with Fortran 90 array section syntax, using zero-based indexing.
5555
For example, `varName( 12:22 , 0:100:2, :, 17)` specifies an array section for a four dimensional variable.
5656
The first dimension includes all the elements from 12 to 22 inclusive, the second dimension includes the elements from 0 to 100 inclusive with a stride of 2, the third includes all the elements in that dimension, and the fourth includes just the 18th element.
57+
The [CDM section specification](section_specification_ref.html) describes the section string syntax in more detail.
5758

5859
The following code to dump data from your program is equivalent to the above ToolsUI actions:
5960

@@ -98,20 +99,22 @@ Or suppose you want to loop over all time steps, and make it general to handle a
9899
In this case, we call reduce(0), to reduce dimension 0, which we know has length one, but leave the other two dimensions alone.
99100

100101
Note that `varShape` holds the total number of elements that can be read from the variable; `origin` is the starting index, and `size` is the number of elements to read.
101-
This is different from the Fortran 90 array syntax, which uses the starting and ending array indices (inclusive):
102+
This is different from the section (Fortran 90) array syntax, which uses the starting and ending array indices (inclusive):
102103

103104
{% capture rmd %}
104105
{% includecodeblock netcdf-java&docs/src/test/java/examples/cdmdatasets/ReadingCdmTutorial.java&readSubset %}
105106
{% endcapture %}
106107
{{ rmd | markdownify }}
107108

108-
If you want strided access, you can use the Fortran 90 string routine:
109+
If you want strided access, you can use the section string method:
109110

110111
{% capture rmd %}
111112
{% includecodeblock netcdf-java&docs/src/test/java/examples/cdmdatasets/ReadingCdmTutorial.java&readByStride %}
112113
{% endcapture %}
113114
{{ rmd | markdownify }}
114115

116+
The [CDM section specification](section_specification_ref.html) describes the section string syntax in more detail.
117+
115118
#### Reading with Range Objects
116119

117120
For general programing, use the read method that takes a `List` of `ucar.ma2.Range` objects.

0 commit comments

Comments
 (0)