comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Add a variable to existing NetCDF file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Add a variable to existing NetCDF file [message #89957] Fri, 09 January 2015 12:39 Go to next message
laura.hike is currently offline  laura.hike
Messages: 87
Registered: September 2013
Member
I know this topic was discussed previously, but the only solution given was to use Dave Fanning's suite of NetCDF tools. Seems like there should be an easier answer.

I opened an existing NetCDF file using ncdf_open with the /write option. Then I set up all the information about a new variable (name, dimensions, etc.) I then tried to create the new variable in the NetCDF file using ncdf_vardef:

newid = ncdf_vardef(id, 'swgup', [timeid,latid,lonid], /float)

In response, I get the message

% NCDF_VARDEF: Unable to define variable, not in define mode.

However, the only way I can find to enter define mode in the Exelis documentation is to create a new file using ncdf_create. There must be another way. If not, why is there a /write option in ncdf_open in the first place? It seems silly to have to copy over the whole existing file just to add a variable. From what I can see, this would take hundreds of commands for my file.

Maybe this question is only for the IDL developers, if using Dave's tools will work. I just don't understand why this should be so difficult.

Laura H.
Re: Add a variable to existing NetCDF file [message #89958 is a reply to message #89957] Fri, 09 January 2015 12:50 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
laura.hike@gmail.com writes:

> I know this topic was discussed previously, but the only solution given was to use Dave Fanning's suite of NetCDF tools. Seems like there should be an easier answer.

Easier than what?

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Add a variable to existing NetCDF file [message #89959 is a reply to message #89958] Fri, 09 January 2015 13:09 Go to previous messageGo to next message
laura.hike is currently offline  laura.hike
Messages: 87
Registered: September 2013
Member
Ha, ha! :^) Something that can be done simply using basic IDL commands instead of having to download a whole library. It looks like all that's missing from the existing commands is a way to enter define mode. All the other commands you need are there.

L.


On Friday, January 9, 2015 at 12:50:06 PM UTC-8, David Fanning wrote:
> laura.hike@gmail.com writes:
>
>> I know this topic was discussed previously, but the only solution given was to use Dave Fanning's suite of NetCDF tools. Seems like there should be an easier answer.
>
> Easier than what?
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Add a variable to existing NetCDF file [message #89960 is a reply to message #89959] Fri, 09 January 2015 13:32 Go to previous messageGo to next message
Lajos Foldy is currently offline  Lajos Foldy
Messages: 176
Registered: December 2011
Senior Member
On Friday, January 9, 2015 at 10:10:00 PM UTC+1, laura...@gmail.com wrote:
> Ha, ha! :^) Something that can be done simply using basic IDL commands instead of having to download a whole library. It looks like all that's missing from the existing commands is a way to enter define mode. All the other commands you need are there.

NCDF_CONTROL, id, /redef

regards,
Lajos
Re: Add a variable to existing NetCDF file [message #89961 is a reply to message #89959] Fri, 09 January 2015 13:36 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
laura.hike@gmail.com writes:

> Ha, ha! :^) Something that can be done simply using basic IDL commands instead of having to download a whole library. It looks like all that's missing from the existing commands is a way to enter define mode. All the other commands you need are there.

Maybe you are looking for this:

NCDF_Control, fileID, /REDEF ; Put open file in DEFINE mode.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Add a variable to existing NetCDF file [message #89962 is a reply to message #89961] Fri, 09 January 2015 14:14 Go to previous messageGo to next message
laura.hike is currently offline  laura.hike
Messages: 87
Registered: September 2013
Member
Oh, cool! Hidden in the generic NetCDF command, I see. All I want to do is add one variable to a file....



On Friday, January 9, 2015 at 1:36:47 PM UTC-8, David Fanning wrote:
> laura.hike@gmail.com writes:
>
>> Ha, ha! :^) Something that can be done simply using basic IDL commands instead of having to download a whole library. It looks like all that's missing from the existing commands is a way to enter define mode. All the other commands you need are there.
>
> Maybe you are looking for this:
>
> NCDF_Control, fileID, /REDEF ; Put open file in DEFINE mode.
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Add a variable to existing NetCDF file [message #89963 is a reply to message #89962] Fri, 09 January 2015 14:29 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
laura.hike@gmail.com writes:

> Oh, cool! Hidden in the generic NetCDF command, I see. All I want to do is add one variable to a file....

Because this seems like an awfully easy and common thing to do, I've
added an example of how to add a new variable to an already existing
netCDF file in the file ncdf_file_examples.pro. You can find the new
version of the file here:

http://www.idlcoyote.com/programs/ncdf_file_examples.pro

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Add a variable to existing NetCDF file [message #89964 is a reply to message #89962] Fri, 09 January 2015 14:34 Go to previous messageGo to next message
laura.hike is currently offline  laura.hike
Messages: 87
Registered: September 2013
Member
But it still won't work. Now I get a generic "Unable to define variable" error. Maybe I'll give up, write a tiny new file, and append it to the other using NCL or NCO.


On Friday, January 9, 2015 at 2:14:12 PM UTC-8, laura...@gmail.com wrote:
> Oh, cool! Hidden in the generic NetCDF command, I see. All I want to do is add one variable to a file....
>
>
>
> On Friday, January 9, 2015 at 1:36:47 PM UTC-8, David Fanning wrote:
>> laura.hike@gmail.com writes:
>>
>>> Ha, ha! :^) Something that can be done simply using basic IDL commands instead of having to download a whole library. It looks like all that's missing from the existing commands is a way to enter define mode. All the other commands you need are there.
>>
>> Maybe you are looking for this:
>>
>> NCDF_Control, fileID, /REDEF ; Put open file in DEFINE mode.
>>
>> Cheers,
>>
>> David
>> --
>> David Fanning, Ph.D.
>> Fanning Software Consulting, Inc.
>> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Add a variable to existing NetCDF file [message #89965 is a reply to message #89964] Fri, 09 January 2015 14:35 Go to previous messageGo to next message
laura.hike is currently offline  laura.hike
Messages: 87
Registered: September 2013
Member
Note: I hadn't seen your last message before writing that last one. I'll check your example.



On Friday, January 9, 2015 at 2:34:53 PM UTC-8, laura...@gmail.com wrote:
> But it still won't work. Now I get a generic "Unable to define variable" error. Maybe I'll give up, write a tiny new file, and append it to the other using NCL or NCO.
>
>
> On Friday, January 9, 2015 at 2:14:12 PM UTC-8, laura...@gmail.com wrote:
>> Oh, cool! Hidden in the generic NetCDF command, I see. All I want to do is add one variable to a file....
>>
>>
>>
>> On Friday, January 9, 2015 at 1:36:47 PM UTC-8, David Fanning wrote:
>>> laura.hike@gmail.com writes:
>>>
>>>> Ha, ha! :^) Something that can be done simply using basic IDL commands instead of having to download a whole library. It looks like all that's missing from the existing commands is a way to enter define mode. All the other commands you need are there.
>>>
>>> Maybe you are looking for this:
>>>
>>> NCDF_Control, fileID, /REDEF ; Put open file in DEFINE mode.
>>>
>>> Cheers,
>>>
>>> David
>>> --
>>> David Fanning, Ph.D.
>>> Fanning Software Consulting, Inc.
>>> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>>> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Add a variable to existing NetCDF file [message #89966 is a reply to message #89964] Fri, 09 January 2015 15:02 Go to previous message
laura.hike is currently offline  laura.hike
Messages: 87
Registered: September 2013
Member
Ah, a degenerate dimension was eliminated, changing the variable array size. Got it now.


On Friday, January 9, 2015 at 2:34:53 PM UTC-8, laura...@gmail.com wrote:
> But it still won't work. Now I get a generic "Unable to define variable" error. Maybe I'll give up, write a tiny new file, and append it to the other using NCL or NCO.
>
>
> On Friday, January 9, 2015 at 2:14:12 PM UTC-8, laura...@gmail.com wrote:
>> Oh, cool! Hidden in the generic NetCDF command, I see. All I want to do is add one variable to a file....
>>
>>
>>
>> On Friday, January 9, 2015 at 1:36:47 PM UTC-8, David Fanning wrote:
>>> laura.hike@gmail.com writes:
>>>
>>>> Ha, ha! :^) Something that can be done simply using basic IDL commands instead of having to download a whole library. It looks like all that's missing from the existing commands is a way to enter define mode. All the other commands you need are there.
>>>
>>> Maybe you are looking for this:
>>>
>>> NCDF_Control, fileID, /REDEF ; Put open file in DEFINE mode.
>>>
>>> Cheers,
>>>
>>> David
>>> --
>>> David Fanning, Ph.D.
>>> Fanning Software Consulting, Inc.
>>> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>>> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: object graphics and IDL >= 8.2
Next Topic: Sparse matrixes

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:33:48 PDT 2025

Total time taken to generate the page: 0.00461 seconds