关于.nc格式文件读取

之前基于R语言和matlab写过这方面代码,但是忘了。为了加深记忆决定再写一遍!!

R语言篇

library(ncdf4)
nc<-nc_open('H_halfhourly.upscalingProduct_v1.720.360.2011.nc')
print(nc)

for(i in (6400:14090)){
  j=c(1,1,i)
  data <- ncvar_get(nc, "H_halfhourly",start=j,count=c(720,360,1))

  data_1 <- matrix(NA,nrow=360, ncol=720)
  data_1<-t(data)
  x <- read.csv("E:\\ecosystem_respiration\\BACI\\H\\coor.csv",header=T)
  colnames(data_1) <- x[,2]
  rownames(data_1) <- x[1:360,1]
  write.table(data_1,paste("E:\\ecosystem_respiration\\BACI\\H\\",i,".csv"),sep=",")
  }

 

Matlab篇

clc
clear all;
ncFilePath='E:\ecosystem_respiration\BACI\H_halfhourly.upscalingProduct_v1.array4D.720.360.2011.nc';
% ncdisp(ncFilePath);
ncinfo(ncFilePath);
ncid = netcdf.open(ncFilePath);
% [varname,xtype,dimids,natts] = netcdf.inqVar(ncid,0); %根据变量索引号获取变量的名称
lon=ncread(ncFilePath,'longitude')';%读取经度变量
lat=ncread(ncFilePath,'latitude');%读取纬度变量
% time=ncread(ncFilePath,'hour');%读取时间变量
% H=ncread(ncFilePath,'H_halfhourly',[216,95,1,1],[217,96,48,365]);
% xlswrite('data.xlsx', H) 
netcdf.close(ncid)

 

你可能感兴趣的:(数据处理)