<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span>Yes it is not complete because it is very big and can not be attached.</span></div><div><span>Anyway many thanks for your help.</span></div><div> </div><div><font size="3" face="times new roman, new york, times, serif">With my kind regards<br>Gamal<br>___________________________________________________________<br><b>Gamal <span id="misspell-2" class="mark">Salah</span> El Afandi, <span id="misspell-4" class="mark">Ph</span>.D. <br>College of Agricultural, Environment and Nutrition Sciences </b></font></div>
<div><font size="3" face="times new roman, new york, times, serif"><b>College of Engineering <br>Tuskegee University, Tuskegee Alabama USA<br></b><br></font><a href="http://www.tuskegee.edu/" rel="nofollow" target="_blank"><font size="3" face="times new roman, new york, times, serif">http://www.tuskegee.edu/</font></a><br><a href="http://www.tuskegee.edu/academics/colleges/caens.aspx" rel="nofollow" target="_blank"><font size="3" face="times new roman, new york, times, serif">http://www.tuskegee.edu/academics/colleges/caens.aspx</font></a><br><a href="http://www.tuskegee.edu/academics/colleges/ceps.aspx" rel="nofollow" target="_blank"><font size="3" face="times new roman, new york, times, serif">http://www.tuskegee.edu/academics/colleges/ceps.aspx</font></a><br><a href="http://maindb.unfccc.int/public/roe/expert_list.pl?id_country=66&" rel="nofollow" target="_blank"><font size="3" face="times new roman, new york, times,
serif">http://maindb.unfccc.int/public/roe/expert_list.pl?id_country=66&</font></a><font size="3" face="times new roman, new york, times, serif">;<br></font><a href="http://www.itap.purdue.edu/pto/NATO_KEEO/partCoDir_en.html" rel="nofollow" target="_blank"><font size="3" face="times new roman, new york, times, serif">http://www.itap.purdue.edu/pto/NATO_KEEO/partCoDir_en.html</font></a><br><a href="http://www.ucar.edu/governance/iap/iapreps.shtml" rel="nofollow" target="_blank"><font size="3" face="times new roman, new york, times, serif">http://www.ucar.edu/governance/iap/iapreps.shtml</font></a></div>
<div> </div><div><br><div><blockquote style="padding-left: 5px; margin-top: 5px; margin-left: 5px; border-left-color: rgb(16, 16, 255); border-left-width: 2px; border-left-style: solid;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div dir="ltr"> <font size="2" face="Arial"> <div style="margin: 5px 0px; padding: 0px; border: 1px solid rgb(204, 204, 204); height: 0px; line-height: 0; font-size: 0px;" class="hr" contentEditable="false" readonly="true"></div> <b><span style="font-weight: bold;">From:</span></b> Yaqiang Wang <yaqiang.wang@gmail.com><br> <b><span style="font-weight: bold;">To:</span></b> Dr.Gamal El Afandi <gamalafandy@yahoo.com>; GrADS Users Forum <gradsusr@gradsusr.org> <br> <b><span style="font-weight: bold;">Sent:</span></b> Tuesday, January 31, 2012 9:26 PM<br> <b><span
style="font-weight: bold;">Subject:</span></b> Re: [gradsusr] Convert <span id="misspell-10" class="mark">TXT</span> to <span id="misspell-11" class="mark">NetCDF</span><br> </font> </div> <br>
Your attached <span id="misspell-12" class="mark">txt</span> file is not complete because your program defined<br>the array with 751*801. Following is a <span id="misspell-13" class="mark">IronPython</span> script sample to<br>convert a <span id="misspell-14" class="mark">txt</span> data into <span id="misspell-15" class="mark">NetCDF</span>. Hope it will be helpful. The converted<br><span id="misspell-16" class="mark">NetCDF</span> data file and the figures are attached.<br><br>import <span id="misspell-17" class="mark">clr</span><br><span id="misspell-18" class="mark">clr</span>.<span id="misspell-19" class="mark">AddReferenceByPartialName</span>("System.Windows.Forms")<br><span id="misspell-20" class="mark">clr</span>.<span id="misspell-21" class="mark">AddReferenceByPartialName</span>("System.Drawing")<br>from System import *<br>from System.Windows.Forms import *<br>from System.Drawing import *<br><span id="misspell-22" class="mark">clr</span>.<span
id="misspell-23" class="mark">AddReference</span>("<span id="misspell-24" class="mark">MeteoInfoC</span>.<span id="misspell-25" class="mark">dll</span>")<br>from <span id="misspell-26" class="mark">MeteoInfoC</span> import *<br>from <span id="misspell-27" class="mark">MeteoInfoC</span>.Data import *<br>from MeteoInfoC.Data.MeteoData import *<br><br>import <span id="misspell-28" class="mark">os</span>.path<br>from <span id="misspell-29" class="mark">datetime</span> import *<br>import time<br><br>#---- Set data folder<br><span id="misspell-30" class="mark">DataDir</span> = "F:\\Temp\\"<br><br>#---- Define <span id="misspell-31" class="mark">lon</span> lat numbers<br><span id="misspell-32" class="mark">lonNum</span> = 751<br><span id="misspell-33" class="mark">latNum</span> = 801<br><span id="misspell-34" class="mark">unDef</span> = -999.0<br><br>#---- Create <span id="misspell-35" class="mark">netCDF</span> data info object<br><span id="misspell-36"
class="mark">outfilepath</span> = <span id="misspell-37" class="mark">DataDir</span> + "<a href="http://output.nc" target="_blank">output.<span id="misspell-38" class="mark">nc</span></a>"<br><span id="misspell-39" class="mark">outDataInfo</span> = <span id="misspell-40" class="mark">NetCDFDataInfo</span>()<br><span id="misspell-41" class="mark">outDataInfo</span>.<span id="misspell-42" class="mark">fileName</span> = <span id="misspell-43" class="mark">outfilepath</span><br><span id="misspell-44" class="mark">outDataInfo</span>.<span id="misspell-45" class="mark">UNDEF</span> = <span id="misspell-46" class="mark">unDef</span><br><span id="misspell-47" class="mark">outDataInfo</span>.<span id="misspell-48" class="mark">unlimdimid</span> = 2<br><br>#---- Add dimensions: <span id="misspell-49" class="mark">lon</span>, lat, time<br><span id="misspell-50" class="mark">lonDim</span> = <span id="misspell-51" class="mark">outDataInfo</span>.<span
id="misspell-52" class="mark">AddDimension</span>("<span id="misspell-53" class="mark">lon</span>", <span id="misspell-54" class="mark">lonNum</span>)<br><span id="misspell-55" class="mark">latDim</span> = <span id="misspell-56" class="mark">outDataInfo</span>.<span id="misspell-57" class="mark">AddDimension</span>("lat", <span id="misspell-58" class="mark">latNum</span>)<br><span id="misspell-59" class="mark">timeDim</span> = <span id="misspell-60" class="mark">outDataInfo</span>.<span id="misspell-61" class="mark">AddDimension</span>("time", -1)<br><br>#---- Add variables<br><span id="misspell-62" class="mark">outDataInfo</span>.<span id="misspell-63" class="mark">AddVariable</span>("<span id="misspell-64" class="mark">lon</span>", NetCDF4.NcType.NC_DOUBLE,<br>Array[<span id="misspell-65" class="mark">DimStruct</span>]([<span id="misspell-66" class="mark">lonDim</span>]))<br><span id="misspell-67" class="mark">outDataInfo</span>.<span id="misspell-68"
class="mark">AddVariable</span>("lat", NetCDF4.NcType.NC_DOUBLE,<br>Array[<span id="misspell-69" class="mark">DimStruct</span>]([<span id="misspell-70" class="mark">latDim</span>]))<br><span id="misspell-71" class="mark">outDataInfo</span>.<span id="misspell-72" class="mark">AddVariable</span>("time", NetCDF4.NcType.NC_DOUBLE,<br>Array[<span id="misspell-73" class="mark">DimStruct</span>]([<span id="misspell-74" class="mark">timeDim</span>]))<br><span id="misspell-75" class="mark">outDataInfo</span>.<span id="misspell-76" class="mark">AddVariable</span>("rain", NetCDF4.NcType.NC_DOUBLE,<br>Array[<span id="misspell-77" class="mark">DimStruct</span>]([<span id="misspell-78" class="mark">timeDim</span>, <span id="misspell-79" class="mark">latDim</span>, <span id="misspell-80" class="mark">lonDim</span>]))<br>#---- Add variable attributes<br><span id="misspell-81" class="mark">outDataInfo</span>.<span id="misspell-82"
class="mark">AddVariableAttribute</span>("<span id="misspell-83" class="mark">lon</span>", "units", "degrees_east")<br><span id="misspell-84" class="mark">outDataInfo</span>.<span id="misspell-85" class="mark">AddVariableAttribute</span>("<span id="misspell-86" class="mark">lon</span>", "long_name", "longitude")<br><span id="misspell-87" class="mark">outDataInfo</span>.<span id="misspell-88" class="mark">AddVariableAttribute</span>("lat", "units", "degrees_north")<br><span id="misspell-89" class="mark">outDataInfo</span>.<span id="misspell-90" class="mark">AddVariableAttribute</span>("lat", "long_name", "latitude")<br><span id="misspell-91" class="mark">outDataInfo</span>.<span id="misspell-92" class="mark">AddVariableAttribute</span>("time", "units", "days since 1-1-1 00:00:00")<br><span id="misspell-93" class="mark">outDataInfo</span>.<span id="misspell-94" class="mark">AddVariableAttribute</span>("time", "long_name", "time")<br><span id="misspell-95"
class="mark">outDataInfo</span>.<span id="misspell-96" class="mark">AddVariableAttribute</span>("rain", "units", "mm/day")<br><span id="misspell-97" class="mark">outDataInfo</span>.<span id="misspell-98" class="mark">AddVariableAttribute</span>("rain", "long_name", "precipitation")<br><span id="misspell-99" class="mark">outDataInfo</span>.<span id="misspell-100" class="mark">AddVariableAttribute</span>("rain", "missing_value", <span id="misspell-101" class="mark">unDef</span>)<br><br>#---- Add global attributes<br><span id="misspell-102" class="mark">outDataInfo</span>.<span id="misspell-103" class="mark">AddGlobalAttribute</span>("title", "Daily rainfall estimate")<br><span id="misspell-104" class="mark">outDataInfo</span>.<span id="misspell-105" class="mark">AddGlobalAttribute</span>("institute", "Tuskegee University,<br>Tuskegee Alabama USA")<br><br>#---- Create <span id="misspell-106" class="mark">netCDF</span> file<br><span id="misspell-107"
class="mark">outDataInfo</span>.<span id="misspell-108" class="mark">CreateNCFile</span>(<span id="misspell-109" class="mark">outfilepath</span>)<br><br>#---- Write <span id="misspell-110" class="mark">lon</span>, lat, time data<br><span id="misspell-111" class="mark">lonArray</span> = Array.<span id="misspell-112" class="mark">CreateInstance</span>(Double, <span id="misspell-113" class="mark">lonNum</span>)<br><span id="misspell-114" class="mark">latArray</span> = Array.<span id="misspell-115" class="mark">CreateInstance</span>(Double, <span id="misspell-116" class="mark">latNum</span>)<br><span id="misspell-117" class="mark">timeArray</span> = Array.<span id="misspell-118" class="mark">CreateInstance</span>(Object, 1)<br><br><span id="misspell-119" class="mark">lon</span>1 = -20<br>for i in range(<span id="misspell-120" class="mark">lonNum</span>):<br> <span id="misspell-121" class="mark">lon</span> = <span id="misspell-122"
class="mark">lon</span>1 + 0.1 * i<br> <span id="misspell-123" class="mark">lonArray</span>[i] = <span id="misspell-124" class="mark">lon</span><br># print <span id="misspell-125" class="mark">lon</span><br><span id="misspell-126" class="mark">outDataInfo</span>.<span id="misspell-127" class="mark">WriteVar</span>("<span id="misspell-128" class="mark">lon</span>", <span id="misspell-129" class="mark">lonArray</span>)<br><br>lat1 = -40<br>for i in range(<span id="misspell-130" class="mark">latNum</span>):<br> lat = lat1 + 0.1 * i<br> <span id="misspell-131" class="mark">latArray</span>[i] = lat<br># print <span id="misspell-132" class="mark">latArray</span>[i]<br><span id="misspell-133" class="mark">outDataInfo</span>.<span id="misspell-134" class="mark">WriteVar</span>("lat", <span id="misspell-135" class="mark">latArray</span>)<br><br>t = <span id="misspell-136"
class="mark">datetime</span>.today()<br>st = <span id="misspell-137" class="mark">datetime</span>(1, 1, 1)<br>days = (t - st).days<br><span id="misspell-138" class="mark">timeArray</span>[0] = days<br>#print <span id="misspell-139" class="mark">timeArray</span>[0]<br><span id="misspell-140" class="mark">startArray</span> = Array.<span id="misspell-141" class="mark">CreateInstance</span>(int, 1)<br><span id="misspell-142" class="mark">countArray</span> = Array.<span id="misspell-143" class="mark">CreateInstance</span>(int, 1)<br><span id="misspell-144" class="mark">startArray</span>[0] = 0<br><span id="misspell-145" class="mark">countArray</span>[0] = 1<br><span id="misspell-146" class="mark">outDataInfo</span>.<span id="misspell-147" class="mark">WriteVara</span>("time", <span id="misspell-148" class="mark">startArray</span>, <span id="misspell-149" class="mark">countArray</span>, <span id="misspell-150" class="mark">timeArray</span>)<br><br>#---- Write
rainfall data<br><span id="misspell-151" class="mark">dataArray</span> = Array.<span id="misspell-152" class="mark">CreateInstance</span>(Double, <span id="misspell-153" class="mark">lonNum</span> * <span id="misspell-154" class="mark">latNum</span>)<br>#---- Open text data file<br><span id="misspell-155" class="mark">infile</span> = open(<span id="misspell-156" class="mark">DataDir</span> + "output.<span id="misspell-157" class="mark">txt</span>")<br>i = 0<br>for <span id="misspell-158" class="mark">aline</span> in <span id="misspell-159" class="mark">infile</span>:<br> v = <span id="misspell-160" class="mark">aline</span>.split()[2]<br> <span id="misspell-161" class="mark">dataArray</span>[i] = float(v)<br># print i, <span id="misspell-162" class="mark">dataArray</span>[i]<br> i = i + 1<br><span id="misspell-163" class="mark">infile</span>.close()<br>#---- Write data<br><span
id="misspell-164" class="mark">startArray</span> = Array.<span id="misspell-165" class="mark">CreateInstance</span>(int, 3)<br><span id="misspell-166" class="mark">countArray</span> = Array.<span id="misspell-167" class="mark">CreateInstance</span>(int, 3)<br><span id="misspell-168" class="mark">startArray</span>[0] = 0<br><span id="misspell-169" class="mark">startArray</span>[1] = 0<br><span id="misspell-170" class="mark">startArray</span>[2] = 0<br><span id="misspell-171" class="mark">countArray</span>[0] = 1<br><span id="misspell-172" class="mark">countArray</span>[1] = <span id="misspell-173" class="mark">latDim</span>.<span id="misspell-174" class="mark">dimLen</span><br><span id="misspell-175" class="mark">countArray</span>[2] = <span id="misspell-176" class="mark">lonDim</span>.<span id="misspell-177" class="mark">dimLen</span><br><span id="misspell-178" class="mark">outDataInfo</span>.<span id="misspell-179" class="mark">WriteVara</span>("rain",
<span id="misspell-180" class="mark">startArray</span>, <span id="misspell-181" class="mark">countArray</span>, <span id="misspell-182" class="mark">dataArray</span>)<br><br>#---- Close <span id="misspell-183" class="mark">netCDF</span> file<br><span id="misspell-184" class="mark">outDataInfo</span>.<span id="misspell-185" class="mark">CloseNCFile</span>()<br><br>On Tue, Jan 31, 2012 at 11:55 AM, Dr.Gamal El Afandi<br><<a href="mailto:gamalafandy@yahoo.com" ymailto="mailto:gamalafandy@yahoo.com">gamalafandy@yahoo.com</a>> wrote:<br>> Dear all,<br>> Could you please let me know if anyone have idea about converting the <span id="misspell-188" class="mark">TXT</span> or<br>> ASCII data into <span id="misspell-189" class="mark">NetCDF</span>?<br>> Please attached is the file required to be transformed into <span id="misspell-190" class="mark">NetCDF</span>.<br>> Please below is the program I used to convert from binary to <span
id="misspell-191" class="mark">TXT</span><br>><br>><br>> PROGRAM convert_<span id="misspell-192" class="mark">rfe</span>_bin2<span id="misspell-193" class="mark">asc</span><br>><br>> c <span id="misspell-194" class="mark">cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc</span><br>> c Program: convert_<span id="misspell-195" class="mark">rfe</span>2.f<br>> c<br>> c Description: This program reads in a daily <span id="misspell-196" class="mark">RFE</span> (rainfall estimate) file<br>> c (version 2) in .bin format and creates an <span id="misspell-197" class="mark">ascii</span> integer<br>> c file. Each file contains <span id="misspell-198" class="mark">rfe</span> coordinate data ordered by<br>> rows.<br>>
c Rainfall resolution is 0.1 degree with a domain of<br>> c 20W-55E, 40S-40N.<br>> c<br>> c Inputs: 'input_file' = the 10-day binary <span id="misspell-199" class="mark">precip</span> file to be converted<br>> c<br>> c Output: 'output.<span id="misspell-200" class="mark">txt</span>' = the output <span id="misspell-201" class="mark">ascii</span> converted text file<br>> c<br>> c Modified: July, 2010 by Nick Novella (<a href="mailto:nicholas.novella@noaa.gov" ymailto="mailto:nicholas.novella@noaa.gov">nicholas.novella@noaa.gov</a>)<br>> c<br>> c <span id="misspell-202" class="mark">cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc</span><br>><br>> REAL*4 <span id="misspell-203" class="mark">rfe</span>(751,801),arr(3,601551)<br>>
real*4 lat,<span id="misspell-204" class="mark">lon</span><br>> INTEGER:: i,j,ind<br>> character*25:: input_file<br>><br>> c ##### CHANGE FILE NAME BELOW TO INPUT FILE #####<br>><br>> input_file="all_products.bin.20100621"<br>><br>> c ##################################################<br>><br>> c ##### Initialize the arrays #####<br>> do i = 1,751<br>> do j = 1,801<br>> <span id="misspell-205" class="mark">rfe</span> (i,j) = -999<br>> end do<br>> end do<br>><br>> c ##### Read in the input rainfall data #####<br>> open (unit=22,file=input_file,access="direct",<br>> 1 convert='big_<span id="misspell-206" class="mark">endian</span>',status="old",<span id="misspell-207" class="mark">recl</span>=751*801*4)<br>> read (22, rec=1) <span id="misspell-208" class="mark">rfe</span><br>><br>> c ##### Open the output file #####<br>> open
(88,file="output.<span id="misspell-209" class="mark">txt</span>",access='sequential',<br>> 1 status='unknown',form='formatted')<br>><br>> c ##### The next code converts the input rainfall data. Each row is then<br>> written<br>> c to the output file.<br>><br>> ind=1<br>> lat= -40.0<br>> <span id="misspell-210" class="mark">lon</span>= -20.0<br>> do j=1,801<br>> do i=1,751<br>> arr(1,ind)=lat<br>> arr(2,ind)=<span id="misspell-211" class="mark">lon</span><br>> arr(3,ind)=<span id="misspell-212" class="mark">rfe</span>(i,j)<br>><br>> write (88,499) arr(1,ind), arr(2,ind), arr(3,ind)<br>> 499 format(1X,f6.2,1X,f6.2,1X,f8.2)<br>><br>> ind=ind+1<br>> <span
id="misspell-213" class="mark">lon</span>=<span id="misspell-214" class="mark">lon</span>+0.1<br>> end do<br>> lat=lat+0.1<br>> <span id="misspell-215" class="mark">lon</span>=-20.0<br>> end do<br>><br>><br>><br>><br>><br>> END PROGRAM<br>><br>> With my kind regards<br>> Gamal<br>> ___________________________________________________________<br>> Gamal <span id="misspell-218" class="mark">Salah</span> El Afandi, <span id="misspell-220" class="mark">Ph</span>.D.<br>> College of Agricultural, Environment and Nutrition Sciences<br>> College of Engineering<br>> Tuskegee University, Tuskegee Alabama USA<br>><br>> <a href="http://www.tuskegee.edu/" target="_blank">http://www.tuskegee.edu/</a><br>> <a href="http://www.tuskegee.edu/academics/colleges/caens.aspx"
target="_blank">http://www.tuskegee.edu/academics/colleges/caens.aspx</a><br>> <a href="http://www.tuskegee.edu/academics/colleges/ceps.aspx" target="_blank">http://www.tuskegee.edu/academics/colleges/ceps.aspx</a><br>> <a href="http://maindb.unfccc.int/public/roe/expert_list.pl?id_country=66&;" target="_blank">http://maindb.unfccc.int/public/roe/expert_list.pl?id_country=66&;</a><br>> <a href="http://www.itap.purdue.edu/pto/NATO_KEEO/partCoDir_en.html" target="_blank">http://www.itap.purdue.edu/pto/NATO_KEEO/partCoDir_en.html</a><br>> <a href="http://www.ucar.edu/governance/iap/iapreps.shtml" target="_blank">http://www.ucar.edu/governance/iap/iapreps.shtml</a><br>><br>><br>><br>><br>> _______________________________________________<br>> gradsusr mailing list<br>> <a href="mailto:gradsusr@gradsusr.org" ymailto="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a><br>> <a
href="http://gradsusr.org/mailman/listinfo/gradsusr" target="_blank">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>><br><br><br><br>-- <br>*************************************************<br>Dr. Yaqiang Wang<br>Chinese Academy of Meteorological Sciences (CAMS)<br>46, <span id="misspell-223" class="mark">Zhong</span>-<span id="misspell-224" class="mark">Guan</span>-<span id="misspell-225" class="mark">Cun</span> South Avenue<br>Beijing, 100081<br>China<br><br><a href="mailto:yaqiang.wang@gmail.com" ymailto="mailto:yaqiang.wang@gmail.com">yaqiang.wang@gmail.com</a><br><br><a href="http://www.meteothinker.com" target="_blank">http://www.meteothinker.com</a><br>**************************************************<br><br><br> </div> </div> </blockquote></div> </div></body></html>