63 INTEGER,
PARAMETER :: HLEN = 10000
64 INTEGER,
PARAMETER :: DEFAULT_DECS = 5
66 CHARACTER,
PARAMETER :: SP = achar(32)
67 CHARACTER,
PARAMETER :: LF = achar(10)
68 CHARACTER*2,
PARAMETER :: RECSEP = sp // sp
69 CHARACTER*2,
PARAMETER :: LINSEP = sp // lf
70 CHARACTER*2,
PARAMETER :: BLKSEP = lf // lf
72 CHARACTER(LEN=30),
PARAMETER :: &
73 header_string =
"# Data output of fosite" // linsep
74 CHARACTER(LEN=HLEN) :: header_buf
88 PROCEDURE :: readdataset
90 PROCEDURE :: closefile
94 PROCEDURE :: getfilestatus
115 SUBROUTINE initfileio(this,Mesh,Physics,fmt,fmtname,fpath,filename,extension, &
116 stoptime,dtwall,count,fcycles,sepfiles,unit)
119 CLASS(fileio_base) :: this
120 CLASS(mesh_base) :: Mesh
121 CLASS(physics_base) :: Physics
123 CHARACTER(LEN=*) :: fmtname
124 CHARACTER(LEN=*) :: fpath
125 CHARACTER(LEN=*) :: filename
126 CHARACTER(LEN=*) :: extension
132 INTEGER,
OPTIONAL :: unit
134 INTENT(IN) :: mesh,physics,fmt,fmtname,fpath,filename,extension,stoptime, &
135 dtwall,count,fcycles,sepfiles,unit
136 INTENT(INOUT) :: this
139 CALL this%InitFileIO_common(fmt,fmtname,fpath,filename,extension,fcycles,sepfiles,unit)
141 this%stoptime = stoptime
151 CALL mpi_file_open(mpi_comm_world,
getfilename(this),ior(ior(mpi_mode_rdwr,&
152 mpi_mode_create),ior(mpi_mode_excl,mpi_mode_delete_on_close)),&
153 mpi_info_null,this%handle,this%error)
155 IF (this%error.NE.0)
CALL mpi_file_open(mpi_comm_world,
getfilename(this),&
156 mpi_mode_rdonly,mpi_info_null,this%handle,this%error)
159 IF (this%error.EQ.0)
CALL mpi_file_get_type_extent(this%handle,mpi_integer,&
160 this%intext,this%error)
162 IF (this%error.EQ.0)
CALL mpi_file_get_type_extent(this%handle,
default_mpi_real,&
163 this%realext,this%error)
164 IF (this%error.NE.0)
CALL error(this,
"InitFileIO",
"unable to check file properties")
165 CALL mpi_file_close(this%handle,this%error)
174 SUBROUTINE initfileio_gnuplot(this,Mesh,Physics,IO,fmt,fpath,filename,stoptime,dtwall,&
175 count,fcycles,unit,config)
178 CLASS(fileio_base) :: this
179 CLASS(mesh_base) :: Mesh
180 CLASS(physics_base) :: Physics
181 TYPE(Dict_TYP),
POINTER :: IO
183 TYPE(Dict_TYP),
POINTER,
OPTIONAL :: config
185 CHARACTER(LEN=*) :: fpath
186 CHARACTER(LEN=*) :: filename
193 TYPE(Dict_TYP),
POINTER :: node
194 REAL,
DIMENSION(:,:),
POINTER :: dummy2
195 REAL,
DIMENSION(:,:,:),
POINTER :: dummy3
196 INTEGER :: cartcoords
201 INTEGER,
DIMENSION(Mesh%IMAX-Mesh%IMIN+1) :: blocklen,indices
204 INTENT(IN) :: mesh,physics,fmt,fpath,filename,stoptime,dtwall,count,fcycles,&
206 INTENT(INOUT) :: this
208 CALL this%InitFileIO(mesh,physics,fmt,
"GNUPLOT",fpath,filename,
"dat",stoptime,&
209 dtwall,count,fcycles,.false.,unit)
211 CALL getattr(config,
"/datafile/decimals", this%DECS, default_decs)
216 this%FLEN = this%DECS + 9
217 this%maxcols = len(this%linebuf)/this%FLEN-1
219 ALLOCATE(this%output(this%maxcols),stat=err)
220 IF (this%error.NE.0) &
221 CALL this%Error(
"InitFileIO_gnuplot",
"memory allocation failed for this%output")
225 CALL getattr(config,
"/datafile/cartcoords", cartcoords, 0)
229 IF (cartcoords.EQ.0)
THEN 230 CALL getattr(io,
"/mesh/bary_curv",dummy3)
232 CALL getattr(io,
"/mesh/bary_centers",dummy3)
236 IF (mesh%INUM.EQ.1)
THEN 238 WRITE (this%fmtstr,
'(A5,I2,A1)')
'(A1,A',this%FLEN-3,
')' 239 WRITE(this%linebuf,trim(this%fmtstr))
'#',
'y' 240 this%output(1)%val => dummy3(:,:,2)
242 ELSE IF (mesh%JNUM.EQ.1)
THEN 243 WRITE (this%fmtstr,
'(A5,I2,A1)')
'(A1,A',this%FLEN-3,
')' 244 WRITE(this%linebuf,trim(this%fmtstr))
'#',
'x' 245 this%output(1)%val => dummy3(:,:,1)
248 WRITE (this%fmtstr,
'(A5,I2,A2,I2,A1)')
'(A1,A',this%FLEN-3,
',A',this%FLEN-1,
')' 249 WRITE(this%linebuf,trim(this%fmtstr))
'#',
'x',
'y' 250 this%output(1)%val => dummy3(:,:,1)
251 this%output(2)%val => dummy3(:,:,2)
256 WRITE (this%fmtstr,
'(A,I2,A1)')
'(A',this%FLEN-1,
')' 258 CALL this%GetOutputPointer(mesh,node,this%COLS)
261 this%linelen = this%COLS * this%FLEN
262 IF (this%linelen.GT.len(this%linebuf)) &
263 CALL this%Error(
"InitFileIO_gnuplot", &
264 "linebuffer to small; reducing decimals or number of output fields may help")
266 header_buf = trim(header_string) // trim(header_buf) // this%linebuf(1:this%linelen)
269 this%inum = mesh%IMAX - mesh%IMIN + 1
270 this%jnum = mesh%JMAX - mesh%JMIN + 1
301 WRITE (this%fmtstr,
'(A3,I2,A,I2.2,A5)')
'(ES', this%FLEN-2,
'.', this%DECS,
',A,A)' 303 WRITE (this%linefmt,
'(A,I0,A)')
"(A", this%linelen-1,
")" 312 TYPE(
dict_typ),
POINTER :: root,node,subnode
313 CHARACTER(LEN=*) :: string
314 CHARACTER(LEN=*),
OPTIONAL ::
prefix 315 CHARACTER(LEN=128) :: buf
319 CHARACTER(LEN=128) :: cdummy
322 INTENT(INOUT) :: string,k
326 DO WHILE(
ASSOCIATED(node))
329 CALL getattr(node,
getkey(node),idummy)
330 WRITE(buf,
'(A1,A25,I14,A)')
'#',trim(
getkey(node))//
": ",idummy, linsep
331 WRITE(string(k:),
'(A)')buf
332 k = k + len(trim(buf))
334 CALL getattr(node,
getkey(node),rdummy)
335 WRITE(buf,
'(A1,A25,ES14.5,A)')
'#',trim(
getkey(node))//
": ",rdummy, linsep
336 WRITE(string(k:),
'(A)')buf
337 k = k + len(trim(buf))
344 CALL getattr(node,
getkey(node),ldummy)
345 WRITE(buf,
'(A1,A25,L14,A)')
'#',trim(
getkey(node))//
": ",ldummy, linsep
346 WRITE(string(k:),
'(A)')buf
347 k = k + len(trim(buf))
351 WRITE(buf,
'(A)')
'# ['//trim(
prefix)//
'/'//trim(
getkey(node))//
']' // linsep
353 WRITE(buf,
'(A)')
'# ['//trim(
getkey(node))//
']' // linsep
355 WRITE(string(k:),
'(A)')buf
356 k = k + len(trim(buf))
382 REAL,
DIMENSION(:,:),
POINTER :: dummy2
383 REAL,
DIMENSION(:,:,:),
POINTER :: dummy3
384 REAL,
DIMENSION(:,:,:,:),
POINTER :: dummy4
385 INTEGER,
DIMENSION(4) :: dims
386 INTEGER :: dim3,dim4,i,j
389 INTENT(INOUT) ::
this,k
393 DO WHILE(
ASSOCIATED(node))
397 CALL getattr(node,
getkey(node),dir)
399 ELSE IF (
hasdata(node).AND. .NOT.(
getkey(node).EQ.
"bary_curv".OR. &
400 getkey(node).EQ.
"bary_centers".OR.
getkey(node).EQ.
"corners"))
THEN 405 CALL getattr(node,
getkey(node),dummy2)
406 dims(1:2) = shape(dummy2)
407 IF((dims(1).EQ.mesh%IMAX-mesh%IMIN+1).AND.&
408 (dims(2).EQ.mesh%JMAX-mesh%JMIN+1))
THEN 410 IF (k .GT.
this%maxcols)
THEN 414 this%output(k)%val=> dummy2
417 CALL getattr(node,
getkey(node),dummy3)
418 dims(1:3) = shape(dummy3)
419 IF((dims(1).EQ.mesh%IMAX-mesh%IMIN+1).AND.&
420 (dims(2).EQ.mesh%JMAX-mesh%JMIN+1))
THEN 421 dim3 =
SIZE(dummy3, dim = 3)
422 IF (k+dim3 .GT.
this%maxcols)
THEN 427 this%output(i)%val => dummy3(:,:,i-k)
432 CALL getattr(node,
getkey(node),dummy4)
433 dims(1:4) = shape(dummy4)
434 IF((dims(1).EQ.mesh%IMAX-mesh%IMIN+1).AND.&
435 (dims(2).EQ.mesh%JMAX-mesh%JMIN+1))
THEN 436 dim3 =
SIZE(dummy4, dim = 3)
437 dim4 =
SIZE(dummy4, dim = 4)
438 IF (k+dim3*dim4 .GT.
this%maxcols)
THEN 444 this%output(k+j+(i-1)*dim4)%val => dummy4(:,:,i,j)
455 IF (
this%error.NE.0) &
456 CALL error(
this,
"GetOutputPointer_gnuplot",
"number of output fields exceeds upper limit")
472 INTENT(INOUT) :: time,dt,dtcause
474 IF ((time+dt)/
this%time.GT.1.0)
THEN 475 dt =
this%time - time
477 ELSE IF((time+1.5*dt)/
this%time.GT.1.0)
THEN 478 dt = 0.5*(
this%time - time)
496 SUBROUTINE openfile(this,action,fformat)
499 CLASS(fileio_base) :: this
501 CHARACTER(LEN=*) :: fformat
504 INTEGER(KIND=MPI_OFFSET_KIND) :: offset
507 INTENT(IN) :: action,fformat
508 INTENT(INOUT) :: this
513 CALL mpi_file_open(mpi_comm_world,
getfilename(this),mpi_mode_rdonly, &
514 mpi_info_null,this%handle,this%error)
516 CALL mpi_file_seek(this%handle,this%offset,mpi_seek_set,this%error)
518 OPEN(this%unit,file=
getfilename(this),form=fformat,status=
"OLD", &
519 action=
"READ",position=
"REWIND",iostat=this%error)
524 CALL mpi_file_open(mpi_comm_world,
getfilename(this),ior(mpi_mode_rdonly,&
525 mpi_mode_append),mpi_info_null,this%handle,this%error)
528 CALL mpi_file_seek(this%handle,offset,mpi_seek_end,this%error)
529 CALL mpi_file_sync(this%handle,this%error)
531 OPEN(this%unit,file=
getfilename(this),form=fformat,status=
"OLD", &
532 action=
"READ",position=
"APPEND",iostat=this%error)
536 CALL mpi_file_delete(
getfilename(this),mpi_info_null,this%error)
537 CALL mpi_file_open(mpi_comm_world,
getfilename(this),ior(mpi_mode_wronly,&
538 mpi_mode_create),mpi_info_null,this%handle,this%error)
540 OPEN(this%unit,file=
getfilename(this),form=fformat,status=
"REPLACE",&
541 action=
"WRITE",position=
"REWIND",iostat=this%error)
545 CALL mpi_file_open(mpi_comm_world,
getfilename(this),ior(mpi_mode_rdwr,&
546 mpi_mode_append),mpi_info_null,this%handle,this%error)
549 CALL mpi_file_seek(this%handle,offset,mpi_seek_end,this%error)
550 CALL mpi_file_sync(this%handle,this%error)
552 OPEN(this%unit,file=
getfilename(this),form=fformat,status=
"OLD",&
553 action=
"READWRITE",position=
"APPEND",iostat=this%error)
556 CALL error(this,
"OpenFile",
"Unknown access mode.")
566 CLASS(fileio_base) :: this
570 INTENT(INOUT) :: this
572 CALL this%OpenFile(action,
ascii)
581 CLASS(fileio_base) :: this
583 INTENT(INOUT) :: this
586 CALL mpi_file_close(this%handle,this%error)
588 CLOSE(this%unit,iostat=this%error)
597 CLASS(fileio_base) :: this
599 INTENT(INOUT) :: this
603 CALL mpi_file_write(this%handle,trim(header_buf),len(trim(header_buf)), &
604 mpi_character,this%status,this%error)
606 WRITE (this%unit,fmt=
'(A)',iostat=this%error) trim(header_buf)
616 CLASS(fileio_base) :: this
619 INTENT(OUT) :: success
620 INTENT(INOUT) :: this
635 CLASS(fileio_base) :: this
639 INTENT(INOUT) :: this
655 CLASS(fileio_base) :: this
659 INTENT(INOUT) :: this
676 CLASS(fileio_base) :: this
677 CLASS(mesh_base) :: Mesh
681 INTEGER(KIND=MPI_OFFSET_KIND) :: offset
686 INTENT(INOUT) :: this
689 IF (
ASSOCIATED(timedisc%w))
THEN 690 IF (mesh%FARGO.EQ.3.AND.mesh%SN_shear)
THEN 691 CALL physics%AddBackgroundVelocityX(mesh,timedisc%w,timedisc%pvar,timedisc%cvar)
693 CALL physics%AddBackgroundVelocityY(mesh,timedisc%w,timedisc%pvar,timedisc%cvar)
700 CALL mpi_file_get_size(this%handle,offset,this%error)
702 CALL mpi_barrier(mpi_comm_world,this%error)
705 CALL mpi_file_write_at(this%handle, offset, lf, 1, mpi_character, &
706 this%status, this%error)
711 CALL mpi_file_set_view(this%handle,offset,this%basictype,this%filetype, &
712 'native',mpi_info_null,this%error)
715 WRITE (this%unit,fmt=
'(A)',advance=
'NO') lf
720 WHERE (abs(this%output(k)%val(:,:)).LT.max(tiny(this%output(k)%val(:,:)),1.0d-99))
721 this%output(k)%val(:,:) = 0.0e+00
731 WRITE (this%linebuf((k-1)*this%FLEN+1:k*this%FLEN),trim(this%fmtstr)) &
732 this%output(k)%val(i,j), recsep
735 IF ((j.EQ.mesh%JNUM).AND.((mesh%JNUM.GT.1).OR.(mesh%INUM.EQ.i)))
THEN 737 WRITE (this%linebuf((this%COLS-1)*this%FLEN+1:this%linelen),trim(this%fmtstr)) &
738 this%output(this%COLS)%val(i,j), blksep
741 WRITE (this%linebuf((this%COLS-1)*this%FLEN+1:this%linelen),trim(this%fmtstr)) &
742 this%output(this%COLS)%val(i,j), linsep
748 this%outbuf(k,j-1+mesh%JMIN) = this%linebuf(k:k)
752 WRITE (this%unit,fmt=trim(this%linefmt),advance=
'YES') this%linebuf(1:this%linelen-1)
762 CALL mpi_file_iwrite(this%handle,this%outbuf,this%bufsize,this%basictype,&
764 CALL mpi_wait(request,this%status,this%error)
774 CLASS(fileio_base) :: this
775 CLASS(mesh_base) :: Mesh
776 CLASS(physics_base) :: Physics
777 CLASS(timedisc_base) :: Timedisc
779 INTENT(IN) :: mesh,physics,timedisc
780 INTENT(INOUT) :: this
787 SUBROUTINE error(this,modproc,msg)
790 CLASS(fileio_base),
INTENT(INOUT) :: this
791 CHARACTER(LEN=*),
INTENT(IN) :: modproc
792 CHARACTER(LEN=*),
INTENT(IN) :: msg
795 CALL this%CloseFile_gnuplot()
796 CALL this%Error_fileio(modproc,msg)
804 CLASS(fileio_gnuplot) :: this
807 DEALLOCATE(this%outbuf)
809 DEALLOCATE(this%output)
810 CALL this%Finalize_base()
subroutine finalize(this)
Destructor of common class.
subroutine error(this, modproc, msg, rank, node_info)
Print error message on standard error and terminate the program.
generic source terms module providing functionaly common to all source terms
integer, parameter, public replace
read/write access replacing file
integer, save default_mpi_real
default real type for MPI
type(logging_base), save this
subroutine writedataset(this, Mesh)
Writes all desired data arrays to a file.
type(dict_typ) function, pointer, public getchild(root)
Get the pointer to a direct child of the pointer 'root'.
integer function, public getdatatype(root)
Return the datatype of node 'root'.
character(len=9), parameter ascii
for ASCII data
integer, parameter, public dict_real_fourd
recursive subroutine getoutputpointer(this, Mesh, node, k)
Creates a list of all data arrays which will be written to file.
logical function, public haschild(root)
Check if the node 'root' has one or more children.
integer, parameter, public dtcause_fileio
smallest ts due to fileio
integer, parameter, public dict_char
function, public getkey(root)
Get the key of pointer 'root'.
pure subroutine inctime(this)
Increments the counter for timesteps and sets the time for next output.
subroutine openfile_gnuplot(this, action)
Specific routine to open a file for gnuplot I/O.
base class for geometrical properties
integer, parameter, public dict_real_threed
integer, parameter, public readend
readonly access at end
subroutine initfileio_gnuplot(this, Mesh, Physics, IO, fmt, fpath, filename, stoptime, dtwall, count, fcycles, unit, config)
Constructor for the GNUPLOT file I/O.
I/O for GNUPLOT readable tabular files.
integer, parameter, public dict_real_twod
character(len=11), parameter bin
for BINARY data
subroutine initfileio(this, Mesh, Physics, Timedisc, Sources, config, IO, fmtname, fext)
Generic constructor for file I/O.
type(dict_typ) function, pointer, public getnext(root)
Get the pointer to the next child.
integer, parameter, public dict_int
recursive subroutine writeheaderstring(string, root, k, prefix)
Creates a string with the configuration (from the dictionary)
subroutine writeheader(this)
Writes the configuration as a header to the file.
subroutine readheader_gnuplot(this, success)
Reads the header (not yet implemented)
pure integer function getrank(this)
Get the MPI rank.
pure logical function initialized(this)
Query initialization status.
Dictionary for generic data types.
subroutine writetimestamp_gnuplot(this, time)
Writes the timestep (not yet implemented)
logical function, public hasdata(root)
Checks if the node 'root' has data associated.
subroutine readdataset_gnuplot(this, Mesh, Physics, Timedisc)
Reads the data arrays from file (not yet implemented)
integer, parameter, public append
read/write access at end
subroutine readtimestamp_gnuplot(this, time)
Reads the timestep (not yet implemented)
real function adjusttimestep(this, maxerr, dtold)
adjust the time step
subroutine closefile_gnuplot(this)
routine to close a file
integer, parameter, public dict_real
base module for numerical flux functions
character(len=1), save prefix
preceds info output
integer, parameter, public dict_bool
integer, parameter, public readonly
readonly access
character(len=256) function getfilename(this, fn)
Get the current file name.
subroutine openfile(this, action, fformat)
Generic routine to open a file.