# [ncl-talk] loop ncl array

Guido Cioni guidocioni at gmail.com
Sat Dec 10 05:46:44 MST 2016

```Hey Enric,
You can create an array with your desired time steps and then loop through
that array:

ihours = (/1, 5, 12, 30/)
do i=0,dimsizes(ihours)-1
...
th2(ihours(i),...)
end do

Il 10 dic 2016 12:52 PM, "Agud Pique, Enric" <eagud.q at ccma.cat> ha scritto:

Hello,

The following code extract a variable from a wrfout file, modify the
variable and save it again. This is for all the nTimes of the simulation.
But, I would like to do it for only some hours of the simulation. How can I
do it for exemple, for time 5,6,7,29, 30,31 if nTimes is for exemple 55?

Thank you, best

Enric

#####Code#######

begin

;
; Extract variable
th2 = f->TH2

;
; Determine dimensions of the th2 field
;
dims = dimsizes(th2)
nTimes = dims(0)
south_north = dims(1)
west_east = dims(2)

print("nTimes dimension: "+nTimes)
print("South-North dimension: "+south_north)
print("West-East dimension: "+west_east)

;
; Modify the th2 as needed
;
iTime = 0
do l=0, nTimes-1
;do l=(/"5","6","7","29","30","31"/)
do j=0,south_north-1
do i=0,west_east-1
th2(l,j,i) = th2(l,j,i) + 1  ; increase Th2+ 1
end do
end do
end do
;print(th2)

f->TH2 = th2

end
_______________________________________________
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/20161210/906599e9/attachment.html
```