Re: Declaration to get 8-bit (or 16-bit) integer?



Clive Page wrote:
In message <epohfj$j3m$1@xxxxxxxxxxxxxxxxxx>, Paul van Delst <Paul.vanDelst@xxxxxxxx> writes
But seriously, I use this for the multi-byte case:

MODULE Endian_Utility
USE Type_Kinds
IMPLICIT NONE
CONTAINS
FUNCTION Big_Endian()
INTEGER(Short) :: Source = 1_Short
LOGICAL :: Big_Endian
Big_Endian = .FALSE.
IF ( IACHAR(TRANSFER(Source,'a')) == 0 ) Big_Endian = .TRUE.
END FUNCTION Big_Endian
....
END MODULE Endian_Utility

That looks very similar to a module that I posted some years ago. If only I could remember how it worked :-)

Ha! I was going to write the exact same comment but I figured too much tongue in cheek would detract from my post's utility (such as it was). :oD

I probably did crib it from you via clf - most of my generally useful tools I've acquired via clf posts.


Now to a more difficult topic: how to get the effect of LOGICAL*1

What for? :o)

If you want a really large array of logicals, e.g. flags for bad pixels in a huge image, then the difference between 1-byte and 4-byte data can be significant.

Yeah, I was just pulling yer proverbial about that. But, wouldn't an array of integer(byte) achieve the same purpose? Depending on how you name your mask array, values of true/false or 0/1 can be ambiguous either way. But parameters would solve that:

use type_kinds ! definition of integer byte kind in here
integer(byte), parameter :: bad_pixel = 0_byte
integer(byte), parameter :: good_pixel = 1_byte
......
integer, parameter :: n = 100000
......
integer :: image(n,n) ! Assume default for image
integer(byte) :: mask(n,n)

where (mask == good_pixel)
..process pixels in image
end where


It's not as succinct as something like:


use type_kinds
integer, parameter :: n = 100000
......
integer :: image(n,n) ! Assume default for image
logical(byte) :: good_pixels(n,n) ! Assuming you can do this

where (good_pixels)
..process pixels in image
end where


but it's portable. :o)


Does the difference between doing
where (mask == good_pixel)
or
where (good_pixels)
incur any performance penalties?

cheers,

paulv

--
Paul van Delst Ride lots.
CIMSS @ NOAA/NCEP/EMC Eddy Merckx
Ph: (301)763-8000 x7748
Fax:(301)763-8545
.



Relevant Pages

  • Re: COMMON structures and text parsing
    ... The place where this choice is not "cleaner" is when you need to ... index into an array using a logical value. ... Logicals do not. ... do an associative array of logicals and do it "right", ...
    (comp.lang.fortran)
  • Re: COMMON structures and text parsing
    ... index into an array using a logical value. ... I want the compiler to work with me to ... demonstrate my point about "clean" code. ... do an associative array of logicals and do it "right", ...
    (comp.lang.fortran)
  • Re: sumif column contains text
    ... This expression will return an array of either TRUE or FALSE: ... SUMPRODUCT calculates numbers so we have to convert those logicals to ... circle, red circle, yellow circle, blue square, red square and so ...
    (microsoft.public.excel.misc)
  • Re: sumif column contains text
    ... Valko" wrote: ... This expression will return an array of either TRUE or FALSE: ... SUMPRODUCT calculates numbers so we have to convert those logicals to ... circle, red circle, yellow circle, blue square, red square and so ...
    (microsoft.public.excel.misc)
  • Re: one-liner for characater replacement
    ... Bit strings and LOGICAL arrays? ... It looks like an array ... likely only serve to allow reverse engineering to LOGICALs ... but only for comparison purposes. ...
    (comp.lang.fortran)