Mike
I can think of two ways of doing this the 'loops' that you have, but in fact I don't think you need the loops at all:
>dT = slice(1:) - slice(:nlev-2) ;temperature change between levels
> ii = ind(dT.gt.0) ;levels where inversion occurs
> if (not(ismissing(ii(0))) then
>pressure = lev(ii+1) ; need to add one to the index because the array dT is one less element than lev
>end if
In this case, the variable 'Pressure' will be the same size as ii so should pick up all inversions. This will also be much quicker if you're having to do multiple times/cells, since loops are generally slower than operations on an entire array.
Will
From: Mike Pirhalla <glacierbayncl@gmail.com<mailto:glacierbayncl@gmail.com>>
Date: Wednesday, 30 January 2013 1:15 PM
To: "ncl-talk@ucar.edu<mailto:ncl-talk@ucar.edu>" <ncl-talk@ucar.edu<mailto:ncl-talk@ucar.edu>>
Subject: Do Loops & Saving in External file
Hello,
I need some help/guidance with my current program. Right now, the program pulls WRF pressure and temperature data for one hour at one grid cell. I have a variable called “slice” which has temperatures on 16 levels, as well as “PO” with pressures on the corresponding levels. I need the DO LOOP to cycle through the temperatures. If the temperature of one level is warmer than the last, I need the program to print that level. However, there may be more than one inversion. For my case, I have 2 inversions and am finding this loop does not record both. It overwrites the last value and only records one. This is then same for the corresponding temperature.
Do I need to use a write_matrix instead?
Thanks, any help would be greatly appreciated!
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/wrf/WRFUserARW.ncl"
begin
;=====================
; Retrieve Data
;=====================
f = addfile ("/import/archive/u1/uaf/molders/GLACIERBAY/WITH/wrfout_d01_2008-07-15_00:00:00"+".nc", "r")
;===Get temperature data===
T = wrf_user_getvar(f,"tc",-1)
slice = T(bottom_top|:,Time|11:11,south_north|45,west_east|61)
;===Get pressure data===
P = wrf_user_getvar(f,"pressure",-1)
P0 = dim_avg_n_Wrap(P(0:24,:,45,61),0)
printVarSummary(P0)
print(P0)
print(slice)
;===========================
; Calculate Inversion Levels
;===========================
time=0
do lev=0,15
if(slice(lev+1,time) .gt. slice(lev,time)) then
print(lev)
pressure=P0(lev+1)
print(pressure)
temp=slice(lev+1,:)
print(temp)
end if
end do
;==========================
; Generate External File
;==========================
asciiwrite("inversion_data.txt",pressure)
end
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Jan 29 20:23:44 2013
This archive was generated by hypermail 2.1.8 : Tue Jan 29 2013 - 22:44:26 MST