Source

gohdf / hdf4 / hdf4_test.go

Full commit
// Copyright 2011 GoHDF Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package hdf4

import (
	"log"
	"testing"
)

const hdfPath = "/home/fhs/csdirs/src/pkg/cluster/glasslab_cluster/data/modis_crefl_tbase.hdf"

func TestOpen(t *testing.T) {
	file, err := Open(hdfPath)
	if err != nil {
		t.Fatalf("Open failed: %v\n", err)
	}
	defer file.Close()

	for i := 0; i < len(file.Records); i++ {
		rec := &file.Records[i]
		switch rec.Tag {
		case DFTAG_VERSION, DFTAG_NT, DFTAG_SDD, DFTAG_NDG, DFTAG_VG:
			file.LookupRecord(int(rec.Tag), int(rec.Ref))
		}
	}

	rec, err := file.LookupRecord(DFTAG_NT, -1)
	if err != nil {
		t.Fatalf("LookupRecord failed: %v", err)
	}
	log.Printf("nt = %v\n", rec.Info.(*NumType))

	rec, err = file.LookupRecord(DFTAG_SDD, -1)
	if err != nil {
		t.Fatalf("LookupRecord failed: %v", err)
	}
	log.Printf("sdd = %v\n", rec.Info.(*SDD))

	rec, err = file.LookupRecord(DFTAG_NDG, -1)
	if err != nil {
		t.Fatalf("LookupRecord failed: %v", err)
	}
	log.Printf("sdd = %T\n", rec.Info.(*NDG))

	rec, err = file.LookupRecord(DFTAG_VG, -1)
	if err != nil {
		t.Fatalf("LookupRecord failed: %v", err)
	}
	vg := rec.Info.(*VGroup)
	log.Printf("vg = %v (name=%s, class=%s)\n", vg, string(vg.Name), string(vg.Class))

	log.Printf("Records=%v\n", file.Records)
	log.Printf("Version=%v\n", file.Version)

	for i := 0; i < len(file.Records); i++ {
		rec = &file.Records[i]
		if rec.parsing {
			t.Errorf("Record still being parsed: %v", rec)
		}
		if rec.Info == nil {
			log.Printf("tag %d not parsed\n", rec.Tag)
		}
	}
}