-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Data2 implementation and Data3 fix (#14)
* Integration data for testing * data2: empty test * Data2 implementation * shortcut for data * fix spacial differenting * enforce tests * refacto data2 and data3
- Loading branch information
1 parent
1901316
commit 45a796e
Showing
26 changed files
with
131,165 additions
and
413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package griblib | ||
|
||
import "fmt" | ||
|
||
type bitGroupParameter struct { | ||
Reference uint64 | ||
Width uint64 | ||
Length uint64 | ||
} | ||
|
||
func (bitGroup bitGroupParameter) zeroGroup() []int64 { | ||
result := []int64{} | ||
for l := 0; l < int(bitGroup.Length); l++ { | ||
result = append(result, 0) | ||
} | ||
|
||
return result | ||
} | ||
|
||
// | ||
// Test to see if the group widths and lengths are consistent with number of | ||
// values, and length of section 7. | ||
// | ||
func checkLengths(bitGroups []bitGroupParameter, dataLength int) error { | ||
totBit := 0 | ||
totLen := 0 | ||
|
||
for _, param := range bitGroups { | ||
totBit += int(param.Width) * int(param.Length) | ||
totLen += int(param.Length) | ||
} | ||
|
||
if totBit/8 > int(dataLength) { | ||
return fmt.Errorf("Checksum err %d - %d", dataLength, totBit/8) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// | ||
// Extract Each Group's reference value | ||
// | ||
func (template *Data2) extractGroupReferences(bitReader *BitReader) ([]uint64, error) { | ||
numberOfGroups := int64(template.NG) | ||
return bitReader.readUintsBlock(int(template.Bits), numberOfGroups, true) | ||
} | ||
|
||
// | ||
// Extract Each Group's bit width | ||
// | ||
func (template *Data2) extractGroupBitWidths(bitReader *BitReader) ([]uint64, error) { | ||
numberOfGroups := int64(template.NG) | ||
widths, err := bitReader.readUintsBlock(int(template.GroupWidthsBits), numberOfGroups, true) | ||
if err != nil { | ||
return widths, err | ||
} | ||
|
||
for j := range widths { | ||
widths[j] += uint64(template.GroupWidths) | ||
} | ||
|
||
return widths, nil | ||
} | ||
|
||
// | ||
// Extract Each Group's length (number of values in each group) | ||
// | ||
func (template *Data2) extractGroupLengths(bitReader *BitReader) ([]uint64, error) { | ||
numberOfGroups := int64(template.NG) | ||
lengths, err := bitReader.readUintsBlock(int(template.GroupScaledLengthsBits), numberOfGroups, true) | ||
if err != nil { | ||
return lengths, err | ||
} | ||
|
||
for j := range lengths { | ||
lengths[j] = (lengths[j] * uint64(template.GroupLengthIncrement)) + uint64(template.GroupLengthsReference) | ||
} | ||
lengths[numberOfGroups-1] = uint64(template.GroupLastLength) | ||
return lengths, nil | ||
} | ||
|
||
func (template *Data2) extractBitGroupParameters(bitReader *BitReader) ([]bitGroupParameter, error) { | ||
result := []bitGroupParameter{} | ||
// | ||
// Extract Each Group's reference value | ||
// | ||
references, err := template.extractGroupReferences(bitReader) | ||
if err != nil { | ||
return result, err | ||
} | ||
|
||
// | ||
// Extract Each Group's bit width | ||
// | ||
widths, err := template.extractGroupBitWidths(bitReader) | ||
if err != nil { | ||
return result, err | ||
} | ||
|
||
// | ||
// Extract Each Group's length (number of values in each group) | ||
// | ||
lengths, err := template.extractGroupLengths(bitReader) | ||
if err != nil { | ||
return result, err | ||
} | ||
|
||
for index := range references { | ||
result = append(result, bitGroupParameter{ | ||
Reference: references[index], | ||
Width: widths[index], | ||
Length: lengths[index], | ||
}) | ||
} | ||
|
||
bitReader.resetOffset() | ||
|
||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.