Skip to content

Commit

Permalink
make field writer more closely match scidac file metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jcosborn committed Oct 12, 2023
1 parent 4289fdd commit f8d4c7c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
17 changes: 17 additions & 0 deletions src/io/qioInternal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import physics/qcdTypes
export qcdTypes
import rng
export rng
import typetraits

# For IO with matching types; see read[T]/write[T]
#template IOtype*(x:typedesc[SVec0]):untyped = float32
Expand Down Expand Up @@ -34,3 +35,19 @@ template IOtypeP*[T](x:typedesc[T]):typedesc =
eval(toSingle(IOtype(type T)))
else:
T

template IOnameDefault*[T](x:typedesc[T]):string =
"QDP_" & T.name
template IOname*[T](x:typedesc[T]):string =
T.IOnameDefault
#template IOname*[N:static int](x:typedesc[Color[MatrixArray[N,N,float]]]):string =
# "QDP_F" & $N & "_ColorMatrix"
#template IOname*[N:static int](x:typedesc[Color[MatrixArray[N,N,DComplex]]]):string =
# "QDP_D" & $N & "_ColorMatrix"
template IOname*[N:static int,T](x:typedesc[Color[MatrixArray[N,N,T]]]):string =
when T is SComplex:
"QDP_F" & $N & "_ColorMatrix"
elif T is DComplex:
"QDP_D" & $N & "_ColorMatrix"
else:
IOnameDefault T
14 changes: 7 additions & 7 deletions src/io/writerQio.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import base
import layout
import qio
#import strutils
import macros
import field
import os, times
import iocommon
import qioInternal

type Writer*[V: static[int]] = ref object
layout*: Layout[V]
Expand Down Expand Up @@ -69,7 +69,8 @@ proc open(wr: var Writer; ql: var QIO_Layout, md: string) =
#oflag.serpar = QIO_SERIAL;
oflag.serpar = QIO_PARALLEL
oflag.mode = QIO_TRUNC
oflag.ildgstyle = QIO_ILDGLAT
#oflag.ildgstyle = QIO_ILDGLAT
oflag.ildgstyle = QIO_ILDGNO
#oflag.ildgLFN = NULL

var qioMd = QIO_string_create()
Expand Down Expand Up @@ -108,9 +109,6 @@ proc close*(wr: var Writer) =
wiorank = addr wr.iorank
wr.status = QIO_close_write(wr.qw)

import typetraits
import qioInternal

proc get[T](buf: cstring; index: csize_t; count: cint; arg: pointer) =
type destT = cArray[IOtype(T)]
type srcT1 = cArray[T]
Expand Down Expand Up @@ -178,15 +176,17 @@ proc write[T](wr: var Writer, v: var openArray[ptr T], lat: openArray[int],
upper[i] = lat[i].cint

if precs == precs0:
var datatype = "QEX_" & type(v[0][]).IOtype.name
#var datatype = "QEX_" & type(v[0][]).IOtype.name
var datatype = type(v[0][]).IOtype.IOname
var recInfo = QIO_create_record_info(QIO_FIELD, lower[0].addr,
upper[0].addr, nd.cint, cstring datatype,
cstring precs, nc, ns, size.cint, nv)
wr.status = QIO_write(wr.qw, recInfo, qioMd, get[T], vsize.csize_t,
wordSize.cint, v[0].addr)
QIO_destroy_record_info(recInfo)
else:
var datatype = "QEX_" & type(v[0][]).IOtypeP.name
#var datatype = "QEX_" & type(v[0][]).IOtypeP.name
var datatype = type(v[0][]).IOtypeP.IOname
var recWordSize = case precs:
of "F": 4
of "D": 8
Expand Down
11 changes: 5 additions & 6 deletions src/io/writerQiolite.nim
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import base
import layout
import strutils, strformat
import macros
import field
import os
import scidacio
import qioInternal

var verb = 0

Expand Down Expand Up @@ -63,9 +63,6 @@ proc hyperindex(x: seq[cint]; subl,offs: seq[int]): int =
for i in countdown(n-1,0):
result = result*subl[i] + (x[i]-offs[i])

import typetraits
import qioInternal

proc get[T](buf: cstring; index: int; count: int; arg: openArray[ptr T]) =
type destT = cArray[IOtype(T)]
type srcT1 = cArray[T]
Expand Down Expand Up @@ -133,10 +130,12 @@ proc write[T](wr: var Writer, v: var openArray[ptr T], lat: openArray[int],
wr.sw.record.datacount = objcount
wr.sw.record.typesize = iotypebytes
if ioprec==tprec:
var datatype = "QDP_" & type(v[0][]).IOtype.name
#var datatype = "QDP_" & type(v[0][]).IOtype.name
var datatype = type(v[0][]).IOtype.IOname
wr.sw.record.datatype = datatype
else:
var datatype = "QDP_" & type(v[0][]).IOtypeP.name
#var datatype = "QDP_" & type(v[0][]).IOtypeP.name
var datatype = type(v[0][]).IOtypeP.IOname
wr.sw.record.datatype = datatype
var buf = create(char, iobytes)

Expand Down
2 changes: 2 additions & 0 deletions tests/base/tfieldio.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ proc save(f: var Field) =
proc reader(): auto =
result = l.newReader(fn)
check(result.status==0)
check(result.fileMetadata==filemd)

proc finish(r: var Reader) =
r.close
Expand All @@ -54,6 +55,7 @@ proc load(r: var Reader, f: Field) =
var f2 = f.newOneOf
r.read(f2)
check(r.status==0)
check(r.recordMetadata==recordmd)
f2 -= f
let n2 = f2.norm2
check(n2==0)
Expand Down

0 comments on commit f8d4c7c

Please sign in to comment.