读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;
}