How do I append new data to a new variable in a NETCDF file ?

조회 수: 11 (최근 30일)
俊 马
俊 马 2023년 2월 21일
댓글: 俊 马 2023년 2월 28일
I want to append new data to a new variable in the existing netcdf file and let other variables remain unchanged. However, when I use:
ncid=netcdf.open('E:\data\Landcover\MCD12Q1\heihe\surfdata_40x40_hh_gravtest.nc','WRITE');
gravid = netcdf.defVar(ncid,'PCT_GRAVEL','double',[40 40 10]);
error shows:
Operation not allowed in data mode (NC_ENOTINDEFINE)
do you know how to solve it ? thanks
  댓글 수: 1
dpb
dpb 2023년 2월 21일
I "know (almost) nuthink!" per Sgt Schultz about NetCDF files, but the MATLAB interface supplies a higher-level abstracted function <nccreate> that purports to be able to do that. I'd suggest trying it.
If that fails, you'll have to dig a whole lot deeper into the file content of the file you have and the details of the required syntax/operations to add to it.
I dunno if .defVar is the first thing you can call or if you have to do more preliminary work first; it's a pretty complex format/system...

댓글을 달려면 로그인하십시오.

채택된 답변

Raghunathraju
Raghunathraju 2023년 2월 27일
Hi,
As per my understanding, you want to append new data to a new variable in a NETCDF file.
You have used the following code to get your work done.
ncid=netcdf.open('E:\data\Landcover\MCD12Q1\heihe\surfdata_40x40_hh_gravtest.nc','WRITE');
gravid = netcdf.defVar(ncid,'PCT_GRAVEL','double',[40 40 10]);
But the datatype you used in “netcdf.defVar” is double which is invalid for NETCDF .Instead you can use NC_DOUBLE”.
For further reference you can go through the link below
  댓글 수: 1
俊 马
俊 马 2023년 2월 28일
it didn't work... unless I use "ncid=netcdf.create...." instead of "ncid=netcdf.cpen...." but thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by