IR_FieldIO.scala 3.18 KB
Newer Older
1
2
package exastencils.field.ir

3
4
import scala.collection.mutable.ListBuffer

5
import exastencils.base.ir._
6
import exastencils.config.Knowledge
7
import exastencils.core.Duplicate
8
import exastencils.io.ir._
9
import exastencils.logger.Logger
10
import exastencils.visualization.ir.postprocessing.IR_ResolveVisualizationPrinters
11

12
/// IR_FieldIO
13
14
15
16
17
18
19
20
21
22
23
24
25

object IR_FieldIO {
  private var counter : Int = 0
  def getNewStreamName() : String = {
    counter += 1
    "fieldStream_%03d".format(counter)
  }

  private var fileNameCounter : Int = 0
  def getNewFileName() : String = {
    fileNameCounter += 1
    "fieldName_%03d".format(fileNameCounter)
  }
26
27
28
29
30
31
32

  private var resolveId : Int = Duplicate(IR_ResolveVisualizationPrinters.funcsResolved) // vis. funcs are resolved first
  def getNewResolveId() : Int = {
    val ret = Duplicate(resolveId)
    resolveId += 1
    ret
  }
33
34
}

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
abstract class IR_FieldIO extends IR_Statement with IR_Expandable {

  // general members
  def filename : IR_Expression
  def field : IR_Field
  def slot : IR_Expression
  def ioInterface : IR_Expression
  def doWrite : Boolean
  def onlyVals : Boolean
  def includeGhostLayers : Boolean
  def canonicalFileLayout : Boolean

  // locking/fpp specific members (essentially when using "iostreams")
  def useBinary : Boolean
  def separator : IR_Expression
  def condition : IR_Expression

  // dataset which can be specified for a netCDF/HDF5 file (for HDF5 this can be a path)
  def dataset : IR_Expression
54

55
56
57
  // binary representation for MPI-I/O
  def mpiioRepresentation : IR_StringConstant

58
  // wrapper function that generates statements for file access using the specified I/O interface
59
  def generateFileAccess(optSep : Option[IR_Expression] = None, optPrintComponents : Option[ListBuffer[IR_Expression]] = None) : IR_FileAccess = {
60
    val fieldAsDataBuffer = IR_DataBuffer(field, slot, includeGhostLayers, None, dataset = Some(dataset), canonicalFileLayout)
61

62
63
    ioInterface.asInstanceOf[IR_StringConstant].value.toLowerCase match {
      case "lock"  =>
64
        IR_FileAccess_Locking(filename, ListBuffer(fieldAsDataBuffer), useBinary, doWrite, optSep getOrElse separator, condition, optPrintComponents)
65
      case "fpp"   =>
66
        IR_FileAccess_FPP(filename, ListBuffer(fieldAsDataBuffer), useBinary, doWrite, optSep getOrElse separator, condition, optPrintComponents)
67
      case "mpiio" =>
68
        IR_FileAccess_MPIIO(filename, ListBuffer(fieldAsDataBuffer), doWrite, representation = mpiioRepresentation)
69
      case "hdf5"  =>
70
        IR_FileAccess_HDF5(filename, ListBuffer(fieldAsDataBuffer), doWrite, zlibCompressionLevel = if (onlyVals) Knowledge.hdf5_write_zlib_compression_level else 0)
71
      case "nc"    =>
72
        IR_FileAccess_PnetCDF(filename, ListBuffer(fieldAsDataBuffer), None, doWrite, timeIdx = IR_NullExpression, timeVal = IR_NullExpression, altFileMode = None)
73
      case "sion"  =>
74
        IR_FileAccess_SIONlib(filename, ListBuffer(fieldAsDataBuffer), doWrite, condition)
75
      case _       =>
Richard Angersbach's avatar
Richard Angersbach committed
76
        Logger.error("Ignoring call to " + (if (doWrite) { if (onlyVals) "writeField" else "printField" } else "readField") + " using unsupported I/O interface: " + ioInterface)
77
78
79
    }
  }
}