Re: Error spanning multiple files, addfiles_GetVar

From: Erik Noble <enoble_at_nyahnyahspammersnyahnyah>
Date: Wed, 6 Feb 2008 01:08:48 -0500

Mary,
You rock!

I did mean to type
" finarr(ifil:,:,:) = addfiles_GetVar(b,ALLFILES(ifil*4+2),"VV")"

as you noted.

I didn't see the loop syntax error until you pointed out here though.
Thank you for catching that.
-Erik

On Feb 5, 2008 11:45 PM, Mary Haley <haley_at_ucar.edu> wrote:
> Erik,
>
> Please start reading your error messages more closely before posting to
> this list. Your error message is:
>
> fatal:Subscript out of range, error in subscript #0
>
> If you look at the line where the error message is coming from:
>
> finarr(ifil*4+2,:,:,:) = addfiles_GetVar(b,ALLFILES(ifil*4+2),"VV")
>
> Subscript #0 refers to the leftmost subscript. You are subscripting
> finarr with "ifil*4+2", where "ifil" goes from 0 to (numFILES-1)/4. The
> leftmost dimension of finarr is dimensioned (numFILES-1)/4. If you do
> the arithmetic, "ifil*4+2" is eventually going to be greater than
> (numFILES-1)/4, and hence you will get a subscript out of range error
> message. I think maybe you meant to do something like:
>
> finarr(ifil,:,:,:) = addfiles_GetVar(b,ALLFILES(ifil*4+2),"VV")
>
> However, your do loop will probably need to be fixed, since remember,
> you are starting at index 0, and not index 1. You may need to do this:
>
> do ifil = 0, ((numFILES-1)/4)-1
>
>
> --Mary
>
>
> On Feb 5, 2008, at 6:05 PM, Erik Noble wrote:
>
> > Hi.
> > May I have some help?
> >
> > I am trying to span multiple files, return a variable, and put it into
> > an
> > array.
> > I have 245 4xdaily data files that I am trying to read "VV" from ( yet
> > only
> > at 12 UTC). So this means (245-1)/4 = 61 timesteps tat I am trying to
> > span.
> >
> > I tried making the code below using the concatenate "ListSetType (b,
> > "cat"),
> > addfiles, and addfiles_GetVar" functions similar to the example at
> > http://www.ncl.ucar.edu/Applications/addfiles.shtml
> >
> > I am not sure why I keep getting the "out of range" error below, even
> > though
> > I allocated enough space.
> >
> > Could I have a suggestion here?
> > Humbly yours,
> > Erik
> >
> > fatal:Subscript out of range, error in subscript #0
> > fatal:Execute: Error occurred at or near line 22 in file
> > test_script3.ncl
> >
> >
> > ; Script to Read FNL Reanalysis 4 x Daily data (245 files)
> > ; Read in V data for every 12 UTC timestep
> > ; Create a new array
> > load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> > load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> > load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> > load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
> > load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
> >
> > begin
> > ;========================
> > ; get list of all met_em files and open as "one big file" for array
> > ;========================
> > DATADir = "/Volumes/Data_and_Models/NAMA-SOP3/" ; path to your
> > data -
> > must have trailing "/"
> > ALLFILES = systemfunc ("csh -c ' ls " + DATADir +
> > "met_em.d01.2006*nc'")
> > ; root of data file you want to plot
> > numFILES = dimsizes(ALLFILES) ; 245 files present, 4 hourly data
> > finarr = new((/(numFILES-1)/4,27,110,139/),"float") ;244/4=61,27
> > levels,
> > 110x139 grid
> >
> > do ifil = 0, (numFILES-1)/4
> > b = addfiles(ALLFILES(ifil*4+2),"r")
> > ListSetType (b, "cat")
> > finarr(ifil*4+2,:,:,:) = addfiles_GetVar(b,ALLFILES(ifil*4+2),"VV")
> > end do
> > printVarSummary(finarr)
> > end
> >
> >
> >
> > _______________________________________________
> > ncl-talk mailing list
> > ncl-talk_at_ucar.edu
> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
Received on Tue Feb 05 2008 - 23:08:48 MST

This archive was generated by hypermail 2.2.0 : Thu Feb 07 2008 - 08:58:57 MST