Fortran 中 Netcdf 输出中的奇怪数字

Strange numbers in the output from Netcdf in Fortran

我对 Fortran 相当陌生,尝试读取 3D (80000*100*10) 单精度 NetCDF 数据(但我只是像 (80000,100,1st) 那样读取 2D)。对于下面未显示的一些其他代码,我需要将它们转换为双精度。

如果我对所有 NF90 函数使用真正的单精度,我创建的用于检查 reading/writing 作品是否包含 “0”的 .nc 文件以及变量 'values'.

它确实主要包含“0”和几个奇怪的数字,如果我使用双精度(代码如下所示),这些数字似乎与输入数据没有任何关联。至少我通过这种方式在我的 nc 文件中得到了任何输出。

如果我检查 NF90 函数后的特定行,我没有收到任何编译错误{也没有错误代码 'STATUS'。更新:那是错误的}。 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 文件不包含任何零,甚至在第 3 维中也不包含。然而,输出文件确实包含很多零,但它不是空的。

示例输入:0,095213220 0,099325478 0,10358732 0,10800611 0,11259078 0,11734842 0,12228279 0,12740466 0,13271827 0,1382284639 143 3,1

示例输出:0 0 0 0 0 0 0 0 0,000493943283800036 0,000594558776356280 0,000234268474741839 2,88491937681105-05

我可能在做一些愚蠢的事情,但我暂时不知道要检查什么。

更新:彻底检查保存在状态中的错误代码确实在 NF90_GET_VARA_DOUBLE/(也是真实的)处给出了非零匹配。明天再谈这个。

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