Re: How do I properly close a file after opening it using addfile

From: Wei Huang <huangwei_at_nyahnyahspammersnyahnyah>
Date: Mon Jul 30 2012 - 08:23:41 MDT

Tom,

The proper way to close a file is use function delete.

f = addfile("flnm", "r")

use f for something.

delete(f)

After delete, memory used by f and even f itself is cleared (which means
f can be used for any other purpose, hereafter).

If you have some files in same structure, then you can use
the way Dennis suggested, which is variable (file) reuse.
Which will be more efficient, as it eliminates the steps of
re-create file and delete file (by just re-use the file).

Regards,

Wei

huangwei@ucar.edu
VETS/CISL
National Center for Atmospheric Research
P.O. Box 3000 (1850 Table Mesa Dr.)
Boulder, CO 80307-3000 USA
(303) 497-8924

On Jul 30, 2012, at 7:59 AM, Dennis Shea wrote:

> In NCL, there is no need to close a file after opening it.
> Don't know your setup but
>
> diri = "./" ; "/what/ever/"
> fili = systemfunc("cd "+diri+" ; ls foo*.grb")
> nfili = dimsizes(fili)
>
> do nf=0,nfils-1
> f = addfile(foo(n), "r") ; open
> :
> :
> end do
>
> Each time through the loop the file reference (ie, pointer) is changed.
>
>
> On 7/30/12 7:33 AM, Petroski, Thomas J - MLC wrote:
>> Hello NCL Users –
>>
>> I am using “addfile” to open a GRIB2 file in my NCL code. After reading
>> in the data and storing to local NCL variables, I want to close the
>> GRIB2, then open another GRIB2 file. What is the best way to close the
>> first file before opening a second one?
>>
>> Thank You,
>>
>> Tom
>>
>> _______________________________________________
>>
>> *Thomas J. Petroski*
>>
>> /GMRT Commodities/
>>
>> Bank of America Merrill Lynch
>>
>> Email: tom.petroski@baml.com <mailto:tom.petroski@baml.com>
>>
>> _______________________________________________
>>
>> ------------------------------------------------------------------------
>> This message w/attachments (message) is intended solely for the use of
>> the intended recipient(s) and may contain information that is
>> privileged, confidential or proprietary. If you are not an intended
>> recipient, please notify the sender, and then please delete and destroy
>> all copies and attachments, and be advised that any review or
>> dissemination of, or the taking of any action in reliance on, the
>> information contained in or attached to this message is prohibited.
>> Unless specifically indicated, this message is not an offer to sell or a
>> solicitation of any investment products or other financial product or
>> service, an official confirmation of any transaction, or an official
>> statement of Sender. Subject to applicable law, Sender may intercept,
>> monitor, review and retain e-communications (EC) traveling through its
>> networks/systems and may produce any such EC to regulators, law
>> enforcement, in litigation and as required by law.
>> The laws of the country of each sender/recipient may impact the handling
>> of EC, and EC may be archived, supervised and produced in countries
>> other than the country in which you are located. This message cannot be
>> guaranteed to be secure or free of errors or viruses.
>>
>> References to "Sender" are references to any subsidiary of Bank of
>> America Corporation. Securities and Insurance Products: * Are Not FDIC
>> Insured * Are Not Bank Guaranteed * May Lose Value * Are Not a Bank
>> Deposit * Are Not a Condition to Any Banking Service or Activity * Are
>> Not Insured by Any Federal Government Agency. Attachments that are part
>> of this EC may have additional important disclosures and disclaimers,
>> which you should read. This message is subject to terms available at the
>> following link:
>> http://www.bankofamerica.com/emaildisclaimer. By messaging with Sender
>> you consent to the foregoing.
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Jul 30 08:23:52 2012

This archive was generated by hypermail 2.1.8 : Fri Aug 03 2012 - 14:39:58 MDT