Re: Dimension Problem

From: Kyle Griffin <ksgriffin2_at_nyahnyahspammersnyahnyah>
Date: Tue Feb 19 2013 - 20:33:25 MST

write_matrix is only for writing 2-D arrays.

http://www.ncl.ucar.edu/Document/Functions/Built-in/write_matrix.shtml

When you run it for one hour, the third dimension is a single value and NCL
essentially drops this dimension, leaving you with a 2-D array. When you
run your script for 24 hours, I think you'll find that your variable 'tp'
is 3-D and thus write_matrix has no idea how to write it.

One suggestion is to write each time step individual as its own table into
the file, looping over each time one by one and writing out at each step.
Of course, you can choose to do it however you want depending on the format
you'd prefer to have the data in. There are lots of potential ways to fit
3-D data into a series of 2-D tables!

Kyle

----------------------------------------
Kyle S. Griffin
Department of Atmospheric and Oceanic Sciences
University of Wisconsin - Madison
1225 W Dayton St, Madison, WI 53706
Email: ksgriffin2@wisc.edu

On Tue, Feb 19, 2013 at 9:23 PM, Mike Pirhalla <glacierbayncl@gmail.com>wrote:

> I am getting this error when I try to store my data to a matrix:****
>
> fatal:Number of dimensions in parameter (0) of (write_matrix) is (3), (2)
> dimensions were expected****
>
> fatal:Execute: Error occurred at or near line 140 in file new.ncl****
>
> ** **
>
> The program is calculating multiple inversion levels and exporting the
> results to a file using write_matrix. It works for one hour, but when I
> increase the loop to 24 hours I get the error. It’s doing the calculations
> correctly, just having issues writing the data to the file.****
>
> ** **
>
> What am I doing wrong?
> Thanks for the help,****
>
> Mike****
>
> ** **
>
> ** **
>
> ** **
>
> ======****
>
> 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-06-29_00:00:00"+".nc",
> "r")****
>
> ** **
>
> fout=addfile("/import/home/u1/uaf/mapirhalla/PROGRAMS/SURFACE_WRCC.nc","w")
> ****
>
> fmtf="3F9.2"****
>
> opt=True****
>
> opt@fout="new_data.dat"****
>
> ** **
>
> tp=new((/24,14,2/),float)****
>
> tp=-999****
>
> tp!0 = "Height"****
>
> tp!1 = "Temperature"****
>
> ** **
>
> ** **
>
> ;===Get temperature data===****
>
> T = wrf_user_getvar(f,"tc",-1)****
>
> temp = T(bottom_top|:,Time|:,south_north|45,west_east|61)****
>
> ** **
>
> ;==Get pressure data===****
>
> P = wrf_user_getvar(f,"pressure",-1)****
>
> ** **
>
> ; This is 4 dimensions, wrap dimension quantity to 1****
>
> P0 = dim_avg_n_Wrap(P(:,:,45,61),0)****
>
> ** **
>
> ; Make temp variable one dimension for calculating geoht****
>
> T0= dim_avg_n_Wrap(T(:,:,45,61),0)****
>
> ** **
>
> ** **
>
> ter=wrf_user_getvar(f,"HGT",-1)****
>
> terr=ter(Time|:,south_north|45,west_east|61)****
>
> ** **
>
> ; Calculate the height levels in meters****
>
> geoht = hydro(P0,T0+273.15,terr)****
>
> print(geoht)****
>
> ** **
>
> ** **
>
> ;===========================****
>
> ; Calculate Inversion Levels****
>
> ;===========================****
>
> time=0****
>
> counter=0****
>
> ** **
>
> ** **
>
> do time=1,24 ;start loop time****
>
> do lev=1,15 ;start loop levels****
>
> ** **
>
> counter = 0 ; reset counter for each day****
>
> if(temp(lev+1,time) .gt. temp(lev,time)) then****
>
> print(lev)****
>
> ** **
>
> height=geoht(lev+1)****
>
> print(height)****
>
> ** **
>
> tempdiff=(temp(lev+1,time))-(temp(lev,time)) ;Calc temp difference
> between levels****
>
> geodiff=(geoht(lev+1))-(geoht(lev)) ;Calc height difference
> between levels****
>
> difference=(tempdiff/geodiff)*1000 ;Calc dT/dz * 1000 to
> convert m to km****
>
> ** **
>
> tp(time,counter,0)=geoht(lev+1) ;Writes the height of the
> inversion (line140)****
>
> tp(time,counter,1)=difference ;Writes dT/dz (in C/km) of
> inversion****
>
> ** **
>
> end if****
>
> counter=counter+1 ; Counter to advance to next possible inversion
> level****
>
> ** **
>
> end do ;end loop levels****
>
> time = time + 1****
>
> ** **
>
> end do ;end loop time****
>
> ** **
>
> ** **
>
> ;==========================****
>
> ; Generate External File****
>
> ;==========================****
>
> *write_matrix(tp,fmtf,opt) line 140*
>
> end****
>
> _______________________________________________
> 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 Feb 19 20:33:57 2013

This archive was generated by hypermail 2.1.8 : Thu Feb 21 2013 - 11:26:43 MST