Operating System - OpenVMS
1747658 Members
2319 Online
108751 Solutions
New Discussion юеВ

Re: Fortran IAND equivalent command in VMS DCL

 
SOLVED
Go to solution
Nelson Juinio
New Member

Fortran IAND equivalent command in VMS DCL

Good day.

Is there an equivalent VMS DCL command of Fortran IAND? I am trying to figure out how to check in DCL if a bit mask has been set for a database field. The database field has been exported to a text file and I extract the database field from the text string.

Here is the sample Fortran code that I want to copy over in DCL/VMS .COM file.

logical*4 function bit_check (arg1,arg2)
implicit none

integer*4 arg1,arg2

bit_check = 0 .ne. IAND (arg1,arg2)
return
end
12 REPLIES 12
Robert Gezelter
Honored Contributor

Re: Fortran IAND equivalent command in VMS DCL

Nelson,

The operator is ".AND."

Example:

$ X = 5
$ Y = 7
$ WRITE SYS$OUTPUT X .AND. Y

- Bob Gezelter, http://www.rlgsc.com
Nelson Juinio
New Member

Re: Fortran IAND equivalent command in VMS DCL

Hello Bob,

Thanks for the quick reply! Although I am not getting the result that I need.

I need to be able to check an integer symbol if it has a particular bit mask turned on.

$ open infile test.tab
$ read infile inrecord
$ flags = f$extract(104,12,inrecord)
$ show sym flags
FLAGS = " 320"
$ flag1 = 1
$ flag2 = 2
$ flag3 = 4
$ flag4 = 8
$ flag5 = 16
$ flag6 = 32
$ flag7 = 64
$ flag8 = 128
$ flag9 = 256
$ numflags = f$integer(flags)
$ show sym numflags
NUMFLAGS = 320 Hex = 00000140 Octal = 00000000500
$ if flag7 .AND. numflags then write sys$output "flag7 is on"
$ if flag9 .AND. numflags then write sys$output "flag9 is on"

The flags value of 320 is a combination of flag7 (64) and flag9 (256).

What am I doing wrong? Or is this even possible in DCL?

Thanks again!

Kind regards,
Nelson
David B Sneddon
Honored Contributor
Solution

Re: Fortran IAND equivalent command in VMS DCL

Try

$ if ((flag7 .AND. numflags) .ne. 0) then write sys$output "flag7 is on"
$ if ((flag9 .AND. numflags) .ne. 0) then write sys$output "flag9 is on"

Dave
Thomas Ritter
Respected Contributor

Re: Fortran IAND equivalent command in VMS DCL

$ if flag7 .AND. numflags then write sys$output "flag7 is on"
$ if flag9 .AND. numflags then write sys$output "flag9 is on"

The expression will be true if flag7 = numflags.
If numflags is 320 then then it will never be true. 64 is 1000000. 320 is 101000000.

You are confusioning vectors with masks.

Thomas Ritter
Respected Contributor

Re: Fortran IAND equivalent command in VMS DCL

Forgot, use


F$CVSI

Converts the specified bits in the specified character string to
a signed number.

Format

F$CVSI(start-bit,number-of-bits,string)
Hein van den Heuvel
Honored Contributor

Re: Fortran IAND equivalent command in VMS DCL

The test for TRUE is based on the LOW BIT being on or off.

Your .AND. will result in the test flag being set, but that is not bit 0.
But if the value (320 has either flag7 or flag9 set then an AND with that delivers a non-zero value. Thus, as David write test for non-zero:


$ flag7 = 64
$ x = 320
$ y = x.and.flag7
$ show symb y
Y = 64 Hex = 00000040 Octal = 00000000100
$ if y then write sys$output "true"
$ z = (x.and.flag7).ne.0
$ show symb z
Z = 1 Hex = 00000001 Octal = 00000000001
$ if z then write sys$output "true"
true
$


Hein.
Steven Schweda
Honored Contributor

Re: Fortran IAND equivalent command in VMS DCL

> The test for TRUE is based on the LOW BIT
> being on or off.

Same as in Fortran, right? Which is why the
test in the Fortran code was "0 .ne.[...]"

Come to think of it, who still uses IAND()
in Fortran? Logical operators (like .AND.)
have been in common use for decades.

In other words, logical operations in DCL
look and act a lot like logical operations in
Fortran, unless your Fortran dates back to
1966.
Nelson Juinio
New Member

Re: Fortran IAND equivalent command in VMS DCL

Thank you all for your help and valuable inputs. :)
John Kamaka
New Member

Re: Fortran IAND equivalent command in VMS DCL

Nelson, see the attached hack. It's not pretty but you can see how to get multiple bit values for small numbers. Sample output:

$ @cvui 320
320=101000000
flag7 is on
flag9 is on

$ @cvui 444
444=110111100
flag3 is on
flag4 is on
flag5 is on
flag6 is on
flag8 is on
flag9 is on