主题:文件读取出错,文件号
est:do ii=1,est_sta_num,1
open(0,file=trim(filepat)//trim(est_sta_pro(ii))//
* '的'//trim(est_sta_nam(ii))//'.txt')
! print*,'end open',ii,'est_sta';pause
ix=ceiling((est_sta_x(ii)-xbeg-10.)/step)
iy=ceiling((est_sta_y(ii)-ybeg-10.)/step)
allocate (loca(k),stat=er)
if (er.ne.0) then
print *,'allocate wrong 208';pause
end if
t_no=0;print*,ix,iy,trim(est_sta_nam(ii)),
* lab(ix,iy),trim(sta_nam(lab(ix,iy)))
do jj=1,k,1
! if (jj.gt.68) then
! print*,jj,ctrl(jj,1),trim(sta_nam(ctrl(jj,1))),ctrl(jj,2),
! * sta_nam(ctrl(jj,2));pause
! end if
if ((ctrl(jj,1).eq.lab(ix,iy)).and.
* (ctrl(jj,2).ne.lab(ix,iy))) then
! print*,ctrl(jj,1),trim(sta_nam(ctrl(jj,1))),ctrl(jj,2)
! * ,trim(sta_nam(ctrl(jj,2))),t_no+1
t_no=t_no+1;loca(t_no)=ctrl(jj,2)
open (t_no,file=trim(filepat)//
* trim(sta_pro(ctrl(jj,2)))//'\'//
* trim(sta_nam(ctrl(jj,2)))//
* '.txt',status='old')
print*,t_no,sta_id((ctrl(jj,2))),
* trim(sta_pro(ctrl(jj,2)))//'\'//trim(sta_nam(ctrl(jj,2)))
elseif ((ctrl(jj,1).ne.lab(ix,iy)).and.
* (ctrl(jj,2).eq.lab(ix,iy))) then
! print*,ctrl(jj,1),trim(sta_nam(ctrl(jj,1))),ctrl(jj,2)
! * ,trim(sta_nam(ctrl(jj,2))),t_no+1
t_no=t_no+1;loca(t_no)=ctrl(jj,1)
open (t_no,file=trim(filepat)//
* trim(sta_pro(ctrl(jj,1)))//'\'//
* trim(sta_nam(ctrl(jj,1)))//
* '.txt',status='old')
print*,t_no,sta_id((ctrl(jj,1))),
* trim(sta_pro(ctrl(jj,1)))//'\'//trim(sta_nam(ctrl(jj,1)))
end if
end do
open (t_no+1,file=trim(filepat)//trim(sta_pro(lab(ix,iy)))//
* '\'//trim(sta_nam(lab(ix,iy)))//'.txt',status='old')
print*,t_no+1,sta_id(lab(ix,iy)),
* trim(sta_pro(lab(ix,iy)))//'\'//trim(sta_nam(lab(ix,iy)))
loca(t_no+1)=lab(ix,iy)
! print *,ii,'open file';pause
allocate (fil(t_no+1),stat=er)
if (er.ne.0) then
print *,'allocate wrong 206';pause
end if
fil_no=0
do k=1,t_no+1,1
inyear=.true.
do while (inyear==.true.)
read(unit=k,fmt=*,iostat=iostat) id,year,month,day,
* airp,max_airp,min_airp,temp,max_temp,min_temp,
* humid,min_humid,prec,wind,max_wind,
* max_wind_dir,ext_wind,ext_wind_dir,sun
if ((year.eq.1974).and.(month.eq.12).and.(day.eq.31))
* then
fil_no=fil_no+1;fil(fil_no)=k;print*,'1:',id,
* k;inyear=.false.;exit
elseif ((year.gt.1984).or.(iostat<0)) then
close(k);print*,'2:',id,k;inyear=.false.;exit
end if
end do
end do
这段代码里面的代开文件和读取取文件的语句中,相同设备号对应的文件不一样。这是为什么?运行界面如图片所示。初来乍到,谢谢大家。
open(0,file=trim(filepat)//trim(est_sta_pro(ii))//
* '的'//trim(est_sta_nam(ii))//'.txt')
! print*,'end open',ii,'est_sta';pause
ix=ceiling((est_sta_x(ii)-xbeg-10.)/step)
iy=ceiling((est_sta_y(ii)-ybeg-10.)/step)
allocate (loca(k),stat=er)
if (er.ne.0) then
print *,'allocate wrong 208';pause
end if
t_no=0;print*,ix,iy,trim(est_sta_nam(ii)),
* lab(ix,iy),trim(sta_nam(lab(ix,iy)))
do jj=1,k,1
! if (jj.gt.68) then
! print*,jj,ctrl(jj,1),trim(sta_nam(ctrl(jj,1))),ctrl(jj,2),
! * sta_nam(ctrl(jj,2));pause
! end if
if ((ctrl(jj,1).eq.lab(ix,iy)).and.
* (ctrl(jj,2).ne.lab(ix,iy))) then
! print*,ctrl(jj,1),trim(sta_nam(ctrl(jj,1))),ctrl(jj,2)
! * ,trim(sta_nam(ctrl(jj,2))),t_no+1
t_no=t_no+1;loca(t_no)=ctrl(jj,2)
open (t_no,file=trim(filepat)//
* trim(sta_pro(ctrl(jj,2)))//'\'//
* trim(sta_nam(ctrl(jj,2)))//
* '.txt',status='old')
print*,t_no,sta_id((ctrl(jj,2))),
* trim(sta_pro(ctrl(jj,2)))//'\'//trim(sta_nam(ctrl(jj,2)))
elseif ((ctrl(jj,1).ne.lab(ix,iy)).and.
* (ctrl(jj,2).eq.lab(ix,iy))) then
! print*,ctrl(jj,1),trim(sta_nam(ctrl(jj,1))),ctrl(jj,2)
! * ,trim(sta_nam(ctrl(jj,2))),t_no+1
t_no=t_no+1;loca(t_no)=ctrl(jj,1)
open (t_no,file=trim(filepat)//
* trim(sta_pro(ctrl(jj,1)))//'\'//
* trim(sta_nam(ctrl(jj,1)))//
* '.txt',status='old')
print*,t_no,sta_id((ctrl(jj,1))),
* trim(sta_pro(ctrl(jj,1)))//'\'//trim(sta_nam(ctrl(jj,1)))
end if
end do
open (t_no+1,file=trim(filepat)//trim(sta_pro(lab(ix,iy)))//
* '\'//trim(sta_nam(lab(ix,iy)))//'.txt',status='old')
print*,t_no+1,sta_id(lab(ix,iy)),
* trim(sta_pro(lab(ix,iy)))//'\'//trim(sta_nam(lab(ix,iy)))
loca(t_no+1)=lab(ix,iy)
! print *,ii,'open file';pause
allocate (fil(t_no+1),stat=er)
if (er.ne.0) then
print *,'allocate wrong 206';pause
end if
fil_no=0
do k=1,t_no+1,1
inyear=.true.
do while (inyear==.true.)
read(unit=k,fmt=*,iostat=iostat) id,year,month,day,
* airp,max_airp,min_airp,temp,max_temp,min_temp,
* humid,min_humid,prec,wind,max_wind,
* max_wind_dir,ext_wind,ext_wind_dir,sun
if ((year.eq.1974).and.(month.eq.12).and.(day.eq.31))
* then
fil_no=fil_no+1;fil(fil_no)=k;print*,'1:',id,
* k;inyear=.false.;exit
elseif ((year.gt.1984).or.(iostat<0)) then
close(k);print*,'2:',id,k;inyear=.false.;exit
end if
end do
end do
这段代码里面的代开文件和读取取文件的语句中,相同设备号对应的文件不一样。这是为什么?运行界面如图片所示。初来乍到,谢谢大家。