SCALE-RM
scale_stdio.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
13  !-----------------------------------------------------------------------------
14  !
15  !++ used modules
16  !
17  use gtool_file_h, only: &
18  file_hshort, &
19  file_hmid, &
21  !-----------------------------------------------------------------------------
22  implicit none
23  private
24  !-----------------------------------------------------------------------------
25  !
26  !++ included parameters
27  !
28 #include "scalelib.h"
29  !-----------------------------------------------------------------------------
30  !
31  !++ Public procedure
32  !
33  public :: io_setup
34  public :: io_log_setup
35  public :: io_get_available_fid
36  public :: io_make_idstr
37  public :: io_arg_getfname
38  public :: io_cnf_open
39 
40  !-----------------------------------------------------------------------------
41  !
42  !++ Public parameters & variables
43  !
44  integer, public, parameter :: h_short = file_hshort
45  integer, public, parameter :: h_mid = file_hmid
46  integer, public, parameter :: h_long = file_hlong
47 
48  character(len=H_MID), public :: h_modelname
49  character(len=H_MID), public :: h_libname
50  character(len=H_MID), public :: h_source
51  character(len=H_MID), public :: h_institute = 'AICS/RIKEN'
52 
53  character(len=6), public, parameter :: io_stdout = "STDOUT"
54  integer, public, parameter :: io_fid_stdout = 6
55  integer, public :: io_fid_conf = 7
56  integer, public :: io_fid_log = 8
57 
58  character(len=H_LONG), public :: io_log_basename = 'LOG'
59  logical, public :: io_l = .false.
60  logical, public :: io_lnml = .false.
61  logical, public :: io_log_suppress = .false.
62  logical, public :: io_log_allnode = .false.
63  logical, public :: io_log_nml_suppress = .false.
64 
65  !-----------------------------------------------------------------------------
66  !
67  !++ Private procedure
68  !
69  !-----------------------------------------------------------------------------
70  !
71  !++ Private parameters & variables
72  !
73  integer, private, parameter :: io_minfid = 10
74  integer, private, parameter :: io_maxfid = 99
75  integer, private, parameter :: io_rgnoffset = 0
76 
77  !-----------------------------------------------------------------------------
78 contains
79  !-----------------------------------------------------------------------------
81  subroutine io_setup( &
82  MODELNAME, &
83  call_from_launcher, &
84  fname_in )
85  implicit none
86 
87  namelist / param_io / &
88  h_source, &
89  h_institute, &
94 
95  character(len=H_MID), intent(in) :: MODELNAME
96  logical, intent(in) :: call_from_launcher
97  character(len=H_LONG), intent(in), optional :: fname_in
98 
99  character(len=H_LONG) :: fname
100  integer :: ierr
101  !---------------------------------------------------------------------------
102 
103  if ( call_from_launcher ) then
104  if ( present(fname_in) ) then
105  fname = fname_in
106  else
107  write(*,*) ' xxx Not imported name of config file! STOP.'
108  stop 1
109  endif
110  else
111  fname = io_arg_getfname( is_master=.true. )
112  endif
113 
114  !--- Open config file till end
115  io_fid_conf = io_cnf_open( fname, & ! [IN]
116  is_master=.true. ) ! [IN]
117 
118  h_modelname = trim(modelname)
119  h_libname = 'SCALE Library ver. '//trim(libversion)
120  h_source = trim(modelname)
121 
122  !--- read PARAM
123  rewind(io_fid_conf)
124  read(io_fid_conf,nml=param_io,iostat=ierr)
125  if ( ierr > 0 ) then !--- fatal error
126  write(*,*) ' xxx Not appropriate names in namelist PARAM_IO . Check!'
127  stop 1
128  endif
129 
130  return
131  end subroutine io_setup
132 
133  !-----------------------------------------------------------------------------
135  subroutine io_log_setup( &
136  myrank, &
137  is_master )
138  implicit none
139 
140  integer, intent(in) :: myrank
141  logical, intent(in) :: is_master
142 
143  character(len=H_LONG) :: fname
144  integer :: ierr
145  !---------------------------------------------------------------------------
146 
147  if ( .NOT. io_log_suppress ) then
148  if ( is_master ) then ! master node
149  io_l = .true.
150  else
152  endif
153  endif
154 
155  if ( io_log_nml_suppress ) then
156  io_lnml = .false.
157  else
158  io_lnml = io_l
159  endif
160 
161  if ( io_l ) then
162 
163  !--- Open logfile
164  if ( io_log_basename == io_stdout ) then
166  else
168  call io_make_idstr(fname,trim(io_log_basename),'pe',myrank)
169  open( unit = io_fid_log, &
170  file = trim(fname), &
171  form = 'formatted', &
172  iostat = ierr )
173  if ( ierr /= 0 ) then
174  write(*,*) 'xxx File open error! :', trim(fname)
175  stop 1
176  endif
177  endif
178 
179  write(io_fid_log,*) ''
180  write(io_fid_log,*) ' -+++++++++; '
181  write(io_fid_log,*) ' ++++++++++++++= '
182  write(io_fid_log,*) ' ++++++++++++++++++- '
183  write(io_fid_log,*) ' +++++++++++++++++++++ '
184  write(io_fid_log,*) ' .+++++++++++++++++++++++ '
185  write(io_fid_log,*) ' +++++++++++++++++++++++++ '
186  write(io_fid_log,*) ' +++++++++++++++++++++++++++ '
187  write(io_fid_log,*) ' =++++++=x######+++++++++++++; '
188  write(io_fid_log,*) ' .++++++X####XX####++++++++++++ '
189  write(io_fid_log,*) ' =+xxx=, ++++ +++++=##+ .###++++++++++- '
190  write(io_fid_log,*) ' ,xxxxxxxxxx- +++++.+++++=## .##++++++++++ '
191  write(io_fid_log,*) ' xxxxxxxxxxxxx -+++x#;+++++#+ ##+++++++++. '
192  write(io_fid_log,*) ' xxxxxxxx##xxxx, ++++# +++++XX #+++++++++- '
193  write(io_fid_log,*) ' xxxxxxx####+xx+x ++++#.++++++# #+++++++++ '
194  write(io_fid_log,*) ' +xxxxxX#X #Xx#= =+++#x=++++=#. x=++++++++ '
195  write(io_fid_log,*) ' xxxxxx#, x### .++++#,+++++#= x++++++++ '
196  write(io_fid_log,*) ' xxxxxx#. ++++# +++++x# #++++++++ '
197  write(io_fid_log,*) ' xxxxxx+ ++++#-+++++=# #++++++++ '
198  write(io_fid_log,*) ',xxxxxX -+++XX-+++++#, +++++++++ '
199  write(io_fid_log,*) '=xxxxxX .++++#.+++++#x -++++++++ '
200  write(io_fid_log,*) '+xxxxx= ++++#.++++++# ++++++++# '
201  write(io_fid_log,*) 'xxxxxx; ++++#+=++++=# ++++++++# '
202  write(io_fid_log,*) 'xxxxxxx ,+++x#,+++++#- ;++++++++- '
203  write(io_fid_log,*) '#xxxxxx +++=# +++++xX ++++++++# '
204  write(io_fid_log,*) 'xxxxxxxx ++++#-+++++=# +++++++++X '
205  write(io_fid_log,*) '-+xxxxxx+ ++++X#-++++=#. -++; =++++++++# '
206  write(io_fid_log,*) ' #xxxxxxxx. .+++++# +++++#x =++++- +++++++++XX '
207  write(io_fid_log,*) ' #xxxxxxxxxx=--=++++++#.++++++# ++++++ -+++++++++x# '
208  write(io_fid_log,*) ' #+xxxxxxxxxx+++++++#x=++++=# ++++++;=+++++++++++x# '
209  write(io_fid_log,*) ' =#+xxxxxxxx+++++++##,+++++#= =++++++++++++++++++##. '
210  write(io_fid_log,*) ' X#xxxxxxxx++++++## +++++x# ;x++++++++++++++++##. '
211  write(io_fid_log,*) ' x##+xxxx+++++x## +++++=# ##++++++++++++x##X '
212  write(io_fid_log,*) ' ,###Xx+++x###x -++++=#, .####x+++++X####. '
213  write(io_fid_log,*) ' -########+ -#####x .X#########+. '
214  write(io_fid_log,*) ' .,. ...... .,. '
215  write(io_fid_log,*) ' '
216  write(io_fid_log,*) ' .X####### +###- =###+ ###x x######## '
217  write(io_fid_log,*) ' .######### ######X ####### #### .#########x '
218  write(io_fid_log,*) ' ####+++++= X#######. -#######x .###; ####x+++++. '
219  write(io_fid_log,*) ' ### ###= #### #### x### #### -###. '
220  write(io_fid_log,*) ' .### #### ###+ X### ###X =###. #### '
221  write(io_fid_log,*) ' ###- ;###, .###+ -### #### x##########+ '
222  write(io_fid_log,*) ' +####x #### #### #### #### ###########. '
223  write(io_fid_log,*) ' x######. =### ###, .###- ###+ x###-------- '
224  write(io_fid_log,*) ' =##### X### -### #### ,### #### '
225  write(io_fid_log,*) ' .###=x###; .###+ ###X ###X ####. '
226  write(io_fid_log,*) ' ###########; ###########+ ########### ########### ,##########. '
227  write(io_fid_log,*) '-########### ,##########, #########X ########## +######### '
228  write(io_fid_log,*) ',,,,,,,,,,. ,,,,,,,,, .,,,,,,,. .,,,,,,,, ,,,,,,,, '
229  write(io_fid_log,*) ' '
230  write(io_fid_log,*) ' SCALE : Scalable Computing by Advanced Library and Environment '
231  write(io_fid_log,*) ''
232  write(io_fid_log,*) trim(h_libname)
233  write(io_fid_log,*) trim(h_modelname)
234  write(io_fid_log,*) ''
235  write(io_fid_log,*) '++++++ Module[STDIO] / Categ[IO] / Origin[SCALElib]'
236  write(io_fid_log,*) ''
237  write(io_fid_log,*) '*** Open config file, FID = ', io_fid_conf
238  write(io_fid_log,*) '*** Open log file, FID = ', io_fid_log
239  write(io_fid_log,*) '*** basename of log file = ', trim(io_log_basename)
240  write(io_fid_log,*) '*** detailed log output = ', io_lnml
241 
242  else
243  if( is_master ) write(*,*) '*** Log report is suppressed.'
244  endif
245 
246  return
247  end subroutine io_log_setup
248 
249  !-----------------------------------------------------------------------------
252  function io_get_available_fid() result(fid)
253  implicit none
254 
255  integer :: fid
256  logical :: i_opened
257  !---------------------------------------------------------------------------
258 
259  do fid = io_minfid, io_maxfid
260  inquire(fid,opened=i_opened)
261  if ( .NOT. i_opened ) return
262  enddo
263 
264  end function io_get_available_fid
265 
266  !-----------------------------------------------------------------------------
268  subroutine io_make_idstr( &
269  outstr, &
270  instr, &
271  ext, &
272  rank )
273  implicit none
274 
275  character(len=*), intent(out) :: outstr
276  character(len=*), intent(in) :: instr
277  character(len=*), intent(in) :: ext
278  integer, intent(in) :: rank
279 
280  character(len=H_SHORT) :: srank
281  !---------------------------------------------------------------------------
282 
283  write(srank,'(I6.6)') rank + io_rgnoffset
284 
285  outstr = trim(instr)//'.'//trim(ext)//trim(srank)
286 
287  return
288  end subroutine io_make_idstr
289 
290  !-----------------------------------------------------------------------------
293  function io_arg_getfname( is_master ) result(fname)
294  implicit none
295 
296  logical, intent(in) :: is_master
297  character(len=H_LONG) :: fname
298  !---------------------------------------------------------------------------
299 
300  if ( command_argument_count() < 1 ) then
301  if(is_master) write(*,*) 'xxx Program needs config file from argument! STOP.'
302  stop 1
303  else
304  call get_command_argument(1,fname)
305  endif
306 
307  end function io_arg_getfname
308 
309  !-----------------------------------------------------------------------------
312  function io_cnf_open( &
313  fname, &
314  is_master ) &
315  result(fid)
316  implicit none
317 
318  character(len=*), intent(in) :: fname
319  logical, intent(in) :: is_master
320  integer :: fid
321 
322  integer :: ierr
323  !---------------------------------------------------------------------------
324 
325  fid = io_get_available_fid()
326 
327  open( unit = fid, &
328  file = trim(fname), &
329  form = 'formatted', &
330  status = 'old', &
331  iostat = ierr )
332 
333  if ( ierr /= 0 ) then
334  if(is_master) write(*,*) 'xxx Failed to open config file! STOP.'
335  if(is_master) write(*,*) 'xxx filename : ', trim(fname)
336  stop 1
337  endif
338 
339  end function io_cnf_open
340 
341 end module scale_stdio
342 !-------------------------------------------------------------------------------
logical, public io_l
output log or not? (this process)
Definition: scale_stdio.F90:59
integer, parameter, public file_hlong
integer, parameter, public h_long
Character length (short=256)
Definition: scale_stdio.F90:46
module STDIO
Definition: scale_stdio.F90:12
integer, parameter, public io_fid_stdout
Definition: scale_stdio.F90:54
character(len=h_long) function, public io_arg_getfname(is_master)
get config filename from argument
character(len=h_mid), public h_modelname
name and version of the model
Definition: scale_stdio.F90:48
integer, parameter, public file_hmid
subroutine, public io_log_setup(myrank, is_master)
Setup LOG.
character(len=6), parameter, public io_stdout
Definition: scale_stdio.F90:53
logical, public io_log_suppress
suppress all of log output?
Definition: scale_stdio.F90:61
character(len=h_mid), public h_source
for file header
Definition: scale_stdio.F90:50
integer function, public io_get_available_fid()
search & get available file ID
subroutine, public io_make_idstr(outstr, instr, ext, rank)
generate process specific filename
subroutine, public io_setup(MODELNAME, call_from_launcher, fname_in)
Setup.
Definition: scale_stdio.F90:85
logical, public io_log_allnode
output log for each node?
Definition: scale_stdio.F90:62
integer, parameter, public h_short
Character length (short=16)
Definition: scale_stdio.F90:44
character(len=h_mid), public h_institute
for file header
Definition: scale_stdio.F90:51
logical, public io_lnml
output log or not? (for namelist, this process)
Definition: scale_stdio.F90:60
module FILE I/O HEADER
integer, parameter, public file_hshort
integer, public io_fid_conf
Config file ID.
Definition: scale_stdio.F90:55
character(len=h_mid), public h_libname
name and version of the library
Definition: scale_stdio.F90:49
integer, parameter, public h_mid
Character length (short=64)
Definition: scale_stdio.F90:45
integer, public io_fid_log
Log file ID.
Definition: scale_stdio.F90:56
character(len=h_long), public io_log_basename
basename of logfile
Definition: scale_stdio.F90:58
logical, public io_log_nml_suppress
suppress all of log output?
Definition: scale_stdio.F90:63
integer function, public io_cnf_open(fname, is_master)
open config file