爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 11143|回复: 0

[其他] 用ncl写nc文件,数据小数点后保留的位数

[复制链接]

新浪微博达人勋

发表于 2021-10-10 20:14:59 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
大家好。我刚开始使用ncl,用ncl写nc文件,但是在把经纬度写到nc文件后,经纬度本来是小数后面2位数,lat:[-89.95, -89.85, ... , 89.85, 89.95]
lon:[-179.95,-179.85, ..., 179.85, 179.95]
不管我是用lat=fspan(-89.95, 89.95, 1800)
lon=fspan(-179.95, 179.95, 3600)
还是从原本的nc数据里面读取lat,lon重新写入新的nc文件中
或者从txt文件里面读取已经写好的lat,lon数据写入到nc文件中,
nc文件的经纬度数据从小数点后两位变成在小数点后多出很多位数
QQ图片20211010201340.png
这个问题困扰我很多天,希望大家能帮我解决一下
  1. lat_1 = asciiread("filepath/lat.txt", 1800, "float")
  2. lon_1 = asciiread("filepath/lon.txt", 3600, "float")
  3. time  = new(12,double,"No_FillValue")
  4. YYYY = tointeger(year) ;将字符转为数值
  5. do i = 0, ntim-1
  6.     MM = i+1
  7.     time(i) = cd_inv_calendar(YYYY, MM, 01, 00, 00, 00, "hours since 1985-01-01 00:00:00", 0)
  8. end do

  9. do i = 0, dimsizes(pollutant_names)-1
  10.     emi_1 = emi_anthro_1(i,:,:,:)
  11.     var = pollutant_names(i)
  12.     fout_name = "PKU_" + pollutant_names(i) + "_" + year + "_anthro.nc"
  13.     ;Remove the file if it already existed
  14.     system("rm -f " + diro + fout_name)
  15.    
  16.     ;create the file:
  17.     fout = addfile(diro + fout_name, "c")
  18.    
  19.     ;define some file properties:
  20.     atts = True
  21.     atts@title = "NetCDF file containing " + pollutant_names(i) + " anthropogenic emission dataset"
  22.     fout@creation_date=systemfunc("date")
  23.     fileattdef(fout, atts)

  24.     ;define dimensions:
  25.     dim_Names = (/"time","lat","lon"/)
  26.     dim_Sizes = (/12, nlat, nlon/)
  27.     dim_Unlim = (/True, False, False/)
  28.     filedimdef(fout, dim_Names, dim_Sizes, dim_Unlim)

  29.     ;define file variables:
  30.     filevardef(fout, "time", "double", "time")
  31.     filevardef(fout, "lat", "float", "lat")
  32.     filevardef(fout, "lon", "float", "lon")
  33.     filevardef(fout, var, "double", (/"time","lat","lon"/))
  34.     ;define file variables attributes:
  35.     ;;time
  36.     tatts = True
  37.     tatts@long_name = "Time"
  38.     tatts@units = "hours since 1985-01-01 00:00:00"
  39.     tatts@axis      = "T"
  40.     filevarattdef(fout, "time", tatts)
  41.     ;;latitude
  42.     latatts = True
  43.     latatts@long_name = "latitude"
  44.     latatts@units     = "degree_north"
  45.     latatts@axis      = "X"
  46.     filevarattdef(fout, "lat", latatts)
  47.     ;;longitude
  48.     lonatts = True
  49.     lonatts@long_name = "longitude"
  50.     lonatts@units     = "degree_east"
  51.     lonatts@axis      = "Y"
  52.     filevarattdef(fout, "lon", lonatts)
  53.     ;;emission data
  54.     emiatts = True
  55.     emiatts@long_name = "Gridded emission desities of " + pollutant_names(i)
  56.     emiatts@units = "kg m-2 s-1"
  57.     filevarattdef(fout, var, emiatts)

  58.    
  59.     ;write out  the data
  60.     fout->lat   = (/lat_1/)
  61.     fout->lon   = (/lon_1/)
  62.     fout->time  = (/time/)
  63.     fout->$var$ = (/emi_1/)
  64. end do
  65. print("Finish the Step 5")
复制代码


密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表