Fortran Coder

查看: 6182|回复: 2

[文件读写] 通过经纬度,连接两个文件的值,得到的结果却不对

[复制链接]

25

帖子

8

主题

0

精华

熟手

F 币
164 元
贡献
104 点
发表于 2017-11-29 14:17:23 | 显示全部楼层 |阅读模式
通过相同的经纬度,将作物面积与作物收获结束的时间连接起来,
作物面积格式为(即integrated_swpyh.csv文件格式): QQ图片20171129134457.png
作物收获结束的时间单位为:day of year,范围为18-365天且必为整数
但通过以下代码,却得到(harvest.end的)结果为: QQ图片20171129135258.png ,请问各位大神,错误到底在哪里,实在不明白了,,拜托拜托
代码:
[Fortran] 纯文本查看 复制代码
         program linkall
         implicit none
         integer i,j

         integer,dimension(792303)::allockey_h,m_h,n_h
         real,dimension(792303)::lon_h,lat_h,swpy_h
         real,dimension(792303)::harvest_1,harveste_1
         character*15,dimension(792303)::name_h
         integer,parameter::latitude=1800,longitude=3600   !calendar
         integer ierr,ncid,varid,len_file
         real lon_2(longitude)
         real lat_2(latitude)
         real harvest_2(longitude,latitude)
         real harveste_2(longitude,latitude)
         character*299 calendar_file
         character c
         include 'netcdf.inc'

         calendar_file="/home/iga/data/xycao/calendar/output/Swep.op.nc"

         harvest_1=0.1
         harveste_1=0.1
         m_h=0
         n_h=0

         !open the Swep.op.nc and extract information

         len_file=len_trim(calendar_file)
         ierr=nf_open(trim(calendar_file),nf_write,ncid)

         ierr=nf_inq_varid(ncid,'harvest',varid)    !get"harvest"
         ierr=nf_get_var_real(ncid,varid,harvest_2)

         ierr=nf_inq_varid(ncid,'harvest.end',varid) !get"harvest.end"
         ierr=nf_get_var_real(ncid,varid,harveste_2)

         ierr=nf_inq_varid(ncid,'longitude',varid)    !get"longitude"
         ierr=nf_get_var_real(ncid,varid,lon_2)


         ierr=nf_inq_varid(ncid,'latitude',varid)    !get"latitude"
         ierr=nf_get_var_real(ncid,varid,lat_2)

         open(20,file="/home/iga/data/xycao/area/swpy/integrated_swpyh.csv")
         open(22,file="/home/iga/data/xycao/area/swpy/lh.csv)

         !open the integrated_swpyh.csv and extract information
         do i=1,792303
            read(20,*) allockey_h(i),name_h(i),lon_h(i),lat_h(i),swpy_h(i)
         end do

         ! match lon and lat by a loop program,harvest area
         do i=1,792303             !longitude

            do j=1,3600
              if(abs(lon_h(i)-lon_2(j))-minval(abs(lon_h(i)-lon_2))==0) then
                m_h(i)=j
              end if
            end do
         end do

         do i=1,792303              !latitude
            do j=1,1800
              if(abs(lat_h(i)-lat_2(j))-minval(abs(lat_h(i)-lat_2))==0) then
                n_h(i)=j
              end if
            end do
         end do

         do i=1,792303              !assign harvest_2 to harvest_1
           harvest_1(i)=harvest_2(m_h(i),n_h(i))
         end do

         do i=1,792303              !assign harveste_2 to harveste_1
           harveste_1(i)=harveste_2(m_h(i),n_h(i))
         end do

          ! Last, write varibales into a new file
            do i=1,792303
            write(22,*) allockey_h(i),',',name_h(i),',',lon_h(i),',',lat_h(i),',',swpy_h(i),',',&

                          harveste_1(i),',',m_h(i),',',n_h(i)

          end do
           close(20)

           close(22)

        end program linkall

25

帖子

8

主题

0

精华

熟手

F 币
164 元
贡献
104 点
 楼主| 发表于 2017-11-29 14:29:01 | 显示全部楼层
还是要艾特大神@fcode,实在 不好意思,

490

帖子

4

主题

0

精华

大宗师

F 币
3298 元
贡献
1948 点

水王勋章元老勋章热心勋章

发表于 2017-11-29 16:23:29 | 显示全部楼层

回帖奖励 +5

http://v.fcode.cn/
请点击fortran视频教程主页,右边的
QQ群交流
按钮
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-4-17 03:42

Powered by Tencent X3.4

© 2013-2024 Tencent

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