Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/commonMain/kotlin/com/sunya/netchdf/NetchdfFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fun openNetchdfFile(filename : String, strict : Boolean = false) : Netchdf? {
NetchdfFileFormat.NC_FORMAT_NETCDF4_CLASSIC -> Hdf5File(useFilename, strict)
NetchdfFileFormat.HDF5 -> Hdf5File(useFilename, strict)
NetchdfFileFormat.HDF4 -> Hdf4File(useFilename)
else -> null // throw RuntimeException(" unsupported NetcdfFileFormat $format")
else -> null
}
}
}
Expand All @@ -38,7 +38,7 @@ fun openNetchdfFileWithFormat(filename : String, format : NetchdfFileFormat) : N
NetchdfFileFormat.NC_FORMAT_NETCDF4_CLASSIC -> Hdf5File(useFilename, false)
NetchdfFileFormat.HDF5 -> Hdf5File(useFilename, false)
NetchdfFileFormat.HDF4 -> Hdf4File(useFilename)
else -> null // throw RuntimeException(" unsupported NetcdfFileFormat $format")
else -> null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ enum class NetchdfFileFormat(private val version: Int, private val formatName: S
val h5type = searchForwardHdf5(raf, magic)
if (h5type != null) return h5type

val h4type = searchForwardHdf4(raf, magic)
val h4type = searchForwardHdf4(raf)
return h4type ?: INVALID
}

Expand Down Expand Up @@ -284,7 +284,7 @@ enum class NetchdfFileFormat(private val version: Int, private val formatName: S
return null
}

private fun searchForwardHdf4(raf: OpenFileIF, want: ByteArray): NetchdfFileFormat? {
private fun searchForwardHdf4(raf: OpenFileIF): NetchdfFileFormat? {
val size: Long = raf.size()
val state = OpenFileState(0L, true)
var startPos = 0L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ internal class LinkedByteSource(val h4 : H4builder,
private val state : OpenFileState
private var segno = -1
private var segSize = 0
private var buffer = ByteArray(0)
private var exhausted = false
val totalSize: Int

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class H4builder(val raf: OpenFileIF, val valueCharset: Charset) {
val ndd: Int = raf.readShort(state).toUShort().toInt() // number of DD blocks
link = raf.readInt(state).toUInt().toLong() // point to the next DDH; link == 0 means no more
var pos = state.pos
for (i in 0 until ndd) {
repeat (ndd) {
val tag: Tag = readTag(raf, state)
pos += 12
state.pos = pos // tag usually changed the file pointer
Expand Down Expand Up @@ -425,7 +425,7 @@ class H4builder(val raf: OpenFileIF, val valueCharset: Charset) {
}

// compute the vb and add to the group
val vb = SDread(tagNDG!!, vgroup.name, group, dims) ?: return
val vb = SDread(tagNDG, vgroup.name, group, dims) ?: return

// tagVH's on the group tag (TagVGroup) might be attributes
tagVHs.forEach {
Expand Down Expand Up @@ -558,7 +558,7 @@ class H4builder(val raf: OpenFileIF, val valueCharset: Charset) {
println(" **** NO dimensions found for SD ${dataGroup.refCode()}")
return null
}
val dimSDD = dimSDDout!!
val dimSDD = dimSDDout

val nt: TagNT = tagidMap[tagid(dimSDD.data_nt_ref, TagEnum.NT.code)] as TagNT?
?: throw IllegalStateException(" **** NO nt tag found for SD ${dataGroup.refCode()}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ internal class H4chunkIterator<T>(h4 : H4builder, val v2: Variable<*>, val wantS

private val vinfo = v2.spObject as Vinfo
private val elemSize = vinfo.elemSize
private val datatype = v2.datatype
private val wantSpace = IndexSpace(wantSection)

private val tiledData : H4tiledData = H4tiledData(h4, v2.shape, vinfo.chunkLengths, vinfo.chunks!!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal class H4tiledData(val h4 : H4builder, varShape : LongArray, chunk : Int

internal class H4CompressedDataChunk(
val h4 : H4builder,
val offsets: IntArray, // offset index of this chunk, reletive to entire array
val offsets: IntArray, // offset index of this chunk, relative to entire array
private val compress: SpecialComp?
) {
fun isMissing() = (compress == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private fun transform(org: ODLgroup, trans: ODLgroup) {
}

if (wantName != null) {
val nestedTrans = ODLgroup(wantName!!, trans)
val nestedTrans = ODLgroup(wantName, trans)
trans.nested.add(nestedTrans)
if (org.variables.isNotEmpty()) {
nestedTrans.variables.add(transformVariables(org))
Expand Down Expand Up @@ -234,7 +234,7 @@ internal fun ODLparseFromString(text: String): ODLgroup {
} else if (line.startsWith("END")) {
// noop
} else if (currentObject != null) {
addFieldToObject(currentObject as ODLobject, line)
addFieldToObject(currentObject, line)
} else {
addFieldToGroup(currentStruct, line)
}
Expand Down Expand Up @@ -399,7 +399,7 @@ class ODLparser(val rootGroup: Group.Builder, val show : Boolean = false) {
return false
}
} catch (ex : Exception) {
logger.warn{" *** ODL cant parse dimension ${att.component1()} length ${att.component2()}"}
logger.warn{" *** ODL cant parse dimension ${att.component1()} length ${att.component2()} message=${ex.message}"}
return false
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/commonMain/kotlin/com/sunya/netchdf/hdf4/Tag.kt
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ internal class TagVH(icode: Int, refno: Int, offset : Long, length : Int) : Tag(
fld_isize = IntArray(nfields) { h4.raf.readShort(state).toUShort().toInt() }
fld_offset = IntArray(nfields) { h4.raf.readShort(state).toUShort().toInt() }
fld_nelems = IntArray(nfields) { h4.raf.readShort(state).toUShort().toInt() } // "Order of the nth field of the Vdata (16-bit integer)"
for (i in 0 until nfields) {
repeat (nfields) {
val slen = h4.raf.readShort(state).toInt()
fld_name.add(h4.raf.readString(state, slen))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ enum class TagEnum(val desc: String, val code: Int) {
fun byCode(code: Int): TagEnum {
if (hashCodes == null) { // LOOK may fail when multithreading
val mapit = mutableMapOf<Int, TagEnum>()
values().forEach { mapit[it.code] = it}
entries.forEach { mapit[it.code] = it}
hashCodes = mapit
}
val te = hashCodes!![code]
Expand Down
2 changes: 1 addition & 1 deletion core/src/commonMain/kotlin/com/sunya/netchdf/hdf4/Vinfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal class Vinfo(val refno: Int) : Comparable<Vinfo?> {
return this
}

// make sure needed info is present : call this when variable needs to be read
// make sure that the needed info is present: call this when variable needs to be read
// this allows us to defer getting layout info until then
fun setLayoutInfo(header: H4builder) {
if (tagData == null) return
Expand Down
144 changes: 0 additions & 144 deletions core/src/commonMain/kotlin/com/sunya/netchdf/hdf5/BTree1.kt

This file was deleted.

33 changes: 19 additions & 14 deletions core/src/commonMain/kotlin/com/sunya/netchdf/hdf5/BTree1data.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,19 @@ internal class BTree1data(
keyValues.add(Pair(order, DataChunk(key, childPointer)))
lastOrder = order
} else {
children.add(BTreeNode(childPointer, this))
children.add( BTreeNode(childPointer, this) )
}
}
if (children.isNotEmpty()) {
lastOrder = children.last().lastOrder
}
}

// note there may be unused entries, "All nodes of a particular type of tree have the same maximum degree,
// but most nodes will point to less than that number of children""
}

// this does not have missing data. Use iterator on the Btree1data class
/* return only the leaf nodes, in depth-first order
fun asSequence(): Sequence<Pair<Int, DataChunkIF>> = sequence {
// Handle child nodes recursively (in-order traversal)
if (children.isNotEmpty()) {
children.forEachIndexed { index, childNode ->
yieldAll(childNode.asSequence()) // Yield all elements from the child
}
} else { // If it's a leaf node (no children)
keyValues.forEach { yield(it) }
}
} */

// uses a tree search = O(log n)
fun findDataChunk(wantOrder: Int): DataChunk? {
if (children.isNotEmpty()) { // search tree; assumes that chunks are ordered
children.forEach { childNode ->
Expand All @@ -106,6 +97,10 @@ internal class BTree1data(
return null
}

override fun toString(): String {
return "BTreeNode(address=$address, level=$level, nentries=$nentries, lastOrder=$lastOrder)"
}

}

data class DataChunkKey(val order: Int, val chunkSize: Int, val filterMask : Int)
Expand All @@ -129,3 +124,13 @@ internal class BTree1data(
}
}

interface DataChunkIF {
fun childAddress(): Long
fun offsets(): LongArray
fun isMissing(): Boolean
fun chunkSize(): Int
fun filterMask(): Int?

fun show(tiling : Tiling): String
}

Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ internal class BTree2data(private val h5: H5builder, owner: String, address: Lon

private inner class ChunkIterator : AbstractIterator<ChunkImpl>() {
var count = 0
var first = true

override fun computeNext() {
if (count >= records.size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.sunya.cdm.iosp.OpenFileState
import com.sunya.cdm.util.InternalLibraryApi
import java.util.*

// DataLayoutExtensibleArray4
class ExtensibleArrayIndex(val h5: H5builder, address: Long, datasetDimensions: IntArray, chunkDimensions: IntArray) {
val raf = h5.raf

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import kotlin.math.min

val UNDEFINED_ADDRESS = -1L

// the start of a port of jfhf FractalHeap. May not need it.
class FractalHeapJ(val h5: H5builder, forWho: String, val fractalHeapAddress: Long) {

val raf = h5.raf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class GroupSymbolTable(val btreeAddress : Long) {
val nentries = h5.raf.readShort(state)

var posEntry = state.pos
for (i in 0 until nentries) {
repeat (nentries.toInt()) {
val entry = h5.readSymbolTable(state)
posEntry += entry.dataSize
if (entry.objectHeaderAddress != 0L) { // skip zeroes, probably a bug in HDF5 file format or docs, or me
Expand Down Expand Up @@ -58,7 +58,6 @@ internal fun H5builder.readSymbolTable(state : OpenFileState) : SymbolTableEntry
}
if (debugGroup) rootEntry.show()

// may be btree or symbolic link
var btreeAddress : Long? = null
var nameHeapAddress : Long? = null
var linkOffset : Int? = null
Expand Down
Loading