"""
Fortran module IOOps: July 2017 (dj, updated)
Handling of filenames, closing and opening units
**Authors**
* D. Jaschke
* M. L. Wall
**Details**
Defines a set of methods for input/output inside the MPS.
The following public subroutines / functions are defined depending
on the data type.
+------------------------------+-------------+
| procedure | include.f90 |
+==============================+=============+
| append_basename | X |
+------------------------------+-------------+
| create_filename | X |
+------------------------------+-------------+
| create_IOObject | X |
+------------------------------+-------------+
| delete_file | X |
+------------------------------+-------------+
| io_get_obsin | X |
+------------------------------+-------------+
| io_get_tconv | X |
+------------------------------+-------------+
| io_get_quench | X |
+------------------------------+-------------+
| io_get_obs | X |
+------------------------------+-------------+
| io_get_tobs | X |
+------------------------------+-------------+
| io_get_ftobs | X |
+------------------------------+-------------+
| io_get_measmpo | X |
+------------------------------+-------------+
| io_get_ftconv | X |
+------------------------------+-------------+
| io_get_ftquench | X |
+------------------------------+-------------+
| read_n | X |
+------------------------------+-------------+
"""
[docs]def append_basename_real():
"""
fortran-subroutine - July 2017 (dj, updated)
Append to a file name the character string partName followed by
the value partValue to partDigs digits for real numbers.
**Arguments**
basename : CHARACTER(\*), inout
The base string where additional information is attached to.
partname : CHARACTER(*), in
string to be appended to the `basename`.
partdigs : INTEGER, in
Number of digits in floating point number.
partvalue : REAL, in
Float to be appended to the `basename` after the `partname`.
**Source Code**
.. hidden-code-block:: fortran
:label: show / hide f90 code
subroutine append_basename_real(basename, partname, partdigs, partvalue)
character(len=*), intent(inout) :: basename
character(len=*), intent(in) :: partname
integer, intent(in) :: partdigs
real(KIND=rKind), intent(in) :: partvalue
! Local variables
! ---------------
! for the string specifier
character(16) :: iwstring, specstring
! Write the number of decimal places wanted into a string
write(iwstring, '(I4)') partdigs
! Generate the format type for a float string with partDigs
! decimal places
specstring = "(1f16."//trim(adjustl(iwstring))//")"
! Write the value partValue to a string using partDigs decimal places
write(iwstring, specstring) partvalue
! append partname and the value to the given basename
basename = trim(basename)//partName//trim(adjustl(iwstring))
end subroutine append_basename_real
"""
return
[docs]def append_basename_integer():
"""
fortran-subroutine - July 2017 (dj, updated)
Append to a file name the character string partName followed by
the value partValue for integers.
**Arguments**
basename : CHARACTER(\*), inout
The base string where additional information is attached to.
partname : CHARACTER(*), in
string to be appended to the `basename`.
partvalue : INTEGER, in
integer to be appended to the `basename` after the `partname`.
**Source Code**
.. hidden-code-block:: fortran
:label: show / hide f90 code
subroutine append_basename_integer(basename, partname, partvalue)
CHARACTER(len=*), INTENT(INOUT) :: baseName
CHARACTER(len=*), INTENT(IN) :: partname
INTEGER, INTENT(IN) :: partValue
! Local variables
! ---------------
! for the string specifier
character(16) :: iwstring, specstring
! Write the number of digits wanted into a string
write(iwstring, '(I4)') 16
! Generate the format type for an integer string with
! partDigs digits
specstring = "(I"//trim(adjustl(iwstring))//")"
! Write the value partValue to a string using partDigs digits
write(iwstring, specstring) partvalue
! append partname and the value to the given basename
basename = trim(basename)//partname//trim(adjustl(iwstring))
end subroutine append_basename_integer
"""
return
[docs]def append_basename_string():
"""
fortran-subroutine - July 2017 (dj, updated)
Append to a file name the character string partName
**Arguments**
basename : CHARACTER(*), inout
Append to the input string the string `partname`
partname : CHARACTER(*), in
string to be appended to the `basename`
**Source Code**
.. hidden-code-block:: fortran
:label: show / hide f90 code
subroutine append_basename_string(basename, partname)
character(len=*), intent(inout) :: basename
character(len=*), intent(in) :: partname
! No local variables
! ------------------
basename = trim(basename)//trim(partname)
end subroutine append_basename_string
"""
return
[docs]def create_IOObject():
"""
fortran-subroutine - August 2016 (dj)
Initialize IOObject.
**Arguments**
IOObj : TYPE(IOObj), out
Object containing all information about directories
and filenames on exit.
writedir : CHARACTER(132), in
Name of the temporary directory for simulations.
outdir : CHARACTER(132), in
Name of the output directory for simulations.
job_id : CHARACTER(132), in
Name of the set of simulations.
unique_id : CHARACTER(132), in
Unique identifier for the specific simulation.
qtid : INTEGER, in
Id for the trajectory if open quantum system with
quantum trajectories.
**Details**
(defined in IOOps.f90)
**Source Code**
.. hidden-code-block:: fortran
:label: show / hide f90 code
subroutine create_IOObject(IOObj, writedir, outdir, job_id, unique_id, qtid)
type(IOObject), intent(out) :: IOObj
character(len=132), intent(in) :: writedir, outdir, job_id, unique_id
integer, intent(in) :: qtid
! Take care of qtidstr
if(qtid /= 0) then
write(IOObj%qtidstr, '(A3,I9.9)') '_qt', qtid
end if
call create_filename(IOObj%outdir, outdir)
call create_filename(IOObj%writedir, writedir)
! Create basis name for write
call create_filename(IOObj%basewrite, writedir)
call append_basename(IOObj%basewrite, job_id)
call append_basename(IOObj%basewrite, unique_id)
! Create basis name for output
call create_filename(IOObj%baseout, outdir)
call append_basename(IOObj%baseout, job_id)
call append_basename(IOObj%baseout, unique_id)
! Create filename for MPOs
IOObj%mponame = IOObj%basewrite
call append_basename(IOObj%mponame, 'Hamirules')
call append_basename(IOObj%mponame, IOObj%qtidstr)
call append_basename(IOObj%mponame, '.dat')
! Create filename for Operators
IOObj%opsname = IOObj%basewrite
call append_basename(IOObj%opsname, 'Ops')
call append_basename(IOObj%opsname, IOObj%qtidstr)
call append_basename(IOObj%opsname, '.dat')
! Create filename for quantum numbers
IOObj%qname = IOObj%basewrite
call append_basename(IOObj%qname, 'qnumbers')
call append_basename(IOObj%qname, IOObj%qtidstr)
call append_basename(IOObj%qname, '.dat')
! Create filename for initial q-state
IOObj%qstatename = IOObj%basewrite
call append_basename(IOObj%qstatename, 'InitialState')
call append_basename(IOObj%qstatename, IOObj%qtidstr)
call append_basename(IOObj%qstatename, '.dat')
! Create filename for hparams
IOObj%hparamsname = IOObj%basewrite
call append_basename(IOObj%hparamsname, 'HamiParams')
call append_basename(IOObj%hparamsname, IOObj%qtidstr)
call append_basename(IOObj%hparamsname, '.dat')
! Create filename for infinite MPS
IOObj%infname = IOObj%basewrite
call append_basename(IOObj%infname, 'MPS.dat')
! Create filename for convergence MPS
IOObj%convname = IOObj%basewrite
call append_basename(IOObj%convname, 'MPS')
call append_basename(IOObj%convname, IOObj%qtidstr)
call append_basename(IOObj%convname, '.dat')
! Create filename for convergence eMPS
IOObj%econvname = IOObj%basewrite
call append_basename(IOObj%econvname, 'eMPS')
call append_basename(IOObj%econvname, IOObj%qtidstr)
call append_basename(IOObj%econvname, '.dat')
! Create filename for checkpoint in tMPS
IOObj%lastmps = IOObj%baseout
call append_basename(IOObj%lastmps, '_time_last')
call append_basename(IOObj%lastmps, IOObj%qtidstr)
call append_basename(IOObj%lastmps, '.dat')
! Create filename for dynamics
IOObj%dynname = IOObj%basewrite
call append_basename(IOObj%dynname, 'Dynamics')
call append_basename(IOObj%dynname, IOObj%qtidstr)
call append_basename(IOObj%dynname, '.dat')
! Create filename for finite T
IOObj%finitetname = IOObj%basewrite
call append_basename(IOObj%finitetname, 'MPSDynamics.dat')
! create base filename for static output
IOObj%obsname = IOObj%baseout
call append_basename(IOObj%obsname, 'ObsOut')
! create base filename for convergence parameters dynamics
IOObj%tconvname = IOObj%basewrite
call append_basename(IOObj%tconvname, 'tMPS')
! create base filename for quench
IOObj%quenchname = IOObj%basewrite
call append_basename(IOObj%quenchname, 'Quench')
! create base filename for ii-th output in quench
IOObj%tobsname = IOObj%baseout
call append_basename(IOObj%tobsname, 'ObsOutDynamics/')
! create base filename for measurement-MPOs
IOObj%measmponame = IOObj%basewrite
call append_basename(IOObj%measmponame, 'ObsMPO')
end subroutine create_IOObject
"""
return
[docs]def delete_file():
"""
fortran-subroutine - August 2017 (dj)
Delete the file.
**Arguments**
flnm : CHARACTER(\*), in
This file should be deleted.
unit : INTEGER, in
Open file on this unit to delete it.
**Source Code**
.. hidden-code-block:: fortran
:label: show / hide f90 code
subroutine delete_file(flnm, unit)
character(len=*), intent(in) :: flnm
integer, intent(in) :: unit
! No local variables
! ------------------
open(unit=unit, file=trim(adjustl(flnm)), action='read')
close(unit, status='delete')
end subroutine delete_file
"""
return
[docs]def io_get_obsin():
"""
fortran-function - ?? (mlw)
Build filename for reading observable setup in statics.
**Arguments**
IOObj : TYPE(IOObject), in
Object containing all necessary information to build
filenames.
extrastub : CHARACTER(\*), in
Additional string attached to filename.
**Source Code**
.. hidden-code-block:: fortran
:label: show / hide f90 code
function io_get_obsin(IOObj, extrastub) result(obsname)
type(IOObject), intent(in) :: IOObj
character(len=*), intent(in) :: extrastub
character(len=132) :: obsname
obsname = IOObj%basewrite
call append_basename(obsname, extrastub)
call append_basename(obsname, 'Obs')
!if(len(trim(extrastub)) > 1) then
! ! extrastub = 'Dynamics'
call append_basename(obsname, IOObj%qtidstr)
!end if
call append_basename(obsname, '.dat')
end function io_get_obsin
"""
return
[docs]def io_get_tconv():
"""
fortran-function - ?? (mlw)
Build filename for ii-th convergence parameters in time evolution.
**Arguments**
IOObj : TYPE(IOObject), in
Object containing all necessary information to build
filenames.
ii : INTEGER, in
Integer identifier for the ii-th quench.
**Source Code**
.. hidden-code-block:: fortran
:label: show / hide f90 code
function io_get_tconv(IOObj, ii) result(convname)
type(IOObject), intent(in) :: IOObj
integer, intent(in) :: ii
character(len=132) :: convname
convname = IOObj%tconvname
call append_basename(convname, '_', ii)
call append_basename(convname, IOObj%qtidstr)
call append_basename(convname, '.dat')
end function io_get_tconv
"""
return
[docs]def io_get_quench():
"""
fortran-function - ?? (mlw)
Build filename for ii-th quench in time evolution.
**Arguments**
IOObj : TYPE(IOObject), in
Object containing all necessary information to build
filenames.
ii : INTEGER, in
Integer identifier for the ii-th quench.
**Source Code**
.. hidden-code-block:: fortran
:label: show / hide f90 code
function io_get_quench(IOObj, ii) result(quenchname)
type(IOObject), intent(in) :: IOObj
integer, intent(in) :: ii
character(len=132) :: quenchname
quenchname = IOObj%quenchname
call append_basename(quenchname, '_', ii)
call append_basename(quenchname, IOObj%qtidstr)
call append_basename(quenchname, '.dat')
end function io_get_quench
"""
return
[docs]def io_get_obs():
"""
fortran-function - ?? (mlw)
Build filename for ii-th output in statics.
**Arguments**
IOObj : TYPE(IOObject), in
Object containing all necessary information to build
filenames.
ii : INTEGER, in
Integer identifier for the ground and excited states.
jj : INTEGER, in
Integer identifier for the convergence parameter.
**Source Code**
.. hidden-code-block:: fortran
:label: show / hide f90 code
function io_get_obs(IOObj, ii, jj) result(obsname)
type(IOObject), intent(in) :: IOObj
integer, intent(in) :: ii
integer, intent(in), optional :: jj
character(len=132) :: obsname
obsname = IOObj%obsname
call append_basename(obsname, '', ii)
if(present(jj)) call append_basename(obsname, '_', jj)
call append_basename(obsname, '.dat')
end function io_get_obs
"""
return
[docs]def io_get_tobs():
"""
fortran-function - ?? (mlw)
Build filename for ii-th output in time evolution.
**Arguments**
IOObj : TYPE(IOObject), in
Object containing all necessary information to build
filenames.
ii : INTEGER, in
Integer identifier for the ii-th quench.
**Source Code**
.. hidden-code-block:: fortran
:label: show / hide f90 code
function io_get_tobs(IOObj, ii) result(obsname)
type(IOObject), intent(in) :: IOObj
integer, intent(in) :: ii
character(len=132) :: obsname
obsname = IOObj%tobsname
call append_basename(obsname, 'Dynamics_', ii)
!call append_basename(obsname, IOObj%qtidstr)
!call append_basename(obsname, '.dat')
end function io_get_tobs
"""
return
[docs]def io_get_ftobs():
"""
fortran-function - ?? (mlw)
Build filename for ii-th output in time evolution.
**Arguments**
IOObj : TYPE(IOObject), in
Object containing all necessary information to build
filenames.
ii : INTEGER, in
Integer identifier for the ii-th quench.
**Source Code**
.. hidden-code-block:: fortran
:label: show / hide f90 code
function io_get_ftobs(IOObj, ii) result(obsname)
type(IOObject), intent(in) :: IOObj
integer, intent(in) :: ii
character(len=132) :: obsname
obsname = IOObj%baseout
call append_basename(obsname, 'FiniteT_', ii)
!call append_basename(obsname, IOObj%qtidstr)
!call append_basename(obsname, '.dat')
end function io_get_ftobs
"""
return
[docs]def io_get_measmpo():
"""
fortran-function - ?? (mlw)
Build filename for measurement MPOs.
**Arguments**
IOObj : TYPE(IOObject), in
Object containing all necessary information to build
filenames.
ii : INTEGER, in
Integer identifier.
**Source Code**
.. hidden-code-block:: fortran
:label: show / hide f90 code
function io_get_measmpo(IOObj, ii) result(mponame)
type(IOObject), intent(in) :: IOObj
integer, intent(in) :: ii
character(len=132) :: mponame
mponame = IOObj%measmponame
call append_basename(mponame, '_', ii)
call append_basename(mponame, IOObj%qtidstr)
call append_basename(mponame, '.dat')
end function io_get_measmpo
"""
return
[docs]def io_get_ftconv():
"""
fortran-function - ?? (mlw)
Build filename for ii-th convergence parameters in finite T evolution.
**Arguments**
IOObj : TYPE(IOObject), in
Object containing all necessary information to build
filenames.
ii : INTEGER, in
Integer identifier.
**Source Code**
.. hidden-code-block:: fortran
:label: show / hide f90 code
function io_get_ftconv(IOObj, ii) result(convname)
type(IOObject), intent(in) :: IOObj
integer, intent(in) :: ii
character(len=132) :: convname
convname = IOObj%basewrite
call append_basename(convname, 'MPStMPS')
call append_basename(convname, '_', ii)
call append_basename(convname, '.dat')
end function io_get_ftconv
"""
return
[docs]def io_get_ftquench():
"""
fortran-function - ?? (mlw)
Build filename for ii-th quench in time evolution.
**Arguments**
IOObj : TYPE(IOObject), in
Object containing all necessary information to build
filenames.
ii : INTEGER, in
Integer identifier.
**Source Code**
.. hidden-code-block:: fortran
:label: show / hide f90 code
function io_get_ftquench(IOObj, ii) result(quenchname)
type(IOObject), intent(in) :: IOObj
integer, intent(in) :: ii
character(len=132) :: quenchname
quenchname = IOObj%basewrite
call append_basename(quenchname, 'MPSQuench')
call append_basename(quenchname, '_', ii)
call append_basename(quenchname, '.dat')
end function io_get_ftquench
"""
return
[docs]def read_n_integer():
"""
fortran-subroutine - July 2017 (dj, updated)
Read n contiguous integer numbers from an open file.
**Arguments**
vec : integer(\*), out
The vector to store the values read from the file.
nn : INTEGER, in
Number of entries in the vector.
unit : INTEGER, in
The filehandle is open on this unit.
**Source Code**
.. hidden-code-block:: fortran
:label: show / hide f90 code
subroutine read_n_integer(vec, nn, unit)
integer, intent(out) :: vec(:)
integer, intent(in) :: nn, unit
! Local variables
! ---------------
! for the string specifier
character(16) :: iwstring, specstring
write(iwstring, '(I4)') nn
specString = "("//trim(adjustl(iwstring))//"I16)"
read(unit, specstring) vec
end subroutine read_n_integer
"""
return
[docs]def read_n_real():
"""
fortran-subroutine - July 2017 (dj, updated)
Read n contiguous real(KIND=rKind) numbers from an open file.
**Arguments**
vec : real(KIND=rKind)(\*), out
The vector to store the values read from the file.
nn : INTEGER, in
Number of entries in the vector.
unit : INTEGER, in
The filehandle is open on this unit.
**Source Code**
.. hidden-code-block:: fortran
:label: show / hide f90 code
subroutine read_n_real(vec, nn, unit)
real(KIND=rKind), intent(out) :: vec(:)
integer, intent(in) :: nn, unit
! Local variables
! ---------------
! for the string specifier
character(16) :: iwstring, specstring
write(iwstring, '(I4)') nn
specString = "("//trim(adjustl(iwstring))//"E30.15)"
read(unit, specstring) vec
end subroutine read_n_real
"""
return