          SUBROUTINE H_UPDATE_DATASIZE(NDATA)
C
C----------------------------------------------------------------------
C
C.IDENTIFICATION: Subroutine H_UPDATE_DATASIZE              
C.LIBRARY:        GENERAL
C.AUTHOR:         L.Chiappetti - IFCTR Milano
C.VERSIONS:       0.0 - xx Aug 92 - First version in panterxas
C                 0.1 -  7 Sep 92 - made as a subroutine
C                 1.0 - 30 Oct 92 - unchanged                 
C.PURPOSE:        update miniheader if data size has changed  
C.METHOD:         write the value NDATA in miniheader
C                 and also in NAXIS2 header keyword
C                 error code ir returned thru VOSCOMMON               
C.SYNTAX:         CALL H_UPDATE_DATASIZE(ndata)
C
C.PARAMETERS:     INTEGER  ndata  the correct number of data records (in)
C.RESTRICTIONS:   this routine will flush the mini header to disk, and also
C                 the main header (which in the meanwhile had been over-
C                 written on disk by the new data), calling H_ADD_KEYWORD   
C                 with the flush flag set
C.NOTES:          the first data record is zoff+1, the second zoff+2, etc.
C                 the first header record follows the last data record
C                 zoff is computed internally 
C.FILES:          none
C.REFERENCES:     H_FLUSH_MINIH and H_ADD_KEYWORD in same library
C
C----------------------------------------------------------------------
C
C     include  'implicit_none.inc'
      INTEGER  NDATA,ZOFF
      include  'voscommon.inc'
      include  'hcommon.inc'
C
C     make sure the header is up to date : the previous keywords were
C     overwritten by the data, therefore reset the mini-header, and set
C     NAXIS2 to the number of events, then flush to disk to ensure update
C
       VOSCOMMON_ERROR=0
       MINIH_ALL=HCOMMON_MINIH(HCOMMON_CURFILE)
C      derive offset for data area here
       IF(MINIH_RECLEN.GT.28)THEN
         ZOFF=1
       ELSE
         ZOFF=28/MINIH_RECLEN
         IF(MOD(28,MINIH_RECLEN).NE.0)ZOFF=ZOFF+1
       ENDIF
      MINIH_DATASIZE=NDATA 
      CALL H_FLUSH_MINIH(ZOFF)
      IF (VOSCOMMON_ERROR.NE.0.OR.VOSCOMMON_SYSTEMERROR.NE.0)RETURN
      CALL H_MODIFY_JKEYWORD('NAXIS2'  ,NDATA ,1,1)  
C     IF (VOSCOMMON_ERROR.NE.0.OR.VOSCOMMON_SYSTEMERROR.NE.0)RETURN
      RETURN
      END 
