Re: get values from wrfout file for all lat, lon points

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Fri Oct 04 2013 - 11:58:14 MDT

On Oct 3, 2013, at 4:56 PM, Luis Fernando Montana Roa <lfmontanar@unal.edu.co> wrote:

> Thanks Mary, the wrfout file is about 24 GB and ASCII data is used as input to the CPT tool for local analysis.

Wow, do you need to write out all 24 GB to an ASCII file? Does CPT allow for any other formats? If it takes any kind of "binary" format, like Fortran binary, I recommend this. NCL has several binary writing programs:

http://www.ncl.ucar.edu/Document/Functions/io.shtml

> Is there a more efficient way of doing it?

The most efficient way is to actually write a Fortran subroutine that writes the output to a file. But, this is still going to be slow (but faster than NCL).

You can then use our WRAPIT tool to create a *.so file, which allows you to call this Fortran program directly from NCL.

For some WRAPIT examples, see:

http://www.ncl.ucar.edu/Document/Tools/WRAPIT.shtml#Examples

Example 5 shows how to do 2-dimensional array printing. This example is simplistic, but you can use this as a base for creating a Fortran subroutine that writes data to a file.

There may be some folks out there with more knowledge about the best way to write an efficient Fortran program that writes a lot of ASCII data. You can also try googling this.

Good luck,

--Mary

>
> -- Fernando
>
> On Thu, Oct 3, 2013 at 10:21 AM, Mary Haley <haley@ucar.edu> wrote:
> It looks like you are running into a memory issue. How big are the variables you are trying to write to ASCII?
>
> Is there a reason you need to write ASCII files? We usually recommend against this, especially if they are very large. This is an inefficient and cumbersome way to store data.
>
> If you continue to have problems, then I will need to have access to your script and data. Please see:
>
> http://www.ncl.ucar.edu/report_bug.shtml
>
> --Mary
>
> On Oct 3, 2013, at 6:18 AM, Luis Fernando Montana Roa <lfmontanar@unal.edu.co> wrote:
>
> > Sorry, I had failed to attach the script. There goes.
> >
> > -- Fernando
> >
> >
> > On Thu, Oct 3, 2013 at 7:16 AM, Luis Fernando Montana Roa <lfmontanar@unal.edu.co> wrote:
> > Thanks Mary, I did the settings with your suggestions and tried the script attached. But when I run it, get the following error:
> >
> > fatal:NclMalloc Failed:[errno=12]
> > fatal:Exp: Could not allocate memory for result type, can't continue
> >
> > fatal:["Execute.c":8128]:Execute: Error occurred at or near line 25 in file w_2.ncl
> >
> > -- Fernando
> >
> >
> > On Wed, Oct 2, 2013 at 2:25 PM, Mary Haley <haley@ucar.edu> wrote:
> > I think you simply need to change the "do" loop that writes out the ASCII file so that it writes the whole arrays, rather than one time step at a time.
> >
> > For example, instead of:
> >
> > line = new(ntimes+1,string)
> >
> > line(0) = " Time Temperature Pressure Relative_Humidity U V Wind_speed"
> >
> > do it = 0,ntimes-1
> >
> > line(it+1) = sprintf("%5.0f",it) +" " \
> > +sprintf("%18.2f", T_C(it)) +" " \
> > +sprintf("%12.2f", P(it)) +" " \
> > +sprintf("%12.2f", RH(it)) +" " \
> > +sprintf("%12.2f", ua) +" " \
> > +sprintf("%12.2f", va) +" " \
> > +sprintf("%12.2f", wind_speed(it))
> >
> > end do
> >
> > You can do this (UNTESTED):
> >
> > filename = "out_2_1.txt"
> > format = "%5.0f %18.2f %12.2f %12.2f %12.2f %12.2f %12.2f"
> > write_table(filename,"w",header,"%s")
> > write_table(filename,"w",[/it, t_C, P, RH, ua, va, wind_speed/],format)
> >
> > --Mary
> >
> >
> > On Oct 1, 2013, at 8:35 PM, Luis Fernando Montana Roa <lfmontanar@unal.edu.co> wrote:
> >
> > > Thanks Mary, what I need is to write an ascii file with variable values for each time step and grid point, as shown below.:
> > >
> > > Time Lat Lon Temp Pres RH U V Wind_speed
> > > 0 -10.0 -85.0 20.89 101.05 92.24 1.58 -1.26 2.02
> > > 0 -10.0 -84.5 19.94 101.01 96.16 2.18 -1.6 2.7
> > > ...
> > > 0 -9.5 -85.0 19.94 101.01 96.16 2.18 -1.6 2.7
> > > 0 -9.5 -84.5 19.65 101.04 96.88 2.84 -1.4 3.17
> > > ...
> > > 1 -10.0 -85.0 19.94 101.01 96.16 2.18 -1.6 2.7
> > > 1 -10.0 -84.5 19.65 101.04 96.88 2.84 -1.4 3.17
> > > ...
> > > 1 -9.5 -85.0 19.37 101015.75 97.29 3.09 -0.98 3.24
> > > 1 -9.5 -84.5 19.08 101026.23 97.51 3.23 -0.76 3.32
> > > ...
> > >
> > > I will appreciate any help in this regard.
> > >
> > > -- Fernando
> > >
> > > ---------- Forwarded message ----------
> > > From: Mary Haley <haley@ucar.edu>
> > > Date: Tue, Oct 1, 2013 at 3:03 PM
> > > Subject: Re: get values from wrfout file for all lat,lon points
> > > To: Luis Fernando Montana Roa <lfmontanar@unal.edu.co>
> > > Cc: ncl-talk@ucar.edu
> > >
> > >
> > > Hi Luis,
> > >
> > > I'm not sure exactly sure of your question. You don't need to get individual point locations for one lat/lon pair at a time. You can simply do the calculation across all lat/lon values.
> > >
> > > For example, instead of this do loop:
> > >
> > > do it = 0,ntimes-1
> > >
> > > time = it
> > > Latitude = 4.16
> > > Longitude = -74.87
> > >
> > > res = True
> > > res@returnInt = True
> > > point = wrf_user_ll_to_ij(in,Longitude,Latitude,res)
> > >
> > > x = point(0)
> > > y = point(1)
> > >
> > > U = wrf_user_getvar(in, "U", time)
> > > ua_in = wrf_user_unstagger(U,U@stagger)
> > > ua = ua_in(0:0,x,y)
> > > V = wrf_user_getvar(in, "V", time)
> > > va_in = wrf_user_unstagger(V,V@stagger)
> > > va = va_in(0:0,x,y)
> > > wind_speed(it) = sqrt(ua^2+va^2)
> > > copy_VarCoords(ua,wind_speed(it))
> > > wind_speed@Units= "m/s"
> > >
> > > T_in = wrf_user_getvar(in, "T2", time)
> > > T_k = T_in(x,y)
> > > T_C(it) = T_k-273.15
> > > T_C@Units="C"
> > >
> > > P_in = wrf_user_getvar(in, "PSFC", time)
> > > P(it) = P_in(x,y)
> > > P_rh=P_in(x,y)
> > >
> > > Q_in = wrf_user_getvar(in, "Q2", time)
> > > Q(it) = Q_in(x,y)
> > > Q_rh=Q_in(x,y)
> > >
> > > RH(it) = wrf_rh(Q_rh, P_rh, T_k)
> > >
> > > end do
> > >
> > > I think you can just do this, using the special value of -1 for time:
> > >
> > > time = -1
> > > U = wrf_user_getvar(in, "U", time) ; This will get U across all times, lats, and lons
> > > ua = wrf_user_unstagger(U,U@stagger)
> > > V = wrf_user_getvar(in, "V", time)
> > > va = wrf_user_unstagger(V,V@stagger)
> > > wind_speed( = sqrt(ua^2+va^2)
> > > copy_VarCoords(ua,wind_speed)
> > > wind_speed@Units= "m/s"
> > >
> > > T = wrf_user_getvar(in, "T2", time)
> > > T_C = T-273.15
> > > T_C@Units="C"
> > >
> > > Q_rh = wrf_user_getvar(in, "Q2", time)
> > > P_rh = wrf_user_getvar(in, "PSFC", time)
> > > RH = wrf_rh(Q_rh, P_rh, T_k)
> > >
> > >
> > >
> > >
> > > On Sep 30, 2013, at 4:47 PM, Luis Fernando Montana Roa <lfmontanar@unal.edu.co> wrote:
> > >
> > > > Hi, I have this script to write the values of some variables to a single point. How do I adjust it for all points (lat, lon) available in the file?
> > > > Thanks,
> > > >
> > > > --
> > > > Fernando
> > > > <w_v_x.ncl>_______________________________________________
> > > > 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
> >
> >
> >
> > <w_2.ncl>_______________________________________________
> > 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

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Oct 4 11:58:22 2013

This archive was generated by hypermail 2.1.8 : Fri Oct 04 2013 - 16:45:17 MDT