回 帖 发 新 帖 刷新版面

主题:文件读取出错,文件号

    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
这段代码里面的代开文件和读取取文件的语句中,相同设备号对应的文件不一样。这是为什么?运行界面如图片所示。初来乍到,谢谢大家。

回复列表 (共4个回复)

沙发

如果是关了再打开就没问题.

P.S. 楼主,你用f90/95代码风格+fixed格式,比较眼花.

板凳

那样应该没问题,但是我后面的read部分是为了确定在文件中的位置,后面还有需要读取的数据。设备号对应的文件出错了,是什么问题,应该怎么写修改。大家帮帮忙啊,我弄了好几天都是这个错误。

3 楼

请大家帮帮忙啊,我小菜级别,弄了好几天这个错误了。

4 楼

已经弄好了,是读取文件的时候出现了错误,系统给出了一个错误值。还是谢谢!

我来回复

您尚未登录,请登录后再回复。点此登录或注册