! WRF-Chem code used in Fastj adapted for MONARCH

!WRF was developed at the National Center for Atmospheric Research (NCAR)
!which is operated by the University Corporation for Atmospheric Research
!(UCAR). NCAR and UCAR make no proprietary claims, either statutory or
!otherwise, to this version and release of WRF and consider WRF to be in
!the public domain for use by any person or entity for any purpose without
!any fee or charge. UCAR requests that any WRF user include this notice on
!any partial or full copies of WRF. WRF is provided on an "AS IS" basis and
!any warranties, either express or implied, including but not limited to
!implied warranties of non-infringement, originality, merchantability and
!fitness for a particular purpose, are disclaimed. In no event shall UCAR be
!liable for any damages, whatsoever, whether direct, indirect, consequential
!or special, that arise out of or in connection with the access, use or
!performance of WRF, including infringement actions.

!#**********************************************************************************  
! This computer software was prepared by Battelle Memorial Institute, hereinafter
! the Contractor, under Contract No. DE-AC05-76RL0 1830 with the Department of 
! Energy (DOE). NEITHER THE GOVERNMENT NOR THE CONTRACTOR MAKES ANY WARRANTY,
! EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE.
!
! miscellaneous debuging routines for CBMZ and MOSAIC
!**********************************************************************************  
	module module_peg_util


	contains


!-----------------------------------------------------------------------
	subroutine peg_debugmsg( lun, level, str )
!
! when lun >  0, writes "str" to unit "lun"
! when lun <= 0, passes "str" on to wrf_debug
!
	implicit none
! subr arguments
	integer, intent(in) :: lun, level
	character(len=*), intent(in) :: str
! local variables
	integer n

	n = max( 1, len_trim(str) )
	if (lun .gt. 0) then
	    write(lun,'(a)') str(1:n)
	else
!	    call wrf_debug( level, str(1:n) )
	end if
	return
	end subroutine peg_debugmsg


!-----------------------------------------------------------------------
	subroutine peg_message( lun, str )
!
! when lun >  0, writes "str" to unit "lun"
! when lun <= 0, passes "str" on to wrf_message
!
	implicit none
! subr arguments
	integer, intent(in) :: lun
	character(len=*), intent(in) :: str
! local variables
	integer n

	n = max( 1, len_trim(str) )
	if (lun .gt. 0) then
	    write(lun,'(a)') str(1:n)
	else
!	    call wrf_message( str(1:n) )
            WRITE(0,*) str(1:n)
	end if
	return
	end subroutine peg_message


!-----------------------------------------------------------------------
	subroutine peg_error_fatal( lun, str )
!
! when lun >  0, writes "str" to unit "lun"
! then (always)  passes "str" on to wrf_error_fatal
!
	implicit none
! subr arguments
	integer, intent(in) :: lun
	character(len=*), intent(in) :: str
! local variables
	integer n

	n = max( 1, len_trim(str) )
	if (lun .gt. 0) write(lun,'(a)') str(1:n)
!	call wrf_error_fatal( str(1:n) )
        WRITE(0,*) 'ERROR FATAL:',str(1:n)
	return
	end subroutine peg_error_fatal


!-----------------------------------------------------------------------
	end module module_peg_util
