<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>&quot;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).&quot;</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 &quot;default sequence&quot;, 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">&lt;<a href="mailto:dyjbean@gmail.com" target="_blank">dyjbean@gmail.com</a>&gt;</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&#39;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">&lt;<a href="mailto:dbrown@ucar.edu" target="_blank">dbrown@ucar.edu</a>&gt;</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&#39;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 &lt;<a href="mailto:dyjbean@gmail.com" target="_blank">dyjbean@gmail.com</a>&gt; wrote:<br>&gt; hi, i met a strange problem between grads and ncl.<br>&gt;<br>&gt; the below is the ctl file for the data,<br>&gt; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>&gt;<br>&gt; dset E:\lnw\postvar2010010100<br>&gt; options sequential big_endian<br>&gt; options sequential<br>&gt; title post output from grapes<br>&gt; undef -9.99E+33<br>&gt; xdef  360 linear    0.0000    1.0000<br>&gt; ydef  180 linear  -89.5000    1.0000<br>&gt; zdef   29 levels<br>&gt;  1000.000000<br>&gt;  962.5000000<br>&gt;  925.0000000<br>&gt;  887.5000000<br>&gt;  850.0000000<br>&gt;  800.0000000<br>&gt;  750.0000000<br>&gt;  700.0000000<br>&gt;  650.0000000<br>&gt;  600.0000000<br>&gt;  550.0000000<br>&gt;  500.0000000<br>&gt;  450.0000000<br>&gt;  400.0000000<br>&gt;  350.0000000<br>&gt;  300.0000000<br>&gt;  275.0000000<br>&gt;  250.0000000<br>&gt;  225.0000000<br>&gt;  200.0000000<br>&gt;  175.0000000<br>&gt;  150.0000000<br>&gt;  125.0000000<br>&gt;  100.0000000<br>&gt;  70.00000000<br>&gt;  50.00000000<br>&gt;  30.00000000<br>&gt;  20.00000000<br>&gt;  10.00000000<br>&gt; tdef   21 linear 00z01JAN2010   360mn<br>&gt; vars 46<br>&gt; u 29 0 u_wind<br>&gt; v 29 0 v_wind<br>&gt; t 29 0 temperature<br>&gt; h 29 0 geopotential height<br>&gt; q2 29 0 specific humidity<br>&gt; q3 29 0 specific humidity<br>&gt; q4 29 0 specific humidity<br>&gt; q5 29 0 specific humidity<br>&gt; q6 29 0 specific humidity<br>&gt; q7 29 0 specific humidity<br>&gt; ozone 29 0 cloud fraction from microphy<br>&gt; w 29 0 vertical wind<br>&gt; ps 0 0 surface pressure<br>&gt; psl 0 0 sea level pressure<br>&gt; rainc 0 0 precipitation<br>&gt; rainnc 0 0 precipitation<br>&gt; ts 0 0 surface temperature<br>&gt; glw 0 0 surface downward lw<br>&gt; gsw 0 0 surface net sw<br>&gt; glwu 0 0 surface upward lw<br>&gt; tglwu 0 0 toa upward lw<br>&gt; gclw 0 0 surface clear sky downward lw<br>&gt; gclwu 0 0 surface clear sky upward lw<br>&gt; tgclwu 0 0 toa clear sky upward lw<br>&gt; gswu 0 0 surface upward sw<br>&gt; tgsw 0 0 toa net sw<br>&gt; tgswu 0 0 toa upward sw<br>&gt; gcsw 0 0 surface clear sky net sw<br>&gt; gcswu 0 0 surface clear sky upward sw<br>&gt; tgcsw 0 0 toa clear sky net sw<br>&gt; tgcswu 0 0 toa clear sky upward sw<br>&gt; tcc 0 0 total cloud cover<br>&gt; hcc 0 0 high cloud cover<br>&gt; mcc 0 0 middle cloud cover<br>&gt; lcc 0 0 low cloud cover<br>&gt; tvw 0 0 column integrated qv<br>&gt; tcw 0 0 column integrated qc<br>&gt; tiw 0 0 column integrated qi<br>&gt; hfx 0 0 sueface heat flux<br>&gt; qfx 0 0 sueface vapour flux<br>&gt; zs 0 0 terrain<br>&gt; q2m 0 0 specific humidity at 2m<br>&gt; t2m 0 0 temperature at 2m<br>&gt; u10m 0 0 u wind at 10m<br>&gt; v10m 0 0 v wind at 10m<br>&gt; pblh 0 0 pbl height<br>&gt; endvars<br>&gt;<br>&gt; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>&gt;<br>&gt; according to the above ctl file, we can find some variables 4D and others<br>&gt; 1D,<br>&gt; so i gave the following code  in ncl for test:<br>&gt;<br>&gt; ++++++++++++++++++++++++++++++++++++++++<br>&gt; fili=&quot;postvar2010010100&quot;<br>&gt; nlat=180<br>&gt; mlon=360<br>&gt; nlev=29<br>&gt; ntim=21<br>&gt;<br>&gt; setfileoption(&quot;bin&quot;,&quot;ReadByteOrder&quot;,&quot;BigEndian&quot;)<br>&gt; uwind=fbinrecread(fili,0,(/mlon,nlat,nlev,ntim/),&quot;float&quot;)<br>&gt;<br>&gt; ++++++++++++++++++++++++++++++++++++++++<br>&gt;<br>&gt; but there come the following warning,<br>&gt; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>&gt; warning:fbinrecread: size specified is less than record size, some data will<br>&gt; not be read<br>&gt; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>&gt;<br>&gt; i changed its dimension description with &quot;-1&quot; instead of<br>&gt; (/mlon,nlat,nlev,ntim/),as follows,<br>&gt;<br>&gt; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>&gt; uwind1=fbinrecread(fili,0,-1,&quot;float&quot;)<br>&gt; print(dimsizes(uwind1))<br>&gt;<br>&gt; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>&gt;<br>&gt; then, come to the following result,<br>&gt;<br>&gt; +++++++++++++++++++++++++++++++++<br>&gt;  print(dimsizes(uu))<br>&gt; (0)     64800<br>&gt; +++++++++++++++++++++++++++++++++<br>&gt;<br>&gt; so i use the following code to read the first variable,<br>&gt;<br>&gt; ++++++++++++++++++++++++++++++++++++++++++++++++++++<br>&gt; uwind2=fbinrecread(fili,0,(/mlon,nlat/),&quot;float&quot;)<br>&gt; ++++++++++++++++++++++++++++++++++++++++++++++++++++<br>&gt;<br>&gt; there is no warning appeared.<br>&gt;<br>&gt;<br>&gt; the above result shows that the first variable has the dimension &quot;mlon*nlat&quot;<br>&gt; not &quot;mlon*nlat*nlev*ntim&quot;,which is so wierd.<br>&gt; and i cannot distinguish which level and time the uwind2 represented.<br>&gt;<br>&gt; can somebody give me some advice about this difference between ctl file&#39;s<br>&gt; description and ncl realization?<br>&gt;<br>&gt; if i should add two cycle, like following,<br>&gt;<br>&gt; ++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>&gt; do i=0,ntim-1<br>&gt;   do j=0,nlev-1<br>&gt;      uwind=fbinrecread(fili,0,(/mlon,nlat/),&quot;float&quot;)<br>&gt;      vwind=fbinrecread(fili,1,(/mlon,nlat/),&quot;float&quot;)<br>&gt;      ttemp=fbinrecread(fili,2,(/mlon,nlat/),&quot;float&quot;)<br>&gt;<br>&gt;      ....................<br>&gt;      u10m=fbinrecread(fili,43,(/mlon,nlat/),&quot;float&quot;)<br>&gt;      v10m=fbinrecread(fili,44,(/mlon,nlat/),&quot;float&quot;)<br>&gt;      pblh=fbinrecread(fili,45,(/mlon,nlat/),&quot;float&quot;)<br>&gt;   end do<br>&gt; end do<br>&gt;<br>&gt; +++++++++++++++++++++++++++++++++++++++++++++++++++++<br>&gt;<br>&gt;<br>&gt; any help will be appreciated,thanks<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br></div></div>&gt; _______________________________________________<br>&gt; ncl-talk mailing list<br>&gt; List instructions, subscriber options, unsubscribe:<br>&gt; <a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>&gt;<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>