How to append new variables to existing netcdf?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to append new variables to existing netcdf?

zs1992
Hi everyone, I'm using Octave 5.1 and I'd like to do the following: Create a
netcdf with plenty of variables. If new variables are founded in the future,
append them to existing netcdf.variables.

I created a netcdf with ncwriteschema('mynetcdf.nc',Var), where known
variables are stored in Var.variables. Now I have come across a new
variable, and I've stored it in a new group NewVar.Variables. I tried to do
ncwriteschema('mynetcdf.nc',NewVar), but it failed with a message "error,
netcdf, File exist && NC_noclobber".

I noticed that there's not other input argument for 'ncwriteschema',
therefore I can't define nc mode as clobber with this command. So I did the
following:
ncid=netcdf_create('mynetcdf','CLOBBER');
netcdf_reDef(ncid);
ncwriteschema('mynetcdf',Var);
This time, another error popped up, saying 'error, netcdf, operation not
allowed in define mode'.

Now I'm out of options. Is there any way to append new variables to exising
netcdf file?



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

RE: How to append new variables to existing netcdf?

JohnD
> Message: 1
> Date: Tue, 29 Oct 2019 07:21:24 -0500 (CDT)
> From: zs1992 <[hidden email]>
> To: [hidden email]
> Subject: How to append new variables to existing netcdf?
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset=us-ascii
>
> Hi everyone, I'm using Octave 5.1 and I'd like to do the following: Create a
> netcdf with plenty of variables. If new variables are founded in the future,
> append them to existing netcdf.variables.
>
> I created a netcdf with ncwriteschema('mynetcdf.nc',Var), where known
> variables are stored in Var.variables. Now I have come across a new
> variable, and I've stored it in a new group NewVar.Variables. I tried to do
> ncwriteschema('mynetcdf.nc',NewVar), but it failed with a message "error,
> netcdf, File exist && NC_noclobber".
>
> I noticed that there's not other input argument for 'ncwriteschema',
> therefore I can't define nc mode as clobber with this command. So I did the
> following:
> ncid=netcdf_create('mynetcdf','CLOBBER');
> netcdf_reDef(ncid);
> ncwriteschema('mynetcdf',Var);
> This time, another error popped up, saying 'error, netcdf, operation not
> allowed in define mode'.
>
> Now I'm out of options. Is there any way to append new variables to exising
> netcdf file?
>
>

Can you provide a small working example code of what you are doing ?



Reply | Threaded
Open this post in threaded view
|

RE: How to append new variables to existing netcdf?

zs1992
Sure.
A few notes on my program:
1,I have more than 100 variables, in the example I only listed 3.
2,As it is mentioned in the program,the first part and second part are run
separately, therefore when new variables are found, they are stored in
different groups.
Basically, I'm looking for a solution that appends new variables to existing
variables in existing netcdf file. Feel free to contact me if more
information is needed.


example_program.m
<https://octave.1599824.n4.nabble.com/file/t373531/example_program.m>  



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: How to append new variables to existing netcdf?

Nir Krakauer-3
Have you tried nccreate() followed by ncwrite()? The example here
might be useful:
http://modb.oce.ulg.ac.be/mediawiki/index.php/Write_a_slice_at_a_time_in_a_NetCDF_file


Reply | Threaded
Open this post in threaded view
|

Re: How to append new variables to existing netcdf?

zs1992
Nir Krakauer-3 wrote
> Have you tried nccreate() followed by ncwrite()? The example here
> might be useful:
> http://modb.oce.ulg.ac.be/mediawiki/index.php/Write_a_slice_at_a_time_in_a_NetCDF_file

Hi Nir,
I didn't use nccreate mainly because I don't know where and how to define
global attributes, dimensions and variable attributes in that way. In my
task, some global attributes should be updated when new variables are found.
Dimension is time, with three items(Name, Length, Unlimited), but in this
command, according to the example, dimension only has two items(Name,
Length). Therefore I'm unsure of which command to use after nccreate.





--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

RE: How to append new variables to existing netcdf?

zs1992
In reply to this post by JohnD
JohnD wrote
>> Message: 1
>> Date: Tue, 29 Oct 2019 07:21:24 -0500 (CDT)
>> From: zs1992 &lt;

> zs1992name@

> &gt;
>> To:

> help-octave@

>> Subject: How to append new variables to existing netcdf?
>> Message-ID: <

> 1572351684004-0.post@.nabble

>>
>> Content-Type: text/plain; charset=us-ascii
>>
>> Hi everyone, I'm using Octave 5.1 and I'd like to do the following:
>> Create a
>> netcdf with plenty of variables. If new variables are founded in the
>> future,
>> append them to existing netcdf.variables.
>>
>> I created a netcdf with ncwriteschema('mynetcdf.nc',Var), where known
>> variables are stored in Var.variables. Now I have come across a new
>> variable, and I've stored it in a new group NewVar.Variables. I tried to
>> do
>> ncwriteschema('mynetcdf.nc',NewVar), but it failed with a message "error,
>> netcdf, File exist && NC_noclobber".
>>
>> I noticed that there's not other input argument for 'ncwriteschema',
>> therefore I can't define nc mode as clobber with this command. So I did
>> the
>> following:
>> ncid=netcdf_create('mynetcdf','CLOBBER');
>> netcdf_reDef(ncid);
>> ncwriteschema('mynetcdf',Var);
>> This time, another error popped up, saying 'error, netcdf, operation not
>> allowed in define mode'.
>>
>> Now I'm out of options. Is there any way to append new variables to
>> exising
>> netcdf file?
>>
>>
>
> Can you provide a small working example code of what you are doing ?

Sure.
I guess I've replied to your response in the wrong way, so here is my
program.
A few notes on my program:
1,I have more than 100 variables, in the example I only listed 3.
2,As it is mentioned in the program,the first part and second part are run
separately, therefore when new variables are found, they are stored in
different groups.
Basically, I'm looking for a solution that appends new variables to existing
variables in existing netcdf file. Feel free to contact me if more
information is needed.
example_program.m
<https://octave.1599824.n4.nabble.com/file/t373531/example_program.m>  



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html