NETCDF 文件格式 C库编译

  1.安装z 库(压缩库)(必装)

      wget http://prdownloads.sourceforge.net/libpng/zlib-1.2.5.tar.gz

      tar -zxf zlib-1.2.5.tar.gz

      cd ./zlib-1.2.5

      ./configure

      make check install -j 4

   2. 安装openssl(可选)

     wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz

      tar -zxf openssl-1.1.1k.tar.gz

      cd ./openssl-1.1.1k

      ./config

      make && make install

   3. 安装libcurl(必装)

     wget https://curl.se/download/curl-7.78.0.tar.gz

      tar -zxf curl-7.78.0.tar.gz

      cd ./curl-7.78.0

      ./configure --without-ssl

      make && make install  

  4.安装 hd5 库 (必装)

    1. 直接下载编译好的库,放置到指定目录之下

       https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8/hdf5-1.8.7/bin/linux/

       解压,放置到/usr/local

      2. 源码编译(可能会报错)

       wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8/hdf5-1.8.22/src/hdf5-                1.8.22.tar.gz

       tar -xvf hdf5-1.8.22.tar.gz

       cd ./hdf5-1.8.22

      ./configure --with-zlib=/usr/local/lib --prefix=/usr/local/hdf5

      make check -j 5

      make install

    接下来配置路径

      终端输入 sudo gedit ~/.bashrc(修改bashrc文件)

     export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/hdf5/lib

    export PATH=$PATH:/usr/local/hdf5/bin

   export CPATH=:$CPATH:/usr/local/hdf5/include

  5.编译netcdf库

   wget https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-c-4.8.0.tar.gz

  tar -zxf netcdf-c-4.8.0.tar.gz

  cd ./netcdf-c-4.8.0

 ./configure --prefix=/netcdf/result/  LDFLAGS=-L/usr/local/hdf5/lib    CPPFLAGS=-I/usr/local/hdf5/include

 make && make install

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用netcdf读取nc文件的c语言代码示例: ```c #include <stdio.h> #include <stdlib.h> #include <netcdf.h> #define FILE_NAME "example.nc" int main() { int ncid, varid; int status; size_t latlen, lonlen; float *lat, *lon, *data; // Open the file if ((status = nc_open(FILE_NAME, NC_NOWRITE, &ncid))) goto error; // Get the variable id if ((status = nc_inq_varid(ncid, "lat", &varid))) goto error; // Get the variable length if ((status = nc_inq_dimlen(ncid, varid, &latlen))) goto error; // Allocate memory for the variable lat = (float*) malloc(latlen * sizeof(float)); // Read the variable data if ((status = nc_get_var_float(ncid, varid, lat))) goto error; // Repeat for the "lon" variable if ((status = nc_inq_varid(ncid, "lon", &varid))) goto error; if ((status = nc_inq_dimlen(ncid, varid, &lonlen))) goto error; lon = (float*) malloc(lonlen * sizeof(float)); if ((status = nc_get_var_float(ncid, varid, lon))) goto error; // Repeat for the "data" variable if ((status = nc_inq_varid(ncid, "data", &varid))) goto error; data = (float*) malloc(latlen * lonlen * sizeof(float)); if ((status = nc_get_var_float(ncid, varid, data))) goto error; // Output the data for (size_t i = 0; i < latlen; i++) { for (size_t j = 0; j < lonlen; j++) { printf("(%f, %f): %f\n", lat[i], lon[j], data[i*lonlen+j]); } } // Close the file and free the memory nc_close(ncid); free(lat); free(lon); free(data); return 0; error: printf("Error: %s\n", nc_strerror(status)); return 1; } ``` 这段代码打开名为 "example.nc" 的文件,读取其中名为 "lat"、"lon" 和 "data" 的三个变量,并将它们的值输出到屏幕上。在使用该代码时,请确保在编译时链接 netcdf

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值