NetCDF(Network Common Data Format)是数据访问函数库的接口,以数组的形式存储和检索数据,WRF和CESM数据处理是较为常见的NetCDF,广泛应用于大气、海洋、地球、环境模拟等领域;
1、NetCDF 文件格式
NetCDF Classic Format (CDF-1)
NetCDF 64-bit Offset Format (CDF-2)
NetCDF 64-bit Data Format (CDF-5)
NetCDF-4 Format
OS: CentOS-7
2、安装GNU编译器
# wget http://mirrors.ustc.edu.cn/gnu/gcc/gcc-9.3.0/gcc-9.3.0.tar.gz
# tar zxvf gcc-9.3.0.tar.gz
# cd gcc-9.3.0
# sh ./contrib/download_prerequisites
# mkdir build && cd build
# ../configure --prefix=/usr/local/gcc --disable-bootstrap --enable-languages=c,c++,fortran --disable-multilib
# make -j
# make install
# vim ~/.bashrc
export GCC_HOME=/usr/local/gcc
export PATH=$GCC_HOME/bin:$PATH
export CPATH=$GCC_HOME/include:$CPANT
export LD_LIBRARY_PATH=$GCC_HOME/lib:$GCC_HOME/lib64:$LD_LIBARAY_PATH
export LIBRARY_PATH=$GCC_HOME/lib:$GCC_HOME/lib64:$LIBRARY_PATH
3、安装szip
# wget https://support.hdfgroup.org/ftp/lib-external/szip/2.1.1/src/szip-2.1.1.tar.gz # tar zxvf szip-2.1.1.tar.gz # cd szip-2.1.1 # mkdir build && cd build # ../configure --prefix=/usr/local/szip # make -j # make install # export LD_LIBRARY_PATH=/usr/local/szip/lib:$LD_LIBRARY_PATH
4、安装OpenMPI
# yum install -y hwloc-libs libevent-devel # wget https://download.open-mpi.org/release/open-mpi/v4.1/openmpi-4.1.0.tar.bz2 # tar jxvf openmpi-4.1.0.tar.bz2 # cd openmpi-4.1.0/ # mkdir build && cd build # ../configure --prefix=/usr/local/openmpi --enable-shared # make -j # make install
5、安装HDF5
# yum install -y zlib-devel
# wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.7/src/hdf5-1.10.7.tar.gz # tar zxvf hdf5-1.10.7.tar.gz # cd hdf5-1.10.7 # mkdir build && cd build # CC=mpicc FC=mpifort F77=mpifort \ ../configure --prefix=/usr/local/hdf5 --enable-fortran --enable-parallel --enable-shared \ --enable-hl --with-szlib=/usr/local/szip # make -j # make install
6、安装PNetCDF
# wget https://parallel-netcdf.github.io/Release/pnetcdf-1.12.2.tar.gz # tar zxvf pnetcdf-1.12.2.tar.gz # cd pnetcdf-1.12.2 # mkdir build && cd build # CFLAGS="-fPIC -DPIC" CXXFLAGS="-fPIC -DPIC" FCFLAGS="-fPIC" FFLAGS="-fPIC" \ CC=mpicc CXX=mpicxx FC=mpifort F77=mpifort \ ../configure --prefix=/usr/local/pnetcdf --enable-shared --enable-fortran --enable-large-file-test # make -j # make install
7、安装NetCDF-C
# wget https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.7.4.tar.gz -O netcdf-c-4.7.4.tar.gz # tar zxvf netcdf-c-4.7.4.tar.gz # cd netcdf-c-4.7.4 # mkdir build && cd build # CFLAGS="-I/usr/local/hdf5/include -I/usr/local/pnetcdf/include" \ CPPFLAGS="-I/usr/local/hdf5/include -I/usr/local/pnetcdf/include" \ LDFLAGS="-L/usr/local/hdf5/lib -L/usr/local/pnetcdf/lib" \ CC=mpicc ../configure --prefix=/usr/local/netcdf \ --enable-shared --enable-static --enable-pnetcdf --enable-netcdf-4 \ --enable-largefile --enable-large-file-tests # make -j # make install
8、安装NetCDF-Fortran
与NetCDF-C安装在同一目录
# wget https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-fortran-4.5.3.tar.gz # tar zxvf netcdf-fortran-4.5.3.tar.gz # cd netcdf-fortran-4.5.3 # mkdir build && cd build # export NETCDF=/usr/local/netcdf # export LD_LIBRARY_PATH=$NETCDF/lib:$LD_LIBRARY_PATH # CFLAGS="-I$HDF5/include -I$NETCDF/include" \ FCFLAGS="-I$HDF5/include -I$NETCDF/include" \ FFFLAGS="-I$HDF5/include -I$NETCDF/include" \ CPPFLAGS="-I$HDF5/include -I$NETCDF/include" \ LDFLAGS="-L$HDF5/lib -L$NETCDF/lib" \ CC=mpicc FC=mpifort F77=mpifort \ ../configure --prefix=/usr/local/netcdf \ --enable-shared --enable-static --enable-large-file-tests --enable-largefile # make -j # make install
9、环境变量
# cat ~/.bashrc ## GCC-9.3 export GCC_HOME=/usr/local/gcc export PATH=$GCC_HOME/bin:$PATH export CPATH=$GCC_HOME/include:$CPANT export LD_LIBRARY_PATH=$GCC_HOME/lib:$GCC_HOME/lib64:$LD_LIBARAY_PATH export LIBRARY_PATH=$GCC_HOME/lib:$GCC_HOME/lib64:$LIBRARY_PATH ## SZIP-2.1.1 export LD_LIBRARY_PATH=/usr/local/szip/lib:$LD_LIBRARY_PATH ## OpenMPI-4.1 export PATH=/usr/local/openmpi/bin:$PATH export LD_LIBRARY_PATH=/usr/local/openmpi/lib:$LD_LIBRARY_PATH export CPATH=/usr/local/openmpi/include:$CPATH ## HDF5-1.10.7 export HDF5=/usr/local/hdf5
export PHDF5=$HDF5 export PATH=$HDF5/bin:$PATH export LD_LIBRARY_PATH=$HDF5/lib:$LD_LIBRARY_PATH export CPATH=$HDF5/include:$CPATH ## PnetCDF-1.12.2 export PNETCDF=/usr/local/pnetcdf export PATH=$PNETCDF/bin:$PATH export LD_LIBRARY_PATH=$PNETCDF/lib:$LD_LIBRARY_PATH export CPATH=$PNETCDF/include:$CPATH ## netCDF-c-4.7.4 and netCDF-fortran-4.5.3 export NETCDF=/usr/local/netcdf export PATH=$NETCDF/bin:$PATH export LD_LIBRARY_PATH=$NETCDF/lib:$LD_LIBRARY_PATH export CPATH=$NETCDF/include:$CPATH