3

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:

CDF file

I am using Matlab R2015a (release 8.5).

Any help please.

Mushi
  • 367
  • 2
  • 4
  • 14
  • What does `cdfinfo` function print for this file? What is the error reported by `cdfread`? – Dima Chubarov Dec 31 '18 at 21:26
  • If you can switch to Python, you could make use of the [cdflib](https://github.com/MAVENSDC/cdflib) module that handles the file correctly. – Dima Chubarov Dec 31 '18 at 21:36
  • 'cdfinfo' give the following message: "Error using cdflibmex" – Mushi Jan 01 '19 at 10:08
  • Which MATLAB version do you have installed? This question seems to lack some important information, please try to add as much detail as possible by editing your original post instead of adding new information in the comments. Would you try the [commands proposed by Fangjun Jiang](https://www.mathworks.com/matlabcentral/answers/18056-can-not-read-in-a-cdf#answer_24326) on MATLAB Answers and post the output here? – Dima Chubarov Jan 01 '19 at 11:38
  • 1
    I have gone through this link and everything seems fine when I run the commands recommended by Fangjun Jiang with example.cdf. This is why I am so concerned that I am not finding any clue after trying things which seem obvious. It may need some deeper knowledge and that's why I am here asking this question. Could you pelase download the file on the given link (in my post) and let me know what you are getting. Thanks. – Mushi Jan 01 '19 at 13:00

1 Answers1

5

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'
Dima Chubarov
  • 16,199
  • 6
  • 40
  • 76