Re: problem in looping

From: Erika Folova <e.folova_at_nyahnyahspammersnyahnyah>
Date: Mon Sep 24 2012 - 16:42:18 MDT

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
Received on Mon Sep 24 16:42:26 2012

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