1 Replies - 3901 Views - Last Post: 18 June 2012 - 12:53 PM Rate Topic: -----

#1 dammerung  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 20-June 11

fortran: 4 byte real stored in 4 byte char array

Posted 15 June 2012 - 01:18 PM

Can anyone explain what the program is doing to the real numbers to get the output I posted. Is this some sort of bit manipulation? I'm trying to replicate this in c++, but I haven't been able to figure out what is going on...

code:
	PROGRAM TESTING
	
	IMPLICIT NONE

	real(4) test
	character(4) buff

	test = 123

	write(buff, 100) test
	write(*,*) buff	

	test = 123.0

	write(buff, 100) test
	write(*,*) buff	
	test = 123.01

	write(buff, 100) test
	write(*,*) buff	
	
	test = 123.001

	write(buff, 100) test
	write(*,*) buff	

100	FORMAT(A4)	
 
	END PROGRAM



output:
   B
   B
 ▼♣B
  B
Press any key to continue



thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: fortran: 4 byte real stored in 4 byte char array

#2 dammerung  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 20-June 11

Re: fortran: 4 byte real stored in 4 byte char array

Posted 18 June 2012 - 12:53 PM

some more sample code (and a bump):
	PROGRAM TESTING
	
	IMPLICIT NONE

	real(4) test
	character(4) buff

	test = 0.123

	write(buff, 100) test
	write(*,*) buff	

	test = 1.23

	write(buff, 100) test
	write(*,*) buff	
	test = 12.3

	write(buff, 100) test
	write(*,*) buff	
	
	test = 1230

	write(buff, 100) test
	write(*,*) buff	

100	FORMAT(A4)	
 
	END PROGRAM



with output:
 mτ√=
 p?
 ═╠DA
  └D
Press any key to continue


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1