open_potential_history_writer Subroutine

public subroutine open_potential_history_writer(app, resumed, potential_history_opened, potential_history_unit)

電位履歴 CSV のオープンとヘッダ初期化を行う。

Arguments

Type IntentOptional Attributes Name
type(app_config), intent(in) :: app

出力設定を含むアプリ設定。

logical, intent(in) :: resumed

再開実行かどうか。

logical, intent(out) :: potential_history_opened

ファイルを開けた場合に .true.

integer, intent(out) :: potential_history_unit

電位履歴CSVの出力ユニット番号(未使用時は -1)。


Calls

proc~~open_potential_history_writer~~CallsGraph proc~open_potential_history_writer open_potential_history_writer proc~ensure_output_dir ensure_output_dir proc~open_potential_history_writer->proc~ensure_output_dir

Called by

proc~~open_potential_history_writer~~CalledByGraph proc~open_potential_history_writer open_potential_history_writer program~main main program~main->proc~open_potential_history_writer

Source Code

  subroutine open_potential_history_writer(app, resumed, potential_history_opened, potential_history_unit)
    type(app_config), intent(in) :: app
    logical, intent(in) :: resumed
    logical, intent(out) :: potential_history_opened
    integer, intent(out) :: potential_history_unit
    character(len=1024) :: path
    integer :: ios
    logical :: file_exists

    potential_history_opened = .false.
    potential_history_unit = -1
    if (.not. app%write_output) return
    if (.not. app%write_potential_history) return
    if (app%history_stride <= 0) return

    call ensure_output_dir(app%output_dir)

    path = trim(app%output_dir)//'/potential_history.csv'
    inquire (file=trim(path), exist=file_exists)
    if (resumed) then
      open (newunit=potential_history_unit, file=trim(path), status='unknown', position='append', action='write', iostat=ios)
    else
      open (newunit=potential_history_unit, file=trim(path), status='replace', action='write', iostat=ios)
    end if
    if (ios /= 0) error stop 'Failed to open potential history file.'

    if (.not. resumed .or. .not. file_exists) then
      write (potential_history_unit, '(a)') 'batch,elem_idx,potential_V'
    end if
    potential_history_opened = .true.
  end subroutine open_potential_history_writer