[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDFJava #NMT-724530]: vlen_t big_endian problem



Hi Bruno:

Ive reissued the release version 4.2.18.20101223.2214, available at

http://www.unidata.ucar.edu/software/netcdf-java/ 

with this bug fixed. thanks for reporting the problem.

John

> Hello,
> 
> I've problem when read vlen_t data stored in big endian format. In attached
> file all variable are read correctly except  the variable levels from type
> vlen_t. For example, for value 549 the value read by as.getInt(i) is
> 620888064, in Hexadecimal 549 is 00 00 02 25 and 620888064 is 25 02 00 00...
> I correct this manually, but can you update the java API?
> Best Wishes,
> 
> Bruno Santos
> 
> 
> Here the code:
> *Array data = dataLevels.read(initialIndex + ":" + finalIndex +
> ",:");*
> // loop over outer dimension
> int x = 0;
> long samplesTotal = 0;
> long maxSamples = 200000L;
> 
> *while (data.hasNext() && samplesTotal < maxSamples) {*
> Array as = (Array) data.next(); // inner variable length array
> of short
> //ArrayInt.D1 as = (ArrayInt.D1) data.next(); // inner variable
> length array of short
> long nextTime = 0;
> long timeSlice = 0;
> 
> //System.out.println("Data: " + data.next().getClass());
> if (sPeriodArray.get(x) > 0) {
> timeSlice = sPeriodArray.get(x);
> } else {
> //----------Change
> long samplesPerSecond = sRateArray.get(x);
> timeSlice = 1000000000 / samplesPerSecond;
> }
> 
> //System.out.println("as.getSize: " + as.getSizeBytes());
> //System.out.println("as.getSize: " + as.getSize());
> int i = 0;
> while (i < as.getSize()){
> *//Incorrect value*
> int aux = as.getInt(i);
> 
> *                if (bigEndian){*
> *                    int aux1;*
> *                    int aux2;*
> *                    int aux3;*
> *                    int aux4;*
> *
> *
> *                    aux1 = (aux & 0xFF) << 24;*
> *                    aux2 = (aux & 0xFF00) << 8;*
> *                    aux3 = (aux & 0xFF0000) >> 8;*
> *                    aux4 = (aux & 0xFF000000) >> 24;*
> *
> *
> *                   //Corrected value*
> *                    aux = (aux1 & 0xFF000000) | (aux2 & 0x00FF0000)| (aux3
> & 0x0000FF00) | (aux4 & 0x000000FF);*
> }
> }
> 
> 


Ticket Details
===================
Ticket ID: NMT-724530
Department: Support netCDF Java
Priority: Normal
Status: Closed