Ubuntu 20.4 源代码方式安装 cdo(笔记)

目录

  • 动机
  • 安装过程
  • python 调用cdo

动机

我找到的处理 era5-land 代码在需要用到 cdo,但是 sudo apt-get install cdo 总是出现 abort (core dump) 等问题,所以放弃这种安装方式,不走捷径,安装源代码,也就是 cdo-x.x.x.tar.gz。

安装过程

# 下载网站
https://src.fedoraproject.org/repo/pkgs/
# 例如:
https://src.fedoraproject.org/repo/pkgs/hdf5/hdf5-1.6.6.tar.gz/


INSTALL_DIR=/home/user/soft
mkdir $INSTALL_DIR

# Install netcdf:
tar xzf netcdf-3.6.3.tar.gz
cd netcdf-3.6.3/
./configure --prefix=$INSTALL_DIR --disable-f77
make
make install
cd ..

# Install szip:
tar xzf szip-2.1.tar.gz
cd szip-2.1/
./configure --prefix=$INSTALL_DIR CFLAGS="-lm"
make
make check
make install
cd ..

# Install zlib:
tar xzf zlib-1.2.3.tar.gz
cd zlib-1.2.3/
./configure --shared --prefix=$INSTALL_DIR
make
make install
cd ..

# Install hdf5 (with zlib and szip support):

   # 在文件 /home/user/soft/hdf5-1.6.6/perform/zip_perf.c 中做了以下修改
        /* do compressed data write 
        output = open(filename, O_RDWR | O_CREAT);*/
        /* Change by Liyongkang */
        output = open(filename, O_RDWR | O_CREAT, 0600);


tar xzf hdf5-1.6.6.tar.gz
cd hdf5-1.6.6/
./configure --with-zlib=$INSTALL_DIR --with-szlib=$INSTALL_DIR --prefix=$INSTALL_DIR
make
make install
cd ..

# Install proj
tar xzf proj-4.6.1.tar.gz
cd proj-4.6.1/
./configure --prefix=$INSTALL_DIR
make
make install
cd ..

# Install cdo (with hdf5 and netcdf support):  错误
tar xzf cdo-1.3.1.tar.gz
cd cdo-1.3.1/
./configure --with-hdf5=$INSTALL_DIR --with-szlib=$INSTALL_DIR --with-netcdf=$INSTALL_DIR --with-proj=$INSTALL_DIR --with-zlib=$INSTALL_DIR --prefix=$INSTALL_DIR CC=gcc CFLAGS="-g -D_REENTRANT -O2"
make
make install
cd ..

# Install cdo (with hdf5 and netcdf support):自己修改的版本
tar xzf cdo-1.7.2.tar.gz
cd cdo-1.7.2/
./configure --with-hdf5=$INSTALL_DIR --with-szlib=$INSTALL_DIR --with-netcdf=$INSTALL_DIR --with-proj=$INSTALL_DIR --with-zlib=$INSTALL_DIR --prefix=$INSTALL_DIR CC=gcc CFLAGS="-g -D_REENTRANT -O2"
make
make install
cd ..

# 通过 source , 添加全局变量 至 ~/.bashrc:
sudo gedit ~/.bashrc

# 复制以下内容至.bashrc 末尾
export INSTALL_DIR=/home/user/soft
export LD_LIBRARY_PATH=$INSTALL_DIR/lib
export PATH=$INSTALL_DIR/bin:$PATH

python 调用cdo

import subprocess

command1= '/home/user/soft/bin/cdo expr,"var1=6.112*exp(17.67*(var168-273.15)/(var168-273.15+243.5))" '+"ERA5_2D_2019010900"+" "+"ERA5_E_2019010900"

你可能感兴趣的:(ubuntu,cdo,ubuntu,笔记,linux)