# Re: center_finite_diff_n for relative vorticity

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Sun Dec 19 2010 - 15:40:31 MST

do nl=0,nlat-1
dvdx(nl,:) = center_finite_diff_n (v(nl,:), dX, False, 0, 0)
end do

do ml=0,mlon-1
dudy(:,ml) = center_finite_diff_n (v(:,ml), dY, False, 0, 0)
end do

Essentially the same as in fortran 90, Matlab,....

On 12/19/10 3:28 PM, Bold Khan wrote:
> Dennis, Thank you! This was an oversight on my part. I made this correction.
> So the script, the way it's written, works. But I am not sure if its
> actually right. I don't feel that it is.
> May I have a little conceptual help?
>
> If I want to calculate vorticity: (i.e. rv = (dv/dy) - (du/dx)
> Do dv/dx and dvdy need to be in the same loop or can they be
> separate as I have done?
> And, since I yearn to be an efficient NCLer, and avoid do loops where
> possible, is there a way not
> to use loops for this calculation?
>
> Again, thank you for your time.
> Still trying to wrap my brain around this.
> -Bold
>
>
> 05:12:16 ]> ncl tester.ncl
> University Corporation for Atmospheric Research
> NCAR Command Language Version 5.2.1
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
> (0)
> (0) min=-4.3992e-05 max=4.80107e-05
>
> CODE
>
> ;======================== some contants
> pi = 4.0*atan(1.0)
> FILEIN = "era_uv.nc"
> ;======================== Read in file and variables
> U=a->U
> u=U(0,{700},:,:)
> V=a->V
> v=V(0,{700},:,:)
>
> lat = a->lat
> lon = a->lon
> nlat = dimsizes(lat)
> mlon = dimsizes(lon)
> dlon = (max(lon)-min(lon))/(mlon-1)
> dlat = (max(lat)-min(lat))/(nlat-1)
> ;===================================== Arrays
> dvdx = new ( (/nlat,mlon/), typeof(v), v@_FillValue)
> dudy = new ( (/nlat,mlon/), typeof(v), v@_FillValue)
> ;===================================== loops
> do nl=0,nlat-1
> dvdx(nl,:) = center_finite_diff_n (v(nl,:), dX, False, 0, 0)
> end do
> do ml=0,mlon-1
> dudy(:,ml) = center_finite_diff_n (v(:,ml), dY, False, 0, 0)
> end do
> vor = dvdx - dudy
>
> printMinMax(vor,True)
>
>
>
> On Sun, Dec 19, 2010 at 4:44 PM, Dennis Shea<shea@ucar.edu> wrote:
>> You did not define the variables correctly.
>>
>> You created the following arrays
>>
>>> dvdx = new ( (/nlat,mlon/), typeof(v), v@_FillValue)
>>> dudx = new ( (/nlat,mlon/), typeof(v), v@_FillValue)
>>
>> Then you used
>>
>>> dvdx(nl,:) = center_finite_diff_n (v(nl,:), dX, False, 0, 0)
>> :
>>> dudy(:,ml) = center_finite_diff_n (v(:,ml), dY, False, 0, 1)
>>
>> Where did you preallocate space for dudy??
>> The error messages told you exactly what the problem is:
>>
>>> fatal:Undefined identifier: (dudy) is undefined, can't continue
>>> fatal:Execute: Error occurred at or near line 30 in file tester.ncl
>>>
>>> fatal:Variable (dudy) is undefined
>>> fatal:Execute: Error occurred at or near line 33 in file tester.ncl
>>>
>>> fatal:Variable (vor) is undefined
>>
>> vor is undefined because the dudy is undefined
>>
>> ==
>>
>> I think waht you want is:
>>
>> dudy = new ( (/nlat,mlon/), typeof(v), v@_FillValue)
>>
>>
>> On 12/19/10 12:55 PM, Bold Khan wrote:
>>>
>>> Dear ncl users,
>>> Could I have some help? I am still learning ncl.
>>> I am getting confused with using the center_finite_diff_n command to
>>> calculate relative vorticity (RV) with non-cyclic data.
>>> I want to calculate (RV) using center_finite_diff_n, instead of just
>>> resorting to using the uv2vr_cfd command that is available, because I
>>> want to calculate RV and then shear vorticity separately.
>>> I am following example 6 at
>>>
>>> http://www.ncl.ucar.edu/Document/Functions/Built-in/center_finite_diff_n.shtml.
>>>
>>> 1) Do dv/dx and dvdy need to be in the same loop or can they be
>>> separate as I have done?
>>> 2) Since we want to try and avoid do loops in ncl, is there a way not
>>> to use loops for this calculation
>>> Any amount of advice, would be greatly appreciated.
>>> Sincerely,
>>> Bold
>>>
>>>
>>> [ 02:42:16 ]> ncl tester.ncl
>>> University Corporation for Atmospheric Research
>>> NCAR Command Language Version 5.2.1
>>> The use of this software is governed by a License Agreement.
>>> See http://www.ncl.ucar.edu/ for more details.
>>> fatal:Undefined identifier: (dudy) is undefined, can't continue
>>> fatal:Execute: Error occurred at or near line 30 in file tester.ncl
>>>
>>> fatal:Variable (dudy) is undefined
>>> fatal:Execute: Error occurred at or near line 33 in file tester.ncl
>>>
>>> fatal:Variable (vor) is undefined
>>> fatal:Execute: Error occurred at or near line 35 in file tester.ncl
>>>
>>> [ 02:48:25 ]>
>>>
>>>
>>>
>>> ;;; some contants
>>> pi = 4.0*atan(1.0)
>>> FILEIN = "era_uv.nc"
>>> ;=========================variables
>>> U=a->U
>>> u=U(0,{700},:,:)
>>> V=a->V
>>> v=V(0,{700},:,:)
>>>
>>> lat = a->lat
>>> lon = a->lon
>>> nlat = dimsizes(lat)
>>> mlon = dimsizes(lon)
>>> dlon = (max(lon)-min(lon))/(mlon-1)
>>> dlat = (max(lat)-min(lat))/(nlat-1)
>>> ; Arrays
>>> dvdx = new ( (/nlat,mlon/), typeof(v), v@_FillValue)
>>> dudx = new ( (/nlat,mlon/), typeof(v), v@_FillValue)
>>> ; loops
>>> do nl=0,nlat-1
>>> dvdx(nl,:) = center_finite_diff_n (v(nl,:), dX, False, 0, 0)
>>> end do
>>> do ml=0,mlon-1
>>> dudy(:,ml) = center_finite_diff_n (v(:,ml), dY, False, 0, 1)
>>> end do
>>> vor = dvdx - dudy
>>>
>>> printMinMax(vor,True)
>>> _______________________________________________
>>> 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 Sun Dec 19 15:40:36 2010

This archive was generated by hypermail 2.1.8 : Wed Dec 22 2010 - 16:10:23 MST