
! Copyright (C) 2002 - Observatoire de Paris/Meudon
!                      Universite Paris 7
!                      CNRS (France)
!                      Contact : Jacques.Lebourlot@obspm.fr
!
! This program is free software; you can redistribute it and/or
! modify it under the terms of the GNU General Public License version 2
! as published by the Free Software Foundation.
!
! This program 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 this program; if not, write to the Free Software
! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

! JLB - 24 May 2008

!%%%%%%%%%%%%%%%
PROGRAM prep_pfl
!%%%%%%%%%%%%%%%

   USE PXDR_FLAGS
   USE PXDR_CONSTANTES
   USE PXDR_CHEM_DATA
   USE PXDR_PROFIL
   USE PREP_VAR
   USE PREP_LECTUR
   USE PREP_ABONDA
   USE PREP_COLDEN
   USE PREP_EMISSI
   USE PREP_CHOFRO
   USE PREP_AUTRE

   IMPLICIT NONE

   INTEGER            :: ii
   INTEGER            :: ipoint

   CHARACTER (LEN=50) :: fichi
   CHARACTER (LEN=50) :: fichout

!--------+---------+---------+---------+---------+---------+---------+-*-------+

   PRINT *, "***********************************"
   PRINT *, "*                                 *"
   PRINT *, "*   PREPARE PROFILE FILE          *"
   PRINT *, "*                                 *"
   PRINT *, "***********************************"

   !========================================================
   ! Choose the input file (.bin file)
   !========================================================

   PRINT *
   PRINT *, 'Enter name of "bin" file'
   READ (*,'(a50)') fichi
   fichi = TRIM(ADJUSTL(fichi))
   ipoint = INDEX(fichi,'.',back=.true.)
   IF (ipoint > 1) THEN
      modele = fichi(1:ipoint-1)
      PRINT *, modele
   ENDIF
   out_dir = TRIM(out_dir)//TRIM(modele)//"/"
   fichier = TRIM(out_dir)//TRIM(fichi)

   !========================================================
   ! READ INPUT DATAFILE
   !========================================================

   CALL PLECTUR

   !========================================================
   ! Create *.pfl file
   !========================================================

   fichout = TRIM(ADJUSTL(modele))//".pfl"
   fichier = TRIM(out_dir)//fichout
   PRINT *,'Output written in: ', TRIM(ADJUSTL(fichier))
   OPEN (25, file = fichier, status = 'unknown')
   WRITE (25,'(i8,1x,"1")') npo+1
   DO ii = 0, npo
      WRITE (25,*) tau(ii)*tautav, tgaz(ii), densh(ii), gaspressure(ii)
   ENDDO
   CLOSE (25)

END PROGRAM prep_pfl
