Re: Memory error when using clmMonTLL?

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Mon Nov 02 2009 - 14:32:31 MST

'clmMonTLL' was one of the 1st to be added to contributed.ncl.
For historical reasons, NCL's dimension reordering
was used. The introduction of the dim*_n functions
allows the climatologies to be calculated without reordering.

I have attached an *untested* code. Please load it after
the contributed.ncl library.

Good luck

Bridget Thrasher wrote:
> The following block of code is throwing a malloc error:
>
> all_files = systemfunc("ls "+dobs+"/*.nc | grep -v 'aggr_'")
> fall = addfiles(all_files,"r")
> print("All obs files read")
> ListSetType(fall,"cat")
> print("Obs files concatenated")
> if (typeof(fall[0]->$var$).eq."double") then
> all_obs = dble2flt(fall[:]->$var$)
> else
> all_obs = fall[:]->$var$
> end if
> printVarSummary(all_obs)
> mon_avg_obs = clmMonTLL(all_obs)
> print("mon_avg_obs created")
> delete(all_obs)
>
>
> Output:
>
> Copyright (C) 1995-2009 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 5.1.1
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
> (0) All obs files read
> (0) Obs files concatenated
>
> Variable: all_obs
> Type: float
> Total Size: 2094012000 bytes
> 523503000 values
> Number of Dimensions: 3
> Dimensions and sizes: [time | 600] x [lat | 621] x [lon | 1405]
> Coordinates:
> lat: [24.0625..49.9375]
> lon: [-125.0208..-66.4792]
> Number Of Attributes: 1
> _FillValue : 1e+20
>
> ncl(28773) malloc: *** mmap(size=2094014464) failed (error code=12)
> *** error: can't allocate region
> *** set a breakpoint in malloc_error_break to debug
> fatal:NclMalloc Failed:[errno=12]
>
>
> Any idea why clmMonTLL would cause this kind of error? Shouldn't it be
> allocating a smaller array than the one it's reading in? I seem to be
> coming up against this type of error a lot lately.
>
> -Bridget
>
>
> --
> Bridget Thrasher, PhD
> Postdoctoral Researcher
> Climate Central
> www.climatecentral.org <http://www.climatecentral.org>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

undef("clmMonTLL")
function clmMonTLL (x[*][*][*]:numeric)
local dimx, ntim, nlat, mlon, i, nmo, nmos, monAveLLT
begin
  dimx = dimsizes(x)
  ntim = dimx(0)

  nmos = 12
  modCheck ("clmMonTLL", ntim, nmos) ; error check
 ;rankCheck("clmMonTLL", x, 3) ; not needed due to prototyping
      
  nlat = dimx(1)
  mlon = dimx(2)
;
; Compute all 12 monthly averages first.
;
   aveMonth = new((/nmos,nlat,mlon/),typeof(x) \
                                    ,getFillValue(x))
   do nmo=0,nmos-1
      aveMonth(nmo,:,:) = dim_avg_n( x(nmo:ntim-1:nmos,:,:), 0 )
   end do

; copy attributes and add a couple of informational attributes
; only need to do this if plotting or writing to netCDF file

   copy_VarAtts (x,aveMonth)
   aveMonth@time_op_ncl = "Climatology: "+ (ntim/nmos) +" years"
   aveMonth@info = "function clmMonLLT: contributed.ncl"

; copy spatial (eg, lat/lon) coordinate variables

   do i=1,2
      if (.not.ismissing(x!i)) then
          aveMonth!i = x!i
          if (iscoord(x,x!i)) then
              aveMonth&$aveMonth!i$ = x&$x!i$
          end if
      end if
   end do

   aveMonth!0 = "month" ; create a "month" named dim
   aveMonth&month = ispan(0,nmos-1,1) ; create a month coord var

   return (aveMonth)
end

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Nov 2 14:32:19 2009

This archive was generated by hypermail 2.1.8 : Fri Nov 06 2009 - 09:15:29 MST