Re: mean power spectrum

From: <yjin7_at_nyahnyahspammersnyahnyah>
Date: Tue Apr 22 2014 - 14:22:46 MDT

Hi Dennis,

Really appreciate your help. Another question is in Example 5 (https://www.ncl.ucar.edu/Document/Functions/Built-in/specx_anal.shtml)

   df = 2.0*nseg ; deg of freedom
                                                              ; all segments
   df@spcx = spcavg ; assign the mean spc
   df@frq = dof@frq
   spcavg@xlag1 = r1

The last line should be df@xlag1 = r1?

Thank you.
Best regards
Yan

______________________________________
From: Dennis Shea <shea@ucar.edu>
Sent: Monday, April 21, 2014 9:08 AM
To: yjin7@masonlive.gmu.edu; ncl-talk@ucar.edu
Subject: Re: mean power spectrum

Please read the documentation of variables.

NCL is a *strongly typed language*. By design, the default mode
will not allow numeric values of a 'higher' level to be assigned
to a 'lower level'. The reason is that information may be lost.

See: https://www.ncl.ucar.edu/Document/Manuals/language_man.pdf
        Section 2.17
or the Reference Manual:
         http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/
========================================
double
float
long integer
integer
short
byte
===========
     xd = 1.357d0 ; double
     xf = 5.314 ; float
     xi = 1 ; integer

Let yd, yf, yi be previously defined

The following are legal because no information is lost

     yd=xi yd=xf yd=xd ; any number can be promoted to double
     yf=xf yi=xi
     yi=xi

The following are illegal because information may be lost.

     yi=xf yi=xd
     yf=xd

The user must explicitly convert the type. This indicates
the user knows what he/she is doing.
For example

     yf=tofloat(xd)
     yi=toint(xd)

or, use the reassignment operator (6.1.2 or newer).
See reference manual

     yf := xd (yf:=xd)
     yi := xd

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
You gave

   Variable: pc2dT
   Type: double ; <======================

   r1zsum = 0.0 ; <===== type float

   r1 = dof@xlag1 ; same type as 'pc2DT' ; double

   r1zsum = r1zsum + 0.5*(log((1.0+r1)/(1.0-r1)))
                           ****** double*********

So 'float = float + double' is *not* allowed

The error message is telling you the problem.

> fatal:["NclVar.c":1382]:Assignment type mismatch, right hand side
can't be coerced to type of left hand side

In this case the solution is simple

    r1zsum = 0.0d0 ; make double

+++++++++++++++++++++++++++++++++++++++++++++
Please ... when you have problems use 'printVarSummary(...)'
at each step orior to the line with the
error. Carefully examine the type and shape of variables.

On 4/18/14, 4:23 PM, yjin7@masonlive.gmu.edu wrote:
> Hi Dennis,
>
> Thank you very much for your help. But When I used the code in Example 5, there is still a problem.
>
> In my code, I defined pw=pc2dT, which has the following information:
> ;---------------------------------------
> Variable: pc2dT
> Type: double
> Total Size: 29520 bytes
> 3690 values
> Number of Dimensions: 2
> Dimensions and sizes: [year | 30] x [day | 123]
> Coordinates:
> Number Of Attributes: 1
> _FillValue : -999000000
> ;-----------------------------------------
>
> Then, I copied the code in Example 5, and pasted it line by line in NCL, but there is an error in the last line of the loop:
>
> ;===============================
> ; power spectra
> ;===============================
> ;x(nseg,ntim), nseg is nyrs here, ntim is nday here;
> ntim = nday
> nseg = nyrs
> pw = pc2dT
>
> d = 0 ; detrending opt: 0=>remove mean 1=>remove mean + detrend
> sm = 21 ; smooth: should be at least 3 and odd
> pct = 0.10 ; percent taper: (0.0 <= pct <= 1.0) 0.10 common.
>
> ;************************************************
> ; calculate mean spectrum spectrum and lag1 auto cor
> ;************************************************
>
> ; loop over each segment of length ntim
>
> spcavg = new ( ntim/2, typeof(pw))
> spcavg = 0.0
>
> ncl 122> spcavg = 0.0
> ncl 123>
> ncl 124> r1zsum = 0.0
> ncl 125>
> ncl 126> do n=0,nseg-1
> ncl 127> dof = specx_anal(pw(n,:),d,sm,pct) ; current segment spc
> ncl 128> spcavg = spcavg + dof@spcx ; sum spc of each segment
> ncl 129> r1 = dof@xlag1 ; extract segment lag-1
> ncl 130> r1zsum = r1zsum + 0.5*(log((1.0+r1)/(1.0-r1))) ; sum the Fischer Z
> ncl 131> end do
>
> fatal:["NclVar.c":1382]:Assignment type mismatch, right hand side can't be coerced to type of left hand side
> fatal:["Execute.c":8126]:Execute: Error occurred at or near line 130
>
> ;---------------------------------------
>
> Here is the error message:
> fatal:["NclVar.c":1382]:Assignment type mismatch, right hand side can't be coerced to type of left hand side
> fatal:["Execute.c":8126]:Execute: Error occurred at or near line 130
>
> Thank you very much.
> Best regards
> Yan
>
> _____________________________________
> From: Dennis Shea <shea@ucar.edu>
> Sent: Thursday, April 17, 2014 9:43 AM
> To: yjin7@masonlive.gmu.edu; ncl-talk@ucar.edu
> Subject: Re: mean power spectrum
>
> Hello,
>
> http://www.ncl.ucar.edu/Document/Functions/Built-in/specx_anal.shtml
>
> Did you look at Example 5?
>
> ==================
> If you are doing this and you receive an error message, then you
> must provide more information then stating that what
> you are doing does not work.
>
> Cheers
>
>
>
> On 4/17/14, 7:30 AM, yjin7@masonlive.gmu.edu wrote:
>> Hello everyone,
>>
>> I am using specx_anal() to calculate the power spectrum of daily OLR for one month for each year, and make the average for 30 years. I tried to save the data as frqcy(:,:)= specx_anal()@frq, but it seems incorrect.
>>
>> Any advice is appreciated!
>> Best regards
>> Yan
>>
>>
>>
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Apr 22 14:23:17 2014

This archive was generated by hypermail 2.1.8 : Tue Apr 29 2014 - 09:04:20 MDT