[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