matlabcommon-data-format# 'cdfread' not reading .cdf file Matlab

I am not able to read '.cdf' files using Matlab `cdfread`

function. I have also tried `netcdf`

The file 'mvn_lpw_l2_lpnt_20180814_v03_r02.cdf' is available here:

I am using Matlab R2015a (release 8.5).

Any help please.

Solution

To read the data from NASA Space Physics Data Facility (SPDF) you are encouraged to use the CDF handling library from SPDF. This version of the library is provided for free and can be downloaded directly from SPDF. The Installation instructions are fairly straightforward and there is little that can be added to it.

The version of cdflib that comes with MATLAB does not support some of the features used in MAVEN files. With MATLAB provided CDFLIB running on MATLAB 2017a (9.2.0) you get

```
>> cdfinfo('mvn_lpw_l2_lpnt_20180814_v03_r02.cdf')
Error using cdflibmex
33 is not a recognized DATATYPE mode.
[... stack trace ...]
>> data = cdfread('mvn_lpw_l2_lpnt_20180814_v03_r02.cdf')
Error using cdflibmex
33 is not a recognized DATATYPE mode.
[... stack trace ...]
```

With SPDF version of CDF routines you would get the correct output:

```
>> mvninfo = spdfcdfinfo('mvn_lpw_l2_lpnt_20180814_v03_r02.cdf')
mvninfo =
struct with fields:
Filename: 'mvn_lpw_l2_lpnt_20180814_v03_r02.cdf'
FileModDate: '01-Jan-2019 03:18:45'
FileSize: 2579209
Format: 'CDF'
FormatVersion: '3.6.3'
FileSettings: [1×1 struct]
Subfiles: {}
Variables: {7×12 cell}
GlobalAttributes: [1×1 struct]
VariableAttributes: [1×1 struct]
LibVersion: '3.7.0'
PatchVersion: '3.7.0.0'
```

And `spdfcdfread`

returns the data as a MATLAB array

```
>> mvndata = spdfcdfread('mvn_lpw_l2_lpnt_20180814_v03_r02.cdf')
mvndata =
1×7 cell array
Columns 1 through 3
[17532×10 single] [17532×1 double] [17532×1 double]
Columns 4 through 6
[17532×10 single] [17532×10 single] [17532×1 single]
Column 7
[17532×1 single]
```

A probable cause for the error in MATLAB CDFLIB functions comes from the TT2000 datatype that is used for the `epoch`

variable in MAVEN files.

```
data epoch time_unix ddata_lo ddata_up flag info
________ ________ _________ ________ ________ ________ ________
'single' 'tt2000' 'double' 'single' 'single' 'single' 'single'
```

- how to reshape a cell array to matrix in desired size
- Using Mat_CreateVer for MATLAB versions higher than 7.3
- Making a numpy ndarray matrix symmetric
- Matlab 2021 and2023 cross compatability
- How to plot figures at the end of the for loop MATLAB?
- Variable transfer from App Designer to general .m script file
- Anomalous behavior of the Simulink signal - Simscape
- What is the fastest method to searsch for a part of a matrix inside of a large matrix?
- Can I Prevent Git from Using XTerm Escape Sequences?
- Use VPA to evaluate tiny probabilities
- Generate Array of Random Numbers with Specified Standard Deviation and Mean
- Matlab update plot with multiple data lines/curves
- Matlab vectorize for loop (grid depends on loop index)
- How to use a flag variable to break all the for-loops in spmd statement?
- How to produce the indexes from pdist2 function in Octave?
- Calculation of sensitivity and specificity from confusion matrix
- How do I read comma separated values from a .txt file in MATLAB using textscan()?
- How do you code Garson's algorithm in matlab to find the relative importance of parameters when training a neural network model?
- add data label to a grouped bar chart in matlab
- Using 1D convolutional with same shape so it will work with FFT?
- super fast median of matrix in OpenCV (as fast as MATLAB)
- How to create a struct or type from a dictionary in Julia?
- MATLAB Delay an Input Signal
- Is there an Octave equivalent of Matlab's `contains` function?
- Matlab define callback function for mouse click on a biograph
- getting a return value from a function in MATLAB
- How to convert nifti file to AFNI file?
- load .mat file, but not on the workspace
- Fast plane fitting to many points
- Cubic spline interpolation vs polynomial interpolation