Chapter 25 Quiz: Scientific Data Formats

Twenty questions to check your grasp of NetCDF, HDF5, and the metadata conventions that make scientific data reproducible. Mix of multiple choice, true/false (with justification — the justification is the point), short answer, and "what does this produce?". Target: 16/20. Below that, reread §25.1 (why) and §25.2/§25.3 (the two APIs); the answer key maps every question to its section.


Multiple Choice

Q1. The single property that distinguishes a self-describing format from a raw stream file is that it stores, alongside the data: - (a) the data in compressed form - (b) the array's shape, type, byte order, and metadata - (c) a checksum for integrity - (d) the source code that wrote it

Q2. Every nf90_* function returns: - (a) the number of bytes written - (b) the variable ID - (c) an integer status code (nf90_noerr == 0 on success) - (d) nothing; NetCDF raises exceptions

Q3. In HDF5's data model, the analogue of a NetCDF variable is a: - (a) group - (b) dataspace - (c) attribute - (d) dataset

Q4. Compression in HDF5 requires: - (a) a contiguous storage layout - (b) chunking - (c) double precision data - (d) a group to hold the dataset

Q5. You write a variable over dimensions [x_dimid, y_dimid] from Fortran, and ncdump shows it as var(y, x). This means: - (a) your data is transposed and you must swap the dimension list - (b) nothing is wrong — ncdump lists axes row-major, Fortran stores column-major, and the library bridges them - (c) the file is corrupt - (d) you forgot nf90_enddef

Q6. The best default for gridded data you intend to publish to other scientists is: - (a) raw stream binary, for speed - (b) a text CSV, for readability - (c) CF-compliant NetCDF, for the tool ecosystem - (d) a compiler-specific unformatted file

Q7. NF90_NETCDF4 matters because a NetCDF-4 file: - (a) is stored as HDF5 underneath, so it gains chunking and compression - (b) drops the self-describing metadata to save space - (c) can only be read by NetCDF version 4 - (d) is text rather than binary

Q8. A coordinate variable in NetCDF is: - (a) any 2D variable - (b) a 1D variable with the same name as a dimension, holding that axis's physical coordinates - (c) a global attribute named coordinates - (d) the _FillValue of a variable


True / False (state true or false and justify in one sentence)

Q9. Raw Fortran unformatted I/O (Chapter 7) is portable between a little-endian and a big-endian machine.

Q10. Writing a real(dp) field as full-precision text and reading it back always recovers the exact original bits.

Q11. In HDF5, an open dataspace or dataset is cleaned up automatically when its Fortran variable goes out of scope, just like an allocatable array.

Q12. A NetCDF file must be switched from define mode to data mode with nf90_enddef before any nf90_put_var writes data.

Q13. You may invent a standard_name string for a variable as long as it is descriptive.

Q14. NetCDF-4 and HDF5 are mutually exclusive choices with nothing in common.


Short Answer

Q15. Name the four ways §25.1 said text files fail at scale, in one word each.

Q16. Give the canonical NetCDF write sequence as a chain of six nf90_* call names, in order, from creating the file to closing it.

Q17. What two library calls must bracket every HDF5 program, and what happens if you omit the first?

Q18. Define chunking and state the two capabilities it enables that a contiguous layout cannot.


What Does This Produce?

Q19. This NetCDF writer stores temperature(i,j) = i + j on a $3 \times 3$ grid, then a reader sums all nine values. What sum does the reader print, and why can you state it exactly without running either program?

do j = 1, 3
   do i = 1, 3
      temperature(i, j) = real(i + j, dp)
   end do
end do
! ... nf90_put_var(ncid, varid, temperature) ...   then round-trip and sum

Q20. A program calls nf90_put_var before nf90_enddef, checking every status with a check wrapper that error stops on failure. Describe what happens when you run it, and name the fix.


Answer Key

Q Answer Rationale (one line)
1 b Self-describing = shape, type, byte order, and metadata travel with the data.
2 c NetCDF reports success/failure through a returned integer status; check every one.
3 d A dataset is HDF5's typed multidimensional array — the analogue of a NetCDF variable.
4 b The deflate filter runs per chunk, so compression needs chunked storage.
5 b ncdump is row-major (C order); Fortran is column-major; the library maps them — no transpose.
6 c CF-compliant NetCDF is read out of the box by ParaView, xarray, cdo, ncview, Panoply.
7 a NetCDF-4 stores data in an HDF5 container, inheriting chunking and compression.
8 b A coordinate variable shares a dimension's name and holds that axis's physical coordinates.
9 False Unformatted files record no byte order; little- vs big-endian scrambles every number.
10 False Only if the format is round-trip-safe and rounding is correct both ways; a lossy format (e.g. f8.2) drops digits.
11 False An HDF5 handle is a library object, not a Fortran object; you must h5*close_f it by hand.
12 True Data may be written only in data mode; classic NetCDF errors on put_var in define mode.
13 False standard_name is a controlled vocabulary; an invented value is non-compliant — use long_name.
14 False NetCDF-4 is HDF5 underneath; they share the storage layer.
15 Bulky, slow, lossy, mute Size ~3×, per-value conversion, dropped digits, and no metadata.
16 nf90_createnf90_def_dimnf90_def_varnf90_put_attnf90_enddefnf90_put_varnf90_close Define structure, end define mode, write data, close. (Seven names; put_att optional.)
17 h5open_fh5close_f; omit h5open_f and the Fortran interface is uninitialized, so all later calls fail They initialize and finalize the HDF5 Fortran library.
18 Chunking = storing an array as fixed-size tiles; enables partial (sub-region) I/O and per-chunk compression A contiguous block allows neither.
19 36.00 $\sum_{i,j}(i+j) = 3\sum i + 3\sum j = 3\cdot6 + 3\cdot6 = 36$; binary round trip is bit-exact, so the value is determinate.
20 The check wrapper catches the nonzero status from the mis-ordered put_var and error stops with the NetCDF message; the fix is to move nf90_enddef above nf90_put_var Define, then fill — never write in define mode.

Topics to Review by Question

  • Why text/binary don't scale (§25.1): Q1, Q9, Q10, Q15
  • NetCDF model & API (§25.2): Q2, Q5, Q12, Q16, Q19, Q20
  • HDF5 model & API (§25.3): Q3, Q4, Q11, Q17, Q18
  • Reading & choosing (§25.4): Q6, Q7, Q14
  • CF conventions (§25.5): Q8, Q13

A score of 16+ means you can write and read both formats and label output for reproducibility. If you missed Q5, Q9, or Q11, revisit the three "gotchas" that bite everyone: the row-major/column-major display, endianness in raw binary, and manual handle cleanup in HDF5.