Fortran中Netcdf的输出中有奇怪的数字

时间:2017-12-21 12:43:33

标签: input fortran output netcdf

我对Fortran很新,并尝试读取3D(80000 * 100 * 10)单精度NetCDF数据(但我只是读取它像2D(80000,100,1st))。我需要将它们转换为双精度,以用于下面未显示的其他代码。

我创建的.nc文件,用于检查读/写是否包含" 0"如果我对所有NF90功能使用真正的单精度以及变量值#39。

它主要包含" 0"以及几个奇怪的数字,如果我使用双精度(下面显示的代码),似乎无法以可想到的方式与输入数据相关联。至少我这样在我的nc文件中得到任何输出。

我没有收到任何编译错误{以及错误代码'状态'如果我在NF90功能后检查特定的行。更新:那是错误的}。 Input_test.nc的创建完全符合预期的尺寸,但与实际值无关。

我的代码是:

PROGRAM read

     Implicit None

     INCLUDE 'netcdf.inc'

     INTEGER :: NCID, horstart, verstart, horlen, verlen, horcount, vercount, STATUS, STATUS2

     REAL(kind=8), DIMENSION(80000,100) :: values


     horstart = 1

     verstart = 1

     horcount = 80000 !!(tried to use this instead of horlen, doesn't change anything)

     vercount = 100 !!(tried to use this instead of verlen, doesn't change)

     varname = 'pres'




!! get input data

     STATUS = NF90_OPEN('my_valid_path/file.nc', 0, NCID)


     STATUS = NF90_INQ_DIMID(NCID, 'ncells', horid)
     STATUS = NF90_INQ_DIMID(NCID, 'height', verid)

     STATUS = NF90_INQ_DIMLEN(NCID,horid,horlen)
     STATUS = NF90_INQ_DIMLEN(NCID,verid,verlen)

     STATUS = NF90_INQ_VARID(NCID,varname,varid)

     STATUS = NF90_GET_VARA_DOUBLE(NCID,varid,[horstart,verstart,1],[horlen,verlen,1],values)

STATUS = NF90_CLOSE(NCID)    




        STATUS = NF90_CREATE ('some_path/input_test.nc', 0, ncid);     

        STATUS = NF90_DEF_DIM (ncid, 'hor',horcount, dimhor)
        STATUS = NF90_DEF_DIM (ncid, 'ver',vercount, dimver)
        STATUS = NF90_DEF_DIM (ncid, '1d',1, dimcode)

        STATUS = NF90_DEF_VAR(ncid,'pres',NF90_DOUBLE,2,[dimhor,dimver],pres_id)
        STATUS = NF90_DEF_VAR(ncid,'status',NF90_INT,1,dimcode,stat_id)

        STATUS = NF90_ENDDEF(ncid)

        STATUS = NF90_PUT_VARA_DOUBLE(ncid,pres_id,[horstart,verstart],[horcount,vercount],values)
        STATUS = NF90_PUT_VARA_INT(ncid,stat_id,1,1,STATUS2)

        STATUS = NF90_CLOSE(ncid)

我读取的nc文件不包含任何零,即使在第三维也不包含。但是输出文件确实包含很多零,但它不是空的。

输入示例:0,095213220 0,099325478 0,10358732 0,10800611 0,11259078 0,11734842 0,12228279 0,12740466 0,13271827 0,13822863 0,14394356

输出示例:0 0 0 0 0 0,000493943283800036 0,000594558776356280 0,000234268474741839 2,88491937681101e-05 2,09666131608306e-16 7,30948746534081e-20

我可能做了一些愚蠢的事情,但我暂时没有想法要检查什么。

更新:彻底检查STATUS中保存的错误代码确实在NF90_GET_VARA_DOUBLE /(也是REAL)处给出了非零匹配。明天再回来。

1 个答案:

答案 0 :(得分:0)

使用错误处理程序,我得出上述代码有效的结论。错误最终来自我试图读取的变量的拼写错误。

相关问题