subroutine lec_det(output,det_casdi,ndet)
use mod_script
implicit none
character(135) :: aa
character(*) :: output
integer :: ifil,pos,i,det_casdi(norb,ndet),j,nbt,it1,ip1,nelac,norb
integer :: ndet,nel,ninac
common/info/nelac,norb,nel,ninac
character sgn
logical :: yw=.false.

call open_chose_number(ifil,trim(output),'old','formatted')
i=0
do
   read(ifil,'(a)') aa
   if(index(aa,'VECTEUR PROPRE NUMERO')/=0) exit
enddo
do
   read(ifil,'(a)',end=4) aa
   pos=index(aa,'0=>')
   if(pos==0) cycle
   pos=pos-2
   i=i+1
   if(yw)print'(a)','DET CASDI lu dans output  '//trim(aa)
   det_casdi(:,i)=0
   do j=1,norb
      if(j<=nel/2) det_casdi(j,i)=2
   enddo
   !write(6,'(a,i6,3x,40i3)') 'DET_CASDI_REF',i,DET_CASDI(:,i)
   if(pos<=5) goto 8
! lecture trous
   nbt=0
   do
      read(aa(pos-5:pos-1),'(i3,a)',err=5) it1,sgn
      !print*,'it1,sgn',it1,sgn
      if(it1==0) goto 5
      nbt=nbt+1
      if(sgn=='+') then
         if(det_casdi(it1,i)==2) det_casdi(it1,i)=-1
         if(det_casdi(it1,i)==1) det_casdi(it1,i)=0
      endif
      if(sgn=='-') then
         if(det_casdi(it1,i)==2) det_casdi(it1,i)=1
         if(det_casdi(it1,i)==-1) det_casdi(it1,i)=0
      endif
      pos=pos-5
      if(pos<=5) goto 5
   enddo
   5 continue

   !lecture parts
   if(nbt<5) then
      pos=index(aa,'0=>')-2
      do
         read(aa(pos+5:pos+9),'(i3,a)',err=6) ip1,sgn
         !print*,'ip1,sgn',ip1,sgn
         if(ip1==0) goto 6
         if(sgn=='+') then
            if(det_casdi(ip1,i)==0) det_casdi(ip1,i)=1
            if(det_casdi(ip1,i)==-1) det_casdi(ip1,i)=2
         endif
         if(sgn=='-') then
            if(det_casdi(ip1,i)==0) det_casdi(ip1,i)=-1
            if(det_casdi(ip1,i)==1) det_casdi(ip1,i)=2
         endif
         pos=pos+5
         !write(6,'(a,i6,3x,40i3)') 'DET_CASDI',i,DET_CASDI(:,i)
    
      enddo
      6 continue
   else
      read(2,'(a)') aa
      if(yw)print*,trim(aa)
      pos=6
      do j=1,nbt
         read(aa(pos:pos+4),'(i3,a)') ip1,sgn
         !print*,'ip1,sgn',ip1,sgn
         if(sgn=='+') then
            if(det_casdi(ip1,i)==0) det_casdi(ip1,i)=1
            if(det_casdi(ip1,i)==-1) det_casdi(ip1,i)=2
         endif
         if(sgn=='-') then
            if(det_casdi(ip1,i)==0) det_casdi(ip1,i)=-1
            if(det_casdi(ip1,i)==1) det_casdi(ip1,i)=2
         endif
         pos=pos+5
      enddo
   endif 
8 continue
  if(yw)write(6,'(a,i6,3x,40i3)') 'DET_CASDI',i,DET_CASDI(:,i)!;stop

enddo
4 continue

end
