f1 = addfile("sample.grb2","r") print(f1) lat2d = f1->gridlat_0 lon2d = f1->gridlon_0 data = f1->TMP_P0_L100_GLC0 lv = f1->lv_ISBL0 l0 = min(lon2d) l1 = max(lon2d) printMinMax(lon2d,0) size = dimsizes(data) print(size) ; ; span from the min longitude to the max longitude ; lonspan = fspan(l0,l1,size(2)) ; ; create a array of constant latitude matching the size of the longitude array ; latspan = new(size(2),typeof(lonspan)) latspan = 40.0 ; ; get the 2d indexes of nearest values with constant latitude ; ix2d = getind_latlon2d(lat2d,lon2d,latspan,lonspan) ;print(ix2d) lonxc = new(size(2),float) ; ; get the actual longitude values along ; the constant latitude line ; do i = 0,size(2)-1 lonxc(i) = lon2d(ix2d(i,0),ix2d(i,1)) end do ; ; there may be duplicate longitude values in the actual longitude array ; remove them because the contouring routines want strictly monotonic ; coordinate values ; lonxc_n = get_unique_values(lonxc) indlonxc = new(dimsizes(lonxc_n),integer) do i = 0,dimsizes(lonxc_n)-1 ix := ind(lonxc_n(i) .eq. lonxc) indlonxc(i) = ix(0) end do ; ; get the data values that correspond to the unique longitude values ; dataxc = new((/size(0),dimsizes(lonxc_n)/),typeof(data)) do i = 0,dimsizes(lonxc_n)-1 dataxc(:,i) = data(:,ix2d(indlonxc(i),0),ix2d(indlonxc(i),1)) end do ; ; add coordinate arrays to the cross section data ; dataxc!0 = "level" dataxc&level = lv dataxc!1 = "lon" dataxc&lon = lonxc_n printMinMax(dataxc&lon,0) ; ; draw ; wks = gsn_open_wks("x11","testxc") res = True res@cnFillOn = True res@trYReverse = True plot = gsn_csm_contour(wks,dataxc,res)