Giter Site home page Giter Site logo

Comments (12)

piyushrpt avatar piyushrpt commented on July 29, 2024

The solution to this would be something like this:

!c Do this early in the function
integer*2 b1, b2, b3, b4  

...
!c Whenever you want to interpret 4 bytes as big endian int32
b1 = indata(40)
b2 = indata(39)
b3 = indata(38)
b4 = indata(37)

and then use these integer*2 variables in the iand statements.

This error is due to gfortran in gcc9 complying with the standards unlike earlier versions which were lax.

from isce2.

S0sh0rt avatar S0sh0rt commented on July 29, 2024

FYI: I just noticed that the multiplication signs are mostly missing. Looks like the blog is interpreting them as formatting characters. There should be a multiplication "asterisk" before each of the 256s.
Thank you. The lines I removed and added are below.
integer*4 b1, b2, b3, b4 !iyear=iand(indata(40),255)256256*256+iand(indata(39),255)256256+iand(indata(38),255)256+iand(indata(37),255) !idoy=iand(indata(44),255)256256256+iand(indata(43),255)256256+iand(indata(42),255)256+iand(indata(41),255)
!ims=iand(indata(48),255)256256
256+iand(indata(47),255)256256+iand(indata(46),255)256+iand(indata(45),255)
b1 = indata(40)
b2 = indata(39)
b3 = indata(38)
b4 = indata(37)
iyear=iand(b1,255)256256
256+iand(b2,255)256256+iand(b3,255)256+iand(b4,255)
b1 = indata(44)
b2 = indata(43)
b3 = indata(42)
b4 = indata(41)
idoy=iand(b1,255)256256
256+iand(b2,255)256256+iand(b3,255)256+iand(b4,255)
b1 = indata(48)
b2 = indata(47)
b3 = indata(46)
b4 = indata(45)
ims=iand(b1,255)256256
256+iand(b2,255)256256+iand(b3,255)*256+iand(b4,255)

from isce2.

piyushrpt avatar piyushrpt commented on July 29, 2024

Could you issue a Pull Request with these changes?

from isce2.

S0sh0rt avatar S0sh0rt commented on July 29, 2024

from isce2.

rtburns-jpl avatar rtburns-jpl commented on July 29, 2024

I'm far from a fortran expert but would it be more correct to use a _1 suffix to specify that the literals are integer*1s? Changing each 255 to 255_1 fixes the issue for me (using macports gfortran-mp-9)

from isce2.

S0sh0rt avatar S0sh0rt commented on July 29, 2024

rtburns has the best suggestion. It is cleaner and has the smallest change.

from isce2.

rtburns-jpl avatar rtburns-jpl commented on July 29, 2024

Great, I'll submit a PR then

from isce2.

piyushrpt avatar piyushrpt commented on July 29, 2024
test.f90:9:40:

         print *, check, iand(check,255_1)
                                        1
Error: Integer too big for its kind at (1). This check can be disabled with the option -fno-range-check

Would be a little cautious. Here is a test program to confirm:

program testbits
    integer*1 check
    integer i
    integer*1 allbits
    integer*2 shortcopy

    allbits = -1
    do i=-128, 127
        check = i
        shortcopy = i
        print *, check, iand(check,allbits),iand(shortcopy,255)
    end do

end program

Changing allbits to 255_1 still results in negative numbers.

from isce2.

rtburns-jpl avatar rtburns-jpl commented on July 29, 2024

Hmm. And unsigned ints don't appear to be standard in fortran.

What do the iands achieve here? If indata is already type integer*1 are they even needed?

from isce2.

S0sh0rt avatar S0sh0rt commented on July 29, 2024

My question also: The iands mask off the sign bit extended from the 8 bit value. since it needs to be treated as unsigned? I do recall that unsigned bytes were always a difficulty with Fortran.
Note that I had to change I*2 to I*4 in the initial fix I posted.

from isce2.

piyushrpt avatar piyushrpt commented on July 29, 2024

the problem is that fortran doesnt support unsigned ints. The information is read in as a byte stream (integer1 which is signed) and then converted to 4byte unsigned ints representing time tags. The iand converts values to unsigned equivalents. 255 cannot be stored in an integer1. An integer*2 can store the result of an iand operation.

from isce2.

rtburns-jpl avatar rtburns-jpl commented on July 29, 2024

How about just making the byte mask -1_1?

Edit: nevermind, looks like you can't assume twos-complement in fortran

from isce2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.