Convert Char String to ASCII-96 Symbol 
Author Message
 Convert Char String to ASCII-96 Symbol

Hi folks.  I need to recreate fortran source code for a number of
subroutines on an OpenVMS system (they don't have the source code.)
One of the routines does a "Convert Character String to ASCII-96
Symbol."  Here is how it works:

CHARACTER*8 IN_STR
INTEGER INT_ARRAY(1:2)
EXTERNAL A8TOR8

IN_STR='ABCD1234'
CALL A8TOR8(IN_STR,INT_ARRAY)

PRINT '(Z20)', INT_ARRAY(1)
PRINT '(Z20)', INT_ARRAY(2)

END

Output:
41424344
31323334

I need to rewrite the A8TOR8 subroutine so it works exactly the same as
it does above.  Any suggestions on how to do this in Fortran?

Thanks.



Fri, 28 Nov 2008 23:04:21 GMT  
 Convert Char String to ASCII-96 Symbol

Quote:

> Hi folks.  I need to recreate fortran source code for a number of
> subroutines on an OpenVMS system (they don't have the source code.)
> One of the routines does a "Convert Character String to ASCII-96
> Symbol."  Here is how it works:

> CHARACTER*8 IN_STR
> INTEGER INT_ARRAY(1:2)
> EXTERNAL A8TOR8

> IN_STR='ABCD1234'
> CALL A8TOR8(IN_STR,INT_ARRAY)

> PRINT '(Z20)', INT_ARRAY(1)
> PRINT '(Z20)', INT_ARRAY(2)

> END

> Output:
> 41424344
> 31323334

> I need to rewrite the A8TOR8 subroutine so it works exactly the same as
> it does above.  Any suggestions on how to do this in Fortran?

> Thanks.

Looks like IN_STR and INT_ARRAY have the same bit patterns, although
this may not be true on the target machine.

Have a look at the intrinsic TRANSFER

Dave Flower



Fri, 28 Nov 2008 23:49:10 GMT  
 Convert Char String to ASCII-96 Symbol

Quote:
>Hi folks.  I need to recreate fortran source code for a number of
>subroutines on an OpenVMS system (they don't have the source code.)
>One of the routines does a "Convert Character String to ASCII-96
>Symbol."  Here is how it works:

>CHARACTER*8 IN_STR
>INTEGER INT_ARRAY(1:2)
>EXTERNAL A8TOR8

>IN_STR='ABCD1234'
>CALL A8TOR8(IN_STR,INT_ARRAY)

>PRINT '(Z20)', INT_ARRAY(1)
>PRINT '(Z20)', INT_ARRAY(2)

>END

>Output:
>41424344
>31323334

>I need to rewrite the A8TOR8 subroutine so it works exactly the same as
>it does above.  Any suggestions on how to do this in Fortran?

>Thanks.

 It seems you could do it easiest with equivalence (or whatever
its present name is)

  integer iout(2)
  character*8 astrn
  equivalence (astrn,iout(1))

  astrn='ABCD1234'

  print'(2z20)',iout

 Chris



Fri, 28 Nov 2008 17:53:17 GMT  
 Convert Char String to ASCII-96 Symbol

Quote:


> > I need to rewrite the A8TOR8 subroutine so it works exactly the same as
> > it does above.  Any suggestions on how to do this in Fortran?

> Looks like IN_STR and INT_ARRAY have the same bit patterns, although
> this may not be true on the target machine.

> Have a look at the intrinsic TRANSFER

I haven't verified the bit-pattern match, but that seemed like one of
the plausible options even without checking, so I'll believe David's
comment, along with his suggestion to use TRANSFER.

I just want to emphasize his "this may not be true on the target
machine" comment. Constructs like this are inherently non-portable. You
really need to understand not only how it is working, but also what your
code is using this for. With operations that depend on bit patterns like
this, it might not be *POSSIBLE* to make something that works "exactly"
the same on all machines. Please note that I meant that "not possible"
quite literally; I did not mean it as a synonym for "difficult". If the
requirement is to match both the bit pattern and the interpretation of
that bit pattern, then that is not possible on a machine where the sam
ebit pattern is interpreted in a different way (for example, on a
machine with different byte sex).

Therefore, my message is that you need to understand more about the code
than just the single line that calls this function. TRANSFER might
indeed do what is needed, but that depends on a higher-level
understanding of what the need is; just saying "do exactly the same
thing" is not adequate in matters of bit-pattern-dependence like this.

--
Richard Maine                     | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov            |       -- Mark Twain



Sat, 29 Nov 2008 00:06:30 GMT  
 Convert Char String to ASCII-96 Symbol
Thanks for the replys.  A couple of notes:

1) The program is being migrated from a different hardware platform,
but the same O/S (OpenVMS.)  Somewhere along the line they lost or
never received the source modules from the vendor.
2) The Equivalance won't work in this case.  In my example above I am
printing the integer values in hex.  For example, ABCD is 41424344 in
hex.  I need to convert ABCD to an Integer that when converted to hex
gives 41424344.  What I need to do is convert each byte from the string
to hex, concatenate together and then convert the hex # to decimal.  I
just need to find all the conversion functions in Fortran.  That's
where I need your help.  I'll keep searching the net (I have no Fortran
docs.)

Thanks. Grant.



Sat, 29 Nov 2008 00:45:26 GMT  
 Convert Char String to ASCII-96 Symbol

Quote:
>Thanks for the replys.  A couple of notes:

>1) The program is being migrated from a different hardware platform,
>but the same O/S (OpenVMS.)  Somewhere along the line they lost or
>never received the source modules from the vendor.
>2) The Equivalance won't work in this case.  In my example above I am
>printing the integer values in hex.  For example, ABCD is 41424344 in
>hex.  I need to convert ABCD to an Integer that when converted to hex
>gives 41424344.  What I need to do is convert each byte from the string
>to hex, concatenate together and then convert the hex # to decimal.  I
>just need to find all the conversion functions in Fortran.  That's
>where I need your help.  I'll keep searching the net (I have no Fortran
>docs.)

>Thanks. Grant.

 ? 'ABCD' = hex 41424344  (on a big endian system anyway ..
                          but VMS is small endian ? no?)

 but the hex # is already an integer                        
   = (((65*256+66)*256+67)*256+68

  so what's the problem ?

 Maybe a few more examples would clarify.

  (but when you print out a hex number, no matter what
the endian-ness , the MSB is first. On a small-e_ system,
 'ABCD' would print in Z20 as 44434241)  

Chris



Fri, 28 Nov 2008 19:29:47 GMT  
 Convert Char String to ASCII-96 Symbol

(snip)

Quote:
>  ? 'ABCD' = hex 41424344  (on a big endian system anyway ..
>                           but VMS is small endian ? no?)

VAX is little endian, I believe Alpha is bi-endian, but VMS
most likely runs it little endian.  Itanic should be bi-endian,
as its ancestors, HPPA and IA-32 are big and little endian,
respectively.

(snip)

Quote:
>   (but when you print out a hex number, no matter what
> the endian-ness , the MSB is first. On a small-e_ system,
>  'ABCD' would print in Z20 as 44434241)  

In converting an eight byte little endian value, the two
integer values should be exchanged from the order they
are printed by the OP.

To really answer the question, we need to know how this routine
is actually used in a real program.  Note especially that floating
point values are mixed endian on VAX, and A8TOR8 could imply that
it is being used with floating point values.

-- glen



Sat, 29 Nov 2008 01:52:24 GMT  
 Convert Char String to ASCII-96 Symbol

Quote:

> Hi folks.  I need to recreate fortran source code for a number of
> subroutines on an OpenVMS system (they don't have the source code.)
> One of the routines does a "Convert Character String to ASCII-96
> Symbol."  Here is how it works:

> CHARACTER*8 IN_STR
> INTEGER INT_ARRAY(1:2)
> EXTERNAL A8TOR8

> IN_STR='ABCD1234'
> CALL A8TOR8(IN_STR,INT_ARRAY)

> PRINT '(Z20)', INT_ARRAY(1)
> PRINT '(Z20)', INT_ARRAY(2)

> END

> Output:
> 41424344
> 31323334

> I need to rewrite the A8TOR8 subroutine so it works exactly the same as
> it does above.  Any suggestions on how to do this in Fortran?

> Thanks.

Here's a brute force solution. It should work with a very minimal set
of assumptions and be able to ignore byte and word ordering. Note that
printing out with a Z edit descriptor *might not* display what you
expect. But the *integer* values are correct.

Does this routine convert symbols to hash values for use in a symbol
table???

      CHARACTER*8 IN_STR
      INTEGER INT_ARRAY(1:2)
      EXTERNAL A8TOR8

      IN_STR='ABCD1234'
      CALL A8TOR8(IN_STR,INT_ARRAY)

C you can *not* be sure that Zn will convert integer
C to hex string as you expect
C you *might* see:
C
C           41424344
C           31323334

      PRINT '(Z20)', INT_ARRAY(1)
      PRINT '(Z20)', INT_ARRAY(2)

C so print them out as *integers*
C and expect to see:
C 1094861636
C 825373492

      PRINT *,INT_ARRAY(1)
      PRINT *,INT_ARRAY(2)

      END

      SUBROUTINE A8TOR8(S,T)
      CHARACTER*8 S
      INTEGER T(2)
      T(1)=0
      DO 10 I=1,4
        T(1)=T(1)*256+ICHAR(S(I:I))
10    CONTINUE
      T(2)=0
      DO 20 I=5,8
        T(2)=T(2)*256+ICHAR(S(I:I))
20    CONTINUE
      RETURN
      END

-- e-mail: epc8 at juno dot com



Sat, 29 Nov 2008 02:14:28 GMT  
 Convert Char String to ASCII-96 Symbol
That works beautifully!  Thanks!  Just 30 or so more routines to write
that have no source :(.

One other note regarding big/little endian.  Source code on VMS ports
between the various hardware platforms (VAX/Alpha/Itanium) without
issue.  Or at least I've ported many programs and have never had a
problem...

Quote:


> > Hi folks.  I need to recreate fortran source code for a number of
> > subroutines on an OpenVMS system (they don't have the source code.)
> > One of the routines does a "Convert Character String to ASCII-96
> > Symbol."  Here is how it works:

> > CHARACTER*8 IN_STR
> > INTEGER INT_ARRAY(1:2)
> > EXTERNAL A8TOR8

> > IN_STR='ABCD1234'
> > CALL A8TOR8(IN_STR,INT_ARRAY)

> > PRINT '(Z20)', INT_ARRAY(1)
> > PRINT '(Z20)', INT_ARRAY(2)

> > END

> > Output:
> > 41424344
> > 31323334

> > I need to rewrite the A8TOR8 subroutine so it works exactly the same as
> > it does above.  Any suggestions on how to do this in Fortran?

> > Thanks.

> Here's a brute force solution. It should work with a very minimal set
> of assumptions and be able to ignore byte and word ordering. Note that
> printing out with a Z edit descriptor *might not* display what you
> expect. But the *integer* values are correct.

> Does this routine convert symbols to hash values for use in a symbol
> table???

>       CHARACTER*8 IN_STR
>       INTEGER INT_ARRAY(1:2)
>       EXTERNAL A8TOR8

>       IN_STR='ABCD1234'
>       CALL A8TOR8(IN_STR,INT_ARRAY)

> C you can *not* be sure that Zn will convert integer
> C to hex string as you expect
> C you *might* see:
> C
> C           41424344
> C           31323334

>       PRINT '(Z20)', INT_ARRAY(1)
>       PRINT '(Z20)', INT_ARRAY(2)

> C so print them out as *integers*
> C and expect to see:
> C 1094861636
> C 825373492

>       PRINT *,INT_ARRAY(1)
>       PRINT *,INT_ARRAY(2)

>       END

>       SUBROUTINE A8TOR8(S,T)
>       CHARACTER*8 S
>       INTEGER T(2)
>       T(1)=0
>       DO 10 I=1,4
>         T(1)=T(1)*256+ICHAR(S(I:I))
> 10    CONTINUE
>       T(2)=0
>       DO 20 I=5,8
>         T(2)=T(2)*256+ICHAR(S(I:I))
> 20    CONTINUE
>       RETURN
>       END

> -- e-mail: epc8 at juno dot com



Sat, 29 Nov 2008 02:49:40 GMT  
 Convert Char String to ASCII-96 Symbol

Quote:
> C you can *not* be sure that Zn will convert integer
> C to hex string as you expect...

Why not? As of f90, Z is a standard edit descriptor for integers. Using
for non-integers is nonstandard and could produce different results on
compilers that accept it at all. Pre-f90, it is an extension, and so
might be open to various interpretation. Negative numbers are an issue
not addressed by the standard's treatment. But for positive integers in
f90, I see no reason why the output of Zn should not be portable.

Note that the standard's definition does *NOT* depend on the details of
the internal representation (such as byte order). It depends only on the
value. If you are, perhaps, thinking that the Z edit descriptor converts
each byte independently, ignoring the machine's byte order, then that's
not what the F90 standard specifies.

Now I could see that one might end up with a byte order different from
what the OP needs; that's perhaps the main question in my mind. But what
I don't see is that byte order has anything to do with the difference
between I and Z formatting, since they are both specified in terms of
numeric values - not in terms of bit representations.

Quote:
> C so print them out as *integers*

But the Z edit descriptor *IS* for integers. It converts an internal
integer into a character representation in base 16, much like The I edit
descriptor (or list-directed, as you used) converts an internal integer
into a character representation in base 10. But the base 16 form is no
more or no less an integer than the base 10 form. Both forms are
character representations of the integer using different bases.

--
Richard Maine                     | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov            |       -- Mark Twain



Sat, 29 Nov 2008 04:05:27 GMT  
 Convert Char String to ASCII-96 Symbol

Quote:


> > C you can *not* be sure that Zn will convert integer
> > C to hex string as you expect...

> Why not? As of f90, Z is a standard edit descriptor for integers. Using
> for non-integers is nonstandard and could produce different results on
> compilers that accept it at all. Pre-f90, it is an extension, and so
> might be open to various interpretation. Negative numbers are an issue
> not addressed by the standard's treatment. But for positive integers in
> f90, I see no reason why the output of Zn should not be portable.

Hmm. Maybe I was thinking of f77. The original code seems to be at
least that old.

Quote:
> Note that the standard's definition does *NOT* depend on the details of
> the internal representation (such as byte order). It depends only on the
> value. If you are, perhaps, thinking that the Z edit descriptor converts
> each byte independently, ignoring the machine's byte order, then that's
> not what the F90 standard specifies.

> Now I could see that one might end up with a byte order different from
> what the OP needs; that's perhaps the main question in my mind. But what
> I don't see is that byte order has anything to do with the difference
> between I and Z formatting, since they are both specified in terms of
> numeric values - not in terms of bit representations.

> > C so print them out as *integers*

At least I was sure what would happen here.

Quote:
> But the Z edit descriptor *IS* for integers. It converts an internal
> integer into a character representation in base 16, much like The I edit
> descriptor (or list-directed, as you used) converts an internal integer
> into a character representation in base 10. But the base 16 form is no
> more or no less an integer than the base 10 form. Both forms are
> character representations of the integer using different bases.

Thanks for the correction. (Mea culpa...)

-- elliot



Sat, 29 Nov 2008 04:52:58 GMT  
 Convert Char String to ASCII-96 Symbol

Quote:

> That works beautifully!  Thanks!  Just 30 or so more routines to write
> that have no source :(.

> One other note regarding big/little endian.  Source code on VMS ports
> between the various hardware platforms (VAX/Alpha/Itanium) without
> issue.  Or at least I've ported many programs and have never had a
> problem...



> > > Hi folks.  I need to recreate fortran source code for a number of
> > > subroutines on an OpenVMS system (they don't have the source code.)
> > > One of the routines does a "Convert Character String to ASCII-96
> > > Symbol."  Here is how it works:

> > > CHARACTER*8 IN_STR
> > > INTEGER INT_ARRAY(1:2)
> > > EXTERNAL A8TOR8

> > > IN_STR='ABCD1234'
> > > CALL A8TOR8(IN_STR,INT_ARRAY)

> > > PRINT '(Z20)', INT_ARRAY(1)
> > > PRINT '(Z20)', INT_ARRAY(2)

> > > END

> > > Output:
> > > 41424344
> > > 31323334

> > > I need to rewrite the A8TOR8 subroutine so it works exactly the same as
> > > it does above.  Any suggestions on how to do this in Fortran?

> > > Thanks.

> >       CHARACTER*8 IN_STR
> >       INTEGER INT_ARRAY(1:2)
> >       EXTERNAL A8TOR8

> >       IN_STR='ABCD1234'
> >       CALL A8TOR8(IN_STR,INT_ARRAY)

> > C           41424344
> > C           31323334

> >       PRINT '(Z20)', INT_ARRAY(1)
> >       PRINT '(Z20)', INT_ARRAY(2)

> >       END

> >       SUBROUTINE A8TOR8(S,T)
> >       CHARACTER*8 S
> >       INTEGER T(2)
> >       T(1)=0
> >       DO 10 I=1,4
> >         T(1)=T(1)*256+ICHAR(S(I:I))
> > 10    CONTINUE
> >       T(2)=0
> >       DO 20 I=5,8
> >         T(2)=T(2)*256+ICHAR(S(I:I))
> > 20    CONTINUE
> >       RETURN
> >       END

> > -- e-mail: epc8 at juno dot com

I went back and looked at the MACRO-32 code for this routine which was
included in a disassembly of a different set of routines that you
subsequently posted. In addition it appears that the original MACRO-32
routine replaced characters below space and above 0x7f with with space.

-- elliot



Wed, 03 Dec 2008 05:28:10 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Help- convert ascii code into char strings

2. How to convert binary string to char string ?

3. split Char and convert to ascii

4. Any code to convert char to ascii?

5. ASCII vs. CHAR [CHAR]

6. How to efficiently convert String to Symbol in VW 2.0

7. Converting String to Symbol?

8. how to convert float number into char string?

9. Converting a string to a symbol

10. Newbie: How to convert a string in symbol?

11. convert string to list of symbols

12. Question on converting string to symbol

 

 
Powered by phpBB® Forum Software