
module cortes

!
!     Copyright 2003-2008 Pedro Bernaola-Galvan, Pedro Carpena & Jose L. Oliver
!     This program is distributed under the terms of the GNU General Public License (GPL)

!     This file is part of IsoFinder

!     IsoFinder is free software: you can redistribute it and/or modify
!     it under the terms of the GNU General Public License as published by
!     the Free Software Foundation, either version 3 of the License, or
!     (at your option) any later version.

!     IsoFinder is distributed in the hope that it will be useful,
!     but WITHOUT ANY WARRANTY; without even the implied warranty of
!     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
!     GNU General Public License for more details.

!     You should have received a copy of the GNU General Public License
!     along with IsoFinder.  If not, see <http://www.gnu.org/licenses/>.

!***************************************************************************

!     References:

!     J L Oliver, P Carpena, M Hackenberg, P Bernaola-Galván  (2004)  
!     IsoFinder : computational prediction of isochores in genome sequences
!     Nucleic Acids Research  32:  W287-W292   

!     IsoFinder project: http://isofinder.sourceforge.net/
!     IsoFinder web server: http://bioinfo2.ugr.es/IsoF/isofinder.html

!     Contacts:

!     Pedro Bernaola(1), Pedro Carpena(1) & Jose L. Oliver(2)
!     (1) Dpto. de Física Aplicada II, Universidad de Málaga, Spain
!         rick@ctima.uma.es, pcarpena@ctima.uma.es
!     (2) Dpto. de Genética, Universidad de Granada, Spain
!         oliver@ugr.es

!***************************************************************************

!A linked list to store all cuts
type corte
  integer*4 posic
  integer*4 frec(0:1)
  integer*1 intact
  type(corte), pointer :: next,prev
end type


CONTAINS


!***************************************************

subroutine init_list(first,last,&
           nwords,f_words)
  type(corte), pointer::first,last
  integer*4 nwords
  integer*4, dimension(:):: f_words

  allocate(first)
  allocate(last)

  first%posic=0
  first%frec=0
  first%next=>last
  first%intact=0
  nullify(first%prev)

  last%posic=nwords
  last%frec=f_words
  last%intact=0
  nullify(last%next)
  last%prev=>first
end subroutine init_list

!***********************************************

subroutine insert(p,posic,frec)
  type(corte), pointer :: p,newp
  integer*4               posic,frec(:)


  allocate(newp)

  newp%posic=posic
  newp%frec=frec
  newp%next=>p%next
  newp%prev=>p
  newp%intact=0

  p%next%prev=>newp
  p%next=>newp


END SUBROUTINE insert

!**************************************************


SUBROUTINE restore_list(first)
  type(corte),pointer :: first,p

  p=>first
  do while (associated(p%next))
    p%intact=0
    p=>p%next
  enddo
end subroutine restore_list

!***********************************************
end MODULE cortes