Numbers Numbers Numbers 
Author Message
 Numbers Numbers Numbers

    As most of you know in languages like VB numbers are read lowest
bytes first.  This is causing me problems because I am writing a fortran
DLL that is passing integer 2 byte numbers to a VB front end.  For
example, the number read from a file in FORTRAN is CA05 in hex.  The
number after I pass it to VB is 5CA.  Do any of you know how I can avoid
playing games any just pass the numbers correctly between the two.   Any
help is greatly appreciated.

    -Samir



Sun, 29 Jun 2003 12:17:12 GMT  
 Numbers Numbers Numbers
FPT (http://simcon.uk.com) will allow you to declare a Fortran variable
as foreign - i.e. of a foreign data type like a byte-swapped integer or a
VAX D-FLOAT on an IEEE machine.  It will then automatically insert a
translation routine whenever the number is written or read.

Best wishes,

John.



Sun, 29 Jun 2003 17:46:41 GMT  
 Numbers Numbers Numbers


Quote:
>    As most of you know in languages like VB numbers are read lowest
>bytes first.  This is causing me problems because I am writing a FORTRAN
>DLL that is passing integer 2 byte numbers to a VB front end.  For
>example, the number read from a file in FORTRAN is CA05 in hex.  The
>number after I pass it to VB is 5CA.  Do any of you know how I can avoid
>playing games any just pass the numbers correctly between the two.   Any
>help is greatly appreciated.

Something is wrong here - for the most part, LANGUAGES don't specify
byte ordering, that's a property of the underlying processor.  If "VB"
means Microsoft Visual Basic, then the underlying processor is always
"little endian", the lowest addressed byte has the least significant
bit.  Therefore, just from what you've written here, I don't see how
you could be seeing the results you're describing, no matter whose
Fortran you're using.

Can you give us a short example showing both the Fortran and VB code
you're using that demonstrates the "swap"?  I suspect there's
something else going on that's not shown in your posting.


Fortran Engineering
Compaq Computer Corporation, Nashua NH

Compaq Fortran web site: http://www.compaq.com/fortran



Mon, 30 Jun 2003 04:05:03 GMT  
 Numbers Numbers Numbers
Here is my code:

VB End:
Dim num As Integer
Dim DataArray(1 To 800, 1 To 800) As Integer
Dim xpos As Integer
Dim ypos As Integer

    xpos = 512
    ypos = 512
    Call inc(num, DataArray(1, 1), xpos, ypos)     <== This is the FORTRAN
DLL call that I am making
    MsgBox Hex(num)
    Msgbox DataArray(1,1)

FORTRAN End (Salford compiler):
SUBROUTINE INC(NUM_BUFF,TEST1,xpos,ypos)
    CHARACTER*80 FILENAME
    INTEGER*2 HANDLE, ERRCODE
    INTEGER*2 NUM_BUFF
    INTEGER*2 xpos,ypos
    INTEGER*2 TEST1(xpos,ypos)

     FILENAME = 'c:\temp\jixin\test'


     DO j = 1,xpos,1
        DO i = 1,ypos,1

           TEST1(i,j) = NUM_BUFF
        ENDDO
     ENDDO


 END
----------------------------------------------
    If in VB I look at wither NUM_BUFF or TEST(i,j) the output number is
different than what it should be by what I said earlier.  The first 2 bytes
of the file are CA05 but I get 5CA.  Thanks for the help, let me know what
you think.

    -Samir Shah

Quote:



> >    As most of you know in languages like VB numbers are read lowest
> >bytes first.  This is causing me problems because I am writing a FORTRAN
> >DLL that is passing integer 2 byte numbers to a VB front end.  For
> >example, the number read from a file in FORTRAN is CA05 in hex.  The
> >number after I pass it to VB is 5CA.  Do any of you know how I can avoid
> >playing games any just pass the numbers correctly between the two.   Any
> >help is greatly appreciated.

> Something is wrong here - for the most part, LANGUAGES don't specify
> byte ordering, that's a property of the underlying processor.  If "VB"
> means Microsoft Visual Basic, then the underlying processor is always
> "little endian", the lowest addressed byte has the least significant
> bit.  Therefore, just from what you've written here, I don't see how
> you could be seeing the results you're describing, no matter whose
> Fortran you're using.

> Can you give us a short example showing both the Fortran and VB code
> you're using that demonstrates the "swap"?  I suspect there's
> something else going on that's not shown in your posting.


> Fortran Engineering
> Compaq Computer Corporation, Nashua NH

> Compaq Fortran web site: http://www.compaq.com/fortran



Mon, 30 Jun 2003 07:17:31 GMT  
 Numbers Numbers Numbers

Here is my code:

VB End:
Dim num As Integer
Dim DataArray(1 To 800, 1 To 800) As Integer
Dim xpos As Integer
Dim ypos As Integer

    xpos = 512
    ypos = 512
    Call inc(num, DataArray(1, 1), xpos, ypos)     <== This is the FORTRAN
DLL call that I am making
    MsgBox Hex(num)
    Msgbox DataArray(1,1)

FORTRAN End (Salford compiler):
SUBROUTINE INC(NUM_BUFF,TEST1,xpos,ypos)
    CHARACTER*80 FILENAME
    INTEGER*2 HANDLE, ERRCODE
    INTEGER*2 NUM_BUFF
    INTEGER*2 xpos,ypos
    INTEGER*2 TEST1(xpos,ypos)

     FILENAME = 'c:\temp\jixin\test'


     DO j = 1,xpos,1
        DO i = 1,ypos,1

           TEST1(i,j) = NUM_BUFF
        ENDDO
     ENDDO


 END
----------------------------------------------
    If in VB I look at wither NUM_BUFF or TEST(i,j) the output number is
different than what it should be by what I said earlier.  The first 2 bytes
of the file are CA05 but I get 5CA.  Thanks for the help, let me know what
you think.

    -Samir Shah

Quote:



> >    As most of you know in languages like VB numbers are read lowest
> >bytes first.  This is causing me problems because I am writing a FORTRAN
> >DLL that is passing integer 2 byte numbers to a VB front end.  For
> >example, the number read from a file in FORTRAN is CA05 in hex.  The
> >number after I pass it to VB is 5CA.  Do any of you know how I can avoid
> >playing games any just pass the numbers correctly between the two.   Any
> >help is greatly appreciated.

> Something is wrong here - for the most part, LANGUAGES don't specify
> byte ordering, that's a property of the underlying processor.  If "VB"
> means Microsoft Visual Basic, then the underlying processor is always
> "little endian", the lowest addressed byte has the least significant
> bit.  Therefore, just from what you've written here, I don't see how
> you could be seeing the results you're describing, no matter whose
> Fortran you're using.

> Can you give us a short example showing both the Fortran and VB code
> you're using that demonstrates the "swap"?  I suspect there's
> something else going on that's not shown in your posting.


> Fortran Engineering
> Compaq Computer Corporation, Nashua NH

> Compaq Fortran web site: http://www.compaq.com/fortran



Mon, 30 Jun 2003 07:14:00 GMT  
 Numbers Numbers Numbers

Quote:

> Here is my code:

> VB End:
> Dim num As Integer
> Dim DataArray(1 To 800, 1 To 800) As Integer
> Dim xpos As Integer
> Dim ypos As Integer

>     xpos = 512
>     ypos = 512
>     Call inc(num, DataArray(1, 1), xpos, ypos)     <== This is the
> FORTRAN DLL call that I am making
>     MsgBox Hex(num)
>     Msgbox DataArray(1,1)

> FORTRAN End (Salford compiler):
> SUBROUTINE INC(NUM_BUFF,TEST1,xpos,ypos)
>     CHARACTER*80 FILENAME
>     INTEGER*2 HANDLE, ERRCODE
>     INTEGER*2 NUM_BUFF
>     INTEGER*2 xpos,ypos
>     INTEGER*2 TEST1(xpos,ypos)

>      FILENAME = 'c:\temp\jixin\test'


>      DO j = 1,xpos,1
>         DO i = 1,ypos,1

>            TEST1(i,j) = NUM_BUFF
>         ENDDO
>      ENDDO


>  END
> ----------------------------------------------
>     If in VB I look at wither NUM_BUFF or TEST(i,j) the output number
> is different than what it should be by what I said earlier.  The first
> 2 bytes of the file are CA05 but I get 5CA.  Thanks for the help, let
> me know what you think.

>     -Samir Shah




> > >    As most of you know in languages like VB numbers are read
> > lowest
> > >bytes first.  This is causing me problems because I am writing a
> > FORTRAN
> > >DLL that is passing integer 2 byte numbers to a VB front end.  For
> > >example, the number read from a file in FORTRAN is CA05 in hex.
> > The
> > >number after I pass it to VB is 5CA.  Do any of you know how I can
> > avoid
> > >playing games any just pass the numbers correctly between the
> > two.   Any
> > >help is greatly appreciated.

> > Something is wrong here - for the most part, LANGUAGES don't specify

> > byte ordering, that's a property of the underlying processor.  If
> > "VB"
> > means Microsoft Visual Basic, then the underlying processor is
> > always
> > "little endian", the lowest addressed byte has the least significant

> > bit.  Therefore, just from what you've written here, I don't see how

> > you could be seeing the results you're describing, no matter whose
> > Fortran you're using.

> > Can you give us a short example showing both the Fortran and VB code

> > you're using that demonstrates the "swap"?  I suspect there's
> > something else going on that's not shown in your posting.


> > Fortran Engineering
> > Compaq Computer Corporation, Nashua NH

> > Compaq Fortran web site: http://www.compaq.com/fortran

  I see nothing initializing "num" AKA "NUM_BUFF", unless that is an
implied record number.
  In any event, memory representation is "little endian" as mentioned
and a hex "print" in either language will show the integer value in "big
endian" form.
  However, if one reads (either language) in a binary or unformatted (2
bytes or characters) manner, the order seen will be the internal or
"little endian" order.
  All that is shown here is the read of a file written in an unknown
manner; I have never used formatted file writes if FORTRAN, but i
understand that FORTRAN adds some code to designate either data type
and/or record lenghts along with the values.  If the file was written as
a FORTRAN formmated file, that might explain some of it; the read as
shown is unknown to me, and may not be strictly compatible to the actual
file contents.
  Try:
      OPEN (UNIT=1,FILE=FILENAME,FORM='UNFORMATTED',ACCESS=
     + 'SEQUENTIAL',RECORDTYPE='FIXED')
 and read into a character array and look at the actual contents (a nice
way to read a multi-megabyte text file fast; edit in RAM and write back
fast).


Mon, 30 Jun 2003 12:48:50 GMT  
 Numbers Numbers Numbers
What people are telling you is that If the first two bytes are CA05
(in that order), then those two bytes interpreted as a 2byte integer
on an intel hardware (which is little endian) is the decimal number
1482 or 5CA hex.

There is nothing wrong.

hth,
John



Quote:
>The first 2 bytes
>of the file are CA05 but I get 5CA.  Thanks for the help, let me know what
>you think.

>    -Samir Shah



Mon, 30 Jun 2003 13:47:19 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. BUG: Scientific Number to String/String to Number

2. Finding out number of threads or number of open windows in the app

3. Auto-numbering & Invoice Numbers

4. auto-numbered key - how to set the starting number

5. how can I make imaginary number with known real number

6. indexing numbers as numbers or strings

7. number to string .... string to number

8. Numbers from 1 to 10 (was Numbers from 1 to 10 in Over 4500 Languages)

9. Numbers from 1 to 10 (was Numbers from 1 to 10 in Over 4500 Languages)

10. VPREXX Help? Adding number to string number

11. number to string to number

12. Binary number -> Integer number

 

 
Powered by phpBB® Forum Software