CommonDataFormat.jl
A Julia package for reading Common Data Format (CDF) files, widely used in space physics for storing multidimensional data arrays and metadata. See CDFDatasets.jl for a high-level interface.
Installation
using Pkg
Pkg.add("CommonDataFormat")Quick Start
using CommonDataFormat
# Load a CDF file
omni_file = joinpath(pkgdir(CommonDataFormat), "data/omni_coho1hr_merged_mag_plasma_20240901_v01.cdf")
ds = CDFDataset(omni_file)CDFDataset{CommonDataFormat.NoCompression, Int64}
path: /home/runner/work/CommonDataFormat.jl/CommonDataFormat.jl/data/omni_coho1hr_merged_mag_plasma_20240901_v01.cdf
variables:
Epoch : (720,) support_data CDF_EPOCH [2024-09-01T00:00:00 … 2024-09-30T23:00:00]
heliographicLatitude : (720,) data CDF_REAL4 [7.2 … 6.8]
heliographicLongitude : (720,) data CDF_REAL4 [261.6 … 291.0]
BR : (720,) data CDF_REAL4 [6.7 … -2.6]
BT : (720,) data CDF_REAL4 [-8.2 … 2.1]
BN : (720,) data CDF_REAL4 [-3.6 … 3.5]
ABS_B : (720,) data CDF_REAL4 [11.4 … 6.7]
V : (720,) data CDF_REAL4 [377.0 … 424.0]
elevAngle : (720,) data CDF_REAL4 [-2.5 … 5.6]
azimuthAngle : (720,) data CDF_REAL4 [1.7 … -1.9]
N : (720,) data CDF_REAL4 [4.5 … 3.6]
T : (720,) data CDF_REAL4 [82095.0 … 107645.0]
CDR (CDF Descriptor Record):
Version: 3.9.0
Encoding: 1
Flags: 0x00000003
- Majority: Row
- Single File Format: true
- Checksum Used: false
- MD5 Checksum: false
Identifier: -1
attributes: Dict{String, Vector} with 28 entries:
"Rules_of_use" => ["Public"]
"TITLE" => ["Near-Earth Heliosphere Data (OMNI)"]
"Instrument_type" => ["Plasma and Solar Wind", "Magnetic Fields (spac…
"Project" => ["SPDF"]
"alt_logical_source" => ["Combined_OMNI_1AU-MagneticField-Plasma-Particl…
"Discipline" => ["Space Physics>Interplanetary Studies"]
"Time_resolution" => ["1 hour"]
"Logical_file_id" => ["omni_coho1hr_merged_mag_plasma_00000000_v01"]
"LINK_TEXT" => ["COHO dataset", "Additional analysis tools for …
"PI_name" => ["J.H. King, N. Papatashvilli"]
"spase_DatasetResourceID" => ["spase://NASA/NumericalData/OMNI/COHO/MergedMag…
"TEXT" => ["Hourly averaged definitive multispacecraft int…
"Data_type" => ["COHO1HR>Definitive Hourly data from cohoweb"]
"PI_affiliation" => ["AdnetSystems, NASA GSFC"]
"LINK_TITLE" => ["Documentation", "COHOWeb service"]
"Data_version" => ["1"]
"Acknowledgement" => ["NSSDC"]
"Source_name" => ["OMNI (1AU IP Data)>Merged 1 Hour Interplantary…
"Generation_date" => ["Ongoing"]
⋮ => ⋮API Reference
CommonDataFormat.ADRCommonDataFormat.ADRCommonDataFormat.AEDRCommonDataFormat.CDFDatasetCommonDataFormat.CDRCommonDataFormat.CDRCommonDataFormat.EpochCommonDataFormat.Epoch16CommonDataFormat.GDRCommonDataFormat.GDRCommonDataFormat.HeaderCommonDataFormat.TT2000CommonDataFormat.VDRCommonDataFormat.VDRCommonDataFormat.VVRCommonDataFormat.VXRCommonDataFormat.VXRCommonDataFormat.rVDRCommonDataFormat.attribCommonDataFormat.attribCommonDataFormat.attribnamesCommonDataFormat.decode_cdr_flagsCommonDataFormat.is_big_endian_encodingCommonDataFormat.is_cdf_v3CommonDataFormat.is_nrvCommonDataFormat.majority_swap!CommonDataFormat.@read_be_fields
CommonDataFormat.ADR — Type
Attribute Descriptor Record (ADR)
Contains a description of an attribute in a CDF. There will be one ADR per attribute. The ADRhead field of the ADR contains the file offset of the first ADR.
CommonDataFormat.ADR — Method
ADR(buf, offset, RecordSizeType)Load an Attribute Descriptor Record from the buffer at the specified position.
CommonDataFormat.AEDR — Type
AEDRAttribute g/r Entry Descriptor Record. Describes a global entry (for global attributes) or rVariable entry (for variable attributes).
CommonDataFormat.CDFDataset — Method
CDFDataset(filename)Load a CDF file and return a CDFDataset object.
Example
cdf = CDFDataset("data.cdf")CommonDataFormat.CDR — Type
CDF Descriptor Record (CDR) - the main file header record Contains version, encoding, format information, and pointer to GDR
CommonDataFormat.CDR — Method
CDR(buffer, pos, FieldSizeT)Load a CDF Descriptor Record from the IO stream at the specified offset. This follows the CDF specification for CDR record structure.
CommonDataFormat.Epoch — Type
EpochMilliseconds since Year 0 (01-Jan-0000 00:00:00.000) Represented as a single double.
CommonDataFormat.Epoch16 — Type
Epoch16Picoseconds since Year 0 (01-Jan-0000 00:00:00.000.000.000.000) Represented as two doubles (seconds and picoseconds).
CommonDataFormat.GDR — Type
Global Descriptor Record (GDR) - contains global information about the CDF file Points to variable and attribute descriptor records
CommonDataFormat.GDR — Method
GDR(buffer::Vector{UInt8}, pos, FieldSizeT)Load a Global Descriptor Record from the buffer at the specified offset.
CommonDataFormat.Header — Type
CDF Record header structure - common to all record types
CommonDataFormat.TT2000 — Type
TT2000Nanoseconds since J2000 (01-Jan-2000 12:00:00.000.000.000) with leap seconds, represented as an 8-byte integer.
CommonDataFormat.VDR — Type
Variable Descriptor Record (VDR) - describes a single variable
CommonDataFormat.VDR — Method
VDR(io::IO, FieldSizeT)Load a Variable Descriptor Record from the IO stream at the specified offset.
CommonDataFormat.VVR — Type
Variable Value Record (VVR) - contains actual variable data
CommonDataFormat.VXR — Type
Variable Index Record (VXR) - contains pointers to variable data records
CommonDataFormat.VXR — Method
VXR(source, offset, RecordSizeType)Load a Variable Index Record from the source at the specified offset.
CommonDataFormat.rVDR — Method
rVDR(io::IO, FieldSizeT)Load a Variable Descriptor Record from the IO stream at the specified offset.
CommonDataFormat.attrib — Method
attrib(cdf::CDFDataset, attribute_name::String)Retrieve all entries for a named attribute from the CDF file.
CommonDataFormat.attrib — Method
attrib(cdf::CDFDataset)Load all attributes from the CDF file.
CommonDataFormat.attribnames — Method
attribnames(cdf::CDFDataset)Return a list of attribute names in the CDF file.
CommonDataFormat.decode_cdr_flags — Method
decode_cdr_flags(flags::UInt32)Decode the CDR flags field into individual boolean flags.
CDF Flags (from CDF specification):
- Bit 0: Majority (1=row-major, 0=column-major)
- Bit 1: File format (1=single-file, 0=multi-file)
- Bit 2: Checksum used (1=checksum present, 0=no checksum)
- Bit 3: MD5 checksum method (requires bit 2=1)
CommonDataFormat.is_big_endian_encoding — Method
is_big_endian_encoding(encoding)Determine if a CDF encoding uses big-endian byte order based on CDF specification encoding values.
CommonDataFormat.is_cdf_v3 — Method
is_cdf_v3(magic_bytes)Determine if this is a CDF v3 file based on the magic number.
CommonDataFormat.is_nrv — Method
Whether or not the variable is a non-record variable
CommonDataFormat.majority_swap! — Method
majority_swap!(data, dims_without_record)Convert row-major data layout to column-major (Julia's native layout) in-place. For row-major CDF files, this reverses the dimension order (except record dimension).
CommonDataFormat.@read_be_fields — Macro
@read_be_fields buffer pos T1 T2 ...Unrolls sequential big-endian reads starting at pos within buffer. Returns a tuple of the parsed values and the updated position, mirroring read_be_i but without the runtime ntuple/offset bookkeeping.
Example
values, next = @read_be_fields buf pos UInt32 Int16