Re: Problems creating new array with calculated values

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Thu Sep 06 2012 - 09:40:31 MDT

Hi Hyacinth,
Try this:

dimZ = dimsizes(NOAA(0,:,:)
nino3_cases_maps = new ((/n_nino3,dimZ(0),dimZ(1)/),float)

I think the problem is that in this code:
nino3_cases_maps = new ((/n_nino3,dimsizes(NOAA(0,:,:))/),float)

NCL sees n_nino3 as a scalar (which is fine), but sees the
dimsizes(NOAA(0,:,:) as an _array_ or size 2, which is why it is giving
you this error message:
  fatal:_NclBuildArray: each element of a literal array must have the
same dimension sizes, at least one item doesn't

If my suggestion does not fix your issue please let ncl-talk know.. Adam

On 09/06/2012 09:19 AM, Hyacinth Nnamchi wrote:
> Hi Users,
>
> I'd like to create an array to hold a new data:
> nino3_cases_maps = new ((/n_nino3,dimsizes(NOAA(0,:,:))/),float)
>
> But I got the following error message:
>
> fatal:_NclBuildArray: each element of a literal array must have the
> same dimension sizes, at least one item doesn't
> fatal:["Execute.c":7556]:Execute: Error occurred at or near line 50 in
> file trial_comp_1.ncl
>
> Perhaps the problem is that a dimension of the an array (n_nino3) is
> not known before hand, and ncl is supposed to take it from a preceding
> calculation. Does anyone know what am doing wrong here?
>
> Thanks in advance.
>
> Hyacinth
>
> Copyright (C) 1995-2012 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 6.1.0-beta
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
>
>
> ;****************************** *******************
> 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"
> begin
>
> ; ==============================================================
> ; User defined parameters
> ; ==============================================================
>
> yrStrt = 1900
> yrLast = 2011
>
> season = "DJF" ; choose Jun-Jul-Aug seasonal mean
> ;=============================================================
> ; Open the file: Read only the user specified period
> ; ==============================================================
> f = addfile ("/home/nnamchi/work/datasets/sst/sst.mnmean.nc", "r")
> TIME = f->time
> YYYY = cd_calendar(TIME,-1)/100 &nbs p; ; entire file
> iYYYY = ind(YYYY.ge.yrStrt .and. YYYY.le.yrLast)
> noaa = short2flt(f->sst(iYYYY,:,:))
> printVarSummary(noaa)
> delete([/TIME,YYYY,iYYYY/]) ; Release memory
> ; ==============================================================
> ; global seasonal mean; de-trend; flip longitudes
> ; ==============================================================
> NOAA = month_to_season (noaa,season)
> nyrs = dimsizes(NOAA&time)
> printVarSummary(NOAA) ; note the longitude coord
>
> NOAA = dtrend_msg_n(NOAA&time,NOAA,True,False,0) ;de-trend data
>
> NOAA = lonFlip(NOAA)
>
> ;===========================================
> nino3&nbs p; = wgt_areaave_Wrap(NOAA(time |:, {lon|-150:-90}, {lat |
> -5:5}),1.0, 1.0, 0) ;Nino 3 index
> nino3 = dim_standardize_Wrap(nino3,0) ; normalize
>
> ;=====================================================
>
> n_nino3 = dim_num_n(nino3.ge.1.,0)
> print(n_nino3) ; 21 cases shown, integer
>
> nino3_cases = nino3.ge.1.
> print(nino3_cases) ;True indicated for the timesteps
> corresponding to n_nino3
>
>
> nino3_cases_maps = new ((/n_nino3,dimsizes(NOAA(0,:,:))/),float)
> ;LINE PROBLEM
>
> printVarSummary(nino3_cases_maps)
>
>
> ;============================================================
> nino3_POS = dim_avg_n_Wrap(nino3_cases_maps,0)
> copy_VarCoords(NOAA(0,:,:),nino3_POS)
>
> ;============================================================
> ; PLOTS*;============================================================
> wks = gsn_open_wks("eps","nino3_POS")
> gsn_define_colormap(wks,"BlueWhiteOrangeRed")
>
> plot = new(1,graphic) ; create graphic array
> ; only needed if paneling
> res = True
> res@cnLevelSelectionMode = "ManualLevels" ; set manual contour levels
> res@cnMinLevelValF = -2. ; set min contour level
> res@cnMaxLevelValF = 2. ; set max contour level
> res@cnLevelSpacingF = .05 ; set contour spacing
> res@gsnDraw = False ; don't draw yet
> res@gsnFrame = False ; don't advance frame yet
> res@gsnSpreadColors = True ; spread out color table
> ;res@mpFillDrawOrder = "PostDraw"
> res @gsnPaperOrientation = "portrait"
> res@mpFillOn = True ; turn off map fill
> res@cnLinesOn = True ; turn off contour lines
> res@mpGeophysicalLineThicknessF = 1
> res@cnFillOn = True ; turn on color fill
> res@cnLinesOn = False ; True is default
> res@cnLineLabelsOn = True ; True is default
> res@lbLabelBarOn = False ; turn off in dividual lb's
> res@cnConstFLabelOn = False
>
> res@cnLineLabelsOn = False ; True is default
> res@cnInfoLabelOn = False
>
> ;===============
> ;******************************************
> ; Create plots
> ;==========================================
>
> plot(0) = gsn_csm_contour_map(wks,nino3_POS,res)
>
>
> ;====================================================================
> ; panel plot only resources
> resP = True ; modify the panel plot
> resP@gsnPanelLabelBar = True ; add common colorbar
> resP@lbLabelAutoStride = True ; auto stride on labels
> resP@gsnPanelYWhiteSpacePercent = 0.0 ; default is 1.0
> resP@gsnMaximize = True ; large format
> resP@gsnPaperOrientation = "portrait"
> resP@gsnPanelFigureStrings= (/"a","b","c","d","e","f"/) ; add
> strings to panel
> resP@amJust = "TopRight"
> resP@gsnPanelFigureStringsFontHeightF = .01
> resP@gsnPanelFigureStringsPerimOn = False
> resP@gsnMaximize = True ; large format
> gsn_panel(wks,plot,(/1,1/),resP)
>
> end
> *
> *
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> *

-- 
______________________________________________________________
Adam Phillips                                asphilli@ucar.edu
NCAR/Climate and Global Dynamics Division       (303) 497-1726
P.O. Box 3000				
Boulder, CO 80307-3000    http://www.cgd.ucar.edu/cas/asphilli

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Sep 6 09:40:40 2012

This archive was generated by hypermail 2.1.8 : Tue Sep 11 2012 - 15:30:42 MDT