Unfortunately, I don’t work on Linux but on Windows. Do you know a similar program for Windows?
I tried to run the python script again with other modifications, but it seems that tNum = mydata.GetTimeNumber() is equal to zero as I have the following error message:
ZeroDivisionError: Attempted to divide by zero.
I don’t understand why.
Here is the modified code:
Code: Select all
#--------------------------------------------------------
# Author: Yaqiang Wang
# Date: 2012-11-29
# Purpose: Derive station PBL data from ARL meteorological data
# Note: Sample
#-----------------------------------------------------------
import clr
from System import *
from System.Globalization import *
clr.AddReference("MeteoInfoC.dll")
from MeteoInfoC import *
from MeteoInfoC.Data import *
from MeteoInfoC.Data.MeteoData import *
import os.path
#---- Set directories
dataDir = "C:\\Users\\hdelattre\\Documents\\Doctorat\\GlobalDataAssimilationSystem\\"
#---- Set times - this case show seasonal variation
sTime = DateTime.Parse("2011-07-01")
eTime = DateTime.Parse("2011-08-31")
aTime = sTime
#---- Create a MeteoDataInfo object
mydata = MeteoDataInfo()
#---- Set lon/lat of the location
lon = 4.0
lat = 44.0
#---- Set output text file
outpath = dataDir + 'PBL_data.txt'
outf = open(outpath, 'w')
outf.write('Time,PBLH')
#---- Loop
i = 0
sum = 0.0
while aTime <= eTime:
for w in range(5):
inFile = dataDir + "gdas1." + aTime.ToString("MMM", CultureInfo("en-us")).ToLower() + aTime.ToString("yy") + ".w" + (w + 1).ToString()
print "inFile", inFile
if os.path.isfile(inFile):
arldata = mydata.OpenARLData(inFile) #Open ARL data file
print "arldata",arldata
tNum = mydata.GetTimeNumber()
print mydata.GetTimeNumber()
print "tNum", tNum
for t in range(tNum):
dTime = mydata.GetTime(t)
print "dTime.ToString", dTime.ToString("yyyy-MM-dd HH:00")
mydata.TimeIndex = t #Set time index
gData = mydata.GetGridData("PBLH") #Get PBLH grid data
pblh = gData.ToStation(lon, lat) #Intepolate PBLH data to the location
print 'PBLH = %10.2f' %pblh
outf.write(os.linesep)
outf.write(dTime.ToString("yyyyMMddHH") + ',%-7.2f ' %pblh)
sum += pblh
i += 1
aTime = aTime.AddMonths(1)
outf.close()
#---- Calculate seasonal average PBLH value
ave = sum / i
print 'Average PBLH: %10.2f' %ave
print 'Finished!'