92 procedure(openfile_deferred),
DEFERRED ::
openfile
93 procedure(closefile_deferred),
DEFERRED ::
closefile
96 procedure(getstatus_deferred),
DEFERRED ::
getstatus
105 CHARACTER(LEN=FNAMLEN) :: filename
106 CHARACTER(LEN=FPATLEN) :: path
107 CHARACTER(LEN=FEXTLEN) :: extension
125 INTEGER :: basictype,& !< basic MPI data type
126 cfiletype,& !< data types for MPI i/o
128 INTEGER,
DIMENSION(MPI_STATUS_SIZE) :: status
143 LOGICAL :: cartcoords
148 INTEGER :: inum,jnum,& !< local mesh extent
164 procedure(initfileio_deferred),
DEFERRED :: initfileio_deferred
167 procedure(writeheader),
DEFERRED :: writeheader
169 procedure(writedataset_deferred),
DEFERRED :: writedataset_deferred
179 SUBROUTINE initfilehandle_deferred(this,filename,path,extension,textfile,onefile,cycles,unit)
184 CHARACTER(LEN=*),
INTENT(IN) :: filename
185 CHARACTER(LEN=*),
INTENT(IN) :: path
186 CHARACTER(LEN=*),
OPTIONAL,
INTENT(IN) :: extension
187 LOGICAL,
OPTIONAL,
INTENT(IN) :: textfile
188 LOGICAL,
OPTIONAL,
INTENT(IN) :: onefile
189 INTEGER,
OPTIONAL,
INTENT(IN) :: cycles
190 INTEGER,
OPTIONAL,
INTENT(IN) :: unit
192 SUBROUTINE openfile_deferred(this,action,step)
197 INTEGER,
INTENT(IN) :: action
198 INTEGER,
INTENT(IN) :: step
200 SUBROUTINE closefile_deferred(this,step)
205 INTEGER,
INTENT(IN) :: step
207 FUNCTION getbasename_deferred(this,step)
RESULT (fname)
212 INTEGER,
INTENT(IN) :: step
213 CHARACTER(LEN=256) :: fname
215 FUNCTION getfilename_deferred(this,step)
RESULT (fname)
220 INTEGER,
INTENT(IN) :: step
221 CHARACTER(LEN=256) :: fname
223 FUNCTION getstatus_deferred(this,step)
RESULT(fstatus)
228 INTEGER,
INTENT(IN) :: step
231 SUBROUTINE initfileio_deferred(this,Mesh,Physics,Timedisc,Sources,config,IO)
240 TYPE(
dict_typ),
INTENT(IN),
POINTER :: config
241 TYPE(
dict_typ),
INTENT(IN),
POINTER :: IO
243 SUBROUTINE writedataset_deferred(this,Mesh,Physics,Fluxes,Timedisc,Header,IO)
251 TYPE(
dict_typ),
POINTER :: Header,IO
253 SUBROUTINE writeheader(this,Mesh,Physics,Header,IO)
259 TYPE(
dict_typ),
POINTER :: Header,IO
288 INTEGER,
PARAMETER ::
vtk = 4
321 CHARACTER(LEN=*),
INTENT(IN) :: filename
322 CHARACTER(LEN=*),
INTENT(IN) :: path
323 CHARACTER(LEN=*),
OPTIONAL,
INTENT(IN) :: extension
324 LOGICAL,
OPTIONAL,
INTENT(IN) :: textfile
326 CALL new_fh%InitFilehandle(filename,path,extension,textfile)
330 SUBROUTINE initfilehandle(this,filename,path,extension,textfile,onefile,cycles,unit)
334 CHARACTER(LEN=*),
INTENT(IN) :: filename
335 CHARACTER(LEN=*),
INTENT(IN) :: path
336 CHARACTER(LEN=*),
OPTIONAL,
INTENT(IN) :: extension
337 LOGICAL,
OPTIONAL,
INTENT(IN) :: textfile
338 LOGICAL,
OPTIONAL,
INTENT(IN) :: onefile
339 INTEGER,
OPTIONAL,
INTENT(IN) :: cycles
340 INTEGER,
OPTIONAL,
INTENT(IN) :: unit
342 IF (.NOT.this%Initialized())
CALL this%InitLogging(
fortranfile,
"fortran")
344 IF (len_trim(filename).GT.
fnamlen) &
345 CALL this%Error(
"fileio_base::InitFilehandle",
"file name too long")
346 this%filename = filename
348 IF (len_trim(path).GT.
fpatlen) &
349 CALL this%Error(
"fileio_base::InitFilehandle",
"file path too long")
351 IF (
PRESENT(textfile))
THEN
352 this%textfile = textfile
354 this%textfile = .true.
357 IF (
PRESENT(extension))
THEN
358 IF (len_trim(extension).GT.
fextlen) &
359 CALL this%Error(
"fileio_base::InitFilehandle",
"file name extension too long")
360 this%extension = extension
362 IF (this%textfile)
THEN
363 this%extension =
"txt"
365 this%extension =
"bin"
368 IF (
PRESENT(onefile))
THEN
369 this%onefile = onefile
371 this%onefile = .false.
373 IF (
PRESENT(cycles))
THEN
378 IF (
PRESENT(unit))
THEN
380 CALL this%Error(
"filehandle_fortran::InitFilehandle",
"fortran i/o unit number already assigned")
390 SUBROUTINE initfileio_base(this,Mesh,Physics,Timedisc,Sources,config,IO,fmtname,fext,textfile)
398 TYPE(
dict_typ),
INTENT(IN),
POINTER :: config
399 TYPE(
dict_typ),
INTENT(IN),
POINTER :: IO
400 CHARACTER(LEN=*),
INTENT(IN) :: fmtname
401 CHARACTER(LEN=*),
INTENT(IN) :: fext
402 LOGICAL,
OPTIONAL,
INTENT(IN) :: textfile
404 INTEGER :: fileformat
405 CHARACTER(LEN=MAX_CHAR_LEN) :: fname
406 CHARACTER(LEN=MAX_CHAR_LEN) :: fpath
409 CHARACTER(LEN=32) :: timestamp
410 INTEGER :: cycles,dtwall,cartcoords
414 CALL getattr(config,
"fileformat", fileformat)
416 CALL this%InitLogging(fileformat,fmtname)
419 CALL getattr(config,
"filename" , fname)
421 CALL getattr(config,
"filepath" , fpath, fpath)
424 CALL getattr(config,
"count" , this%count, 1)
430 CALL getattr(config,
"filecycles", cycles, this%count+1)
433 CALL this%Error(
"fileio_base::InitFileIO_base",
"file cycles exceed limits")
435 IF (cycles.GT.1)
THEN
441 CALL getattr(config,
"unit" , unit ,
lastunit+1)
445 CALL getattr(config,
"dtwall" , this%dtwall, 3600)
448 CALL getattr(config,
"stoptime" , this%stoptime, timedisc%stoptime)
449 CALL getattr(config,
"walltime" , this%walltime, huge(1.0))
452 CALL getattr(config,
"step", this%step, 0)
456 CALL getattr(config,
"cartcoords", cartcoords, 1)
457 IF (cartcoords.EQ.0)
THEN
458 this%cartcoords = .false.
460 this%cartcoords = .true.
464 IF (.NOT.
ALLOCATED(this%datafile))
THEN
472 CALL this%datafile%InitFilehandle(fname,fpath,fext,textfile,onefile,cycles,unit)
474 this%starttime = timedisc%time
475 this%time = this%starttime
479 CALL this%Info(
" FILEIO---> file type: " // trim(this%GetName()))
480 CALL this%Info(
" file name: " // trim(this%datafile%GetFilename(this%step)))
481 WRITE (timestamp,
'(ES12.4)') timedisc%time
482 CALL this%Info(
" time stamp: " // trim(timestamp))
483 IF (.NOT.this%cartcoords) &
484 CALL this%Info(
" cruvilinear coords: yes")
487 IF (timedisc%time.GT.0.0)
CALL this%IncTime()
522 TYPE(
dict_typ),
POINTER :: Header,IO
525 IF (
ASSOCIATED(timedisc%w))
THEN
526 SELECT CASE(mesh%fargo%GetDirection())
528 CALL physics%AddBackgroundVelocityX(mesh,timedisc%w,timedisc%pvar,timedisc%cvar)
530 CALL physics%AddBackgroundVelocityY(mesh,timedisc%w,timedisc%pvar,timedisc%cvar)
532 CALL physics%AddBackgroundVelocityZ(mesh,timedisc%w,timedisc%pvar,timedisc%cvar)
537 IF ((.NOT.this%datafile%onefile).OR.this%step.EQ.0)
THEN
538 CALL this%datafile%OpenFile(
replace,this%step)
539 CALL this%WriteHeader(mesh,physics,header,io)
541 CALL this%datafile%OpenFile(
append,this%step)
545 CALL this%WriteDataset_deferred(mesh,physics,fluxes,timedisc,header,io)
548 CALL this%datafile%CloseFile(this%step)
560 CHARACTER(LEN=*) :: res
561 CHARACTER(LEN=*) :: littlestr
562 CHARACTER(LEN=*) :: bigstr
565 CHARACTER,
POINTER :: cTIPO(:)
567 INTENT(IN) :: littlestr, bigstr
571 k = bit_size(itipo)/8
572 ALLOCATE(ctipo(k),stat = this%err)
574 CALL this%Error(
"GetEndianness",
"Unable to allocate memory.")
579 itipo = transfer(ctipo, itipo)
582 IF (btest(itipo,1))
THEN
583 write(res,
'(A)',iostat=this%err)bigstr
585 write(res,
'(A)',iostat=this%err)littlestr
612 INTENT(INOUT) :: time,dt,dtcause
614 IF ((time+dt)/
this%time.GT.1.0)
THEN
615 dt =
this%time - time
617 ELSE IF((time+1.5*dt)/
this%time.GT.1.0)
THEN
618 dt = 0.5*(
this%time - time)
631 IF (.NOT.this%Initialized()) &
632 CALL this%Error(
"fileio_base::Finalize_base",
"FileIO not initialized")
633 IF (
ALLOCATED(this%datafile))
DEALLOCATE(this%datafile)
642 INTEGER,
INTENT(IN) :: action
643 INTEGER,
INTENT(IN) :: step
645 CHARACTER(LEN=32) :: sta,act,pos,frm
665 CALL this%Error(
"fileio_base::OpenFile",
"Unknown access mode.")
668 CALL this%CloseFile(step)
670 OPEN(unit=this%GetUnitNumber(),file=trim(this%GetFilename(step)),status=trim(sta), &
671 access=
'STREAM',action=trim(act),position=trim(pos),form=trim(this%GetFormat()), &
674 CALL this%Error(
"fileio_base::OpenFile",
"File opening failed for: " // &
675 trim(this%GetFilename(step)))
694 INTEGER,
INTENT(IN) :: step
698 CHARACTER(LEN=64) :: act,pos
701 print *,
"DEBUG INFO in fileio_base::GetStatus: called for " // trim(
this%GetFilename(step)), &
702 ", unit:",
this%GetUnitNumber()
706 act=
"NO-RETURN-VALUE"
707 pos=
"NO-RETURN-VALUE"
708 INQUIRE(file=trim(
this%GetFilename(step)),exist=ex,opened=op,action=act,position=pos,iostat=
this%err)
710 print *,
"DEBUG INFO in fileio_base::GetStatus: inquire results (ex,op,act,pos): ", &
711 ex, op,
" " // trim(act) //
" " // trim(pos)
714 CALL this%Error(
"filehandle_fortran::GetStatus",
"serious failure during file inquiry")
720 SELECT CASE(trim(act))
722 SELECT CASE(trim(pos))
728 CASE(
"WRITE",
"READWRITE")
729 SELECT CASE(trim(pos))
753 IF (
this%textfile)
THEN
765 INTEGER,
INTENT(IN) :: step
768 CHARACTER(LEN=16) :: fmtstr
770 WRITE (fmtstr ,
'(A,I1,A)')
"(A1,I0.",
fcyclen-1,
")"
774 ELSE IF (step.EQ.0)
THEN
790 INTEGER,
INTENT(IN) :: step
791 CHARACTER(LEN=256) :: fname
793 IF (
this%onefile)
THEN
795 fname = trim(
this%filename)
798 fname = trim(
this%filename) // trim(
this%GetStepString(step))
807 INTEGER,
INTENT(IN) :: step
820 INTEGER,
INTENT(IN) :: step
823 print *,
"DEBUG INFO in fileio_base::CloseFile: called for " // trim(this%GetFilename(step)), &
824 ", unit:", this%GetUnitNumber()
827 IF (this%GetStatus(step).GT.0)
THEN
828 IF (this%err.EQ.0)
THEN
830 print *,
"DEBUG INFO in fileio_base::CloseFile: closing file ..."
832 CLOSE(unit=this%GetUnitNumber(),iostat=this%err)
835 IF (this%err.NE.0)
THEN
837 print *,
"DEBUG INFO in fileio_base::CloseFile: Fatal error IOSTAT=",this%err
839 CALL this%Error(
"filehandle_fortran::CloseFile",
"Cannot close file " // &
840 trim(this%GetFilename(step)))
852 INQUIRE(unit=this%GetUnitNumber(),opened=op,iostat=this%err)
853 IF (this%err.EQ.0)
CLOSE(unit=this%GetUnitNumber(),iostat=this%err)
863 INTEGER,
INTENT(IN) :: action
864 INTEGER,
INTENT(IN) :: step
866 INTEGER(KIND=MPI_OFFSET_KIND) :: offset
867 INTEGER :: amode,smode,fstatus
869 this%err = mpi_success
870 CALL this%CloseFile(step)
871 IF (this%err.EQ.mpi_success)
THEN
875 amode = mpi_mode_rdonly
879 amode = ior(mpi_mode_rdonly,mpi_mode_append)
883 fstatus = this%GetStatus(step)
884 IF (fstatus.EQ.
closed)
THEN
887 IF (this%GetRank().EQ.0) &
888 CALL mpi_file_delete(trim(this%GetFilename(step)),fstatus,this%err)
889 IF (this%err.NE.mpi_success) &
890 CALL this%Error(
"fileio_base::OpenFile_mpi",
"cannot delete file " // &
891 trim(this%GetFilename(step)))
893 amode = ior(mpi_mode_wronly,mpi_mode_create)
897 amode = ior(mpi_mode_rdwr,mpi_mode_append)
902 CALL this%Error(
"fileio_base::OpenFile_mpi",
"Unknown access mode.")
904 IF (this%err.EQ.mpi_success)
THEN
905 CALL mpi_file_open(mpi_comm_world,trim(this%GetFilename(step)),amode, &
906 mpi_info_null,this%fid,this%err)
907 IF (this%err.EQ.mpi_success)
CALL mpi_file_seek(this%GetUnitNumber(),offset,smode,this%err)
908 IF (this%err.EQ.mpi_success)
CALL mpi_file_sync(this%GetUnitNumber(),this%err)
911 IF (this%err.NE.mpi_success) &
912 CALL this%Error(
"fileio_base::OpenFile_mpi",
"file open failed, aborting")
920 CHARACTER(LEN=*),
INTENT(IN) :: filename
921 CHARACTER(LEN=*),
INTENT(IN) :: path
922 CHARACTER(LEN=*),
OPTIONAL,
INTENT(IN) :: extension
923 LOGICAL,
OPTIONAL,
INTENT(IN) :: textfile
924 LOGICAL,
OPTIONAL,
INTENT(IN) :: onefile
925 INTEGER,
OPTIONAL,
INTENT(IN) :: cycles
926 INTEGER,
OPTIONAL,
INTENT(IN) :: unit
928 IF (.NOT.this%Initialized())
CALL this%InitLogging(
mpifile,
"mpi")
929 CALL this%filehandle_fortran%InitFilehandle(filename,path,extension,textfile,onefile,cycles,unit)
931 this%fid = mpi_file_null
939 INTEGER,
INTENT(IN) :: step
941 INTEGER :: filestatus
945 this%err = mpi_success
947 IF (
this%GetUnitNumber().NE.mpi_file_null)
THEN
949 CALL mpi_file_get_amode(
this%GetUnitnumber(),amode,
this%err)
950 IF (
this%err.NE.mpi_success) &
951 CALL this%Error(
"filehandle_mpi::GetStatus",
"cannot determine file access mode")
953 IF (iand(amode,mpi_mode_rdonly).GT.0)
THEN
954 IF (iand(amode,mpi_mode_append).GT.0)
THEN
959 ELSE IF (iand(amode,ior(mpi_mode_wronly,mpi_mode_create)).GT.0)
THEN
961 ELSE IF (iand(amode,ior(mpi_mode_rdwr,mpi_mode_append)).GT.0)
THEN
970 CALL mpi_file_open(mpi_comm_world,trim(
this%GetFilename(step)),mpi_mode_rdonly, &
973 IF (
this%err.EQ.mpi_success)
THEN
974 CALL mpi_file_sync(
this%GetUnitNumber(),
this%err)
975 IF (
this%err.EQ.mpi_success.AND.
this%GetUnitnumber().NE.mpi_file_null)
THEN
976 CALL mpi_file_close(
this%fid,
this%err)
977 IF (
this%err.NE.mpi_success) &
978 CALL this%Error(
"filehandle_mpi::GetStatus",
"cannot close file")
980 this%fid = mpi_file_null
985 this%err = mpi_success
995 INTEGER,
INTENT(IN) :: step
997 this%err = mpi_success
998 IF (this%GetStatus(step).GT.0)
THEN
999 IF (this%err.EQ.mpi_success)
CALL mpi_file_close(this%fid,this%err)
1000 this%fid = mpi_file_null
1002 IF (this%err.NE.mpi_success) &
1003 CALL this%Error(
"filehandle_mpi::CloseFile",
"Cannot close file " // trim(this%GetFilename(step)))
1014 IF (this%GetUnitNumber().NE.mpi_file_null) &
1015 CALL mpi_file_close(this%fid,this%err)
1016 IF (this%err.NE.mpi_success) &
1017 CALL this%Error(
"filehandle_mpi::Finalize",
"serious error occured while close file")
Dictionary for generic data types.
type(logging_base), save this
integer, parameter, public xdmf
integer, parameter readend
readonly access at end
subroutine finalize_fortran(this)
destructor of Fortran stream handle
subroutine initfilehandle_mpi(this, filename, path, extension, textfile, onefile, cycles, unit)
basic initialization of MPI file handle
integer, parameter readonly
readonly access
integer function getstatus(this, step)
get Fortran file status
subroutine initfileio_base(this, Mesh, Physics, Timedisc, Sources, config, IO, fmtname, fext, textfile)
Basic FileIO initialization.
integer, parameter closed
file closed
pure character(len=fcyclen) function getstepstring(this, step)
Get the time step as string with leading zeros.
character(len=16) function getformat(this)
get Fortran i/o format string
integer, parameter fortranfile
subroutine closefile_mpi(this, step)
close MPI file
integer, parameter append
read/write access at end
subroutine getendianness(this, res, littlestr, bigstr)
Determines the endianness of the system.
subroutine writedataset(this, Mesh, Physics, Fluxes, Timedisc, Header, IO)
Write all data registered for output to the data file.
subroutine initfilehandle(this, filename, path, extension, textfile, onefile, cycles, unit)
basic initialization of Fortran file handle
type(filehandle_fortran) function createfilehandle(filename, path, extension, textfile)
constructor for Fortran file handle
integer, parameter, public vtk
character(len=256) function getfilename(this, step)
Return file name of Fortran stream with full path and extension.
integer, parameter, public gnuplot
integer function getstatus_mpi(this, step)
get MPI file status
integer, parameter fextlen
file name extension length
integer, parameter fpatlen
file path length (without file name)
pure subroutine inctime(this)
Increments the counter for timesteps and sets the time for next output.
integer, parameter replace
read/write access replacing file
subroutine closefile(this, step)
close Fortran stream
integer, parameter, public binary
file I/O types
integer function getunitnumber(this)
get Fortran i/o unit number
character(len=256) function getbasename(this, step)
get the file name without path and extension but with step string appended; if thisonefile suppress t...
integer, parameter fcyclen
length of timestep string
integer, parameter open_undef
open with undefined io action/position
integer, parameter maxcycles
max. number of data files (not counting multiple files per time step in parallel mode)
subroutine openfile_mpi(this, action, step)
Open file for input/ouput in parallel mode.
subroutine finalize_mpi(this)
destructor of MPI file handle handle
integer, parameter mpifile
integer, parameter fnamlen
file name length (without any extension)
subroutine openfile(this, action, step)
Open file to access Fortran stream.
base module for numerical flux functions
subroutine finalize(this)
Destructor of logging_base class.
integer, save default_mpi_real
default real type for MPI
module to manage list of source terms
subroutine finalize_base(this)
integer, parameter, public dtcause_fileio
smallest ts due to fileio
real function adjusttimestep(this, maxerr, dtold)
adjust the time step
class basic (abstract) class for file handles
class for Fortran file handle
class for MPI file handle
container class to manage the list of source terms