[ncl-talk] error message associated with month_to_annual_weighted function

Lei Meng dream916 at gmail.com
Tue Mar 10 14:08:17 MDT 2015


Hi,

I am still unable to get the function month_to_annual_weighted.ncl to work.
I used the function code that you sent. Here is my script:

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "./month_to_annual_weighted.ncl"
begin

  diri = "/Users/nmb1441/research/papers/china/monsoons/cru_data/pet/"
  srcFileName = "cru_ts3.21.1951.1960.pet.dat.nc"
  refile= addfile(diri + srcFileName,"r")

  pet = refile->pet
  lat = refile->lat
  lon = refile->lon
  time = refile->time

  time at calendar = "gregorian"
  yearfrac = cd_calendar(time,  4)

  yyyymm = cd_calendar(time, -1)

  dym      = cd_calendar(time,  -1)

  print(dym)

  printVarSummary(pet)
  printVarSummary(dym)
  pet_annual_total1= month_to_annual_weighted(yyyymm,pet,0)

end

The error message I got is :

fatal:Variable (yrFrac) is undefined, can not assign attribute (calendar)

fatal:["Execute.c":8578]:Execute: Error occurred at or near line 52 in file
./month_to_annual_weighted.ncl


fatal:["Execute.c":8578]:Execute: Error occurred at or near line 28 in file
test-temp1.ncl


I am using ncl 6.2.1.

Thanks!

Lei



On Wed, Jan 28, 2015 at 1:33 PM, Dennis Shea <shea at ucar.edu> wrote:

> [1] Please indicate which version of NCL you are using.
>
> [2] I speculate the following will work
>
>      yyyymm = cd_calendar(time, -1)   ; <===
>      pet_annual_total1= month_to_annual_weighted(yyyymm,pet,0)
>
> [3] Since, I am not sure what version of NCL you have, please load the
> attached
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> load "./month_to_annual_weighted.ncl"
>
> ... your script ...
>
> [4] Note: from 6.2.0 onward,  users do not need to explicitly load the
> gsn_code/gsn_csm/contributed libraries
>
> Goos Luck
>
> On Wed, Jan 28, 2015 at 9:54 AM, Lei Meng <dream916 at gmail.com> wrote:
>
>> Hi,
>>
>> I tried to convert monthly values to annual valued weighted by the number
>> of days. Here is my code:
>>
>> ----
>> 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"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl"
>> begin
>>
>>   diri = "/Users/nmb1441/research/papers/china/monsoons/cru_data/pet/"
>>   srcFileName = "cru_ts3.21.1951.1960.pet.dat.nc"
>>   refile= addfile(diri + srcFileName,"r")
>>
>>   pet = refile->pet
>>   lat = refile->lat
>>   lon = refile->lon
>>   time = refile->time
>>
>>   time at calendar = "gregorian"
>>   yearfrac = cd_calendar(time,  4)
>>
>>   yyyymm1 = cd_calendar(time, 1)
>>
>>   dym      = cd_calendar(time,  1)
>>
>>   print(dym)
>>
>>   printVarSummary(pet)
>>   printVarSummary(dym)
>>   pet_annual_total1= month_to_annual_weighted(dym,pet,0)
>>
>> end
>> --
>> The summaries of variables pet and dym are as follows:
>>
>> Variable: pet
>>
>> Type: double
>>
>> Total Size: 248832000 bytes
>>
>>             31104000 values
>>
>> Number of Dimensions: 3
>>
>> Dimensions and sizes: [time | 120] x [lat | 360] x [lon | 720]
>>
>> Coordinates:
>>
>>             time: [18642..22264]
>>
>>             lat: [-89.75..89.75]
>>
>>             lon: [-179.75..179.75]
>>
>> Number Of Attributes: 5
>>
>>   long_name : potential evapotranspiration
>>
>>   units : mm/day
>>
>>   correlation_decay_distance : -999
>>
>>   _FillValue : 9.969209968386869e+36
>>
>>   missing_value : 9.969209968386869e+36
>>
>> Variable: dym
>>
>> Type: double
>>
>> Total Size: 960 bytes
>>
>>             120 values
>>
>> Number of Dimensions: 1
>>
>> Dimensions and sizes: [120]
>>
>> Coordinates:
>>
>> Number Of Attributes: 1
>>
>>   calendar : gregorian
>>
>> (0) month_to_annual_weighted: mm must be 1-to-12 inclusive
>>
>> The error message is " mm must be 1-to-12 inclusive".
>>
>> dym values are from 195101 to 196012.
>>
>> This is a very simple code. I couldn't figure out what was wrong with my
>> code.
>>
>> The data is too big and I will send it if necessary. Thanks for any
>> suggestions.
>>
>> Lei
>>
>>
>>
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> 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/20150310/247f87a0/attachment.html 


More information about the ncl-talk mailing list