SUBROUTINE initialize_nimrod(params, F, P, spp,init)
TYPE(KORC_PARAMS), INTENT(INOUT) :: params
TYPE(FIELDS), INTENT(INOUT) :: F
TYPE(PROFILES), INTENT(INOUT) :: P
TYPE(SPECIES), DIMENSION(:), INTENT(INOUT) :: spp
LOGICAL, INTENT(IN) :: init
INTEGER :: ii
INTEGER :: pp
INTEGER :: status
INTEGER :: isrc
real(c_double) :: time0,time1
INTEGER (C_INT) :: FIO_tmp
TYPE(C_PTR) :: hint_tmp
real(rp), DIMENSION(3) :: x
REAL(rp), DIMENSION(3) :: Btmp
CHARACTER(150) :: filename
INTEGER, PARAMETER :: list_file = 102
INTEGER :: num_files,ios
if (init) then
F%Efield = Efield
F%PSIp_lim=PSIp_lim
F%PSIp_0=PSIp_0
F%ReInterp_2x1t=ReInterp_2x1t
if (F%ReInterp_2x1t) then
params%magnetic_field_directory=magnetic_field_directory
params%magnetic_field_list=magnetic_field_list
filename=TRIM(params%magnetic_field_directory)//TRIM(params%magnetic_field_list)
OPEN(UNIT=list_file,FILE=filename,STATUS='OLD')
READ(UNIT=list_file,FMT='(I4)',IOSTAT=ios) num_files
if (ios/=0) then
write(6,*) 'Error reading in magnetic_file_list for initialize_nimrod'
call KORC_abort(22)
endif
!write(6,*) 'num_files',num_files
ALLOCATE(params%magnetic_field_filenames(num_files))
ALLOCATE(params%time_of_filenames(num_files))
do ii=1,num_files
READ(UNIT=list_file,FMT='(A15,F12.10)',IOSTAT=ios) params%magnetic_field_filenames(ii),params%time_of_filenames(ii)
params%magnetic_field_filenames(ii)=ADJUSTL(params%magnetic_field_filenames(ii))
!write(6,*) 'ii',ii,'filename ',TRIM(params%magnetic_field_filenames(ii)), &
! ' time',params%time_of_filenames(ii)
enddo
CLOSE(UNIT=list_file)
endif
if (params%restart.or.params%proceed) then
if (.not.F%ReInterp_2x1t) then
filename=TRIM(params%magnetic_field_filename)
else
filename=TRIM(params%magnetic_field_directory)//TRIM(params%magnetic_field_filenames(ind0_2x1t))
end if
status = fio_open_source(FIO_NIMROD_SOURCE, &
filename // C_NULL_CHAR, F%isrc)
isrc=F%isrc
status = fio_get_options(isrc)
status = fio_get_field(isrc, FIO_MAGNETIC_FIELD, F%FIO_B)
hint_tmp=c_null_ptr
x(1)=spp(1)%Ro
x(2)=spp(1)%PHIo
x(3)=spp(1)%Zo
status = fio_eval_field(F%FIO_B, x(1), &
Btmp(1),hint_tmp)
F%Bo = Btmp(2)
F%Eo = 1.0
F%Ro = 1.0
F%Zo = 1.0
status = fio_close_field(F%FIO_B)
status=fio_close_source(F%isrc)
call load_prev_iter(params)
F%ind0_2x1t=params%prev_iter_2x1t+1
else
F%ind0_2x1t=ind0_2x1t
end if
F%ind_2x1t=F%ind0_2x1t
if (.not.F%ReInterp_2x1t) then
filename=TRIM(params%magnetic_field_filename)
else
filename=TRIM(params%magnetic_field_directory)//TRIM(params%magnetic_field_filenames(F%ind_2x1t))
end if
status = fio_open_source(FIO_NIMROD_SOURCE, &
filename // C_NULL_CHAR, F%isrc)
else
status = fio_close_field(F%FIO_B)
status = fio_close_field(F%FIO_B+1) ! actually for E, to account for F%Efield=-1
! status = fio_close_field(F%FIO_A)
status = fio_close_field(P%FIO_ne)
! status = fio_close_field(P%FIO_te)
! status = fio_close_field(P%FIO_ni)
status=fio_close_source(F%isrc)
if (.not.F%ReInterp_2x1t) then
filename=TRIM(params%magnetic_field_filename)
else
filename=TRIM(params%magnetic_field_directory)//TRIM(params%magnetic_field_filenames(F%ind_2x1t))
end if
status = fio_open_source(FIO_NIMROD_SOURCE, &
filename // C_NULL_CHAR, F%isrc)
end if
isrc=F%isrc
status = fio_get_options(isrc)
!if (.not.F%ReInterp_2x1t) then
! status = fio_set_int_option(FIO_TIMESLICE, params%time_slice)
!else
! status = fio_set_int_option(FIO_TIMESLICE, F%ind_2x1t)
!end if
! For NIMROD dump*, status=fio_get_options(isrc)=0, can't set FIO_TIMESLICE
! as was the case for C1.h5 having information on multiple timeslices
status = fio_get_field(isrc, FIO_MAGNETIC_FIELD, F%FIO_B)
status = fio_get_field(isrc, FIO_ELECTRIC_FIELD, F%FIO_E)
!status = fio_get_field(isrc, FIO_VECTOR_POTENTIAL, F%FIO_A)
F%FIO_A=-1
!write(6,*) 'time_of_filenames',time_of_filenames
!write(6,*) 'ind_2x1t',F%ind_2x1t
if (F%ReInterp_2x1t) then
!status = fio_get_real_field_parameter(F%FIO_B, FIO_TIME, time0)
time0=params%time_of_filenames(F%ind_2x1t)
write(output_unit_write,*) 'FIO present time index',F%ind_2x1t
write(output_unit_write,*) 'FIO present time',time0
!status = fio_set_int_option(FIO_TIMESLICE, F%ind_2x1t+1)
!status = fio_get_field(isrc, FIO_MAGNETIC_FIELD, FIO_tmp)
!status = fio_get_real_field_parameter(FIO_tmp, FIO_TIME, time1)
time1=params%time_of_filenames(F%ind_2x1t+1)
write(output_unit_write,*) 'FIO next time index',F%ind_2x1t+1
write(output_unit_write,*) 'FIO next time',time1
!status = fio_set_int_option(FIO_TIMESLICE, F%ind_2x1t)
params%snapshot_frequency=time1-time0
!write(6,*) 'snapshot_frequency',params%snapshot_frequency
!write(6,*) 'dt',params%dt
if (.not.init) then
params%t_skip = FLOOR(params%snapshot_frequency/params%cpp%time/ &
params%dt,ip)
end if
end if
if (.not.F%Efield) F%FIO_E=-1
status = fio_set_int_option(FIO_SPECIES, FIO_ELECTRON);
status = fio_get_field(isrc, FIO_DENSITY, P%FIO_ne);
!status = fio_get_field(isrc, FIO_TEMPERATURE, P%FIO_te);
!status = fio_set_int_option(FIO_SPECIES, FIO_MAIN_ION);
!status = fio_get_field(isrc, FIO_DENSITY, P%FIO_ni);
if (init) then
if (.NOT.(params%restart.OR.params%proceed)) then
hint_tmp=c_null_ptr
x(1)=spp(1)%Ro
x(2)=spp(1)%PHIo
x(3)=spp(1)%Zo
status = fio_eval_field(F%FIO_B, x(1), &
Btmp(1),hint_tmp)
F%Bo = Btmp(2)
F%Eo = 1.0
F%Ro = 1.0
F%Zo = 1.0
end if
do ii = 1, params%num_species
do pp = 1, spp(ii)%ppp
status = fio_allocate_search_hint(isrc, spp(ii)%vars%hint(pp))
!spp(ii)%vars%hint(pp)=c_null_ptr
end do
spp(ii)%vars%cart = .false.
end do
end if
if (params%mpi_params%rank .EQ. 0) then
write(output_unit_write,*) 'Calculate B',F%FIO_B
write(output_unit_write,*) 'Calculate E',F%FIO_E
write(output_unit_write,*) 'Calculate ne',P%FIO_ne
end if
END SUBROUTINE initialize_nimrod