The answer from @miraculixx is correct, but it is assumed that you have already installed the CDF C Library .
Itโs easy to follow the guide here if you donโt even know what format the CDF file was before you found this question in SO.
1. Download the latest CDF C library:
You can find the latest stable version on this link . Take the source code with wget and extract it. Note. the following will create a directory in the current folder ./ , if you want to download the code in a different way, make sure you change the code below.
wget -r -l1 -np -nd -nc http://cdaweb.gsfc.nasa.gov/pub/software/cdf/dist/latest-release/linux/ -A cdf*-dist-all.tar.gz tar xf cdf*-dist-all.tar.gz -C ./ cd cdf*dist
2. Install all the dependencies:
SpacePy , and there are several dependencies in the CDF library (as @Michal Dyzma points out). You can install them all with conda or pip , and apt .
pip install numpy scipy h5py matplotlib networkx apt install build-essential gfortran libncurses5-dev
3. Compile the C library:
You should have downloaded the README.install file, which contains a lot more details in this step than I provided. Two cents is that you want to check which compilation variables are necessary / optional for your system and needs.
make all.help
I will build a Linux distribution using the GNU C compiler. I am not interested in the FORTRAN interface, and my operating system supports shared libraries. I want to install Curses-based tools that allow you to use interactive command-line CDF tools (why we installed the libncurses5-dev dependency in step 2). As a result, this is the final make command:
make OS=linux ENV=gnu CURSES=yes FORTRAN=no UCOPTIONS=-O2 SHARED=yes -j4 all make install
The installation should run smoothly and add all the files to the ./bin , ./include and ./lib .
4. Set the environment variables:
A definitions.B file must be specified in ./bin , which will do this automatically for you, make it executable with chmod+x and add the following line to ~/.bashrc ( Note: 1) I assume that you installed the library along the path $HOME/Libraries/ ; 2) After . ) there is a space:
. $HOME/Libraries/cdf/cdf36_3-dist/bin/definitions.B
IMPORTANT NOTE: In the above file, there is an error in line line 68 , instead of adding to the environment variable LD_LIBRARY_PATH it overwrites it. Easy to fix, replace line line 68 as follows:
export LD_LIBRARY_PATH=$HOME/Libraries/cdf/cdf36_3-dist/lib:$LD_LIBRARY_PATH
If for some reason definitions.B does not exist, simply add the following:
export CDF_BASE=$HOME/Libraries/cdf/cdf36_3-dist export CDF_INC=$CDF_BASE/include export CDF_LIB=$CDF_BASE/lib export CDF_BIN=$CDF_BASE/bin export LD_LIBRARY_PATH=$CDF_BASE/lib:$LD_LIBRARY_PATH
5. You are all set, go and do good:
Assuming you installed spacepy with pip, the following should work out of the box:
from spacepy import pycdf cdf = pycdf.CDF('/path/to/file.cdf') print(cdf)