soccer jersey forums.silverfrost.com :: View topic - format mismatch
forums.silverfrost.com
Welcome to the Silverfrost forums

Author Message
Kingsland Don

Joined: 31 Dec 2019
Posts: 2

 Posted: Mon Jul 15, 2024 10:01 pm    Post subject: format mismatch 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.
PaulLaidler

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

 Posted: Tue Jul 16, 2024 7:01 am    Post subject: Please post some code that illustrates the failure together with the command line options used when compiling.
Kenneth_Smith

Joined: 18 May 2012
Posts: 703
Location: Hamilton, Lanarkshire, Scotland.

Posted: Tue Jul 16, 2024 10:35 am    Post subject:

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
PaulLaidler

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

 Posted: Tue Jul 16, 2024 11:00 am    Post subject: I can see the problem using Kenneth's code and will add it to the list of things to investigate.
Kenneth_Smith

Joined: 18 May 2012
Posts: 703
Location: Hamilton, Lanarkshire, Scotland.

Posted: Tue Jul 16, 2024 11:48 am    Post subject:

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
jlb

Joined: 21 Oct 2020
Posts: 57

 Posted: Tue Jul 16, 2024 3:15 pm    Post subject: 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.
PaulLaidler

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

 Posted: Wed Jul 17, 2024 6:43 am    Post subject: jib That is the point that is being made and I will investigate shortly.
jlb

Joined: 21 Oct 2020
Posts: 57

Posted: Wed Jul 17, 2024 8:37 am    Post subject:

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
Kenneth_Smith

Joined: 18 May 2012
Posts: 703
Location: Hamilton, Lanarkshire, Scotland.

 Posted: Wed Jul 17, 2024 8:55 am    Post subject: 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.
PaulLaidler

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

 Posted: Wed Jul 17, 2024 9:04 am    Post subject: 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.
Kenneth_Smith

Joined: 18 May 2012
Posts: 703
Location: Hamilton, Lanarkshire, Scotland.

Posted: Wed Jul 17, 2024 10:36 am    Post subject:

Paul,

Also B with real data.

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

Ken
PaulLaidler

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

 Posted: Wed Jul 17, 2024 10:51 am    Post subject: Thanks. Yes.
PaulLaidler

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

 Posted: Thu Jul 18, 2024 8:16 am    Post subject: This feature has now been added for the next release of the DLLs.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT + 1 Hour Page 1 of 1