履歴 CSV のオープンとヘッダ初期化を行う。
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(app_config), | intent(in) | :: | app |
出力設定を含むアプリ設定。 |
||
| logical, | intent(in) | :: | resumed |
再開実行かどうか。 |
||
| logical, | intent(out) | :: | history_opened |
履歴ファイルを開けた場合に |
||
| integer, | intent(out) | :: | history_unit |
履歴CSVの出力ユニット番号(未使用時は |
subroutine open_history_writer(app, resumed, history_opened, history_unit) type(app_config), intent(in) :: app logical, intent(in) :: resumed logical, intent(out) :: history_opened integer, intent(out) :: history_unit character(len=1024) :: history_path integer :: ios logical :: history_exists history_opened = .false. history_unit = -1 if (.not. app%write_output) return if (app%history_stride <= 0) return call ensure_output_dir(app%output_dir) history_path = trim(app%output_dir)//'/charge_history.csv' inquire (file=trim(history_path), exist=history_exists) if (resumed) then open (newunit=history_unit, file=trim(history_path), status='unknown', position='append', action='write', iostat=ios) else open (newunit=history_unit, file=trim(history_path), status='replace', action='write', iostat=ios) end if if (ios /= 0) error stop 'Failed to open charge history file.' if (.not. resumed .or. .not. history_exists) then ! 再開時は既存ファイルがある場合だけヘッダ追記を避ける。 write (history_unit, '(a)') 'batch,processed_particles,rel_change,elem_idx,charge_C' end if history_opened = .true. end subroutine open_history_writer