SCALE-RM
gtool_history.f90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
13 !-------------------------------------------------------------------------------
14 ! Warning: This file was generated from gtool_history.f90.erb.
15 ! Do not edit this file.
16 !-------------------------------------------------------------------------------
18  !-----------------------------------------------------------------------------
19  !
20  !++ Used modules
21  !
22  use dc_log, only: &
23  log, &
24 #if defined(__pgi) || defined(__es2)
25  log_fid, &
26 #endif
27  log_lmsg
28  use dc_types, only: &
29  sp, &
30  dp
31  use gtool_file_h, only: &
32  file_hlong, &
33  file_hshort, &
34  file_hmid
35  !-----------------------------------------------------------------------------
36  implicit none
37  private
38  !-----------------------------------------------------------------------------
39  !
40  !++ Public procedures
41  !
42  public :: historyinit
43  public :: historyaddvariable
44  public :: historyputaxis
45  public :: historyputassociatedcoordinates
46  public :: historysettattr
47  public :: historyquery
48  public :: historyput
49  public :: historywrite
50  public :: historywriteall
51  public :: historyget
52  public :: historyoutputlist
53  public :: historyfinalize
54 
55  interface historyputaxis
56  module procedure historyputaxissp
57  module procedure historyputaxisdp
58  end interface historyputaxis
59 
60  interface historyputassociatedcoordinates
69  end interface historyputassociatedcoordinates
70 
71  interface historyput
72  module procedure historyput0dnamesp
73  module procedure historyput0didsp
74  module procedure historyput0dnamedp
75  module procedure historyput0diddp
76  module procedure historyput1dnamesp
77  module procedure historyput1didsp
78  module procedure historyput1dnamedp
79  module procedure historyput1diddp
80  module procedure historyput2dnamesp
81  module procedure historyput2didsp
82  module procedure historyput2dnamedp
83  module procedure historyput2diddp
84  module procedure historyput3dnamesp
85  module procedure historyput3didsp
86  module procedure historyput3dnamedp
87  module procedure historyput3diddp
88  end interface historyput
89 
90  interface historyget
91  module procedure historyget1dsp
92  module procedure historyget1ddp
93  module procedure historyget2dsp
94  module procedure historyget2ddp
95  module procedure historyget3dsp
96  module procedure historyget3ddp
97  end interface historyget
98 
99  type axis
100  character(len=File_HSHORT) :: name
101  character(len=File_HLONG) :: desc
102  character(len=File_HSHORT) :: units
103  character(len=File_HSHORT) :: dim
104  integer :: type
105  real(DP), pointer :: var(:)
106  logical :: down
107  end type axis
108  type assoc
109  character(len=File_HSHORT) :: name
110  character(len=File_HLONG) :: desc
111  character(len=File_HSHORT) :: units
112  character(len=File_HSHORT) :: dims(4)
113  integer :: ndims
114  integer :: type
115  real(DP), pointer :: var(:)
116  end type assoc
117 
118  !-----------------------------------------------------------------------------
119  !
120  !++ included parameters
121  !
122  !-----------------------------------------------------------------------------
123  !
124  !++ Public parameters & variables
125  !
126  !-----------------------------------------------------------------------------
127  !
128  !++ Private procedures
129  !
130  !-----------------------------------------------------------------------------
131  !
132  !++ Private parameters & variables
133  !
134  character(len=File_HMID) :: history_title
135  character(len=File_HMID) :: history_source
136  character(len=File_HMID) :: history_institution
137  character(len=File_HMID) :: history_time_units
138  character(len=File_HMID) :: history_time_since
139  real(DP) :: history_dtsec
140  real(DP) :: history_startdaysec
141 
142  logical :: history_output_step0 = .false.
143  real(DP) :: history_output_start = 0.0_dp
144  logical :: history_error_putmiss = .false.
145 
146  integer, parameter :: history_req_limit = 1000
147  character(len=File_HLONG) :: history_req_basename(history_req_limit)
148  character(len=File_HSHORT) :: history_req_item (history_req_limit)
149  real(DP) :: history_req_tintsec (history_req_limit)
150  integer :: history_req_tintstep(history_req_limit)
151  logical :: history_req_tavg (history_req_limit)
152  logical :: history_req_zinterp (history_req_limit)
153  integer :: history_req_dtype (history_req_limit)
154 
155  integer :: history_req_nmax = 0
156  integer :: history_id_count = 0
157  character(len=File_HSHORT), allocatable :: history_item (:)
158  integer, allocatable :: history_fid (:)
159  integer, allocatable :: history_vid (:)
160  real(DP), allocatable :: history_tintsec (:)
161  integer, allocatable :: history_tintstep(:)
162  logical, allocatable :: history_tavg (:)
163  logical, allocatable :: history_zinterp (:)
164  real(DP), allocatable :: history_varsum (:,:)
165  integer, allocatable :: history_size (:)
166  real(DP), allocatable :: history_tstart (:)
167  integer, allocatable :: history_tstrstep(:)
168  integer, allocatable :: history_tlststep(:)
169  real(DP), allocatable :: history_tsumsec (:)
170 
171 
172  real(DP), parameter :: eps = 1.d-10
173  integer :: history_master
174  integer :: history_myrank
175  integer, allocatable :: history_rankidx(:)
176 
177  integer, parameter :: history_axis_limit = 100
178  integer :: history_axis_count = 0;
179  type(axis) :: history_axis(history_axis_limit)
180 
181  integer, parameter :: history_assoc_limit = 20
182  integer :: history_assoc_count = 0;
183  type(assoc) :: history_assoc(history_assoc_limit)
184 
185  character(LEN=LOG_LMSG), private :: message
186 
187 contains
188  !-----------------------------------------------------------------------------
189  subroutine historyinit( &
190  title, source, institution, & ! (in)
191  array_size, & ! (in)
192  master, myrank, rankidx, & ! (in)
193  time_start, time_interval, & ! (in)
194  time_units, time_since, & ! (in)
195  default_basename, & ! (in) optional
196  default_tinterval, default_tunit, default_taverage, & ! (in) optional
197  default_zinterp, & ! (in) optional
198  default_datatype, & ! (in) optional
199  namelist_filename, namelist_fid & ! (in) optional
200  )
201  use dc_calendar, only: &
202  calendarymdhms2sec
203  use gtool_file_h, only: &
204  file_real4, &
205  file_real8, &
207  implicit none
208 
209  character(len=*), intent(in) :: title
210  character(len=*), intent(in) :: source
211  character(len=*), intent(in) :: institution
212  integer, intent(in) :: array_size
213  integer, intent(in) :: master
214  integer, intent(in) :: myrank
215  integer, intent(in) :: rankidx(:)
216  real(DP), intent(in) :: time_start
217  real(DP), intent(in) :: time_interval
218  character(len=*), intent(in), optional :: time_units
219  character(len=*), intent(in), optional :: time_since
220  character(len=*), intent(in), optional :: default_basename
221  real(DP), intent(in), optional :: default_tinterval
222  character(len=*), intent(in), optional :: default_tunit
223  logical, intent(in), optional :: default_taverage
224  logical, intent(in), optional :: default_zinterp
225  character(len=*), intent(in), optional :: default_datatype
226  character(len=*), intent(in), optional :: namelist_filename
227  integer , intent(in), optional :: namelist_fid
228 
229  character(len=File_HLONG) :: HISTORY_DEFAULT_BASENAME = ''
230  real(DP) :: HISTORY_DEFAULT_TINTERVAL = 1.0_dp
231  character(len=File_HSHORT) :: HISTORY_DEFAULT_TUNIT = 'sec'
232  logical :: HISTORY_DEFAULT_TAVERAGE = .false.
233  logical :: HISTORY_DEFAULT_ZINTERP = .false.
234  character(len=File_HSHORT) :: HISTORY_DEFAULT_DATATYPE = 'REAL4'
235 
236  namelist / param_history / &
237  history_title, &
238  history_source, &
239  history_institution, &
240  history_time_units, &
241  history_default_basename, &
242  history_default_tinterval, &
243  history_default_tunit, &
244  history_default_taverage, &
245  history_default_zinterp, &
246  history_default_datatype, &
247  history_output_step0, &
248  history_output_start, &
249  history_error_putmiss
250 
251  character(len=File_HLONG) :: BASENAME
252  character(len=File_HSHORT) :: ITEM
253  real(DP) :: TINTERVAL
254  character(len=File_HSHORT) :: TUNIT
255  logical :: TAVERAGE
256  logical :: ZINTERP
257  character(len=File_HSHORT) :: DATATYPE
258 
259  namelist / histitem / &
260  basename, &
261  item, &
262  tinterval, &
263  tunit, &
264  taverage, &
265  zinterp, &
266  datatype
267 
268  integer :: fid_conf
269 
270  integer :: ierr
271  integer :: n, ni
272  integer :: memsize
273  intrinsic size
274  !---------------------------------------------------------------------------
275 
276  call log('I', '')
277  call log('I', '+++ Module[HISTORY]/Categ[IO]')
278 
279  !--- read namelist
280  history_title = title
281  history_source = source
282  history_institution = institution
283  history_startdaysec = time_start
284  history_dtsec = time_interval
285  if ( present(time_units) ) then
286  history_time_units = time_units
287  else
288  history_time_units = 'seconds'
289  endif
290  if ( present(time_since) ) then
291  history_time_since = time_since
292  else
293  history_time_since = ''
294  endif
295  if ( present(default_basename) ) then
296  history_default_basename = default_basename
297  endif
298  if ( present(default_tinterval) ) then
299  history_default_tinterval = default_tinterval
300  if ( present(default_tunit) ) then
301  history_default_tunit = default_tunit
302  endif
303  endif
304  if ( present(default_taverage) ) then
305  history_default_taverage = default_taverage
306  endif
307  if ( present(default_zinterp) ) then
308  history_default_zinterp = default_zinterp
309  endif
310  if ( present(default_datatype) ) then
311  history_default_datatype = default_datatype
312  endif
313 
314  if ( present(namelist_fid) ) then
315  fid_conf = namelist_fid
316  rewind(fid_conf)
317  else if ( present(namelist_filename) ) then
318  if ( namelist_filename /= '' ) then
319  open( fid_conf, file = trim(namelist_filename), &
320  form = 'formatted', status = 'old', iostat = ierr)
321  else
322  call log('I', '*** Brank namelist file was specified. Default used. ***')
323  fid_conf = -1
324  endif
325  else
326  call log('I', '*** No namelist was specified. Default used. ***')
327  fid_conf = -1
328  endif
329 
330  if ( fid_conf > 0 ) then
331  read(fid_conf, nml=param_history, iostat=ierr)
332 
333  if( ierr < 0 ) then !--- missing
334  call log('I', '*** Not found namelist. Default used.')
335  elseif( ierr > 0 ) then !--- fatal error
336  call log('E', 'xxx Not appropriate names in namelist PARAM_HISTORY. Check!')
337  endif
338 #if defined(__PGI) || defined(__ES2)
339  write(log_fid,nml=param_history)
340 #else
341  write(message,nml=param_history)
342  call log('I', message)
343 #endif
344  endif
345 
346  ! listup history request
347  history_req_nmax = 0
348  if ( fid_conf > 0 ) then
349  rewind( fid_conf )
350  do n = 1, history_req_limit
351  basename = history_default_basename
352  read(fid_conf, nml=histitem, iostat=ierr)
353  if( ierr /= 0 ) exit
354  if ( basename /= "" ) history_req_nmax = history_req_nmax + 1
355  enddo
356  endif
357 
358  if ( history_req_nmax > history_req_limit ) then
359  write(message,*) '*** request of history file is exceed! n >', history_req_limit
360  call log('I', message)
361  elseif( history_req_nmax == 0 ) then
362  call log('I', '*** No history file specified.')
363  return
364  endif
365 
366  allocate( history_item(history_req_nmax) ); history_item(:) = ''
367  allocate( history_fid(history_req_nmax) )
368  allocate( history_vid(history_req_nmax) )
369  allocate( history_tintsec(history_req_nmax) )
370  allocate( history_tintstep(history_req_nmax) )
371  allocate( history_tavg(history_req_nmax) )
372  allocate( history_zinterp(history_req_nmax) )
373 
374  allocate( history_varsum(array_size,history_req_nmax) )
375  allocate( history_size(history_req_nmax) )
376  allocate( history_tstart(history_req_nmax) )
377  allocate( history_tstrstep(history_req_nmax) )
378  allocate( history_tlststep(history_req_nmax) )
379  allocate( history_tsumsec(history_req_nmax) )
380 
381  if ( fid_conf > 0 ) rewind(fid_conf)
382  memsize = 0
383  ni = 0
384  do n = 1, history_req_limit
385  ! set default
386  basename = history_default_basename
387  item = 'unknown'
388  tinterval = history_default_tinterval
389  tunit = history_default_tunit
390  taverage = history_default_taverage
391  zinterp = history_default_zinterp
392  datatype = history_default_datatype
393 
394  if ( fid_conf > 0 ) then
395  read(fid_conf, nml=histitem,iostat=ierr)
396  if( ierr /= 0 ) exit
397  endif
398 
399  if ( basename == "" ) cycle
400  ni = ni + 1
401 
402  history_req_item(ni) = item
403  history_req_basename(ni) = basename
404  call calendarymdhms2sec( history_req_tintsec(ni), tinterval, tunit )
405  history_req_tintstep(ni) = int( history_req_tintsec(ni) / history_dtsec )
406 
407  history_req_tavg(ni) = taverage
408  history_req_zinterp(ni) = zinterp
409 
410  if ( history_req_tintsec(ni) <= 0.d0 ) then
411  write(message,*) 'xxx Not appropriate time interval. Check!', item, tinterval
412  call log('E', message)
413  endif
414 
415  if ( abs(history_req_tintsec(ni)-real(History_req_tintstep(ni),kind=dp)*history_dtsec) > eps ) then
416  write(message,*) 'xxx time interval must be a multiple of delta t ', &
417  history_req_tintsec(ni), real(History_req_tintstep(ni),kind=dp)*history_dtsec
418  call log('E', message)
419  endif
420 
421  if ( datatype == 'REAL4' ) then
422  history_req_dtype(n) = file_real4
423  elseif( datatype == 'REAL8' ) then
424  history_req_dtype(n) = file_real8
425  else
426  write(message,*) 'xxx Not appropriate DATATYPE. Check!', datatype
427  call log('E', message)
428  endif
429 
430  memsize = memsize + array_size * file_preclist(history_req_dtype(ni))
431  enddo
432 
433  write(message,*) '*** Number of requested history item : ', history_req_nmax
434  call log('I', message)
435  write(message,*) '*** Output default data type : ', history_default_datatype
436  call log('I', message)
437  write(message,*) '*** Memory usage for history data buffer [Mbyte] : ', memsize/1024/1024
438  call log('I', message)
439 
440  if ( (.not. present(namelist_fid)) ) then
441  if ( fid_conf > 0 ) close(fid_conf)
442  endif
443 
444  history_master = master
445  history_myrank = myrank
446  allocate( history_rankidx(size(rankidx)) )
447  history_rankidx(:) = rankidx(:)
448 
449  return
450  end subroutine historyinit
451 
452  !-----------------------------------------------------------------------------
453  subroutine historyaddvariable( &
454  varname, &
455  dims, &
456  desc, &
457  units, &
458  now_step, &
459  id, &
460  zinterp, &
461  existed, &
462  options )
463  use gtool_file, only: &
464  filecreate, &
465  filesetoption, &
466  fileaddvariable, &
467  filesettattr, &
468  fileputaxis, &
469  fileputassociatedcoordinates
470  implicit none
471 
472  character(len=*), intent(in) :: varname
473  character(len=*), intent(in) :: dims(:)
474  character(len=*), intent(in) :: desc
475  character(len=*), intent(in) :: units
476  integer, intent(in) :: now_step
477  integer, intent(out) :: id
478  logical, intent(out) :: zinterp
479  logical, intent(out) :: existed
480  character(len=*), intent(in), optional :: options ! 'filetype1:key1=val1&filetype2:key2=val2&...'
481 
482  character(len=File_HMID) :: tunits
483 
484  logical :: fileexisted
485  integer :: nmax, reqid
486  integer :: n, m
487  integer :: ic, ie, is, lo
488 
489  intrinsic size
490  !---------------------------------------------------------------------------
491 
492  existed = .false.
493 
494  !--- search existing item
495  id = -1
496  nmax = min( history_id_count, history_req_nmax )
497  do n = 1, nmax
498  if ( varname == history_item(n) ) then ! match existing item
499  id = n
500  zinterp = history_zinterp(n)
501  existed = .true.
502  return
503  endif
504  enddo
505 
506  if ( id < 0 ) then ! request-register matching check
507 
508  ! new file registration
509  if ( history_time_since == '' ) then
510  tunits = history_time_units
511  else
512  tunits = trim(history_time_units)//' since '//trim(history_time_since)
513  endif
514 
515  do n = 1, history_req_nmax
516  if ( varname == history_req_item(n) ) then
517  reqid = n
518  if( history_req_basename(reqid) == '' ) exit
519  history_id_count = history_id_count + 1
520  id = history_id_count
521 
522  call filecreate( history_fid(id), & ! (out)
523  fileexisted, & ! (out)
524  trim(history_req_basename(reqid)), & ! (in)
525  history_title, & ! (in)
526  history_source, & ! (in)
527  history_institution, & ! (in)
528  history_master, & ! (in)
529  history_myrank, & ! (in)
530  history_rankidx, & ! (in)
531  time_units = tunits ) ! (in)
532 
533  if ( .not. fileexisted ) then
534 
535  if ( present(options) ) then
536  ic = -1 ! index of ':'
537  ie = -1 ! index of '='
538  is = 1 ! start index
539  lo = len_trim(options)
540  do m = 1, lo+1
541  if ( m == lo+1 .or. options(m:m) == '&' ) then
542  if ( ic == -1 .or. ie == -1 ) then
543  call log('E', 'xxx option is invalid: ' // trim(options))
544  endif
545  call filesetoption(history_fid(id), & ! (in)
546  options(is:ic-1), & ! (in)
547  options(ic+1:ie-1), options(ie+1:m-1) ) ! (in)
548  ic = -1
549  ie = -1
550  is = m + 1
551  else if ( options(m:m) == ':' ) then
552  ic = m
553  else if ( options(m:m) == '=' ) then
554  ie = m
555  endif
556  enddo
557  endif
558 
559  do m = 1, history_axis_count
560  call fileputaxis( history_fid(id), & ! (in)
561  history_axis(m)%name, history_axis(m)%desc, & ! (in)
562  history_axis(m)%units, history_axis(m)%dim, & ! (in)
563  history_axis(m)%type, history_axis(m)%var ) ! (in)
564  enddo
565 
566  do m = 1, history_assoc_count
567  call fileputassociatedcoordinates( history_fid(id), & ! (in)
568  history_assoc(m)%name, history_assoc(m)%desc, & ! (in)
569  history_assoc(m)%units, & ! (in)
570  history_assoc(m)%dims(1:history_assoc(m)%ndims), & ! (in)
571  history_assoc(m)%type, history_assoc(m)%var ) ! (in)
572  enddo
573 
574  endif
575 
576  history_item(id) = varname
577  history_tintsec(id) = history_req_tintsec(reqid)
578  history_tintstep(id) = history_req_tintstep(reqid)
579  history_tavg(id) = history_req_tavg(reqid)
580  history_zinterp(id) = history_req_zinterp(reqid)
581 
582  history_varsum(:,id) = 0.d0
583 
584  if ( history_output_step0 .and. now_step==1 ) then
585  history_tstrstep(id) = 1 - history_tintstep(id)
586  else
587  history_tstrstep(id) = 1
588  endif
589  if ( history_output_start > 0.0_dp ) then
590  history_tstart(id) = history_startdaysec + history_output_start
591  else
592  history_tstart(id) = history_startdaysec
593  end if
594  history_tlststep(id) = history_tstrstep(id)
595  history_tsumsec(id) = 0.d0
596 
597  call fileaddvariable( history_vid(id), & ! (out)
598  history_fid(id), & ! (in)
599  varname, desc, units, dims, & ! (in)
600  history_req_dtype(reqid), & ! (in)
601  history_tintsec(id), & ! (in)
602  history_tavg(id) ) ! (in)
603 
604  if ( .not. fileexisted ) then
605  do m = 1, history_axis_count
606  if ( history_axis(m)%down ) then
607  call filesettattr( history_fid(id), history_axis(m)%name, "positive", "down" )
608  endif
609  enddo
610  endif
611 
612  write(message,*) '*** [HIST] Item registration No.= ', id
613  call log('I', message)
614  write(message,*) '] Name : ', trim(history_item(id))
615  call log('I', message)
616  write(message,*) '] Description : ', trim(desc)
617  call log('I', message)
618  write(message,*) '] Unit : ', trim(units)
619  call log('I', message)
620  write(message,*) '] Interval [sec] : ', history_tintsec(id)
621  call log('I', message)
622  write(message,*) '] Interval [step] : ', history_tintstep(id)
623  call log('I', message)
624  write(message,*) '] Time Average? : ', history_tavg(id)
625  call log('I', message)
626  write(message,*) '] z* -> z conversion? : ', history_zinterp(id)
627  call log('I', message)
628  call log('I', '')
629 
630  zinterp = history_zinterp(id)
631 
632  exit
633  endif
634  enddo
635 
636  endif
637 
638  return
639  end subroutine historyaddvariable
640 
641  !-----------------------------------------------------------------------------
642  ! interface HistoryPutAxis
643  !-----------------------------------------------------------------------------
644  subroutine historyputaxissp( &
645  name, & ! (in)
646  desc, & ! (in)
647  units, & ! (in)
648  dim, & ! (in)
649  var, & ! (in)
650  dtype, & ! (in) optional
651  down & ! (in) optional
652  )
653  use gtool_file_h, only: &
654  file_real4, &
655  file_real8
656  implicit none
657 
658  character(len=*), intent(in) :: name
659  character(len=*), intent(in) :: desc
660  character(len=*), intent(in) :: units
661  character(len=*), intent(in) :: dim
662  real(SP), intent(in) :: var(:)
663  character(len=*), intent(in), optional :: dtype
664  logical, intent(in), optional :: down
665 
666  integer :: type
667  !---------------------------------------------------------------------------
668 
669  if ( present(dtype) ) then
670  if ( dtype == 'REAL4' ) then
671  type = file_real4
672  else if ( dtype == 'REAL8' ) then
673  type = file_real8
674  else
675  write(message,*) 'xxx Not appropriate dtype. Check!', dtype
676  call log('E', message)
677  endif
678  else
679  type = file_real4
680  endif
681 
682  if ( history_axis_count < history_axis_limit ) then
683  history_axis_count = history_axis_count + 1
684  history_axis(history_axis_count)%name = name
685  history_axis(history_axis_count)%desc = desc
686  history_axis(history_axis_count)%units = units
687  history_axis(history_axis_count)%dim = dim
688  history_axis(history_axis_count)%type = type
689  allocate(history_axis(history_axis_count)%var(size(var)))
690  history_axis(history_axis_count)%var = var
691  if ( present(down) ) then
692  history_axis(history_axis_count)%down = down
693  else
694  history_axis(history_axis_count)%down = .false.
695  endif
696  else
697  write(message,*) 'xxx Number of axis exceeds the limit.'
698  call log('E', message)
699  endif
700 
701  return
702  end subroutine historyputaxissp
703  subroutine historyputaxisdp( &
704  name, & ! (in)
705  desc, & ! (in)
706  units, & ! (in)
707  dim, & ! (in)
708  var, & ! (in)
709  dtype, & ! (in) optional
710  down & ! (in) optional
711  )
712  use gtool_file_h, only: &
713  file_real4, &
714  file_real8
715  implicit none
716 
717  character(len=*), intent(in) :: name
718  character(len=*), intent(in) :: desc
719  character(len=*), intent(in) :: units
720  character(len=*), intent(in) :: dim
721  real(DP), intent(in) :: var(:)
722  character(len=*), intent(in), optional :: dtype
723  logical, intent(in), optional :: down
724 
725  integer :: type
726  !---------------------------------------------------------------------------
727 
728  if ( present(dtype) ) then
729  if ( dtype == 'REAL4' ) then
730  type = file_real4
731  else if ( dtype == 'REAL8' ) then
732  type = file_real8
733  else
734  write(message,*) 'xxx Not appropriate dtype. Check!', dtype
735  call log('E', message)
736  endif
737  else
738  type = file_real8
739  endif
740 
741  if ( history_axis_count < history_axis_limit ) then
742  history_axis_count = history_axis_count + 1
743  history_axis(history_axis_count)%name = name
744  history_axis(history_axis_count)%desc = desc
745  history_axis(history_axis_count)%units = units
746  history_axis(history_axis_count)%dim = dim
747  history_axis(history_axis_count)%type = type
748  allocate(history_axis(history_axis_count)%var(size(var)))
749  history_axis(history_axis_count)%var = var
750  if ( present(down) ) then
751  history_axis(history_axis_count)%down = down
752  else
753  history_axis(history_axis_count)%down = .false.
754  endif
755  else
756  write(message,*) 'xxx Number of axis exceeds the limit.'
757  call log('E', message)
758  endif
759 
760  return
761  end subroutine historyputaxisdp
762 
763  !-----------------------------------------------------------------------------
764  ! interface HistoryPutAssociatedCoordinates
765  !-----------------------------------------------------------------------------
767  name, & ! (in)
768  desc, & ! (in)
769  units, & ! (in)
770  dims, & ! (in)
771  var, & ! (in)
772  dtype & ! (in) optional
773  )
774  use gtool_file_h, only: &
775  file_real4, &
776  file_real8
777  implicit none
778 
779  character(len=*), intent(in) :: name
780  character(len=*), intent(in) :: desc
781  character(len=*), intent(in) :: units
782  character(len=*), intent(in) :: dims(:)
783  real(SP), intent(in) :: var(:)
784  character(len=*), intent(in), optional :: dtype
785 
786  integer :: type
787  !---------------------------------------------------------------------------
788 
789  if ( present(dtype) ) then
790  if ( dtype == 'REAL4' ) then
791  type = file_real4
792  else if ( dtype == 'REAL8' ) then
793  type = file_real8
794  else
795  write(message,*) 'xxx Not appropriate dtype. Check!', dtype
796  call log('E', message)
797  endif
798  else
799  type = file_real4
800  endif
801 
802  if ( history_assoc_count < history_assoc_limit ) then
803  history_assoc_count = history_assoc_count + 1
804  history_assoc(history_assoc_count)%name = name
805  history_assoc(history_assoc_count)%desc = desc
806  history_assoc(history_assoc_count)%units = units
807  history_assoc(history_assoc_count)%dims(1:1) = dims
808  history_assoc(history_assoc_count)%ndims = 1
809  history_assoc(history_assoc_count)%type = type
810  allocate(history_assoc(history_assoc_count)%var(size(var)))
811  history_assoc(history_assoc_count)%var = reshape(var, (/size(var)/))
812  else
813  write(message,*) 'xxx Number of associate coordinates exceeds the limit.'
814  call log('E', message)
815  endif
816 
817  return
820  name, & ! (in)
821  desc, & ! (in)
822  units, & ! (in)
823  dims, & ! (in)
824  var, & ! (in)
825  dtype & ! (in) optional
826  )
827  use gtool_file_h, only: &
828  file_real4, &
829  file_real8
830  implicit none
831 
832  character(len=*), intent(in) :: name
833  character(len=*), intent(in) :: desc
834  character(len=*), intent(in) :: units
835  character(len=*), intent(in) :: dims(:)
836  real(DP), intent(in) :: var(:)
837  character(len=*), intent(in), optional :: dtype
838 
839  integer :: type
840  !---------------------------------------------------------------------------
841 
842  if ( present(dtype) ) then
843  if ( dtype == 'REAL4' ) then
844  type = file_real4
845  else if ( dtype == 'REAL8' ) then
846  type = file_real8
847  else
848  write(message,*) 'xxx Not appropriate dtype. Check!', dtype
849  call log('E', message)
850  endif
851  else
852  type = file_real8
853  endif
854 
855  if ( history_assoc_count < history_assoc_limit ) then
856  history_assoc_count = history_assoc_count + 1
857  history_assoc(history_assoc_count)%name = name
858  history_assoc(history_assoc_count)%desc = desc
859  history_assoc(history_assoc_count)%units = units
860  history_assoc(history_assoc_count)%dims(1:1) = dims
861  history_assoc(history_assoc_count)%ndims = 1
862  history_assoc(history_assoc_count)%type = type
863  allocate(history_assoc(history_assoc_count)%var(size(var)))
864  history_assoc(history_assoc_count)%var = reshape(var, (/size(var)/))
865  else
866  write(message,*) 'xxx Number of associate coordinates exceeds the limit.'
867  call log('E', message)
868  endif
869 
870  return
873  name, & ! (in)
874  desc, & ! (in)
875  units, & ! (in)
876  dims, & ! (in)
877  var, & ! (in)
878  dtype & ! (in) optional
879  )
880  use gtool_file_h, only: &
881  file_real4, &
882  file_real8
883  implicit none
884 
885  character(len=*), intent(in) :: name
886  character(len=*), intent(in) :: desc
887  character(len=*), intent(in) :: units
888  character(len=*), intent(in) :: dims(:)
889  real(SP), intent(in) :: var(:,:)
890  character(len=*), intent(in), optional :: dtype
891 
892  integer :: type
893  !---------------------------------------------------------------------------
894 
895  if ( present(dtype) ) then
896  if ( dtype == 'REAL4' ) then
897  type = file_real4
898  else if ( dtype == 'REAL8' ) then
899  type = file_real8
900  else
901  write(message,*) 'xxx Not appropriate dtype. Check!', dtype
902  call log('E', message)
903  endif
904  else
905  type = file_real4
906  endif
907 
908  if ( history_assoc_count < history_assoc_limit ) then
909  history_assoc_count = history_assoc_count + 1
910  history_assoc(history_assoc_count)%name = name
911  history_assoc(history_assoc_count)%desc = desc
912  history_assoc(history_assoc_count)%units = units
913  history_assoc(history_assoc_count)%dims(1:2) = dims
914  history_assoc(history_assoc_count)%ndims = 2
915  history_assoc(history_assoc_count)%type = type
916  allocate(history_assoc(history_assoc_count)%var(size(var)))
917  history_assoc(history_assoc_count)%var = reshape(var, (/size(var)/))
918  else
919  write(message,*) 'xxx Number of associate coordinates exceeds the limit.'
920  call log('E', message)
921  endif
922 
923  return
926  name, & ! (in)
927  desc, & ! (in)
928  units, & ! (in)
929  dims, & ! (in)
930  var, & ! (in)
931  dtype & ! (in) optional
932  )
933  use gtool_file_h, only: &
934  file_real4, &
935  file_real8
936  implicit none
937 
938  character(len=*), intent(in) :: name
939  character(len=*), intent(in) :: desc
940  character(len=*), intent(in) :: units
941  character(len=*), intent(in) :: dims(:)
942  real(DP), intent(in) :: var(:,:)
943  character(len=*), intent(in), optional :: dtype
944 
945  integer :: type
946  !---------------------------------------------------------------------------
947 
948  if ( present(dtype) ) then
949  if ( dtype == 'REAL4' ) then
950  type = file_real4
951  else if ( dtype == 'REAL8' ) then
952  type = file_real8
953  else
954  write(message,*) 'xxx Not appropriate dtype. Check!', dtype
955  call log('E', message)
956  endif
957  else
958  type = file_real8
959  endif
960 
961  if ( history_assoc_count < history_assoc_limit ) then
962  history_assoc_count = history_assoc_count + 1
963  history_assoc(history_assoc_count)%name = name
964  history_assoc(history_assoc_count)%desc = desc
965  history_assoc(history_assoc_count)%units = units
966  history_assoc(history_assoc_count)%dims(1:2) = dims
967  history_assoc(history_assoc_count)%ndims = 2
968  history_assoc(history_assoc_count)%type = type
969  allocate(history_assoc(history_assoc_count)%var(size(var)))
970  history_assoc(history_assoc_count)%var = reshape(var, (/size(var)/))
971  else
972  write(message,*) 'xxx Number of associate coordinates exceeds the limit.'
973  call log('E', message)
974  endif
975 
976  return
979  name, & ! (in)
980  desc, & ! (in)
981  units, & ! (in)
982  dims, & ! (in)
983  var, & ! (in)
984  dtype & ! (in) optional
985  )
986  use gtool_file_h, only: &
987  file_real4, &
988  file_real8
989  implicit none
990 
991  character(len=*), intent(in) :: name
992  character(len=*), intent(in) :: desc
993  character(len=*), intent(in) :: units
994  character(len=*), intent(in) :: dims(:)
995  real(SP), intent(in) :: var(:,:,:)
996  character(len=*), intent(in), optional :: dtype
997 
998  integer :: type
999  !---------------------------------------------------------------------------
1000 
1001  if ( present(dtype) ) then
1002  if ( dtype == 'REAL4' ) then
1003  type = file_real4
1004  else if ( dtype == 'REAL8' ) then
1005  type = file_real8
1006  else
1007  write(message,*) 'xxx Not appropriate dtype. Check!', dtype
1008  call log('E', message)
1009  endif
1010  else
1011  type = file_real4
1012  endif
1013 
1014  if ( history_assoc_count < history_assoc_limit ) then
1015  history_assoc_count = history_assoc_count + 1
1016  history_assoc(history_assoc_count)%name = name
1017  history_assoc(history_assoc_count)%desc = desc
1018  history_assoc(history_assoc_count)%units = units
1019  history_assoc(history_assoc_count)%dims(1:3) = dims
1020  history_assoc(history_assoc_count)%ndims = 3
1021  history_assoc(history_assoc_count)%type = type
1022  allocate(history_assoc(history_assoc_count)%var(size(var)))
1023  history_assoc(history_assoc_count)%var = reshape(var, (/size(var)/))
1024  else
1025  write(message,*) 'xxx Number of associate coordinates exceeds the limit.'
1026  call log('E', message)
1027  endif
1028 
1029  return
1032  name, & ! (in)
1033  desc, & ! (in)
1034  units, & ! (in)
1035  dims, & ! (in)
1036  var, & ! (in)
1037  dtype & ! (in) optional
1038  )
1039  use gtool_file_h, only: &
1040  file_real4, &
1041  file_real8
1042  implicit none
1043 
1044  character(len=*), intent(in) :: name
1045  character(len=*), intent(in) :: desc
1046  character(len=*), intent(in) :: units
1047  character(len=*), intent(in) :: dims(:)
1048  real(DP), intent(in) :: var(:,:,:)
1049  character(len=*), intent(in), optional :: dtype
1050 
1051  integer :: type
1052  !---------------------------------------------------------------------------
1053 
1054  if ( present(dtype) ) then
1055  if ( dtype == 'REAL4' ) then
1056  type = file_real4
1057  else if ( dtype == 'REAL8' ) then
1058  type = file_real8
1059  else
1060  write(message,*) 'xxx Not appropriate dtype. Check!', dtype
1061  call log('E', message)
1062  endif
1063  else
1064  type = file_real8
1065  endif
1066 
1067  if ( history_assoc_count < history_assoc_limit ) then
1068  history_assoc_count = history_assoc_count + 1
1069  history_assoc(history_assoc_count)%name = name
1070  history_assoc(history_assoc_count)%desc = desc
1071  history_assoc(history_assoc_count)%units = units
1072  history_assoc(history_assoc_count)%dims(1:3) = dims
1073  history_assoc(history_assoc_count)%ndims = 3
1074  history_assoc(history_assoc_count)%type = type
1075  allocate(history_assoc(history_assoc_count)%var(size(var)))
1076  history_assoc(history_assoc_count)%var = reshape(var, (/size(var)/))
1077  else
1078  write(message,*) 'xxx Number of associate coordinates exceeds the limit.'
1079  call log('E', message)
1080  endif
1081 
1082  return
1085  name, & ! (in)
1086  desc, & ! (in)
1087  units, & ! (in)
1088  dims, & ! (in)
1089  var, & ! (in)
1090  dtype & ! (in) optional
1091  )
1092  use gtool_file_h, only: &
1093  file_real4, &
1094  file_real8
1095  implicit none
1096 
1097  character(len=*), intent(in) :: name
1098  character(len=*), intent(in) :: desc
1099  character(len=*), intent(in) :: units
1100  character(len=*), intent(in) :: dims(:)
1101  real(SP), intent(in) :: var(:,:,:,:)
1102  character(len=*), intent(in), optional :: dtype
1103 
1104  integer :: type
1105  !---------------------------------------------------------------------------
1106 
1107  if ( present(dtype) ) then
1108  if ( dtype == 'REAL4' ) then
1109  type = file_real4
1110  else if ( dtype == 'REAL8' ) then
1111  type = file_real8
1112  else
1113  write(message,*) 'xxx Not appropriate dtype. Check!', dtype
1114  call log('E', message)
1115  endif
1116  else
1117  type = file_real4
1118  endif
1119 
1120  if ( history_assoc_count < history_assoc_limit ) then
1121  history_assoc_count = history_assoc_count + 1
1122  history_assoc(history_assoc_count)%name = name
1123  history_assoc(history_assoc_count)%desc = desc
1124  history_assoc(history_assoc_count)%units = units
1125  history_assoc(history_assoc_count)%dims(1:4) = dims
1126  history_assoc(history_assoc_count)%ndims = 4
1127  history_assoc(history_assoc_count)%type = type
1128  allocate(history_assoc(history_assoc_count)%var(size(var)))
1129  history_assoc(history_assoc_count)%var = reshape(var, (/size(var)/))
1130  else
1131  write(message,*) 'xxx Number of associate coordinates exceeds the limit.'
1132  call log('E', message)
1133  endif
1134 
1135  return
1138  name, & ! (in)
1139  desc, & ! (in)
1140  units, & ! (in)
1141  dims, & ! (in)
1142  var, & ! (in)
1143  dtype & ! (in) optional
1144  )
1145  use gtool_file_h, only: &
1146  file_real4, &
1147  file_real8
1148  implicit none
1149 
1150  character(len=*), intent(in) :: name
1151  character(len=*), intent(in) :: desc
1152  character(len=*), intent(in) :: units
1153  character(len=*), intent(in) :: dims(:)
1154  real(DP), intent(in) :: var(:,:,:,:)
1155  character(len=*), intent(in), optional :: dtype
1156 
1157  integer :: type
1158  !---------------------------------------------------------------------------
1159 
1160  if ( present(dtype) ) then
1161  if ( dtype == 'REAL4' ) then
1162  type = file_real4
1163  else if ( dtype == 'REAL8' ) then
1164  type = file_real8
1165  else
1166  write(message,*) 'xxx Not appropriate dtype. Check!', dtype
1167  call log('E', message)
1168  endif
1169  else
1170  type = file_real8
1171  endif
1172 
1173  if ( history_assoc_count < history_assoc_limit ) then
1174  history_assoc_count = history_assoc_count + 1
1175  history_assoc(history_assoc_count)%name = name
1176  history_assoc(history_assoc_count)%desc = desc
1177  history_assoc(history_assoc_count)%units = units
1178  history_assoc(history_assoc_count)%dims(1:4) = dims
1179  history_assoc(history_assoc_count)%ndims = 4
1180  history_assoc(history_assoc_count)%type = type
1181  allocate(history_assoc(history_assoc_count)%var(size(var)))
1182  history_assoc(history_assoc_count)%var = reshape(var, (/size(var)/))
1183  else
1184  write(message,*) 'xxx Number of associate coordinates exceeds the limit.'
1185  call log('E', message)
1186  endif
1187 
1188  return
1190 
1191  !-----------------------------------------------------------------------------
1192  ! HistorySetTAttr
1193  subroutine historysettattr( &
1194  varname, &
1195  key, &
1196  val )
1197  use gtool_file, only: &
1198  filesettattr
1199  implicit none
1200 
1201  character(len=*), intent(in) :: varname
1202  character(len=*), intent(in) :: key
1203  character(len=*), intent(in) :: val
1204 
1205  integer :: n
1206  !---------------------------------------------------------------------------
1207 
1208  do n = 1, history_id_count
1209  call filesettattr( history_fid(n), & ! (in)
1210  varname, & ! (in)
1211  key, & ! (in)
1212  val ) ! (in)
1213  enddo
1214 
1215  end subroutine historysettattr
1216 
1217  !-----------------------------------------------------------------------------
1218  ! HistoryQuery
1219  subroutine historyquery( &
1220  itemid, &
1221  step_next, &
1222  answer )
1223  implicit none
1224 
1225  integer, intent(in) :: itemid
1226  integer, intent(in) :: step_next
1227  logical, intent(out) :: answer
1228  !---------------------------------------------------------------------------
1229 
1230  answer = .false.
1231 
1232  if ( history_tavg(itemid) ) then
1233  answer = .true.
1234  elseif( step_next == history_tstrstep(itemid) + history_tintstep(itemid) ) then
1235  answer = .true.
1236  endif
1237 
1238  return
1239  end subroutine historyquery
1240 
1241  !-----------------------------------------------------------------------------
1242  ! interface HistoryPut(by NAME)
1243  subroutine historyput0dnamesp( &
1244  varname, &
1245  step_next, &
1246  var )
1247  implicit none
1248 
1249  character(len=*), intent(in) :: varname
1250  integer, intent(in) :: step_next
1251  real(SP), intent(in) :: var
1252 
1253  integer :: itemid, n
1254  !---------------------------------------------------------------------------
1255 
1256  ! search item id
1257  itemid = -1
1258  do n = 1, history_id_count
1259  if ( varname == history_item(n) ) then
1260  itemid = n
1261  exit
1262  endif
1263  enddo
1264 
1265  call historyput0didsp(itemid, step_next, var)
1266 
1267  return
1268  end subroutine historyput0dnamesp
1269 
1270  !-----------------------------------------------------------------------------
1271  ! interface HistoryPut(by ID)
1272  subroutine historyput0didsp( &
1273  itemid, &
1274  step_next, &
1275  var )
1276  implicit none
1277 
1278  integer, intent(in) :: itemid
1279  integer, intent(in) :: step_next
1280  real(SP), intent(in) :: var
1281 
1282  real(DP) :: dt
1283  integer :: idx
1284  intrinsic shape
1285  !---------------------------------------------------------------------------
1286 
1287  if ( itemid < 0 ) return
1288 
1289  dt = ( step_next - history_tlststep(itemid) ) * history_dtsec
1290 
1291  if ( dt < eps .AND. ( .NOT. history_tavg(itemid) ) ) then
1292  write(message,*) 'xxx History variable was put two times before output!: ', &
1293  trim(history_item(itemid)), &
1294  step_next, history_tlststep(itemid)
1295  call log('E', message)
1296  endif
1297 
1298  if ( history_tavg(itemid) ) then
1299  idx = 1
1300  history_varsum(idx,itemid) = history_varsum(idx,itemid) + var * dt
1301  else
1302  idx = 1
1303  history_varsum(idx,itemid) = var
1304  endif
1305 
1306  history_size(itemid) = idx
1307  history_tlststep(itemid) = step_next
1308  history_tsumsec(itemid) = history_tsumsec(itemid) + dt
1309 
1310  return
1311  end subroutine historyput0didsp
1312  subroutine historyput0dnamedp( &
1313  varname, &
1314  step_next, &
1315  var )
1316  implicit none
1317 
1318  character(len=*), intent(in) :: varname
1319  integer, intent(in) :: step_next
1320  real(DP), intent(in) :: var
1321 
1322  integer :: itemid, n
1323  !---------------------------------------------------------------------------
1324 
1325  ! search item id
1326  itemid = -1
1327  do n = 1, history_id_count
1328  if ( varname == history_item(n) ) then
1329  itemid = n
1330  exit
1331  endif
1332  enddo
1333 
1334  call historyput0diddp(itemid, step_next, var)
1335 
1336  return
1337  end subroutine historyput0dnamedp
1338 
1339  !-----------------------------------------------------------------------------
1340  ! interface HistoryPut(by ID)
1341  subroutine historyput0diddp( &
1342  itemid, &
1343  step_next, &
1344  var )
1345  implicit none
1346 
1347  integer, intent(in) :: itemid
1348  integer, intent(in) :: step_next
1349  real(DP), intent(in) :: var
1350 
1351  real(DP) :: dt
1352  integer :: idx
1353  intrinsic shape
1354  !---------------------------------------------------------------------------
1355 
1356  if ( itemid < 0 ) return
1357 
1358  dt = ( step_next - history_tlststep(itemid) ) * history_dtsec
1359 
1360  if ( dt < eps .AND. ( .NOT. history_tavg(itemid) ) ) then
1361  write(message,*) 'xxx History variable was put two times before output!: ', &
1362  trim(history_item(itemid)), &
1363  step_next, history_tlststep(itemid)
1364  call log('E', message)
1365  endif
1366 
1367  if ( history_tavg(itemid) ) then
1368  idx = 1
1369  history_varsum(idx,itemid) = history_varsum(idx,itemid) + var * dt
1370  else
1371  idx = 1
1372  history_varsum(idx,itemid) = var
1373  endif
1374 
1375  history_size(itemid) = idx
1376  history_tlststep(itemid) = step_next
1377  history_tsumsec(itemid) = history_tsumsec(itemid) + dt
1378 
1379  return
1380  end subroutine historyput0diddp
1381  subroutine historyput1dnamesp( &
1382  varname, &
1383  step_next, &
1384  var )
1385  implicit none
1386 
1387  character(len=*), intent(in) :: varname
1388  integer, intent(in) :: step_next
1389  real(SP), intent(in) :: var(:)
1390 
1391  integer :: itemid, n
1392  !---------------------------------------------------------------------------
1393 
1394  ! search item id
1395  itemid = -1
1396  do n = 1, history_id_count
1397  if ( varname == history_item(n) ) then
1398  itemid = n
1399  exit
1400  endif
1401  enddo
1402 
1403  call historyput1didsp(itemid, step_next, var)
1404 
1405  return
1406  end subroutine historyput1dnamesp
1407 
1408  !-----------------------------------------------------------------------------
1409  ! interface HistoryPut(by ID)
1410  subroutine historyput1didsp( &
1411  itemid, &
1412  step_next, &
1413  var )
1414  implicit none
1415 
1416  integer, intent(in) :: itemid
1417  integer, intent(in) :: step_next
1418  real(SP), intent(in) :: var(:)
1419 
1420  real(DP) :: dt
1421  integer :: idx
1422  integer :: ijk(1)
1423  integer :: i
1424  intrinsic shape
1425  !---------------------------------------------------------------------------
1426 
1427  if ( itemid < 0 ) return
1428 
1429  ijk = shape(var)
1430  dt = ( step_next - history_tlststep(itemid) ) * history_dtsec
1431 
1432  if ( dt < eps .AND. ( .NOT. history_tavg(itemid) ) ) then
1433  write(message,*) 'xxx History variable was put two times before output!: ', &
1434  trim(history_item(itemid)), &
1435  step_next, history_tlststep(itemid)
1436  call log('E', message)
1437  endif
1438 
1439  if ( history_tavg(itemid) ) then
1440  do i = 1, ijk(1)
1441  idx = i
1442  history_varsum(idx,itemid) = history_varsum(idx,itemid) + var(i) * dt
1443  enddo
1444  else
1445  do i = 1, ijk(1)
1446  idx = i
1447  history_varsum(idx,itemid) = var(i)
1448  enddo
1449  endif
1450 
1451  history_size(itemid) = idx
1452  history_tlststep(itemid) = step_next
1453  history_tsumsec(itemid) = history_tsumsec(itemid) + dt
1454 
1455  return
1456  end subroutine historyput1didsp
1457  subroutine historyput1dnamedp( &
1458  varname, &
1459  step_next, &
1460  var )
1461  implicit none
1462 
1463  character(len=*), intent(in) :: varname
1464  integer, intent(in) :: step_next
1465  real(DP), intent(in) :: var(:)
1466 
1467  integer :: itemid, n
1468  !---------------------------------------------------------------------------
1469 
1470  ! search item id
1471  itemid = -1
1472  do n = 1, history_id_count
1473  if ( varname == history_item(n) ) then
1474  itemid = n
1475  exit
1476  endif
1477  enddo
1478 
1479  call historyput1diddp(itemid, step_next, var)
1480 
1481  return
1482  end subroutine historyput1dnamedp
1483 
1484  !-----------------------------------------------------------------------------
1485  ! interface HistoryPut(by ID)
1486  subroutine historyput1diddp( &
1487  itemid, &
1488  step_next, &
1489  var )
1490  implicit none
1491 
1492  integer, intent(in) :: itemid
1493  integer, intent(in) :: step_next
1494  real(DP), intent(in) :: var(:)
1495 
1496  real(DP) :: dt
1497  integer :: idx
1498  integer :: ijk(1)
1499  integer :: i
1500  intrinsic shape
1501  !---------------------------------------------------------------------------
1502 
1503  if ( itemid < 0 ) return
1504 
1505  ijk = shape(var)
1506  dt = ( step_next - history_tlststep(itemid) ) * history_dtsec
1507 
1508  if ( dt < eps .AND. ( .NOT. history_tavg(itemid) ) ) then
1509  write(message,*) 'xxx History variable was put two times before output!: ', &
1510  trim(history_item(itemid)), &
1511  step_next, history_tlststep(itemid)
1512  call log('E', message)
1513  endif
1514 
1515  if ( history_tavg(itemid) ) then
1516  do i = 1, ijk(1)
1517  idx = i
1518  history_varsum(idx,itemid) = history_varsum(idx,itemid) + var(i) * dt
1519  enddo
1520  else
1521  do i = 1, ijk(1)
1522  idx = i
1523  history_varsum(idx,itemid) = var(i)
1524  enddo
1525  endif
1526 
1527  history_size(itemid) = idx
1528  history_tlststep(itemid) = step_next
1529  history_tsumsec(itemid) = history_tsumsec(itemid) + dt
1530 
1531  return
1532  end subroutine historyput1diddp
1533  subroutine historyput2dnamesp( &
1534  varname, &
1535  step_next, &
1536  var )
1537  implicit none
1538 
1539  character(len=*), intent(in) :: varname
1540  integer, intent(in) :: step_next
1541  real(SP), intent(in) :: var(:,:)
1542 
1543  integer :: itemid, n
1544  !---------------------------------------------------------------------------
1545 
1546  ! search item id
1547  itemid = -1
1548  do n = 1, history_id_count
1549  if ( varname == history_item(n) ) then
1550  itemid = n
1551  exit
1552  endif
1553  enddo
1554 
1555  call historyput2didsp(itemid, step_next, var)
1556 
1557  return
1558  end subroutine historyput2dnamesp
1559 
1560  !-----------------------------------------------------------------------------
1561  ! interface HistoryPut(by ID)
1562  subroutine historyput2didsp( &
1563  itemid, &
1564  step_next, &
1565  var )
1566  implicit none
1567 
1568  integer, intent(in) :: itemid
1569  integer, intent(in) :: step_next
1570  real(SP), intent(in) :: var(:,:)
1571 
1572  real(DP) :: dt
1573  integer :: idx
1574  integer :: ijk(2)
1575  integer :: i, j
1576  intrinsic shape
1577  !---------------------------------------------------------------------------
1578 
1579  if ( itemid < 0 ) return
1580 
1581  ijk = shape(var)
1582  dt = ( step_next - history_tlststep(itemid) ) * history_dtsec
1583 
1584  if ( dt < eps .AND. ( .NOT. history_tavg(itemid) ) ) then
1585  write(message,*) 'xxx History variable was put two times before output!: ', &
1586  trim(history_item(itemid)), &
1587  step_next, history_tlststep(itemid)
1588  call log('E', message)
1589  endif
1590 
1591  if ( history_tavg(itemid) ) then
1592  do j = 1, ijk(2)
1593  do i = 1, ijk(1)
1594  idx = j*ijk(i)+i
1595  history_varsum(idx,itemid) = history_varsum(idx,itemid) + var(i,j) * dt
1596  enddo
1597  enddo
1598  else
1599  do j = 1, ijk(2)
1600  do i = 1, ijk(1)
1601  idx = j*ijk(i)+i
1602  history_varsum(idx,itemid) = var(i,j)
1603  enddo
1604  enddo
1605  endif
1606 
1607  history_size(itemid) = idx
1608  history_tlststep(itemid) = step_next
1609  history_tsumsec(itemid) = history_tsumsec(itemid) + dt
1610 
1611  return
1612  end subroutine historyput2didsp
1613  subroutine historyput2dnamedp( &
1614  varname, &
1615  step_next, &
1616  var )
1617  implicit none
1618 
1619  character(len=*), intent(in) :: varname
1620  integer, intent(in) :: step_next
1621  real(DP), intent(in) :: var(:,:)
1622 
1623  integer :: itemid, n
1624  !---------------------------------------------------------------------------
1625 
1626  ! search item id
1627  itemid = -1
1628  do n = 1, history_id_count
1629  if ( varname == history_item(n) ) then
1630  itemid = n
1631  exit
1632  endif
1633  enddo
1634 
1635  call historyput2diddp(itemid, step_next, var)
1636 
1637  return
1638  end subroutine historyput2dnamedp
1639 
1640  !-----------------------------------------------------------------------------
1641  ! interface HistoryPut(by ID)
1642  subroutine historyput2diddp( &
1643  itemid, &
1644  step_next, &
1645  var )
1646  implicit none
1647 
1648  integer, intent(in) :: itemid
1649  integer, intent(in) :: step_next
1650  real(DP), intent(in) :: var(:,:)
1651 
1652  real(DP) :: dt
1653  integer :: idx
1654  integer :: ijk(2)
1655  integer :: i, j
1656  intrinsic shape
1657  !---------------------------------------------------------------------------
1658 
1659  if ( itemid < 0 ) return
1660 
1661  ijk = shape(var)
1662  dt = ( step_next - history_tlststep(itemid) ) * history_dtsec
1663 
1664  if ( dt < eps .AND. ( .NOT. history_tavg(itemid) ) ) then
1665  write(message,*) 'xxx History variable was put two times before output!: ', &
1666  trim(history_item(itemid)), &
1667  step_next, history_tlststep(itemid)
1668  call log('E', message)
1669  endif
1670 
1671  if ( history_tavg(itemid) ) then
1672  do j = 1, ijk(2)
1673  do i = 1, ijk(1)
1674  idx = j*ijk(i)+i
1675  history_varsum(idx,itemid) = history_varsum(idx,itemid) + var(i,j) * dt
1676  enddo
1677  enddo
1678  else
1679  do j = 1, ijk(2)
1680  do i = 1, ijk(1)
1681  idx = j*ijk(i)+i
1682  history_varsum(idx,itemid) = var(i,j)
1683  enddo
1684  enddo
1685  endif
1686 
1687  history_size(itemid) = idx
1688  history_tlststep(itemid) = step_next
1689  history_tsumsec(itemid) = history_tsumsec(itemid) + dt
1690 
1691  return
1692  end subroutine historyput2diddp
1693  subroutine historyput3dnamesp( &
1694  varname, &
1695  step_next, &
1696  var )
1697  implicit none
1698 
1699  character(len=*), intent(in) :: varname
1700  integer, intent(in) :: step_next
1701  real(SP), intent(in) :: var(:,:,:)
1702 
1703  integer :: itemid, n
1704  !---------------------------------------------------------------------------
1705 
1706  ! search item id
1707  itemid = -1
1708  do n = 1, history_id_count
1709  if ( varname == history_item(n) ) then
1710  itemid = n
1711  exit
1712  endif
1713  enddo
1714 
1715  call historyput3didsp(itemid, step_next, var)
1716 
1717  return
1718  end subroutine historyput3dnamesp
1719 
1720  !-----------------------------------------------------------------------------
1721  ! interface HistoryPut(by ID)
1722  subroutine historyput3didsp( &
1723  itemid, &
1724  step_next, &
1725  var )
1726  implicit none
1727 
1728  integer, intent(in) :: itemid
1729  integer, intent(in) :: step_next
1730  real(SP), intent(in) :: var(:,:,:)
1731 
1732  real(DP) :: dt
1733  integer :: idx
1734  integer :: ijk(3)
1735  integer :: i, j, k
1736  intrinsic shape
1737  !---------------------------------------------------------------------------
1738 
1739  if ( itemid < 0 ) return
1740 
1741  ijk = shape(var)
1742  dt = ( step_next - history_tlststep(itemid) ) * history_dtsec
1743 
1744  if ( dt < eps .AND. ( .NOT. history_tavg(itemid) ) ) then
1745  write(message,*) 'xxx History variable was put two times before output!: ', &
1746  trim(history_item(itemid)), &
1747  step_next, history_tlststep(itemid)
1748  call log('E', message)
1749  endif
1750 
1751  if ( history_tavg(itemid) ) then
1752  do k = 1, ijk(3)
1753  do j = 1, ijk(2)
1754  do i = 1, ijk(1)
1755  idx = (k*ijk(2)+j)*ijk(1)+i
1756  history_varsum(idx,itemid) = history_varsum(idx,itemid) + var(i,j,k) * dt
1757  enddo
1758  enddo
1759  enddo
1760  else
1761  do k = 1, ijk(3)
1762  do j = 1, ijk(2)
1763  do i = 1, ijk(1)
1764  idx = (k*ijk(2)+j)*ijk(1)+i
1765  history_varsum(idx,itemid) = var(i,j,k)
1766  enddo
1767  enddo
1768  enddo
1769  endif
1770 
1771  history_size(itemid) = idx
1772  history_tlststep(itemid) = step_next
1773  history_tsumsec(itemid) = history_tsumsec(itemid) + dt
1774 
1775  return
1776  end subroutine historyput3didsp
1777  subroutine historyput3dnamedp( &
1778  varname, &
1779  step_next, &
1780  var )
1781  implicit none
1782 
1783  character(len=*), intent(in) :: varname
1784  integer, intent(in) :: step_next
1785  real(DP), intent(in) :: var(:,:,:)
1786 
1787  integer :: itemid, n
1788  !---------------------------------------------------------------------------
1789 
1790  ! search item id
1791  itemid = -1
1792  do n = 1, history_id_count
1793  if ( varname == history_item(n) ) then
1794  itemid = n
1795  exit
1796  endif
1797  enddo
1798 
1799  call historyput3diddp(itemid, step_next, var)
1800 
1801  return
1802  end subroutine historyput3dnamedp
1803 
1804  !-----------------------------------------------------------------------------
1805  ! interface HistoryPut(by ID)
1806  subroutine historyput3diddp( &
1807  itemid, &
1808  step_next, &
1809  var )
1810  implicit none
1811 
1812  integer, intent(in) :: itemid
1813  integer, intent(in) :: step_next
1814  real(DP), intent(in) :: var(:,:,:)
1815 
1816  real(DP) :: dt
1817  integer :: idx
1818  integer :: ijk(3)
1819  integer :: i, j, k
1820  intrinsic shape
1821  !---------------------------------------------------------------------------
1822 
1823  if ( itemid < 0 ) return
1824 
1825  ijk = shape(var)
1826  dt = ( step_next - history_tlststep(itemid) ) * history_dtsec
1827 
1828  if ( dt < eps .AND. ( .NOT. history_tavg(itemid) ) ) then
1829  write(message,*) 'xxx History variable was put two times before output!: ', &
1830  trim(history_item(itemid)), &
1831  step_next, history_tlststep(itemid)
1832  call log('E', message)
1833  endif
1834 
1835  if ( history_tavg(itemid) ) then
1836  do k = 1, ijk(3)
1837  do j = 1, ijk(2)
1838  do i = 1, ijk(1)
1839  idx = (k*ijk(2)+j)*ijk(1)+i
1840  history_varsum(idx,itemid) = history_varsum(idx,itemid) + var(i,j,k) * dt
1841  enddo
1842  enddo
1843  enddo
1844  else
1845  do k = 1, ijk(3)
1846  do j = 1, ijk(2)
1847  do i = 1, ijk(1)
1848  idx = (k*ijk(2)+j)*ijk(1)+i
1849  history_varsum(idx,itemid) = var(i,j,k)
1850  enddo
1851  enddo
1852  enddo
1853  endif
1854 
1855  history_size(itemid) = idx
1856  history_tlststep(itemid) = step_next
1857  history_tsumsec(itemid) = history_tsumsec(itemid) + dt
1858 
1859  return
1860  end subroutine historyput3diddp
1861 
1862  !-----------------------------------------------------------------------------
1863  ! HistoryWrite
1864  subroutine historywrite( &
1865  itemid, &
1866  step_now )
1867  use dc_calendar, only: &
1868  calendarsec2ymdhms
1869  use gtool_file, only: &
1870  filewrite
1871  implicit none
1872 
1873  integer, intent(in) :: itemid
1874  integer, intent(in) :: step_now
1875 
1876  integer :: isize
1877  real(DP) :: time_str, time_end
1878  real(DP) :: sec_str, sec_end
1879 
1880  real(DP), save :: sec_end_last = -1.0_dp
1881  logical, save :: firsttime = .true.
1882  !---------------------------------------------------------------------------
1883 
1884  if( history_id_count == 0 ) return
1885 
1886  if ( step_now < history_tstrstep(itemid) + history_tintstep(itemid) ) then
1887  return
1888  endif
1889 
1890  if ( history_tlststep(itemid) == history_tstrstep(itemid) ) then
1891  write(message,*) 'xxx History variable was never put after the last output!: ', &
1892  trim(history_item(itemid))
1893  if ( history_error_putmiss ) then
1894  call log('E', message)
1895  else
1896  call log('I', message)
1897  endif
1898  endif
1899 
1900  isize = history_size(itemid)
1901 
1902  if ( history_tavg(itemid) ) then
1903  history_varsum(1:isize,itemid) = history_varsum(1:isize,itemid) / history_tsumsec(itemid)
1904  endif
1905 
1906  if ( firsttime ) then
1907  firsttime = .false.
1908  call historyoutputlist
1909  endif
1910 
1911  sec_str = history_startdaysec + real(History_tstrstep(itemid)-1,kind=DP) * HISTORY_DTSEC
1912  sec_end = history_startdaysec + real(step_now-1 ,kind=DP) * HISTORY_DTSEC
1913 
1914  ! convert time units
1915  call calendarsec2ymdhms( time_str, sec_str, history_time_units )
1916  call calendarsec2ymdhms( time_end, sec_end, history_time_units )
1917 
1918  if ( sec_end .ge. history_tstart(itemid) ) then
1919  if ( sec_end_last < sec_end ) then
1920  write(message,'(A)') '*** Output History'
1921  call log('I', message)
1922  endif
1923 
1924  call filewrite( history_fid(itemid), & ! file id
1925  history_vid(itemid), & ! variable id
1926  history_varsum(1:isize,itemid), & ! data
1927  time_str, & ! start time
1928  time_end ) ! end time
1929  else
1930  if ( sec_end_last < sec_end ) then
1931  write(message,'(A,2F15.3)') '*** Output History: Suppressed ', sec_end, history_tstart(itemid)
1932  call log('I', message)
1933  endif
1934  endif
1935 
1936  history_varsum(:,itemid) = 0.0_dp
1937  history_tstrstep(itemid) = step_now
1938  history_tlststep(itemid) = step_now
1939  history_tsumsec(itemid) = 0.0_dp
1940 
1941  sec_end_last = sec_end
1942 
1943  return
1944  end subroutine historywrite
1945 
1946  !-----------------------------------------------------------------------------
1947  ! HistoryWritaAll
1948  subroutine historywriteall( &
1949  step_now )
1950  implicit none
1951 
1952  integer, intent(in) :: step_now
1953 
1954  integer :: n
1955  !---------------------------------------------------------------------------
1956 
1957  do n = 1, history_id_count
1958  call historywrite( n, step_now )
1959  enddo
1960 
1961  return
1962  end subroutine historywriteall
1963 
1964  !-----------------------------------------------------------------------------
1965  ! interface HistoryGet
1966  subroutine historyget1ddp( &
1967  var, &
1968  basename, &
1969  varname, &
1970  step, &
1971  allow_missing, &
1972  single )
1973  use gtool_file, only: &
1974  fileread
1975  implicit none
1976 
1977  real(DP), intent(out) :: var(:)
1978  character(len=*), intent(in) :: basename
1979  character(len=*), intent(in) :: varname
1980  integer, intent(in) :: step
1981  logical, intent(in), optional :: allow_missing
1982  logical, intent(in), optional :: single
1983  !---------------------------------------------------------------------------
1984 
1985  call fileread( var, & ! [OUT]
1986  basename, & ! [IN]
1987  varname, & ! [IN]
1988  step, & ! [IN]
1989  history_myrank, & ! [IN]
1990  allow_missing, & ! [IN]
1991  single ) ! [IN]
1992 
1993  return
1994  end subroutine historyget1ddp
1995  subroutine historyget1dsp( &
1996  var, &
1997  basename, &
1998  varname, &
1999  step, &
2000  allow_missing, &
2001  single )
2002  use gtool_file, only: &
2003  fileread
2004  implicit none
2005 
2006  real(SP), intent(out) :: var(:)
2007  character(len=*), intent(in) :: basename
2008  character(len=*), intent(in) :: varname
2009  integer, intent(in) :: step
2010  logical, intent(in), optional :: allow_missing
2011  logical, intent(in), optional :: single
2012  !---------------------------------------------------------------------------
2013 
2014  call fileread( var, & ! [OUT]
2015  basename, & ! [IN]
2016  varname, & ! [IN]
2017  step, & ! [IN]
2018  history_myrank, & ! [IN]
2019  allow_missing, & ! [IN]
2020  single ) ! [IN]
2021 
2022  return
2023  end subroutine historyget1dsp
2024  subroutine historyget2ddp( &
2025  var, &
2026  basename, &
2027  varname, &
2028  step, &
2029  allow_missing, &
2030  single )
2031  use gtool_file, only: &
2032  fileread
2033  implicit none
2034 
2035  real(DP), intent(out) :: var(:,:)
2036  character(len=*), intent(in) :: basename
2037  character(len=*), intent(in) :: varname
2038  integer, intent(in) :: step
2039  logical, intent(in), optional :: allow_missing
2040  logical, intent(in), optional :: single
2041  !---------------------------------------------------------------------------
2042 
2043  call fileread( var, & ! [OUT]
2044  basename, & ! [IN]
2045  varname, & ! [IN]
2046  step, & ! [IN]
2047  history_myrank, & ! [IN]
2048  allow_missing, & ! [IN]
2049  single ) ! [IN]
2050 
2051  return
2052  end subroutine historyget2ddp
2053  subroutine historyget2dsp( &
2054  var, &
2055  basename, &
2056  varname, &
2057  step, &
2058  allow_missing, &
2059  single )
2060  use gtool_file, only: &
2061  fileread
2062  implicit none
2063 
2064  real(SP), intent(out) :: var(:,:)
2065  character(len=*), intent(in) :: basename
2066  character(len=*), intent(in) :: varname
2067  integer, intent(in) :: step
2068  logical, intent(in), optional :: allow_missing
2069  logical, intent(in), optional :: single
2070  !---------------------------------------------------------------------------
2071 
2072  call fileread( var, & ! [OUT]
2073  basename, & ! [IN]
2074  varname, & ! [IN]
2075  step, & ! [IN]
2076  history_myrank, & ! [IN]
2077  allow_missing, & ! [IN]
2078  single ) ! [IN]
2079 
2080  return
2081  end subroutine historyget2dsp
2082  subroutine historyget3ddp( &
2083  var, &
2084  basename, &
2085  varname, &
2086  step, &
2087  allow_missing, &
2088  single )
2089  use gtool_file, only: &
2090  fileread
2091  implicit none
2092 
2093  real(DP), intent(out) :: var(:,:,:)
2094  character(len=*), intent(in) :: basename
2095  character(len=*), intent(in) :: varname
2096  integer, intent(in) :: step
2097  logical, intent(in), optional :: allow_missing
2098  logical, intent(in), optional :: single
2099  !---------------------------------------------------------------------------
2100 
2101  call fileread( var, & ! [OUT]
2102  basename, & ! [IN]
2103  varname, & ! [IN]
2104  step, & ! [IN]
2105  history_myrank, & ! [IN]
2106  allow_missing, & ! [IN]
2107  single ) ! [IN]
2108 
2109  return
2110  end subroutine historyget3ddp
2111  subroutine historyget3dsp( &
2112  var, &
2113  basename, &
2114  varname, &
2115  step, &
2116  allow_missing, &
2117  single )
2118  use gtool_file, only: &
2119  fileread
2120  implicit none
2121 
2122  real(SP), intent(out) :: var(:,:,:)
2123  character(len=*), intent(in) :: basename
2124  character(len=*), intent(in) :: varname
2125  integer, intent(in) :: step
2126  logical, intent(in), optional :: allow_missing
2127  logical, intent(in), optional :: single
2128  !---------------------------------------------------------------------------
2129 
2130  call fileread( var, & ! [OUT]
2131  basename, & ! [IN]
2132  varname, & ! [IN]
2133  step, & ! [IN]
2134  history_myrank, & ! [IN]
2135  allow_missing, & ! [IN]
2136  single ) ! [IN]
2137 
2138  return
2139  end subroutine historyget3dsp
2140 
2141  !-----------------------------------------------------------------------------
2142  subroutine historyoutputlist
2143  implicit none
2144 
2145  integer :: n
2146  !---------------------------------------------------------------------------
2147 
2148  call log('I', '')
2149  write(message,*) '*** [HIST] Output item list '
2150  call log('I', message)
2151  write(message,*) '*** Number of history item :', history_req_nmax
2152  call log('I', message)
2153  write(message,*) 'NAME :size :interval[sec]: [step]:timeavg?:zinterp?'
2154  call log('I', message)
2155  write(message,*) '============================================================================'
2156  call log('I', message)
2157 
2158  do n = 1, history_id_count
2159  write(message,'(1x,A,1x,I8,1x,f13.3,1x,I8,1x,L8,1x,L8)') &
2160  history_item(n), history_size(n), history_tintsec(n), history_tintstep(n), history_tavg(n), history_zinterp(n)
2161  call log('I', message)
2162  enddo
2163 
2164  write(message,*) '============================================================================'
2165  call log('I', message)
2166  call log('I', '')
2167 
2168  return
2169  end subroutine historyoutputlist
2170 
2171  !-----------------------------------------------------------------------------
2172  subroutine historyfinalize
2173  use gtool_file, only: &
2174  fileclose
2175  implicit none
2176 
2177  integer :: n
2178  !---------------------------------------------------------------------------
2179 
2180  do n = 1, history_id_count
2181  call fileclose( history_fid(n) )
2182  enddo
2183 
2184  return
2185  end subroutine historyfinalize
2186 
2187 end module gtool_history
2188 !-------------------------------------------------------------------------------
2189 
2190 
2191 
2192 !--
2193 ! vi:set readonly sw=4 ts=8
2194 !
2195 !Local Variables:
2196 !mode: f90
2197 !buffer-read-only:t
2198 !End:
2199 !
2200 !++
subroutine historyput2dassociatedcoordinatesdp(name, desc, units, dims, var, dtype)
subroutine, public filecreate(fid, existed, basename, title, source, institution, master, myrank, rankidx, single, time_units, append)
Definition: gtool_file.f90:150
module GTOOL_FILE
Definition: gtool_file.f90:17
subroutine historyget3ddp(var, basename, varname, step, allow_missing, single)
subroutine historyput1dassociatedcoordinatesdp(name, desc, units, dims, var, dtype)
module TIME
Definition: dc_calendar.f90:17
module DC_Log
Definition: dc_log.f90:14
integer, parameter, public file_hlong
subroutine historyput2dassociatedcoordinatessp(name, desc, units, dims, var, dtype)
integer, parameter, public file_hmid
subroutine historyput3dassociatedcoordinatessp(name, desc, units, dims, var, dtype)
subroutine historyget3dsp(var, basename, varname, step, allow_missing, single)
subroutine, public historywrite(itemid, step_now)
module Gtool_History
subroutine historyget1dsp(var, basename, varname, step, allow_missing, single)
subroutine, public fileclose(fid)
subroutine historyput4dassociatedcoordinatessp(name, desc, units, dims, var, dtype)
integer, parameter, public dp
Definition: dc_types.f90:27
subroutine historyput1dassociatedcoordinatessp(name, desc, units, dims, var, dtype)
subroutine, public filesettattr(fid, vname, key, val)
Definition: gtool_file.f90:942
subroutine, public filesetoption(fid, filetype, key, val)
Definition: gtool_file.f90:422
subroutine, public historyfinalize
subroutine, public historyaddvariable(varname, dims, desc, units, now_step, id, zinterp, existed, options)
subroutine, public historyinit(title, source, institution, array_size, master, myrank, rankidx, time_start, time_interval, time_units, time_since, default_basename, default_tinterval, default_tunit, default_taverage, default_zinterp, default_datatype, namelist_filename, namelist_fid)
subroutine, public log(type, message)
Definition: dc_log.f90:133
subroutine historyget2ddp(var, basename, varname, step, allow_missing, single)
integer, dimension(0:3), parameter, public file_preclist
subroutine, public historyoutputlist
subroutine historyput3dassociatedcoordinatesdp(name, desc, units, dims, var, dtype)
integer, parameter, public sp
Definition: dc_types.f90:30
subroutine historyput4dassociatedcoordinatesdp(name, desc, units, dims, var, dtype)
subroutine, public historywriteall(step_now)
integer, parameter, public file_real4
subroutine historyputaxisdp(name, desc, units, dim, var, dtype, down)
module FILE I/O HEADER
integer, parameter, public file_hshort
subroutine historyget2dsp(var, basename, varname, step, allow_missing, single)
subroutine, public historyquery(itemid, step_next, answer)
integer, parameter, public file_real8
subroutine, public historysettattr(varname, key, val)
subroutine historyputaxissp(name, desc, units, dim, var, dtype, down)