subroutine rd_corr
! 17/02/2003 : ADD CONVECT FLOW
use modresultats
use modgrille
use modvsv
use modnetcdf
cptnul=0
nbFvect=0
nbMasked=0
nbAvgLessThan=0
nbAvgNull=0
nbAvgLessThanANDMaxCorrLessThan=0
nbInstable=0
nbIsTooSmall=0
nbInstableHart=0
nbInstableHartBis=0
nbHartPrefered=0
nbHartCorrTooLow=0
nbCptError=0
nbDiffCIV2CIV1=0
!goto 1001
! ADD THE NULL VECTORS
nb_vectors2=nbnodes+cpt2
allocate(VD2(nb_vectors2,6))
VD2=0.
VD2(1:nbnodes,1:2)=grille(:,1:2)
VD2(1:nbnodes,3:5)=grille(:,4:6)
VD2(1:nbnodes,6)=grille(:,3)
!grille(:,3)=0
!VD2(1:nbnodes,3)=grille0(:,3)
!VD2(1:nbnodes,1:4)=grille0(1:nbnodes,1:4)
!do i=1,nbnodes
! if(VD2(i,3)>0) then
! print*,"U>0 ",VD2(i,1:3)
! endif
! print*,VD2(i,3:4),grille(i,4:6),pixcmx,dt2
!enddo
!!!!!!!!!! PROBLEM OF SIGN +- U,V + convect flow
!goto 444
print*,'PIXCM',pixcmx,pixcmy,pixcmx_out,pixcmy_out
pixcmx_out=pixcmx
pixcmy_out=pixcmy
VD2(1:nbnodes,1)=(VD2(1:nbnodes,1)+VD2(1:nbnodes,3)/2.)/pixcmx_out
VD2(1:nbnodes,2)=(VD2(1:nbnodes,2)+VD2(1:nbnodes,4)/2.)/pixcmy_out
VD2(1:nbnodes,3)=VD2(1:nbnodes,3)/pixcmx/dt2
VD2(1:nbnodes,4)=VD2(1:nbnodes,4)/pixcmy/dt2
!ADD NULL VECTORS (MASKED)
444 continue
do i=1,cpt2
VD2(nbnodes+i,1)=grilletmp2(i,1)/pixcmx_out
VD2(nbnodes+i,2)=grilletmp2(i,2)/pixcmy_out
VD2(nbnodes+i,3:6)=(/0.,0.,1.,0./)
enddo
nbnodes=nbnodes+cpt2
!do i=1,nbnodes
! print*,VD2(i,3:4)
!enddo
!goto 1001
do i=1,nbnodes
! print*,VD2(i,3:4)
!grille(i,3)=1.
!goto 1002
!if((abs(grille(i,4))>30.).or.(abs(grille(i,5))>30.)) grille(i,3)=2
if((grille(i,3)==0.).or.(grille(i,3)==4).or.(grille(i,3)==4)) grille(i,6)=0.
if (grille(i,3)==4.) grille(i,6)=1.
if( (floor(grille(i,3))==3).or.((hole).and.((grille(i,3)==-2.).or.(grille(i,3)==4.)))) then !.or.(grille(i,3)==0.)) then
cptnul=cptnul+1
! grille(i,6)=0.
endif
if(grille(i,3)==0) nbMasked=nbMasked+1
if(grille(i,3)==3) nbAvgLessThan=nbAvgLessThan+1
if(grille(i,3)==3.1) nbAvgNull=nbAvgNull+1
if(grille(i,3)==3.2) nbAvgLessThanANDMAxCorrLessThan=nbAvgLessThanANDMaxCorrLessThan+1
if(grille(i,3)==3.3) nbInstable=nbInstable+1
if(grille(i,3)==-2.)then
! Print*,'Rarely this vectors are false'
ppp=ppp+1
grille(i,6)=0.
nbIsTooSmall=nbIsTooSmall+1
endif
if(grille(i,3)==9) nbInstableHart=nbInstableHart+1
if(grille(i,3)==9.1) nbInstableHartBis=nbInstableHartBis+1
if(grille(i,3)==4) nbDiffCIV2CIV1=nbDiffCIV2CIV1+1
if(grille(i,3)==4.1) nbCptError=nbCptError+1
!if(grille(i,3)==2.) cptnul=cptnul+1 !grille(i,6)=0.75
!if(grille(i,3)==-2.) then
! grille(i,6)=0.75
! print*,'putain ca chie ',i
!endif
1002 continue
enddo
1001 continue
!print*,mg,ng,cptnul,666
if(nbMasked/=0) print*,"nbMasked = ",nbMasked
if(nbAvgLessThan/=0) print*,"nbAvgLessThan = ",nbAvgLessThan
if(nbAvgNull/=0) print*,"nbAvgNull = ",nbAvgNull
if(nbAvgLessThanANDMaxCorrLessThan/=0) print*,"nbAvgLessThanANDMaxCorrLessThan = ",nbAvgLessThanANDMaxCorrLessThan
if(nbInstable/=0) print*,"nbInstable = ",nbInstable
if(nbIsTooSmall/=0) print*,"nbIsTooSmall = ",nbIsTooSmall
if(nbInstableHart/=0) print*,"nbInstableHart = ",nbInstableHart
if(nbInstableHartBis/=0) print*,"nbInstableHartBis = ",nbInstableHartBis
if(nbCptError/=0) print*,"nbCptError = ",nbCptError
if(nbDiffCIV2CIV1/=0) print*,"nbDiffCIV2CIV1 = ",nbDiffCIV2CIV1
return
end
! GRILLE(I,3) EXPLANATIONS :
!
! THIS VALUE IS USED TO KNOW THE LOCAL STATE OF THE NODE, AND KNOW HOW IT HAS SUPPORTED THE DIFFERENT
! CONDITIONNAL ESTIMATIONS
!
! GRILLE2 (INITIAL CONDITIONS)
! IF MASKED (HARD) THEN GRILLE(I,3)==0.
! IF MASKED (SOFT) THEN GRILLE(I,3)==3.
! IF NON MASKED THEN GRILLE(I,3)== -1.
! XCORR IF ARMS(LOCAL A||B BOX)==0. THEN GRILLE(I,3)== 3.
! FIND PEAK
! IF INSTABLE (MAXIMUM IS OUTSIDE !!!!) THEN GRILLE(I,3)== 3.
! IF CLOSE TO THE BORDER THEN GRILLE(I,3)== -2.
! IF EVERYTHING IS FINE THEN GRILLE(I,3)== 1.
! IF THE DIFFERENCE BETWEEN THE ESTIMATOR AND THE RESULT IS MORE THAN 1 PIXEL THEN GRILLE(I,3)== 4.
! RD_CORR
! IF HOLE THEN REMOVE VECTORS FLAGED WITH -2 || 4.
! ALWAYS REMOVE VECTORS FLAGED WITH 3.