For Programmers: Free Programming Magazines  


Home > Archive > Fortran > August 2005 > Fortran (Linux pgf90)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Fortran (Linux pgf90)
David Rudack

2005-08-25, 6:59 pm

I have inherited a code that equivalences a four character string (TDLP)
to its integer value. The code first gets the integer value and then
checks if the integer value is equivalent to the 4 letter character
string TDLP. If they are the same, the program continues. The problem
is that I have compiled this code along with all other associated
codes on a Linux machine using the fortran compilation option of
-byteswapio. I need to do this because the input data is big endian.
When I run the program the subroutine compares the character string of
"PLDT" instead of what it should be comparing, mainly, "TDLP". If I
hardwire in "PLDT" as the character string, the code runs fine and all
the data is switched to little endian and I get good results. It seems
like the character string is not being treated correctly. Is there a
compiler option to get rid of this problem?? Thanx for any help.

---David
glen herrmannsfeldt

2005-08-25, 6:59 pm

David Rudack wrote:

> I have inherited a code that equivalences a four character string (TDLP)
> to its integer value. The code first gets the integer value and then
> checks if the integer value is equivalent to the 4 letter character
> string TDLP. If they are the same, the program continues. The problem
> is that I have compiled this code along with all other associated
> codes on a Linux machine using the fortran compilation option of
> -byteswapio. I need to do this because the input data is big endian.
> When I run the program the subroutine compares the character string of
> "PLDT" instead of what it should be comparing, mainly, "TDLP". If I
> hardwire in "PLDT" as the character string, the code runs fine and all
> the data is switched to little endian and I get good results. It seems
> like the character string is not being treated correctly. Is there a
> compiler option to get rid of this problem?? Thanx for any help.


If it does byte swapping then no, it is not comparing to "PLDT",
but is byte swapping the input data before comparing it.

You can't expect it to know which integer inputs are to be byte
swapped and which aren't by magic. It seems to me that you have
the right solution, compare to "PLDT" instead.

In C, one would use the functions htonl() and ntohl() to do byte
swapping conditional on the machine not being big-endian.
You might see if those would help you here.

-- glen

Greg Lindahl

2005-08-25, 6:59 pm

In article <dekgc3$eed$1@news.nems.noaa.gov>,
David Rudack <David.Rudack@noaa.gov> wrote:

> It seems like the character string is not being treated correctly.


But it sounds like it is read as an integer. If you read it as a
CHARACTER*4 instead, you'll get the result you're looking for. The
I/O runtime can only work with the type you tell it.

-- greg

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com