# [ncl-talk] Calculate Average value for a number of files

Ioannis Koletsis koletsis at meteo.noa.gr
Wed Nov 25 06:08:20 MST 2015

```Dear Jack,

It is exactly what I want….

I modified properly your revised script according to my needs and it works perfectly….

Best regards

Ioannis

From: ncl-talk-bounces at ucar.edu [mailto:ncl-talk-bounces at ucar.edu] On Behalf Of Jack Ogaja
Sent: Tuesday, November 24, 2015 5:36 PM
To: Ioannis Koletsis
Cc: ncl-talk [ncl-talk]
Subject: Re: [ncl-talk] Calculate Average value for a number of files

Dear Ioannis,

You can still use “dim_avg_n” function, you just need to reorganise your code, and I don’t think another loop is necessary.

My suggestions:

[1] Retrieve the variables from all the files at once(hoping you won’t experience any memory problem).

;****

it = -1 ;<== this retrieves the time dimension as well

dust1  = wrf_user_getvar(fS,"DUST_1",it)

dust2  = wrf_user_getvar(fS,"DUST_2",it)

dust3  = wrf_user_getvar(fS,"DUST_3",it)

dust4  = wrf_user_getvar(fS,"DUST_4",it)

dust5  = wrf_user_getvar(fS,"DUST_5",it)

;****

[2] Do most data manipulations outside the loops.

;****

dust_J   = dim_sum_n((/dust1,dust2,dust3,dust4,dust5/),0)*density

dust_tot = dust_J(:,level,:,:)

;****

[3] Calculate the files averages(hoping I understood what you want to do)

;****

n1=0  ;<=== Set to suit your needs

n2=2

do ifil = 0,numFILES-1

if (ifil.eq.n2) then

dust_avg = dim_avg_n(dust_J(n1:n2,level,:,:),0)

print(" average of file|" + n1 + "| and file|" + n2 + "| calculated...")

n1=n1+2

n2=n2+2

end if

;****

;….and then write to the output file(whichever way you wish)

;****

data(npt) = data(npt) + sprintf("%7.3f ", dust_tot(ifil,ml,nl))

if (ifil.eq.n2-2) then ;<== write the averages after every other column

data(npt) = data(npt) + sprintf("%7.3f ", dust_avg(ml,nl))

end if

end do

;****

See the attached script. Test it with your data files. If it doesn’t solve the problem as always write again to ncl-talk.

Jack

---
Αυτό το e-mail ελέγχθηκε για ιούς από το πρόγραμμα Avast antivirus.
https://www.avast.com/antivirus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151125/307f7f3a/attachment.html
```