免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2905 | 回复: 1
打印 上一主题 下一主题

帮我看看时间怎么转成我们能看懂的类型 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-01-11 13:06 |只看该作者 |倒序浏览
from Numeric import *                 # easy access to Numeric
from Scientific.IO.NetCDF import *    # easy access to NetCDF
from mx import DateTime


f = open ( "hdzwx-2002-8-2.txt", 'r' )

y=0
yy=[]
'''for 123 in f.readlines():
    y=y+1
    #print y
    yy.append(y,)
print len(yy) ,type(len(yy))

#g=int(len(yy))
g=144
print g,type(g) '''


uv_value=[]
date_time=[]


for line_no in f.readlines():
        y=y+1
        yy.append(y,)
        g=len(yy)


        tokens = string.split(line_no,"=")
        uv_value.append(string.atoi(tokens[1]))
        #print type(tokens[1])
        #print type(uv_value)
        a=tokens[0]
        #print a
        b=[a]
        #print b
        #print uv_value
                  
        for line_no1 in b:
            tokens1=string.split(line_no1)
            #date=tokens1[0]
            # first token is the year.month.day field
            ymd=string.split(tokens1[0],'-')
            #print ymd
            (year,month,day)=map(string.atoi,ymd)
      
            # 2nd token is the hour:minute:second field
            hms=string.split(tokens1[1],':')
            (hour,minute,second)=map(string.atoi,hms)
         

            # Construct a DateTime object to store the time information
            date_time.append(DateTime.DateTime(year,month,day,hour,minute,second))




   
ncfile = NetCDFFile ( "hdzwx-2002-8-2.nc", 'w' )

#create the dimensions
ncfile.createDimension ( 'lon',1)
ncfile.createDimension ( 'lat',1)
ncfile.createDimension ( 'time',g )
ncfile.createDimension ( 'value',g )

# create the variables

ncfile.manufacter='Shanghai Meteorological Research Institute'
ncfile.instrumenttype='SUR-1'
ncfile.waveband = 'B'
ncfile.wavelong = '200-400(nm)'

latvar = ncfile.createVariable ( 'lat', Float, ('lat',) )
latvar.longname = 'latitude'
latvar.units = 'degrees_north'
latvar[0] = 39.59


lonvar = ncfile.createVariable ( 'lon', Float, ('lon',) )
lonvar.longname = 'longitude'
lonvar.units = 'degrees_east'
lonvar[0] = 116.17

time_var = ncfile.createVariable ( 'time', 'i', ('time',) )
time_var.longname = 'time'
time_var.units = 'day since 2002-08-02 00:00:00  '
time_var[:] = date_time

value_var = ncfile.createVariable ( 'value','i', ('time',) )
value_var.longname = 'Ultraviolet Radiation Value'
value_var.units = 'vatt per square meter'
value_var[:] = uv_value

ncfile.close()

2002-08-02 00:00:00  UV=   0
2002-08-02 00:10:00  UV=   0
2002-08-02 00:20:00  UV=   0
2002-08-02 00:30:00  UV=   0
2002-08-02 00:40:00  UV=   0
2002-08-02 00:50:00  UV =  0
2002-08-02 01:00:00  UV=   0
2002-08-02 01:10:00  UV=   0
2002-08-02 01:20:00  UV=   0
2002-08-02 01:30:00  UV=   0
2002-08-02 01:40:00  UV=   0
2002-08-02 01:50:00  UV=   0
2002-08-02 02:00:00  UV=   0
2002-08-02 02:10:00  UV=   0
2002-08-02 02:20:00  UV=   0
2002-08-02 02:30:00  UV=   0
2002-08-02 02:40:00  UV=   0
2002-08-02 02:50:00  UV=   0
2002-08-02 03:00:00  UV=   0
2002-08-02 03:10:00  UV=   0
2002-08-02 03:20:00  UV=   0
2002-08-02 03:30:00  UV=   0
2002-08-02 03:40:00  UV=   0
2002-08-02 03:50:00  UV=   0
2002-08-02 04:00:00  UV=   0
2002-08-02 04:10:00  UV=   0
2002-08-02 04:20:00  UV=   0
2002-08-02 04:30:00  UV=   0
2002-08-02 04:40:00  UV=   0
2002-08-02 04:50:00  UV=   0
2002-08-02 05:00:00  UV=   9
2002-08-02 05:10:00  UV= 222
2002-08-02 05:20:00  UV= 790
2002-08-02 05:30:00  UV=1613
2002-08-02 05:40:00  UV=2679
2002-08-02 05:50:00  UV=3854
2002-08-02 06:00:00  UV=5376
2002-08-02 06:10:00  UV=7207
2002-08-02 06:20:00  UV=8931
2002-08-02 06:30:00  UV=12328
2002-08-02 06:40:00  UV=14976
2002-08-02 06:50:00  UV=17662
2002-08-02 07:00:00  UV=21321
2002-08-02 07:10:00  UV=19842
2002-08-02 07:20:00  UV=26756
2002-08-02 07:30:00  UV=31236
2002-08-02 07:40:00  UV=37274
2002-08-02 07:50:00  UV=41031
2002-08-02 08:00:00  UV=44312
2002-08-02 08:10:00  UV=40666
2002-08-02 08:20:00  UV=52911
2002-08-02 08:30:00  UV=57185

读出来后日期和时间怎么才能显示和上面一样

论坛徽章:
0
2 [报告]
发表于 2006-01-12 22:51 |只看该作者
好像是同样的问题你已经问了多次了。
论坛里的朋友不可能对每个方面有了解,不可能都有与你一样的环境,不可能都有时间。。。。

这样发一大堆代码不是很好的提问方式,也不要重复提同样的问题
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP