[ncl-talk] help loop

Vanúcia Schumacher vanucia-schumacher at hotmail.com
Tue Jan 16 06:52:46 MST 2018


Hi NCLs


I would like to create an array of 36 x 12 (time x months) for each lat and lon values from file (91 values), generating 91 separate files.
I tried the script below, but I am not able to generate a loop for what I want to get, if anyone can give a help I appreciate.


 lats  = asciiread("lat.txt",(/91,3/),"float")
 lons = asciiread("lon..txt",(/91,3/),"float")
 lat    = lats(:,1)
 lon   = lons(:,2)

nlat   = dimsizes(lat)
nlon  = dimsizes(lon)


 list = systemfunc("ls /cru.*.nc")  ; are 12 files separated by months



var_matriz = new( (/36,dimsizes(list)/), float )
      do j = 0,dimsizes(list)-1

do i=0,nlat(0)-1
do k=0,nlon(0)-1

       a = addfile(list(j), "r")
       var_matriz(:,j) = a->pr(:,i,k)

    arq=True
   arq at fout="ex."+i+".txt"
   write_matrix( var_matriz, dimsizes(list)+"f10.2", arq )


________________________________
De: Vanúcia Schumacher <vanucia-schumacher at hotmail.com>
Enviado: terça-feira, 16 de janeiro de 2018 11:11:09
Para: ncl-talk at ucar.edu
Assunto: help loop


Hi NCLs


I would like to create an array of 36 x 12 (time x months), but I can only generate one file at a time. Also calculate a file (36 x 12) for each lat and lon values from another file (91 values).
I tried the script below, but I am not able to generate a loop for what I want to get, if anyone can give a help I appreciate.


 lats  = asciiread("lat.txt",(/91,3/),"float")
 lons = asciiread("lon..txt",(/91,3/),"float")
 lat    = lats(:,1)
 lon    = lons(:,2)


 f = systemfunc("ls /cru.*.nc")  ; are 12 files separated by months

 N = dimsizes( f )

 do i = 0,N-1
a = addfiles(f(i), "r")
var = a[:]->pr(:,{lat},{lon})
 asciiwrite ("prec.cru."+i+".txt", sprintf("%9.2f", var))
 end do



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180116/fa0e0299/attachment.html>


More information about the ncl-talk mailing list