Re: problem in looping

From: Kyle Griffin <ksgriffin2_at_nyahnyahspammersnyahnyah>
Date: Mon Sep 24 2012 - 19:58:58 MDT

Hi Erika,

In the two emails you've sent, both have errors. In the first (sent only to
me), you loop over just i=0,9 which will not work with iStrt+1 as the time
index. Your best bet is to loop over your original statement (the do
i=iStrt,ilast statement) with the time(i) and SST(i,:,:) statements.

Your second email is similarly close, but still slightly in error. If you
correct the time(iStrt+1) to time(i) and change the gsn_csm_contour
plotting to SST(i,:,:) instead of the SST(n,:,:) you have (I'm not even
sure where n is defined), then you should get the script to work.

The index i, when utilized in the time array, will directly correspond to
the same index you are plotting from the SST variable, and the times will
almost certainly agree.

I'll apologize if I confused you with my comment about i as a counter
confused you - that was merely an alternate solution that could be applied
with my first statement, not in addition to.

Hope this helps better,

Kyle
----------------------------------------
Kyle S. Griffin
Department of Atmospheric and Oceanic Sciences
University of Wisconsin - Madison
1225 W Dayton St, Madison, WI 53706
Room 1421 Email: ksgriffin2@wisc.edu

On Mon, Sep 24, 2012 at 5:42 PM, Erika Folova <e.folova@gmail.com> wrote:

> Hi,
>
> I did what Kyle suggested. I still *get the same error*: *fatal:Subscript
> out of range, error in subscript #0 *. Any suggestion? Thanks a lot.
>
> begin
> f = addfile(./sst.nc", "r") ; ALL times on file
>
> time = f->time
> ymd = cd_calendar(time, -2) ; convert
> * ymdStrt = 20070601 ; year-month start*
> * ymdLast = 20070610 ; year-month last*
> iStrt = ind(ymd.eq.ymdStrt) ; index start
> iLast = ind(ymd.eq.ymdLast) ; index last
> delete(time)
> delete(ymd)
> ==================
> SST = f->sst (iStrt:iLast,:,:) ; read only specified time period
> SST@_FillValue= -999
> * ymd = cd_calendar(SST&time, -2) ; selected period*
> *
> *
> [SNIP]
> =======PLOT
> *do n= iStrt,iLast*
> * wks = gsn_open_wks("pdf","SST"+time(iStrt+1))*
> * gsn_define_colormap(wks,"GreenYellow") *
> * res@tiMainString = "SST Pacific, Time: "+**time(iStrt+1)**+" " *
> * plot = gsn_csm_contour_map(wks,SST(n, :, :),res)*
> * delete(wks)*
> *end do*
> *end*
> ====
>
> Cheers,
>
>
>
>
>
>
> On Mon, Sep 24, 2012 at 11:28 PM, Kyle Griffin <ksgriffin2@wisc.edu>wrote:
>
>> I haven't tested this, but the following line should work if you don't
>> mind keeping the formatting of the dates as-is (e.g. "20060601" format):
>>
>> * res@tiMainString = "SST Pacific, Time: "+time(i)+" "*
>>
>> sted this, but the following line should work if you don't mind keeping
>> the formatting of the dates as-is (e.g. "20060601" format):
>> The time coordinate variable is a 1-D array with the same size as the
>> time dimension of your SST variable. As a result, the index you use for the
>> time in your SST should work for time as well.
>> If 'i' were just a counter for the number of times you have gone through
>> the loop, you could use time(iStrt+i) to achieve a similar result.
>>
>> If you wish to reformat the string, look into uses of the date functions
>> found:
>>
>> http://www.ncl.ucar.edu/Document/Functions/date.shtml
>>
>> I find cd_string (or ut_string if you are in an older version) to be the
>> most useful to format dates the way you like to see them when reading from
>> a time coordinate variable, although others have varying preferences.
>>
>>
>> Kyle
>> ----------------------------------------
>> Kyle S. Griffin
>> Department of Atmospheric and Oceanic Sciences
>> University of Wisconsin - Madison
>> 1225 W Dayton St, Madison, WI 53706
>> Room 1421 Email: ksgriffin2@wisc.edu
>>
>>
>>
>> On Mon, Sep 24, 2012 at 4:17 PM, Erika Folova <e.folova@gmail.com> wrote:
>>
>>> Hi NCL users,
>>>
>>> I just wonder how to figure out this error: fatal:Subscript out of
>>> range, error in subscript #0
>>> I think I've set everything quite well as follow:
>>>
>>> begin
>>> f = addfile(./sst.nc", "r") ; ALL times on file
>>>
>>> time = f->time
>>> ymd = cd_calendar(time, -2) ; convert
>>> ymdStrt = 20070601 ; year-month start
>>> ymdLast = 20070610 ; year-month last
>>> iStrt = ind(ymd.eq.ymdStrt) ; index start
>>> iLast = ind(ymd.eq.ymdLast) ; index last
>>> delete(time)
>>> delete(ymd)
>>>
>>> ==================
>>> SST = f->sst *(iStrt:iLast,:,:)* ; read only specified time
>>> period
>>> SST@_FillValue= -999
>>>
>>> [SNIP]
>>> ==================
>>> print("PLOT --->>>")
>>>
>>> *do i=iStrt, iLast*
>>> wks = gsn_open_wks("pdf","SST"+i)
>>> gsn_define_colormap(wks,"GreenYellow") ; choose color map
>>> * res@tiMainString = "SST Pacific, Time: "+i+" "*
>>> plot = gsn_csm_contour_map(wks,*SST(i,:,:)*,res)
>>> delete(wks)
>>> end do
>>>
>>> end
>>> ======
>>>
>>> I also just wonder how to reversed the index values back to the ymd
>>> values thus i can attach it on my res@tiMainString correctly.
>>> Thanks a lot
>>>
>>> Cheers...
>>>
>>> _______________________________________________
>>> 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 Sep 24 19:59:28 2012

This archive was generated by hypermail 2.1.8 : Wed Sep 26 2012 - 13:56:04 MDT