zhoufcumt的个人博客分享 http://blog.sciencenet.cn/u/zhoufcumt

博文

C 语言多维动态数组的建立和释放

已有 2799 次阅读 2013-6-13 02:28 |个人分类:科研|系统分类:科研笔记| 多维动态数组, 建立和释放

     读netCDF格式数据时,经常会碰到大维数数组问题。C 对于大维数数组,比如类似press[144][73][1464]这样的,必须使用动态数组,以三维数组为例,其它维数类似:
#include <stdio.h>
#include <stdlib.h>
#define ARRAY_SIZE 144*73*1464
typedef struct
{
   double scale;
   double offset;
} ScaleOffset;
int ReadNetcdf(const char * nc_file, const char * var_name, int * start, int * count,
   int * stride, ScaleOffset * scloff, double * data_out, double * time_out)
{
   printf("%sn", "zhoufeng");
}
int main(int argc, char *argv[])
{
   double (*press)[73][1464];
   press = (double (*)[73][1464])malloc(ARRAY_SIZE);
   double time[1464];
   int start[3] = {1, 1, 1}, count[3] = {0, 0, 0}, stride[3] = {1, 1, 1};
   ScaleOffset scloff;
   char nc_file[] = "simple_xy.nc";
 
   if (!(ReadNetcdf(nc_file, "pres", start, count, stride, &scloff,
       &press[0][0][0], time)))
       printf("%sn", "fengzhou");
   free(press);
   return 0;
}




https://blog.sciencenet.cn/blog-350278-698937.html

上一篇:Linux 下 C 接口的 NetCDF 编译、安装、测试
下一篇:Linux 下 Matlab 一些常用命令
收藏 IP: 222.66.117.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-17 15:28

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部