Looping through files

From: Melissa Lazenby <M.Lazenby_at_nyahnyahspammersnyahnyah>
Date: Wed Nov 20 2013 - 06:56:25 MST

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 match"

My code is attached below and any help with these do loops would be greatly appreciated.
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 *climDJF.nc")
 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 06:57:00 2013

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