Add a variable to existing NetCDF file [message #89957] |
Fri, 09 January 2015 12:39  |
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 #89962 is a reply to message #89961] |
Fri, 09 January 2015 14:14   |
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 #89964 is a reply to message #89962] |
Fri, 09 January 2015 14:34   |
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   |
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  |
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.")
|
|
|