user_output_common.F90 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. !#################################################################
  2. !
  3. ! User_Output_Common - common settings and tools for user output
  4. !
  5. !### macro's #####################################################
  6. !
  7. #define TRACEBACK write (gol,'("in ",a," (",a,", line",i5,")")') rname, __FILE__, __LINE__; call goErr
  8. #define IF_NOTOK_RETURN(action) if (status/=0) then; TRACEBACK; action; return; end if
  9. #define IF_ERROR_RETURN(action) if (status> 0) then; TRACEBACK; action; return; end if
  10. !
  11. #include "tm5.inc"
  12. !
  13. !#################################################################
  14. module User_Output_Common
  15. use GO, only : gol, goErr, goPr
  16. implicit none
  17. ! --- in/out -----------------------------------
  18. private
  19. public :: User_Output_Common_Init
  20. public :: User_Output_Common_Done
  21. public :: User_Output_Check_Overwrite
  22. ! --- const ------------------------------------
  23. ! module name:
  24. character(len=*), parameter :: mname = 'User_Output_Common'
  25. ! --- local ------------------------------------
  26. ! allow existing files to be overwritten ?
  27. logical :: output_overwrite
  28. contains
  29. ! ====================================================================
  30. subroutine User_Output_Common_Init( status )
  31. use GO, only : TrcFile, Init, Done, ReadRc
  32. use global_data, only : rcfile
  33. ! --- in/out --------------------------------
  34. integer, intent(out) :: status
  35. ! --- const -------------------------------
  36. character(len=*), parameter :: rname = mname//'/User_Output_Common_Init'
  37. ! --- local ---------------------------------
  38. type(TrcFile) :: rcF
  39. ! --- begin ---------------------------------
  40. ! open settings:
  41. call Init( rcF, rcfile, status )
  42. IF_NOTOK_RETURN(status=1)
  43. ! read flag that allows overwriting existing files:
  44. call ReadRc( rcF, 'output.overwrite', output_overwrite, status )
  45. IF_NOTOK_RETURN(status=1)
  46. ! close rcfile:
  47. call Done( rcF, status )
  48. IF_NOTOK_RETURN(status=1)
  49. ! ok
  50. status = 0
  51. end subroutine User_Output_Common_Init
  52. ! ***
  53. subroutine User_Output_Common_Done( status )
  54. ! --- in/out --------------------------------
  55. integer, intent(out) :: status
  56. ! --- const -------------------------------
  57. character(len=*), parameter :: rname = mname//'/User_Output_Common_Done'
  58. ! --- begin ---------------------------------
  59. ! ok
  60. status = 0
  61. end subroutine User_Output_Common_Done
  62. ! ***
  63. ! check if file with provided filename already exists;
  64. ! if it exists, and output_overwrite flag is .false.,
  65. ! then return with error status 1;
  66. ! otherwise error status 0
  67. subroutine User_Output_Check_Overwrite( filename, status )
  68. ! --- in/out --------------------------------
  69. character(len=*), intent(in) :: filename
  70. integer, intent(out) :: status
  71. ! --- const -------------------------------
  72. character(len=*), parameter :: rname = mname//'/User_Output_Check_Overwrite'
  73. ! --- local ---------------------------------
  74. logical :: exist
  75. ! --- begin ---------------------------------
  76. ! overwriteing existing files not allowed ?
  77. if ( .not. output_overwrite ) then
  78. ! check presence:
  79. inquire( file=trim(filename), exist=exist )
  80. ! and ?
  81. if ( exist ) then
  82. ! info ...
  83. write (gol,'("output file already present :")'); call goErr
  84. write (gol,'(" ",a)') trim(filename); call goErr
  85. write (gol,'("remove the file, or set in the rcfile the flag")'); call goErr
  86. write (gol,'("`output.overwrite` to `T` to overwrite existing files")'); call goErr
  87. TRACEBACK; status=1; return
  88. end if
  89. end if
  90. ! ok
  91. status = 0
  92. end subroutine User_Output_Check_Overwrite
  93. end module User_Output_Common