ROMS
Loading...
Searching...
No Matches
stdout_mod.F
Go to the documentation of this file.
1#include "cppdefs.h"
2 MODULE stdout_mod
3!
4!git $Id$
5!================================================== Hernan G. Arango ===
6! Copyright (c) 2002-2025 The ROMS Group !
7! Licensed under a MIT/X style license !
8! See License_ROMS.md !
9!=======================================================================
10! !
11! It sets the ROMS standard output unit to write verbose execution !
12! information. Notice that the default standard out unit in Fortran !
13! is 6. !
14! !
15! In some applications like coupling or disjointed mpi-communications,!
16! it is advantageous to write standard output to a specific filename !
17! instead of the default Fortran standard output unit 6. If that is !
18! the case, it opens such formatted file for writing. !
19! !
20!=======================================================================
21!
22 USE mod_parallel
23 USE mod_iounits
24 USE mod_scalars
25!
26 USE strings_mod, ONLY : founderror
27!
28 implicit none
29
30 PUBLIC :: stdout_unit
31!
32!-----------------------------------------------------------------------
33! Module parameters.
34!-----------------------------------------------------------------------
35!
36! The following switch tells if the standard output unit/file has
37! been specified. It must be set up only once to avoid errors and
38! is usually called at the beginning of ROMS_initialize. However,
39! it is required earlier during ESM coupling configurations.
40!
41 logical, save :: set_stdoutunit = .true.
42!
43!-----------------------------------------------------------------------
44 CONTAINS
45!-----------------------------------------------------------------------
46!
47 FUNCTION stdout_unit (MyMaster) RESULT (StdOutUnit)
48!
49!***********************************************************************
50! !
51! This function determines ROMS standard output unit to write its !
52! running verbose information. !
53! !
54! On Input: !
55! !
56! MyMaster Switch indicating Master process (logical) !
57! !
58! On Output: !
59! !
60! StdOutUnit Assigned standard output unit (integer; default=6) !
61! !
62!***********************************************************************
63!
64! Imported variable declarations.
65!
66 logical, intent(in) :: mymaster
67!
68! Local variable declararions
69!
70 integer :: io_err
71 integer :: stdoutunit
72!
73 character (len=10 ) :: stdout_file
74 character (len=256) :: io_errmsg
75 character (len=*), parameter :: myfile = &
76 & __FILE__//", stdout_unit"
77!
78 sourcefile=myfile
79!
80!-----------------------------------------------------------------------
81! Set ROMS standard input unit. If requested, set and open standard
82! output file for writing.
83!-----------------------------------------------------------------------
84
85#ifdef ROMS_STDOUT
86!
87! Set the Fortran standard output unit (default unit 6) to direct the
88! ROMS run information to a specific filename. It is advantageous in
89! coupling or disjointed applications that need ROMS information
90! separated from other components.
91!
92# if defined DISTRIBUTE && defined DISJOINTED
93 stdoutunit=60+forkcolor
94 WRITE (stdout_file,'(a,i2.2,a)') 'log', forkcolor+1, '.roms'
95# else
96 stdoutunit=60
97 stdout_file='log.roms'
98# endif
99#else
100!
101! Set default standard output unit in Fortran.
102!
103 stdoutunit=6
104#endif
105
106#ifdef ROMS_STDOUT
107!
108!-----------------------------------------------------------------------
109! Open ROMS standard output file.
110!-----------------------------------------------------------------------
111!
112 io_err=0
113 IF (lappend) THEN
114 OPEN (stdoutunit, file=trim(stdout_file), &
115 & form='formatted', status='old', position='append', &
116 & action='write', iostat=io_err, iomsg=io_errmsg)
117 ELSE
118 OPEN (stdoutunit, file=trim(stdout_file), &
119 & form='formatted', status='replace', &
120 & iostat=io_err, iomsg=io_errmsg)
121 END IF
122 IF (io_err.ne.0) THEN
123 IF (mymaster) WRITE (stdoutunit,10) trim(stdout_file), &
124 & trim(io_errmsg)
125 exit_flag=5
126 10 FORMAT (/,' STDOUT_UNIT - Cannot open standard output file: ', &
127 & a,/,15x,'ERROR: ',a)
128 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
129 END IF
130#endif
131!
132 END FUNCTION stdout_unit
133!
134 END MODULE stdout_mod
character(len=256) sourcefile
integer mymaster
logical lappend
integer exit_flag
integer noerror
integer function, public stdout_unit(mymaster)
Definition stdout_mod.F:48
logical, save set_stdoutunit
Definition stdout_mod.F:41
logical function, public founderror(flag, noerr, line, routine)
Definition strings.F:52