[ncl-talk] Dimension Error Issue

Sakib Ahmed nonicknameforever at gmail.com
Sun Aug 11 06:00:00 MDT 2019


Dear NCL Community,

I'm stuck with a dimension size error issue. Following is what the code
looks like:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

begin

 ustar=new(1,float)

 z0=new((/1,4001/),float)

 ust=fspan(0,4,4001)


ust_array=((/ust^8, ust^7, ust^6, ust^5, ust^4, ust^3, ust^2, ust^1,
ust^0/))


printVarSummary(ust_array)

;polynomial

p_b1= (/-0.000098701949811,  0.001486209983407, -0.007584567778927,
 0.019487056157620, -0.029314498154105,  0.024309735869547,
-0.006997554677642,  0.001258400989803, -0.000043976208055/)

p_b2=(/-0.002182648458354,  0.046387047659009, -0.428830523588356,
 2.251251262348664, -7.334368361013868, 15.163848944684784,
-19.388290305787166,13.970227275905133, -4.319572176336596/)

g=9.806650

do i=0,4000
    ustar=ust(i)

    if (ustar.lt.0.3) then
        z0(:,i)=0.0185/g * ustar^2

    else if (ustar.lt. 2.35) then                      ; this is the loop
where I'm having the issue; not sure how to properly write this in NCL

        p=p_b1
        z0(:,i)=p*(ust_array(:,i))

    else if (ustar.lt.3) then

        p=p_b2
        z0(:,i)=p*ust_array(:,i)


    else
        z0(:,i)=0.001305

    end if
    end if
    end if
end do
end

fatal:Dimension sizes on right hand side of assignment do not match
dimension sizes of left hand side
fatal:["Execute.c":8635]:Execute: Error occurred at or near line 32


printVarSummary(ust_array)

Variable: ust_array
Type: float
Total Size: 144036 bytes
            36009 values
Number of Dimensions: 2
Dimensions and sizes:   [9] x [4001]
Coordinates:

printVarSummary(z0)

Variable: z0
Type: float
Total Size: 16004 bytes
            4001 values
Number of Dimensions: 2
Dimensions and sizes:   [1] x [4001]
Coordinates:
Number Of Attributes: 1
  _FillValue :  9.96921e+36


I'm still new in NCL but I able to solve this same problem in Matlab and
putting this below as a reference. But I'm really interested to do this in
NCL.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Matlab
version;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

z0=[]; ust_array=[];
ustar=[];

ust=[0:001:4];

ust_array=[ust.^8; ust.^7; ust.^6; ust.^5; ust.^4; ust.^3; ust.^2; ust.^1;
ust.^0;];

% polynomial:
p_b1= [-0.000098701949811,  0.001486209983407, ...
    -0.007584567778927,  0.019487056157620, ...
    -0.029314498154105,  0.024309735869547, ...
    -0.006997554677642,  0.001258400989803, ...
    -0.000043976208055];
p_b2=[-0.002182648458354,  0.046387047659009, ...
    -0.428830523588356,  2.251251262348664, ...
    -7.334368361013868, 15.163848944684784, ...
    -19.388290305787166,13.970227275905133, ...
    -4.319572176336596];
g=9.806650;


for i=1:length(ust)

    ustar=ust(i);
    if ustar < 0.3
        z0(i)=0.0185/g * ustar^2;
    elseif ustar < 2.35
        p=p_b1;
        z0(i)=p*ust_array(:,i);
    elseif ustar < 3
        p=p_b2;
        z0(i)=p*ust_array(:,i);
    else
        z0(i)=0.001305;
    end
end

Thank you in advance for the help.
Sakib

Sakib Ahmed
Connecticut College
Environmental Studies Major,
New London, CT 06320
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190811/65381450/attachment.html>


More information about the ncl-talk mailing list