<div dir="ltr"><div>Please in the future include ncl-talk in any replies. Thank you.</div><div><br></div>Well I do not know that much about GrADS, but just quickly looking at their documentation (<a href="http://iges.org/grads/gadoc/variableformats.html">http://iges.org/grads/gadoc/variableformats.html</a>) , I can see they say that<div><br><div>"The default sequence goes in the following order starting from the fastest varying dimension to the slowest varying dimension: longitude (X), latitude (Y), vertical level (Z), variable (VAR), time (T)."</div></div><div><br></div><div>So, keeping in mind that they speak in Fortran terms where the fastest-dimension is listed first, whereas NCL is the opposite, this means to me that all the variables for one time step are written, then all variables for the next time step, and so on. Other text on this page suggests that your file follows the "default sequence", but you may want to verify that.</div><div><br></div><div>We have already determined that a single record in this file covers the lat and lon dimensions. Presumably all records are the same size.</div><div>So if you want, for example, to just read the u variable for all time-steps, you would need to elaborate the code I suggested to you in the last message with another loop for the time dimension and you would need to skip over all the records for the other variables after reading u for a single timestep.</div><div><br></div><div>nvars_with_levels = 12</div><div>nsurface_vars = 34</div><div><span style="font-size:13px">U = new((/ntimes.nlev,nlat,nlon/), float)</span></div><div><span style="font-size:13px">recnum = 0</span></div><div>do j = 0, ntimes -1<br style="font-size:13px"><span style="font-size:13px"> do i = 0, nlev -1</span><br style="font-size:13px"><span style="font-size:13px"> U(j,i,:,:) = fbinrecread(fili,recnum, (/nlat,nlon/))</span></div><div> recnum = recnum + 1<br style="font-size:13px"><span style="font-size:13px"> end do </span><br></div><div><span style="font-size:13px"> recnum = recnum + nlev * (nvars_with_levels - 1) + nsurface_vars ; U has already been handled so there is one less var with levels</span></div><div><span style="font-size:13px">end do</span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px">This is not tested obviously since I do not have your file, but something similar should work. And the same principles would apply for reading other variables in the file.</span></div><div><span style="font-size:13px"> -dave</span><br></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 13, 2015 at 9:35 PM, dyjbean soybean <span dir="ltr"><<a href="mailto:dyjbean@gmail.com" target="_blank">dyjbean@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>hi,David</div>
<div> thanks for you explanation, but the time dimension described in ctl file show it has 21 times, which can be represented in grads as follows,</div>
<div> <img alt="内嵌图片 1" src="cid:ii_14c1654f77d9bbca"></div>
<div> </div>
<div>the responding command shows as the below:</div>
<div> <img alt="内嵌图片 2" src="cid:ii_14c16560b0165707"></div>
<div> </div>
<div>according to the above figure, i think the U component should be 4D not 3D, i have used you code nlev*nlat*nlon, which can run in ncl, but i cannot discern which time it represents.</div>
<div> </div>
<div>but i'm confused how to write the correct code to read the 4D variables in data with ncl including time*level*lat*lon</div><div class="HOEnZb"><div class="h5">
<div> </div>
<div> </div>
<div><br> </div>
<div class="gmail_quote">2015-03-14 4:12 GMT+08:00 David Brown <span dir="ltr"><<a href="mailto:dbrown@ucar.edu" target="_blank">dbrown@ucar.edu</a>></span>:<br>
<blockquote style="BORDER-LEFT:#ccc 1px solid;MARGIN:0px 0px 0px 0.8ex;PADDING-LEFT:1ex" class="gmail_quote">Have you read the applications page on handling GrADS data<br>(<a href="http://www.ncl.ucar.edu/Applications/grads.shtml" target="_blank">http://www.ncl.ucar.edu/Applications/grads.shtml</a>)? The Fortran<br>records in the file contain only a single lat/lon slice of the data.<br>You will need to read multiple records in a loop to get all the U<br>data.<br><br>If you look at the sample script on the web page, you will see that<br>you need to preallocate the variable to the size of the variable you<br>are expecting and then read the data in a loop. I don't know for sure<br>how GrADS binary data files are organized, and I am not sure how the<br>time dimension is being handled: but based on the fact that each<br>variable has a 0 in its specification I am guessing that only one time<br>step is actually in the file even though it gives the time dimension<br>as 21. Assuming that all the U data comes first you could read it<br>using something like this:<br><br>nlat = 180<br>nlon = 360<br>nlev = 29<br><br>U = new((/nlev,nlat,nlon/), float)<br>do i = 0, nlev -1<br> U(i,:,:) = fbinrecread(fili,i, (/nlat,nlon/))<br>end do<br><br>There is a useful function, fbinnumrec<br>(<a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/fbinnumrec.shtml" target="_blank">http://www.ncl.ucar.edu/Document/Functions/Built-in/fbinnumrec.shtml</a>),<br> that will tell you the number of records in the file. It can be<br>helpful to know this number when trying to figure out layout of the<br>data in the file.<br> -dave<br>
<div>
<div><br><br>On Fri, Mar 13, 2015 at 4:02 AM, dyjbean soybean <<a href="mailto:dyjbean@gmail.com" target="_blank">dyjbean@gmail.com</a>> wrote:<br>> hi, i met a strange problem between grads and ncl.<br>><br>> the below is the ctl file for the data,<br>> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>><br>> dset E:\lnw\postvar2010010100<br>> options sequential big_endian<br>> options sequential<br>> title post output from grapes<br>> undef -9.99E+33<br>> xdef 360 linear 0.0000 1.0000<br>> ydef 180 linear -89.5000 1.0000<br>> zdef 29 levels<br>> 1000.000000<br>> 962.5000000<br>> 925.0000000<br>> 887.5000000<br>> 850.0000000<br>> 800.0000000<br>> 750.0000000<br>> 700.0000000<br>> 650.0000000<br>> 600.0000000<br>> 550.0000000<br>> 500.0000000<br>> 450.0000000<br>> 400.0000000<br>> 350.0000000<br>> 300.0000000<br>> 275.0000000<br>> 250.0000000<br>> 225.0000000<br>> 200.0000000<br>> 175.0000000<br>> 150.0000000<br>> 125.0000000<br>> 100.0000000<br>> 70.00000000<br>> 50.00000000<br>> 30.00000000<br>> 20.00000000<br>> 10.00000000<br>> tdef 21 linear 00z01JAN2010 360mn<br>> vars 46<br>> u 29 0 u_wind<br>> v 29 0 v_wind<br>> t 29 0 temperature<br>> h 29 0 geopotential height<br>> q2 29 0 specific humidity<br>> q3 29 0 specific humidity<br>> q4 29 0 specific humidity<br>> q5 29 0 specific humidity<br>> q6 29 0 specific humidity<br>> q7 29 0 specific humidity<br>> ozone 29 0 cloud fraction from microphy<br>> w 29 0 vertical wind<br>> ps 0 0 surface pressure<br>> psl 0 0 sea level pressure<br>> rainc 0 0 precipitation<br>> rainnc 0 0 precipitation<br>> ts 0 0 surface temperature<br>> glw 0 0 surface downward lw<br>> gsw 0 0 surface net sw<br>> glwu 0 0 surface upward lw<br>> tglwu 0 0 toa upward lw<br>> gclw 0 0 surface clear sky downward lw<br>> gclwu 0 0 surface clear sky upward lw<br>> tgclwu 0 0 toa clear sky upward lw<br>> gswu 0 0 surface upward sw<br>> tgsw 0 0 toa net sw<br>> tgswu 0 0 toa upward sw<br>> gcsw 0 0 surface clear sky net sw<br>> gcswu 0 0 surface clear sky upward sw<br>> tgcsw 0 0 toa clear sky net sw<br>> tgcswu 0 0 toa clear sky upward sw<br>> tcc 0 0 total cloud cover<br>> hcc 0 0 high cloud cover<br>> mcc 0 0 middle cloud cover<br>> lcc 0 0 low cloud cover<br>> tvw 0 0 column integrated qv<br>> tcw 0 0 column integrated qc<br>> tiw 0 0 column integrated qi<br>> hfx 0 0 sueface heat flux<br>> qfx 0 0 sueface vapour flux<br>> zs 0 0 terrain<br>> q2m 0 0 specific humidity at 2m<br>> t2m 0 0 temperature at 2m<br>> u10m 0 0 u wind at 10m<br>> v10m 0 0 v wind at 10m<br>> pblh 0 0 pbl height<br>> endvars<br>><br>> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>><br>> according to the above ctl file, we can find some variables 4D and others<br>> 1D,<br>> so i gave the following code in ncl for test:<br>><br>> ++++++++++++++++++++++++++++++++++++++++<br>> fili="postvar2010010100"<br>> nlat=180<br>> mlon=360<br>> nlev=29<br>> ntim=21<br>><br>> setfileoption("bin","ReadByteOrder","BigEndian")<br>> uwind=fbinrecread(fili,0,(/mlon,nlat,nlev,ntim/),"float")<br>><br>> ++++++++++++++++++++++++++++++++++++++++<br>><br>> but there come the following warning,<br>> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>> warning:fbinrecread: size specified is less than record size, some data will<br>> not be read<br>> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>><br>> i changed its dimension description with "-1" instead of<br>> (/mlon,nlat,nlev,ntim/),as follows,<br>><br>> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>> uwind1=fbinrecread(fili,0,-1,"float")<br>> print(dimsizes(uwind1))<br>><br>> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>><br>> then, come to the following result,<br>><br>> +++++++++++++++++++++++++++++++++<br>> print(dimsizes(uu))<br>> (0) 64800<br>> +++++++++++++++++++++++++++++++++<br>><br>> so i use the following code to read the first variable,<br>><br>> ++++++++++++++++++++++++++++++++++++++++++++++++++++<br>> uwind2=fbinrecread(fili,0,(/mlon,nlat/),"float")<br>> ++++++++++++++++++++++++++++++++++++++++++++++++++++<br>><br>> there is no warning appeared.<br>><br>><br>> the above result shows that the first variable has the dimension "mlon*nlat"<br>> not "mlon*nlat*nlev*ntim",which is so wierd.<br>> and i cannot distinguish which level and time the uwind2 represented.<br>><br>> can somebody give me some advice about this difference between ctl file's<br>> description and ncl realization?<br>><br>> if i should add two cycle, like following,<br>><br>> ++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>> do i=0,ntim-1<br>> do j=0,nlev-1<br>> uwind=fbinrecread(fili,0,(/mlon,nlat/),"float")<br>> vwind=fbinrecread(fili,1,(/mlon,nlat/),"float")<br>> ttemp=fbinrecread(fili,2,(/mlon,nlat/),"float")<br>><br>> ....................<br>> u10m=fbinrecread(fili,43,(/mlon,nlat/),"float")<br>> v10m=fbinrecread(fili,44,(/mlon,nlat/),"float")<br>> pblh=fbinrecread(fili,45,(/mlon,nlat/),"float")<br>> end do<br>> end do<br>><br>> +++++++++++++++++++++++++++++++++++++++++++++++++++++<br>><br>><br>> any help will be appreciated,thanks<br>><br>><br>><br>><br>><br>><br>><br>><br>><br>><br>><br>><br>><br>><br>><br>><br></div></div>> _______________________________________________<br>> ncl-talk mailing list<br>> List instructions, subscriber options, unsubscribe:<br>> <a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>><br></blockquote></div><br><br clear="all"><br></div></div><span class="HOEnZb"><font color="#888888">-- <br>
<div>通讯地址:北京市朝阳区大屯路9718信箱 <br> 中国科学院遥感应用研究所<br>邮编:100101<br>电话:010-64860422</div>
</font></span></blockquote></div><br></div>