Re: how delete the array variables in do loop expediently?

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Tue Jun 29 2010 - 09:39:56 MDT

Hi,

I'm afraid there's no easy way around this, unless your variables are the same size every
time in the loop, then you don't need to delete them.

We have it high on our list to add the ability to delete multiple variables with one call.
This will not be in the 5.2.1 release, but maybe in the 6.0.0 release in a few months.

Some minor things you can do: it is not necessary to convert iiyear to a string before you use it.
"iiyear" is an integer, and you can use it directly as part of a string concatenation:

   data = asciiread(data_dir+iiyear+"rain.txt",-1,"string")

I'm not sure what the purpose of this code is:

> do nn = 0,numrec-1
> asciiwrite ("sample.txt", newbtdata)
> end do

This is writing the same data to "sample.txt" numrec times, which is redundant.

What does your "rain.txt" data look like? You might be able to read it in faster
using something other than "str_get_col". I'm hoping that you can read it
in as integers, so you don't have to do the string conversion. Can you send it to me?

--Mary

On Jun 29, 2010, at 1:30 AM, Jie TANG wrote:

> hello,ncl users.
>
> I write a ncl script to read some data from some dataset,shown as below .
> I have to add the delete command to delete the array variables defined in
> the "do iiyear " loop.The delete commands is shown as the red characters.
> Now I want to know is there some method to reinitialize or delete those
> array variables so that I can go on the loop calculation expediently with
> type the delete so many "delete" commands?
>
> data_dir = ("../../../cygdrive/g/data/")
>
> do iiyear=1999,2009
> ccyear = flt2string(iiyear)
> data = asciiread(data_dir+ccyear+"rain.txt",-1,"string")
> cyearmon= str_get_cols(data, 0,5)
> ctime = str_get_cols(data, 0,9)
> iyear = stringtointeger(str_get_cols(data, 0,3)) ; cut the data
> imon = stringtointeger(str_get_cols(data, 4,5))
> iday = stringtointeger(str_get_cols(data, 6,7))
> ihour = stringtointeger(str_get_cols(data, 8,9))
> irain = stringtointeger(str_get_cols(data, 11,11))
> ilat = stringtofloat(str_get_cols(data, 13,15))
> ilon = stringtofloat(str_get_cols(data, 17,20))
> iprs = stringtointeger(str_get_cols(data, 22,25))
> iu = stringtointeger(str_get_cols(data, 32,33))
> cyearmon= str_get_cols(data, 0,5)
> ctime = str_get_cols(data, 0,9)
> numrec = dimsizes(iyear)
> newdata = new( numrec, "string")
> do nn = 0,numrec-1
> asciiwrite ("sample.txt", newbtdata)
> end do
> asciiwrite (ccyear+"rain2.txt",newbtdata(1:inn))
> delete(data)
> delete(cyearmon)
> delete(ctime)
> delete(iyear)
> delete(imon)
> delete(ilat)
> delete(ilon)
> delete(iprs)
> delete(igrade)
> delete(newbtdata)
> end do
> --
> TANG Jie
> Email: totangjie@gmail.com
> Tel: 0086-2154896104
> Shanghai Typhoon Institute,China
> _______________________________________________
> 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 Tue Jun 29 09:40:01 2010

This archive was generated by hypermail 2.1.8 : Fri Jul 02 2010 - 07:45:13 MDT