!------------------------------------------------------------------------------ Subroutine NSpell_and_Leng (X1, N, M1, Imax1) ! So dot han (Imax1) va do dai cac dot (M1(Imax1)) ! Input: Array X(N) with values of 0, 1, or -99 ! Output: Array M(Imax) with values of number of spell Integer :: N, i, k !Integer :: X(NYear*NWeek), M(NYear*NWeek), Imax Integer :: X(N), M(N), IMAX Real :: X1(N), M1(N), IMAX1 X(:) = X1(:) M(:) = 0; IMAX=0; I = 0; M1(:) = 0; IMAX1=0 DO I = I + 1 ! Loop until end of series data IF (I>N) EXIT IF (X(I)==1) THEN ! Event occur at first time of this spell K = 0 ! Number of days event occur continuosly DO IF (X(I)==0.OR.X(I)==-99.OR.I==N) THEN ! End of this spell IF (I==N.AND.X(I)==1) K=K+1 ! For the last spell IF (K/=0) M(K)=M(K)+1 ! Increase for this spell IMAX=IMAX+1 ! Increase number of spells ! PRINT*, K, M(K), IMAX EXIT END IF I = I + 1 K = K + 1 ! How many days of this spell ENDDO ELSE CYCLE END IF IF (I>=N) EXIT ENDDO !!! I=IMAX !??? I=N if (IMAX>0) then DO IF (M(I)/=0) EXIT ! Determine exactly how many spells I=I-1 ENDDO IMAX = I; if (IMAX < N) then ; M(IMAX+1:N) = -99; else; M(:)=-99; IMAX=-99; endif ! Gan lai cho so thuc: M1(:) = M(:); IMAX1 = IMAX else M1(:) = -99; IMAX1 = -99 ! M1(:) = 0; IMAX1 = 0 endif !print*,"imax=",imax,"M=",M(1:imax) End Subroutine NSpell_and_Leng !--------------------------------End of this file--------------------------