[ncl-talk] efficient way of reading numbered directories?

Adam Phillips asphilli at ucar.edu
Thu Feb 21 15:29:40 MST 2019


Hi Tabish,
Yes, a do loop could be used:

DATADir =  "/mnt/rasher/60sensruns/run"
do gg = 1,60
     FILES1 = systemfunc (" ls -1 " + DATADir +gg+ "subset_d03_2014-* ")
     a1 = addfiles(FILES1,"r")
.....

Also note, you could set up a string array that houses the directories
using a do loop
DATADir = new(60,string)
do gg = 1,dimsizes(DATADir)-1
     DATADir(gg-1) = "/mnt/rasher/60sensruns/run"+gg
end do

Adam

On Thu, Feb 21, 2019 at 1:15 PM Tabish Ansari <tabishumaransari at gmail.com>
wrote:

> Hi
>
> I am currently reading in files in a very inefficient way from 60
> directories:
>
> DATADir1 = "/mnt/rasher/60sensruns/run1/"
> DATADir2 = "/mnt/rasher/60sensruns/run2/"
> DATADir3 = "/mnt/rasher/60sensruns/run3/"
> DATADir4 = "/mnt/rasher/60sensruns/run4/"
> DATADir5 = "/mnt/rasher/60sensruns/run5/"
> DATADir6 = "/mnt/rasher/60sensruns/run6/"
> DATADir7 = "/mnt/rasher/60sensruns/run7/"
> DATADir8 = "/mnt/rasher/60sensruns/run8/"
> DATADir9 = "/mnt/rasher/60sensruns/run9/"
> DATADir10 = "/mnt/rasher/60sensruns/run10/"
> DATADir11 = "/mnt/rasher/60sensruns/run11/"
> DATADir12 = "/mnt/rasher/60sensruns/run12/"
> DATADir13 = "/mnt/rasher/60sensruns/run13/"
> DATADir14 = "/mnt/rasher/60sensruns/run14/"
> DATADir15 = "/mnt/rasher/60sensruns/run15/"
> DATADir16 = "/mnt/rasher/60sensruns/run16/"
> DATADir17 = "/mnt/rasher/60sensruns/run17/"
> DATADir18 = "/mnt/rasher/60sensruns/run18/"
> DATADir19 = "/mnt/rasher/60sensruns/run19/"
> DATADir20 = "/mnt/rasher/60sensruns/run20/"
> DATADir21 = "/mnt/rasher/60sensruns/run21/"
> DATADir22 = "/mnt/rasher/60sensruns/run22/"
> DATADir23 = "/mnt/rasher/60sensruns/run23/"
> DATADir24 = "/mnt/rasher/60sensruns/run24/"
> DATADir25 = "/mnt/rasher/60sensruns/run25/"
> DATADir26 = "/mnt/rasher/60sensruns/run26/"
> DATADir27 = "/mnt/rasher/60sensruns/run27/"
> DATADir28 = "/mnt/rasher/60sensruns/run28/"
> DATADir29 = "/mnt/rasher/60sensruns/run29/"
> DATADir30 = "/mnt/rasher/60sensruns/run30/"
> DATADir31 = "/mnt/rasher/60sensruns/run31/"
> DATADir32 = "/mnt/rasher/60sensruns/run32/"
> DATADir33 = "/mnt/rasher/60sensruns/run33/"
> DATADir34 = "/mnt/rasher/60sensruns/run34/"
> DATADir35 = "/mnt/rasher/60sensruns/run35/"
> DATADir36 = "/mnt/rasher/60sensruns/run36/"
> DATADir37 = "/mnt/rasher/60sensruns/run37/"
> DATADir38 = "/mnt/rasher/60sensruns/run38/"
> DATADir39 = "/mnt/rasher/60sensruns/run39/"
> DATADir40 = "/mnt/rasher/60sensruns/run40/"
> DATADir41 = "/mnt/rasher/60sensruns/run41/"
> DATADir42 = "/mnt/rasher/60sensruns/run42/"
> DATADir43 = "/mnt/rasher/60sensruns/run43/"
> DATADir44 = "/mnt/rasher/60sensruns/run44/"
> DATADir45 = "/mnt/rasher/60sensruns/run45/"
> DATADir46 = "/mnt/rasher/60sensruns/run46/"
> DATADir47 = "/mnt/rasher/60sensruns/run47/"
> DATADir48 = "/mnt/rasher/60sensruns/run48/"
> DATADir49 = "/mnt/rasher/60sensruns/run49/"
> DATADir50 = "/mnt/rasher/60sensruns/run50/"
> DATADir51 = "/mnt/rasher/60sensruns/run51/"
> DATADir52 = "/mnt/rasher/60sensruns/run52/"
> DATADir53 = "/mnt/rasher/60sensruns/run53/"
> DATADir54 = "/mnt/rasher/60sensruns/run54/"
> DATADir55 = "/mnt/rasher/60sensruns/run55/"
> DATADir56 = "/mnt/rasher/60sensruns/run56/"
> DATADir57 = "/mnt/rasher/60sensruns/run57/"
> DATADir58 = "/mnt/rasher/60sensruns/run58/"
> DATADir59 = "/mnt/rasher/60sensruns/run59/"
> DATADir60 = "/mnt/rasher/60sensruns/run60/"
>
> For each directory I will further have to do this:
> FILES1 = systemfunc (" ls -1 " + DATADir1 + "subset_d03_2014-* ")
> a1 = addfiles(FILES1,"r")
> pm25_sim_a1    = a1[:]->PM2_5_DRY(:,0,145,79)
>
> (I will have to type this another 59 times for the other directories)
>
> Is there a way to do this more efficiently perhaps in a loop?
>
> Thanks
>
> Tabish
>
> Tabish U Ansari
> PhD student, Lancaster Environment Center
> Lancaster Univeristy
> Bailrigg, Lancaster,
> LA1 4YW, United Kingdom
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>


-- 
Adam Phillips
Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
www.cgd.ucar.edu/staff/asphilli/   303-497-1726

<http://www.cgd.ucar.edu/staff/asphilli>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190221/e3da1a82/attachment.html>


More information about the ncl-talk mailing list