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 
76  !-----------------------------------------------------------------------------
77 contains
78  !-----------------------------------------------------------------------------
80  subroutine io_setup( &
81  MODELNAME, &
82  call_from_launcher, &
83  fname_in )
84  implicit none
85 
86  namelist / param_io / &
87  h_source, &
88  h_institute, &
93 
94  character(len=H_MID), intent(in) :: MODELNAME
95  logical, intent(in) :: call_from_launcher
96  character(len=H_LONG), intent(in), optional :: fname_in
97 
98  character(len=H_LONG) :: fname
99  integer :: ierr
100  !---------------------------------------------------------------------------
101 
102  if ( call_from_launcher ) then
103  if ( present(fname_in) ) then
104  fname = fname_in
105  else
106  write(*,*) ' xxx Not imported name of config file! STOP.'
107  stop 1
108  endif
109  else
110  fname = io_arg_getfname( is_master=.true. )
111  endif
112 
113  !--- Open config file till end
114  io_fid_conf = io_cnf_open( fname, & ! [IN]
115  is_master=.true. ) ! [IN]
116 
117  h_modelname = trim(modelname)
118  h_libname = 'SCALE Library ver. '//trim(libversion)
119  h_source = trim(modelname)
120 
121  !--- read PARAM
122  rewind(io_fid_conf)
123  read(io_fid_conf,nml=param_io,iostat=ierr)
124  if ( ierr > 0 ) then !--- fatal error
125  write(*,*) ' xxx Not appropriate names in namelist PARAM_IO . Check!'
126  stop 1
127  endif
128 
129  return
130  end subroutine io_setup
131 
132  !-----------------------------------------------------------------------------
134  subroutine io_log_setup( &
135  myrank, &
136  is_master )
137  implicit none
138 
139  integer, intent(in) :: myrank
140  logical, intent(in) :: is_master
141 
142  character(len=H_LONG) :: fname
143  integer :: ierr
144  !---------------------------------------------------------------------------
145 
146  if ( .NOT. io_log_suppress ) then
147  if ( is_master ) then ! master node
148  io_l = .true.
149  else
151  endif
152  endif
153 
154  if ( io_log_nml_suppress ) then
155  io_lnml = .false.
156  else
157  io_lnml = io_l
158  endif
159 
160  if ( io_l ) then
161 
162  !--- Open logfile
163  if ( io_log_basename == io_stdout ) then
165  else
167  call io_make_idstr(fname,trim(io_log_basename),'pe',myrank)
168  open( unit = io_fid_log, &
169  file = trim(fname), &
170  form = 'formatted', &
171  iostat = ierr )
172  if ( ierr /= 0 ) then
173  write(*,*) 'xxx File open error! :', trim(fname)
174  stop 1
175  endif
176  endif
177 
178  write(io_fid_log,*) ''
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,*) ' =++++++=x######+++++++++++++; '
187  write(io_fid_log,*) ' .++++++X####XX####++++++++++++ '
188  write(io_fid_log,*) ' =+xxx=, ++++ +++++=##+ .###++++++++++- '
189  write(io_fid_log,*) ' ,xxxxxxxxxx- +++++.+++++=## .##++++++++++ '
190  write(io_fid_log,*) ' xxxxxxxxxxxxx -+++x#;+++++#+ ##+++++++++. '
191  write(io_fid_log,*) ' xxxxxxxx##xxxx, ++++# +++++XX #+++++++++- '
192  write(io_fid_log,*) ' xxxxxxx####+xx+x ++++#.++++++# #+++++++++ '
193  write(io_fid_log,*) ' +xxxxxX#X #Xx#= =+++#x=++++=#. x=++++++++ '
194  write(io_fid_log,*) ' xxxxxx#, x### .++++#,+++++#= x++++++++ '
195  write(io_fid_log,*) ' xxxxxx#. ++++# +++++x# #++++++++ '
196  write(io_fid_log,*) ' xxxxxx+ ++++#-+++++=# #++++++++ '
197  write(io_fid_log,*) ',xxxxxX -+++XX-+++++#, +++++++++ '
198  write(io_fid_log,*) '=xxxxxX .++++#.+++++#x -++++++++ '
199  write(io_fid_log,*) '+xxxxx= ++++#.++++++# ++++++++# '
200  write(io_fid_log,*) 'xxxxxx; ++++#+=++++=# ++++++++# '
201  write(io_fid_log,*) 'xxxxxxx ,+++x#,+++++#- ;++++++++- '
202  write(io_fid_log,*) '#xxxxxx +++=# +++++xX ++++++++# '
203  write(io_fid_log,*) 'xxxxxxxx ++++#-+++++=# +++++++++X '
204  write(io_fid_log,*) '-+xxxxxx+ ++++X#-++++=#. -++; =++++++++# '
205  write(io_fid_log,*) ' #xxxxxxxx. .+++++# +++++#x =++++- +++++++++XX '
206  write(io_fid_log,*) ' #xxxxxxxxxx=--=++++++#.++++++# ++++++ -+++++++++x# '
207  write(io_fid_log,*) ' #+xxxxxxxxxx+++++++#x=++++=# ++++++;=+++++++++++x# '
208  write(io_fid_log,*) ' =#+xxxxxxxx+++++++##,+++++#= =++++++++++++++++++##. '
209  write(io_fid_log,*) ' X#xxxxxxxx++++++## +++++x# ;x++++++++++++++++##. '
210  write(io_fid_log,*) ' x##+xxxx+++++x## +++++=# ##++++++++++++x##X '
211  write(io_fid_log,*) ' ,###Xx+++x###x -++++=#, .####x+++++X####. '
212  write(io_fid_log,*) ' -########+ -#####x .X#########+. '
213  write(io_fid_log,*) ' .,. ...... .,. '
214  write(io_fid_log,*) ' '
215  write(io_fid_log,*) ' .X####### +###- =###+ ###x x######## '
216  write(io_fid_log,*) ' .######### ######X ####### #### .#########x '
217  write(io_fid_log,*) ' ####+++++= X#######. -#######x .###; ####x+++++. '
218  write(io_fid_log,*) ' ### ###= #### #### x### #### -###. '
219  write(io_fid_log,*) ' .### #### ###+ X### ###X =###. #### '
220  write(io_fid_log,*) ' ###- ;###, .###+ -### #### x##########+ '
221  write(io_fid_log,*) ' +####x #### #### #### #### ###########. '
222  write(io_fid_log,*) ' x######. =### ###, .###- ###+ x###-------- '
223  write(io_fid_log,*) ' =##### X### -### #### ,### #### '
224  write(io_fid_log,*) ' .###=x###; .###+ ###X ###X ####. '
225  write(io_fid_log,*) ' ###########; ###########+ ########### ########### ,##########. '
226  write(io_fid_log,*) '-########### ,##########, #########X ########## +######### '
227  write(io_fid_log,*) ',,,,,,,,,,. ,,,,,,,,, .,,,,,,,. .,,,,,,,, ,,,,,,,, '
228  write(io_fid_log,*) ' '
229  write(io_fid_log,*) ' SCALE : Scalable Computing by Advanced Library and Environment '
230  write(io_fid_log,*) ''
231  write(io_fid_log,*) trim(h_libname)
232  write(io_fid_log,*) trim(h_modelname)
233  write(io_fid_log,*) ''
234  write(io_fid_log,*) '++++++ Module[STDIO] / Categ[IO] / Origin[SCALElib]'
235  write(io_fid_log,*) ''
236  write(io_fid_log,*) '*** Open config file, FID = ', io_fid_conf
237  write(io_fid_log,*) '*** Open log file, FID = ', io_fid_log
238  write(io_fid_log,*) '*** basename of log file = ', trim(io_log_basename)
239  write(io_fid_log,*) '*** detailed log output = ', io_lnml
240 
241  else
242  if( is_master ) write(*,*) '*** Log report is suppressed.'
243  endif
244 
245  return
246  end subroutine io_log_setup
247 
248  !-----------------------------------------------------------------------------
251  function io_get_available_fid() result(fid)
252  implicit none
253 
254  integer :: fid
255  logical :: i_opened
256  !---------------------------------------------------------------------------
257 
258  do fid = io_minfid, io_maxfid
259  inquire(fid,opened=i_opened)
260  if ( .NOT. i_opened ) return
261  enddo
262 
263  end function io_get_available_fid
264 
265  !-----------------------------------------------------------------------------
267  subroutine io_make_idstr( &
268  outstr, &
269  instr, &
270  ext, &
271  rank, &
272  isrgn )
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  logical, intent(in), optional :: isrgn
280 
281  character(len=H_SHORT) :: srank
282  !---------------------------------------------------------------------------
283 
284  write(srank,'(I6.6)') rank
285 
286  if ( present(isrgn) ) then
287  if(isrgn) write(srank,'(I8.8)') rank-1
288  endif
289 
290  outstr = trim(instr)//'.'//trim(ext)//trim(srank)
291 
292  return
293  end subroutine io_make_idstr
294 
295  !-----------------------------------------------------------------------------
298  function io_arg_getfname( is_master ) result(fname)
299  implicit none
300 
301  logical, intent(in) :: is_master
302  character(len=H_LONG) :: fname
303  !---------------------------------------------------------------------------
304 
305  if ( command_argument_count() < 1 ) then
306  if(is_master) write(*,*) 'xxx Program needs config file from argument! STOP.'
307  stop 1
308  else
309  call get_command_argument(1,fname)
310  endif
311 
312  end function io_arg_getfname
313 
314  !-----------------------------------------------------------------------------
317  function io_cnf_open( &
318  fname, &
319  is_master ) &
320  result(fid)
321  implicit none
322 
323  character(len=*), intent(in) :: fname
324  logical, intent(in) :: is_master
325  integer :: fid
326 
327  integer :: ierr
328  !---------------------------------------------------------------------------
329 
330  fid = io_get_available_fid()
331 
332  open( unit = fid, &
333  file = trim(fname), &
334  form = 'formatted', &
335  status = 'old', &
336  iostat = ierr )
337 
338  if ( ierr /= 0 ) then
339  if(is_master) write(*,*) 'xxx Failed to open config file! STOP.'
340  if(is_master) write(*,*) 'xxx filename : ', trim(fname)
341  stop 1
342  endif
343 
344  end function io_cnf_open
345 
346 end module scale_stdio
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
subroutine, public io_make_idstr(outstr, instr, ext, rank, isrgn)
generate process specific filename
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_setup(MODELNAME, call_from_launcher, fname_in)
Setup.
Definition: scale_stdio.F90:84
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