[ncl-talk] Do Loop Overwriting Array

Dennis Shea shea at ucar.edu
Fri May 3 15:08:08 MDT 2019


I have only given a cursory glance to your NCL script.

[1] I am sure you are overwriting a variable.

[2] Likely, you have to preallocate [*new*
<https://www.ncl.ucar.edu/Document/Functions/Built-in/new.shtml>] space to
retain array space to save the value(s) for each file.

[3] If you have 26 files and each file has (say) one-time step, then

;   set lat-lon coordinates to match Trial Lake

         nfile = 26
         wrf_pts = new( nfile, "float" )   ; preallocate space for results
         do nf=0,nfile-1
              fwrf    = addfile(...)
              lat2d  = fwrf->XLAT
              lon2d = fwrf->XLONG
              wrf_prec   = fwrf->PREC_ACC_NC(0,:,:)
              wrf_pts(nf) = rcm2points(lat2d,lon2d,wrf_prec, slat,slon,2)
        end do

Of course, if each file has multiple times, ypu will have to make the
appropriate changes.

On Fri, May 3, 2019 at 10:55 AM Zach Rieck <zrr817 at gmail.com> wrote:

> To Whom it May Concern-
>
> I'm running into an issue where my do loop seems to be overwriting instead
> of storing values from files sequentially 26 times like it's meant to.
> Essentially, I have 26 files with similar names I want to pull in precip
> values from. I have 2 arrays defined that have the specific dates for each
> file (date 1 and date 2) and what I want is for i to loop through each file
> and import (1st loop) and then loop through i again to build an array of
> precip values (2nd loop).
>
> The issue is that the 1st loop seems to be only storing the 26th file,
> which I believe is because it is overwriting for some reason. Because of
> this, the 2nd loop breaks my code since the queries I have written are
> outside the scope of the array. Is there a way to preventing this from
> overwriting so that I can add all 26 files and then query them 1 by 1 to
> pull in precipitation values?
>
> Thanks for all the help with my questions, I really appreciate it!
>
> Respectfully,
>
> -Zach Rieck
> zrr817 at gmail.com
> (513)-502-5652
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190503/9d8fe24c/attachment.html>


More information about the ncl-talk mailing list