replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - format mismatch
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

format mismatch

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> 64-bit
View previous topic :: View next topic  
Author Message
Kingsland Don



Joined: 31 Dec 2019
Posts: 2

PostPosted: Mon Jul 15, 2024 10:01 pm    Post subject: format mismatch Reply with quote

I have a problem when trying to determine the internal hexadecimal represent of variables. Everything is fine if the variable was declared to be INTEGER. However if the variable was declared to be REAL the following error message is received at run time: FORMET mismatch; Z format with REAL item. Compiling with Plato does not generate an error message.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8217
Location: Salford, UK

PostPosted: Tue Jul 16, 2024 7:01 am    Post subject: Reply with quote

Please post some code that illustrates the failure together with the command line options used when compiling.
Back to top
View user's profile Send private message AIM Address
Kenneth_Smith



Joined: 18 May 2012
Posts: 818
Location: Lanarkshire, Scotland.

PostPosted: Tue Jul 16, 2024 10:35 am    Post subject: Reply with quote

You can use TRANSFER to convert the bit pattern of the real number to an integer number, and then print that integer in hex.


Code:
implicit none
  real :: number
  integer :: i
  character(len=8)  :: hex_str
  character(len=32) :: binary_str

  number = 123.987
 
  ! Convert bit pattern to integer using TRANSFER and write as hex
  i = transfer(number, i)
  write(hex_str, '(Z8.8)') i

  ! Convert bit pattern to binary string for printing
  call int2bin(i, binary_str)
 
  print*,  number
  print*,  binary_str
  print*,  hex_str

end


subroutine int2bin(input_int, bin_str)
integer, intent(in) :: input_int
character(len=32), intent(out) :: bin_str
integer :: j, temp_int
    temp_int = input_int
    do j = 32, 1, -1
      if (iand(temp_int, 1) .eq. 1) then
        bin_str(j:j) = '1'
      else
        bin_str(j:j) = '0'
      end if
      temp_int = ishft(temp_int, -1)
    end do
end subroutine int2bin

!Remember the internal binary representation will include a sign bit, bits for the exponent, and bits for the mantissa. 


Returns
Code:
      123.987
 01000010111101111111100101011000
 42F7F958
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8217
Location: Salford, UK

PostPosted: Tue Jul 16, 2024 11:00 am    Post subject: Reply with quote

I can see the problem using Kenneth's code and will add it to the list of things to investigate.
Back to top
View user's profile Send private message AIM Address
Kenneth_Smith



Joined: 18 May 2012
Posts: 818
Location: Lanarkshire, Scotland.

PostPosted: Tue Jul 16, 2024 11:48 am    Post subject: Reply with quote

I did not see an error in my example, but then I missed the really obvious case:

Code:
implicit none
real :: number = 123.987
  print'(Z8)', number
end


which should also return 42F7F958
Back to top
View user's profile Send private message
jlb



Joined: 21 Oct 2020
Posts: 80

PostPosted: Tue Jul 16, 2024 3:15 pm    Post subject: Reply with quote

Kenneth
Your last ("obvious") example code compiles but doesn't run (FORMAT mismatch: Z-format with REAL item), on both Win32 and x64, FTN95 version is 9.03.0.0.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8217
Location: Salford, UK

PostPosted: Wed Jul 17, 2024 6:43 am    Post subject: Reply with quote

jib

That is the point that is being made and I will investigate shortly.
Back to top
View user's profile Send private message AIM Address
jlb



Joined: 21 Oct 2020
Posts: 80

PostPosted: Wed Jul 17, 2024 8:37 am    Post subject: Reply with quote

Paul
Sorry, my mistake, I did not read Kenneth's comments on the "obvious" case carefully enough.

Kenneth
Is there a reason for using the subroutine int2bin instead of the "B" format?
Code:
write(*, '(1X,B32.32)') i
Back to top
View user's profile Send private message
Kenneth_Smith



Joined: 18 May 2012
Posts: 818
Location: Lanarkshire, Scotland.

PostPosted: Wed Jul 17, 2024 8:55 am    Post subject: Reply with quote

jlb, int2bin is the solution to one of a series of simple Fortran tutorial exercises I have been developing recently, so it came to mind before the "B" format.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8217
Location: Salford, UK

PostPosted: Wed Jul 17, 2024 9:04 am    Post subject: Reply with quote

It looks like the use of Z with REAL data is included in the 2008 Standard but not before.

At first sight this would require a non-trivial extension to the FTN95 library but I will add it to the wish list.
Back to top
View user's profile Send private message AIM Address
Kenneth_Smith



Joined: 18 May 2012
Posts: 818
Location: Lanarkshire, Scotland.

PostPosted: Wed Jul 17, 2024 10:36 am    Post subject: Reply with quote

Paul,

Also B with real data.

Code:
implicit none
real    :: number = 123.987
  write(*,'(B32.32)') number
end


Ken
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8217
Location: Salford, UK

PostPosted: Wed Jul 17, 2024 10:51 am    Post subject: Reply with quote

Thanks. Yes.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8217
Location: Salford, UK

PostPosted: Thu Jul 18, 2024 8:16 am    Post subject: Reply with quote

This feature has now been added for the next release of the DLLs.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> 64-bit All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group