Search code examples
matlabjulianetcdfuint

Julia NetCDF returns ondly Uint8


I'm migrating from matlab to Julia. Using julia v 0.4.2 and package NetCDF by Meggart

I'm trying to import a variable the same way i import it in matlab:

Tiempo = ncread(Arch,"Times")';

And, if i view the contents of the variable on Matlab i have: type 24x19 char and contents:

Tiempo(1,:) = 2010-03-01_01:00:00

In julia, however, i only get:

julia> typeof(Tiempo[1,:])
Array{UInt8,2}

julia> Tiempo[1,:]
1x19 Array{UInt8,2}:
 0x32  0x30  0x31  0x30  0x2d  0x30  …  0x3a  0x30  0x30  0x3a  0x30  0x30

And i don't know how to use it or how to recover the useful data. Can you throw a light on this?


Solution

  • 7.8 Byte Array Literals
    Another useful non-standard string literal is the byte-array string literal: b"...". This form lets you use string notation to express literal byte arrays—i.e. arrays of UInt8 values.....

    julia> tiempo=b"2010-03-01_01:00:00"
    19-element Array{UInt8,1}:
     0x32
     0x30
     0x31
     0x30
     0x2d
     0x30
     0x33
     0x2d
     0x30
     0x31
     0x5f
     0x30
     0x31
     0x3a
     0x30
     0x30
     0x3a
     0x30
     0x30
    
    julia> ASCIIString(tiempo)
    "2010-03-01_01:00:00"
    

    So, what you have got is a byte array literal, and it's convertible to an ASCIIString type using its constructor with right arguments (e.g a vector of UInt8), Also, to send all elements of a Array{UInt8,2} in a row one possibility could be ASCIIString(Tiempo[1:end]).