Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading string variable data #20

Open
guydillen opened this issue Feb 5, 2021 · 4 comments
Open

Reading string variable data #20

guydillen opened this issue Feb 5, 2021 · 4 comments

Comments

@guydillen
Copy link

Hi,

Hw to read string variable data?

This is my cdl file:

`netcdf test {
dimensions:
station = 9 ;
...
variables:
string station_name(station) ;
...
// global attributes:
...
data:

station_name = "W1", "W2", "W3", "W4", "W5", "W6", "W7",
"W8", "W9" ;

...`

How can I read the string data?

Thanks.

@fhs
Copy link
Owner

fhs commented Feb 5, 2021

Var.ReadBytes doesn't work? Maybe we need to wrap nc_get_vara_string? PRs are welcome.

@guydillen
Copy link
Author

guydillen commented Feb 5, 2021

How should I use Var.ReadBytes: it returns an error and takes a byte slice/array?

// ReadBytes reads the entire variable v into data, which must have enough
// space for all the values (i.e. len(data) must be at least v.Len()).
func (v Var) ReadBytes(data []byte) error {
	if err := okData(v, CHAR, len(data)); err != nil {
		return err
	}
	return newError(C.nc_get_var_text(C.int(v.ds), C.int(v.id), (*C.char)(unsafe.Pointer(&data[0]))))
}

@fhs
Copy link
Owner

fhs commented Feb 5, 2021

I think you need to create a ReadStrings methods that uses C.nc_get_var_string.

func (v Var) ReadStrings(data []string) error

@SergeiMelman
Copy link

SergeiMelman commented Feb 9, 2021

I think It would be good for Attr as well :

func (a Attr) ReadStrings(data []string) error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants