对流云 发表于 2014-12-1 11:09:33

程序 .OR. 续行的问题

Program fengxiang
   Implicit None
   integer, parameter :: nDIR = 18                                                         
character(len=5) , parameter :: cDir(nDIR) = &
    (/'N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW','C','-99'/)
   integer:: hour08(18 ) = 0
   integer:: hour14(18 ) = 0
   integer:: hour20(18 ) = 0
   real:: total(18) =0
   integer::x(18)=0                                                      
   character(len=79):: filename="D:\各地风向资料\230.txt"                        
   integer, parameter :: fileid = 10                                                      
   logical alive
   integer i ,station,month,day, hour , k
    character(len=6) :: cDirRead                                                            
   real l,year
   
    inquire( file=filename, exist=alive)                                                   
   if ( .not.alive ) then
   write(*,*) TRIM(filename)," doesn't exist."
   else
   open(fileid,file=filename,status="old")                                                   
   open(unit=12,file='D:\各地风向资料\处理后数据\230_04.txt')
         
      Do                                                               
       read(fileid,*,iostat=k)station ,year ,month,day,hour,cDirRead                  
       if ( k /= 0 ) exit                                                                  
         if(month==1.or.month==3.or.month==5.or.month==7.or.month==8.or.month==10.&
         or.month==12))then
          l=558.0
      else if(month==4.or.month==6.or.month==9.or.month==11) then
         l=540.0
      else if(month==2) then
         l=29*2*3.0+28*4*3.0
      end if   
         
   if (month==4)then
         if ( hour == 8 ) then                                                                     
             Do k = 1 , nDIR                                                                     
            if ( cDir(k) == cDirRead ) exit                                                
               End Do
          hour08(k) = hour08(k) + 1                                                            
      
         else if(hour==14) then
            Do k = 1 , nDIR                                                                     
             if ( cDir(k) == cDirRead ) exit                                                   
               End Do
         hour14(k) = hour14(k) + 1
      
         else if(hour==20) then
            Do k = 1 , nDIR                                                                     
             if ( cDir(k) == cDirRead ) exit                                                   
               End Do
         hour20(k) = hour20(k) + 1
      end if
       end if   
   End Do
   
   Do i = 1 , nDIR
      x(i)=hour08(i)+hour14(i)+hour20(i)
      total(i)=(hour08(i)+hour14(i)+hour20(i))/l
      write(12,"(a3,3xf6.1,3xi3,3xf10.8)")Trim(cDir(i)),l ,x(i),total(i)
   End Do
   close(fileid)
    end if
stop
End

vvt 发表于 2014-12-1 19:21:23

本帖最后由 vvt 于 2014-12-1 19:23 编辑

第28,29行,续行不对,不能把 .OR. 拆开。而且后面多一个括号 )
改为
if(month==1.or.month==3.or.month==5.or.month==7.or.month==8.or.month==10&
         .or.month==12)then
实际上,对于这种情况,用 Selece Case 更合适。
27 到 35 行可改为

Select Case ( Month )
case ( 1 , 3 , 5 , 7 , 8 , 10 , 12 )
    L = 558.0
case ( 4 , 6 , 9 , 11 )
    L = 540.0
case ( 2 )
    L = 29*2*3.0 + 28*4*3.0
End Select
就可以了。



页: [1]
查看完整版本: 程序 .OR. 续行的问题