<div>The GrADS Users Guide, in the "Creating a Station Data File" section, shows a short sample dataset as follows:</div><div><pre><span class="Apple-style-span" style="font-size: large;">Year Month Stid Lat Lon Rainfall
1980 1 QQQ 34.3 -85.5 123.3
1980 1 RRR 44.2 -84.5 87.1
1980 1 SSS 22.4 -83.5 412.8
1980 1 TTT 33.4 -82.5 23.3
1980 2 QQQ 34.3 -85.5 145.1
1980 2 RRR 44.2 -84.5 871.4
1980 2 SSS 22.4 -83.5 223.1
1980 2 TTT 33.4 -82.5 45.5</span>
</pre></div>I output the attached (test.sta.dat) binary file using an Excel VBA macro, shown here:<div><br><div><div>Private Type stadathdr � � � � 'data type "station data header" (len=24)</div><div>�� �stid As String * 8 � � �'station ID (e.g., "QQQ") � len=8</div>
<div>�� �lat As Single � � � � � 'station latitude �(world � len=4</div><div>�� �lon As Single � � � � � 'station longitude �coords) len=4</div><div>�� �tim As Single � � � � � 'time (grid-relative units) len=4</div>
<div>�� �nlev As Integer � � � � '# data groups after header len=2</div><div>�� �nflg As Integer � � � � 'level indep var set flag � len=2</div><div>End Type</div><div>Sub WriteStaDat()</div><div>�� �Close � � � 'close any open files</div>
<div>�� �Dim hdr As stadathdr</div><div>�� �Dim yr, mo, flg As Integer � � �'year (yyyy), month (m), flag</div><div>�� �Dim rf As Single � � � �'rainfall (mm)</div><div>�� �Dim oldyr, oldmo As Integer � � 'old year, old month</div>
<div>�� �stadatfile = "c:\projectmgr\stationdata\out\test.sta.dat"</div><div>�� �rnum = 8 � '# of data reports to read/write</div><div>�� �flg = 1 � � 'initialize flag</div><div>�� �Range("a1").Select</div>
<div>�� �Open stadatfile For Binary Access Write As #1</div><div>�� �For r = 1 To rnum � � 'loop through data rows, read in data</div><div>�� � � �yr = ActiveCell.Offset(r, 0)</div><div>�� � � �mo = ActiveCell.Offset(r, 1)</div>
<div>�� � � �hdr.stid = ActiveCell.Offset(r, 2)</div><div>�� � � �hdr.lat = ActiveCell.Offset(r, 3)</div><div>�� � � �hdr.lon = ActiveCell.Offset(r, 4)</div><div>�� � � �rf = ActiveCell.Offset(r, 5)</div><div>��� � � If flg = 1 Then</div>
<div>�� � � � � �oldyr = yr: oldmo = mo: flg = 0</div><div>�� � � �End If</div><div>�� � � �If oldyr <> yr Or oldmo <> mo Then �'if new time group</div><div>�� � � � � �hdr.nlev = 0</div><div>�� � � � � �Put #1, , hdr � � 'write station header/time group terminator (no variable)</div>
<div>�� � � � � �'rec = rec + 1</div><div>�� � � �End If</div><div>�� � � �oldyr = yr: oldmo = mo</div><div>�� � � �hdr.tim = 0#: hdr.nlev = 1: hdr.nflg = 1</div><div>�� � � �Put #1, , hdr � �'write station header</div>
<div>�� � � �Put #1, , rf</div><div>�� �Next r</div><div>�� �hdr.nlev = 0</div><div>��� Put #1, , hdr � � 'write last time group terminator</div><div>�� �Close #1</div><div>End Sub</div><div><br></div><div>When I ran the stnmap utility, here were my results:</div>
<div>>stnmap -i c:/projectmgr/stationdata/out/test.sta.ctl</div><div><div>��Name of binary data set: c:\projectmgr\stationdata\out\test.sta.dat</div><div>��Number of times in the data set: 2</div><div>��Number of surface variables: 1</div>
<div>��Number of level dependent variables: 0</div><div><br></div><div>Starting scan of station data binary file.</div><div>Binary data file open: c:\projectmgr\stationdata\out\test.sta.dat</div><div><br></div><div>Processing time step 1</div>
<div>��Invalid station hdr found in station binary file</div><div>��Possible causes: �Invalid level count in hdr</div><div>�� � � � � � � � � �Descriptor file mismatch</div><div>�� � � � � � � � � �File not station data</div>
<div>�� � � � � � � � � �Invalid relative time</div><div>�� � � � � � � � � �Invalid sequential format</div><div>�� �levs = 1123457434 �flag = 542265938 �time = 9.18369e-41�</div><div><br></div><div>It appears the station data file was not properly formatted. �Perhaps someone can understand why I'm getting this result, and how to resolve.</div>
<div><br></div><div>Stephen Mc</div><br><div class="gmail_quote">On Thu, Apr 29, 2010 at 5:15 PM, Stephen McMillan <span dir="ltr"><<a href="mailto:smcmillan@planalytics.com">smcmillan@planalytics.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Does anyone have a "simple" example of an Excel VBA (macro) for creating a station data file for use in GrADS? �I have searched the User Archives but came up empty. �I am familiar with the format instructions and the C and Fortran examples in the GrAD's Users Guide, but wish to use Excel to create the file.<div>
<br></div><div>I could probably eventually translate from the Fortran example to VBA, but it would help if someone has already done that!</div><div><br></div><div>Stephen M</div><div><div><br></div><div><br></div></div>
</blockquote></div><br></div></div></div>
<pre>***************************************************
The information contained in this e-mail message
is intended only for the use of the recipient(s)
named above and may contain information that is
privileged, confidential, and/or proprietary.
If you are not the intended recipient, you may not
review, copy or distribute this message. If you have
received this communication in error, please notify
the sender immediately by e-mail, and delete the original message.
***************************************************