Re: Looping through files

From: Yuqiang Zhang <yuqiangzhang.thu_at_nyahnyahspammersnyahnyah>
Date: Wed Nov 20 2013 - 07:09:39 MST

Hi Melissa,


I think you may need to delete the variable "x" at the end of each model's
loop. I had the similar issue before. It was caused by different dimensions
of each model.


I hope this works. If others have different opinions, please complement.





From: [] On Behalf
Of Melissa Lazenby
Sent: Wednesday, November 20, 2013 8:56 AM
Subject: Looping through files


Hi All

I am trying to find an effective and efficient way to do the same regline
analysis on 44 CMIP5 models for 55 years each. I want to just print the
output of the regline (slope and latitude) for each model for each year and
am battling with the code as it keeps saying there is an error with my loop
"Dimension sizes of left hand side and right hand side of assignment do not

My code is attached below and any help with these do loops would be greatly
Many thanks!

Kind Regards

; regline.ncl

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"


 ; Read all file names in directory
 diri = "/mnt/nfs2/geog/ml382/melphd/eofmodelz/" ; input directory
 fili = systemfunc("cd "+diri+" ; ls *")
 print(fili) ; all file names
 nfili = dimsizes(fili)

 ; Establish list of all possible files; *no* reading is done
 ; 'f' is a variable of type 'list'; index via [...]
 do nf=0,nfili-1
 f = addfile(diri+fili(nf), "r")
 x = f->pr

 end do

 ;f = addfile (fili , "r") ; add file
 ;lat = f->lat ; get lat
 ;lon = f->lon ; get lon
 ;time = f->time ; get time
 ;level = f->z ; get level
 ;pr = f->pr ; get precip

 pr2 = pr(time|0, z|0, {lat|-30:0}, {lon|10:50})


;Calculations of max precip for lat and lon values
    dimpr2 = dimsizes(pr2)
    nlat = dimpr2(0)
    mlon = dimpr2(1)
 pr2MaxLon = new ( mlon, typeof(pr2), pr2@_FillValue)
   do ml=0,mlon-1
      imax = maxind(pr2(:,ml))
      pr2MaxLon(ml) = dble2flt(lat(imax))
   end do

   ;print("pr2MaxLon: "+pr2&lon+" "+pr2MaxLon)
   ;Regression Line
   rcMaxLon = regline(pr2&lon,pr2MaxLon)

   bMaxLon = rcMaxLon@yintercept
   xMaxLon = pr2&lon
   yMaxLon = rcMaxLon*pr2&lon + bMaxLon
   ;print(xMaxLon+" "+yMaxLon)


ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
Received on Wed Nov 20 07:09:52 2013

This archive was generated by hypermail 2.1.8 : Fri Nov 22 2013 - 09:36:32 MST