Re: problem with dimensions

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Fri, 28 Apr 2006 09:55:55 -0600

Hi Jenny,

Whenever you get an "Assignment type mismatch, right hand side can't be
coerced to type of left hand side" error message, it means you are
trying to pass one type of data array into another type of data array.
For instance, trying to pass floats into an integer array...

In this case, you are trying to pass doubles into a float array. For the
line in question:
wslp = tmp

tmp is a double array, while wslp is a float. tmp is a double array
because clat is a double array. (When you multiply clat (double) * slp
(float), the resulting array will be of type double.)

Anyway, for the last few lines of your code try this:

   printVarSummary(clat)
   printVarSummary(wslp)
   printVarSummary(tmp)
   wslp = (/ dble2flt(tmp) /)
   printVarSummary(wslp)

I used dble2flt to convert tmp to a float array, and surrounded it with
(/ /) so that NCL will not wipe out the metadata on the lefthand side.

Good luck,
Adam

Jenny Brandefelt wrote:
> Hi!
>
> I want to use NCL to determine EOF's of CCSM surface pressure.
>
> Before the EOF analysis I want to multiply the data with the
> appropriate gaussian weights. But NCL is not content with the
> dimensions of my arrays.
>
> I would be most grateful if someone has an idea of what is wrong!
>
> The data file contains PS from a run with CCSM3 and is available
> here:
>
> http://www.misu.su.se/~jenny/ps.b30.031.6.cam2.h0.0501-01.nc
>
>
> Thanks,
> Jenny Brandefelt
>
>
>
>
> Output when trying to run my script:
>
> >ncl weight.ps.ncl
> Copyright (C) 1995-2004 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 4.2.0.a032
> The use of this software is governed by a License Agreement.
> See http://ngwww.ucar.edu/ncl/ for more details.
> (0) 1
> (1) 48
> (2) 96
> (0) 1
> (1) 48
> (2) 96
> fatal:Assignment type mismatch, right hand side can't be coerced to type
> of left hand side
> fatal:Execute: Error occurred at or near line 28 in file weight.ps.ncl
>
>
>
>
> The script weight.ps.ncl:
>
> ; ==============================================================
> ; Calculate EOFs of the Sea Level Pressure over the North Atlantic.
> ; ==============================================================
> 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
> ; ==============================================================
> ; Open the file: PS data span (year-month) 501-01 -- 501-12
> ; ==============================================================
> f = addfile ("./ps.b30.031.6.cam2.h0.0501-01.nc", "r")
> slp = f->PS
> ; -----------------------------------------------------------------
> ; create weights: sqrt(cos(lat)) [or sqrt(gw) ]
> ; -----------------------------------------------------------------
> rad = 4.*atan(1.)/180.
> clat = f->lat
> clat = sqrt( cos(rad*clat) ) ; gw for gaussian grid
> ; -----------------------------------------------------------------
> ; weight all observations
> ; -----------------------------------------------------------------
> wslp = slp ; copy meta data
> tmp = slp*conform(slp, sqrt(clat), 1)
> print(dimsizes(slp))
> print(dimsizes(tmp))
> wslp = tmp
> end
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
--------------------------------------------------------------
Adam Phillips			             asphilli_at_ucar.edu
National Center for Atmospheric Research   tel: (303) 497-1726
ESSL/CGD/CAS                               fax: (303) 497-1333
P.O. Box 3000				
Boulder, CO 80307-3000	  http://www.cgd.ucar.edu/cas/asphilli
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Apr 28 2006 - 09:55:55 MDT

This archive was generated by hypermail 2.2.0 : Fri Apr 28 2006 - 10:57:10 MDT