*
* $Id: gpfil.F,v 3.2 2003/12/17 11:32:47 pamela Exp $
*
* $Log: gpfil.F,v $
* Revision 3.2  2003/12/17 11:32:47  pamela
* CALO SIMULATION COMPLETED: geometry and special tracking parameters updated and simulation checked by a comparison with the Trieste's standalone Monte Carlo simulation
*
* Revision 3.1.1.1  2002/07/11 16:02:00  cafagna
* First GPAMELA release on CVS
*
*
*               14/04/2005  12:59     by Marialuigia Ambriola
*CMZ :  3.00/00 30/03/2001  14.16.15  by  Marialuigia Ambriola
*CMZ :  2.01/00 08/03/2000  18.33.09  by  Unknown
*CMZ :  2.00/00 03/03/2000  15.39.05  by  Francesco Cafagna
*CMZ :  1.02/00 22/10/99  17.53.59  by  Francesco Cafagna
*CMZ :  1.01/00 02/05/96  09.43.56  by  Francesco Cafagna
*CMZ :  1.00/02 21/02/96  10.12.34  by  Francesco Cafagna
*-- Author :    Francesco Cafagna   30/11/95
      SUBROUTINE GPFIL
************************************************************************
*                                                                      *
*            To open FFREAD and HBOOK files
*
* Called by: GPAMELA,GXINT
*                                                                      *
* Author: Francesco Cafagna, 30/11/95 15.53.48                         *
*                                                                      *
************************************************************************
#include "gppntp.inc"
#include "gpunit.inc"
*
#include "gcflag.inc"
#include "gcbank.inc"
*ML: 3/5/03
#include "gpkey.inc"
#include "gpseed.inc"
#include "gcunit.inc"
*END ML
      LOGICAL EXISTS
      INTEGER IJUNK
      CHARACTER*160 FNAM
      CHARACTER*4 SUF
*
* User action
*
      CALL GPUFIL
*
*             Open a HBOOK4 direct access file
*
      CALL HROPEN(LUHBK,'GPAMELA',CHHBK,'N',NBSIZE,ISTAT)
*
*             Open the magnetic field map
*
C fc +SELF,IF=UNIX.
C fc       OPEN(UNIT=LUFMAP,FILE=CHFMAP,FORM='UNFORMATTED',
C fc      +     STATUS='OLD')
C fc +SELF,IF=-UNIX.
C fc       OPEN(UNIT=LUFMAP,FILE=CHFMAP,FORM='UNFORMATTED',SHARED,
C fc      +     STATUS='OLD',READONLY)
C fc +SELF.
*ML:
CML17/04/2003      CALL HROPEN(LUFMAP,'FIELD',CHFMAP,' ',NBSIZE,ISTAT)
      CALL HROPEN(LUFMAP,'FIELD',CHFMAP,' ',1024,ISTAT)
*END ML.
*
*ML: (to simulate the TR from TRD)
      OPEN(UNIT=LUTR,FILE=CHTR,FORM='UNFORMATTED',STATUS='UNKNOWN')
*END ML.
*Ml 27/04/04:
      IF(HSEED.EQ.1.OR.HSEED.EQ.2) THEN
         INQUIRE(FILE=CHFSF,EXIST=EXISTS)      
         OPEN(UNIT=LUFSF,FILE=CHFSF,FORM='UNFORMATTED',STATUS='OLD')
      ELSE
         WRITE(CHMAIL,10000) 
         CALL GMAIL(1,0)
      ENDIF
      IF(DCLSFI) THEN
         FNAM=CHLSF
      ELSE
         SUF='SEED'
         IJUNK=INDEX(CHHBK,'HIS')
         FNAM = CHHBK(1:IJUNK-1)//SUF         
      ENDIF
C      OPEN(UNIT=LULSF,FILE=CHLSF,FORM='UNFORMATTED',STATUS='UNKNOWN')
      OPEN(UNIT=LULSF,FILE=FNAM,FORM='UNFORMATTED',STATUS='UNKNOWN')
*end ml. 27/04/04
10000 FORMAT(' GPFIL WARNING: wrong value for data card HFSF. ',
     + 'Input file for random seed not       opened. ',
     +  'The program will ignore this data card.')
      END
