
! $Id: abort_gcm.F 5101 2024-07-23 06:22:55Z abarral $

c
c
      SUBROUTINE abort_gcm(modname, message, ierr)
     
#ifdef CPP_IOIPSL
      USE IOIPSL
#else
! if not using IOIPSL, we still need to use (a local version of) getin_dump
      USE ioipsl_getincom
#endif
 ! ug Pour les sorties XIOS
      USE wxios

#include "iniprint.h"
 
C
C Stops the simulation cleanly, closing files and printing various
C comments
C
C  Input: modname = name of calling program
C         message = stuff to print
C         ierr    = severity of situation ( = 0 normal )

      character(len=*), intent(in):: modname
      integer, intent(in):: ierr
      character(len=*), intent(in):: message

      write(lunout,*) 'in abort_gcm'

      IF (using_xios) THEN
!Fermeture propre de XIOS
        CALL wxios_close()
      ENDIF

#ifdef CPP_IOIPSL
      CALL histclo
      CALL restclo
#endif
      CALL getin_dump
c     CALL histclo(2)
c     CALL histclo(3)
c     CALL histclo(4)
c     CALL histclo(5)
      write(lunout,*) 'Stopping in ', modname
      write(lunout,*) 'Reason = ',message
      if (ierr == 0) then
        write(lunout,*) 'Everything is cool'
        stop
      else
        write(lunout,*) 'Houston, we have a problem, ierr = ', ierr
        stop 1
      endif
      END
