What does 0.1773372103+245 mean in FORTRAN?

  • Context: Fortran 
  • Thread starter Thread starter wyosteve
  • Start date Start date
  • Tags Tags
    Fortran
Click For Summary

Discussion Overview

The discussion revolves around the interpretation of a specific numerical output format in FORTRAN, specifically the representation of floating-point numbers such as 0.1773372103+245. Participants explore the implications of this format in the context of a program calculating electric and magnetic fields due to a spinning charged sphere.

Discussion Character

  • Technical explanation
  • Exploratory
  • Homework-related

Main Points Raised

  • One participant questions the meaning of the output format 0.1773372103+245, suggesting it might represent 0.1773372103 x 10^245.
  • Another participant confirms that the output format is indeed a representation of a number in scientific notation, explaining the historical context of FORTRAN's formatting options for floating-point numbers.
  • Some participants note the variability in output depending on the FORTRAN compiler and the specific format statements used in the code.
  • A participant suggests that experimenting with simpler output statements could help clarify the behavior of the program's output.
  • Code snippets are shared to illustrate the context of the discussion, including variable declarations and output statements.

Areas of Agreement / Disagreement

Participants generally agree on the interpretation of the output format as scientific notation, but there is no consensus on the specific issues within the participant's program that may lead to unexpected results.

Contextual Notes

Participants express uncertainty regarding the specific FORTRAN compiler being used and the formatting options available, which may affect the output. There are also indications that the participant's understanding of formatting is limited, which could contribute to confusion.

wyosteve
Messages
23
Reaction score
0
Hi,
I'm writing a program in FORTRAN (my first) to find E and B fields due to a spinning sphere of charge. Anyways when printing out E and B field magnitudes I am getting numbers like this: 0.1773372103+245
What the heck does this mean!? Is it like 0.1773372103 x 10^245?
Thanks for any enlightenment!
 
Technology news on Phys.org
The old-school FORTRAN formatting was 0.1773372103E245

But we don't know which FORTRAN compiler you are using, we cannot see what your format statement was, if you used one, we don't know what your write statement was, if you used one, etc.

Perhaps for your first FORTRAN program before this program, try assigning a real variable a value and printing it out to see the result. Then try making changes to the value and repeat until you can convince yourself you are sure you can depend on output. If you can find some value that results in output like you have above then that might help explain what is going on.
 
Fortran 90
Here's a text file of my program. Large portions of it are copied from an example code my prof gave us for a similar one dimensional problem. I'll admit I know nothing about formatting (nor do I have time to learn that in detail).
 
here's the code
 

Attachments

wyosteve said:
What the heck does this mean!? Is it like 0.1773372103 x 10^245?

Short answer: yes.

Longer answer: In the first versions of Fortran, the exponent field was defined to be 4 characters long, and formatted as E+dd or E-dd (where each "d" is a decinal digit).

When computer hardware developed so that floating point numbers might have 3-digit exponents, the format options were changed to E+dd, E-dd or +0dd, -0dd for 2-digit exponents, and +ddd, -ddd for 3-digit exponents.

That still wasn't enough for some computer hardware (e.g. the Cray supercomputers could represent numbers with 4-digit expoinents) so the format specifier was also given a new option Ew.dEe where the w and d are as before, and e specifies the number of digits printed in the exponent.
 
ok great that's what I was hoping to hear! of course that means something is defiantly wrong with my program but at least now I know. Thanks
 
AlephZero said:
Short answer: yes.

Longer answer: In the first versions of Fortran, the exponent field was defined to be 4 characters long, and formatted as E+dd or E-dd (where each "d" is a decinal digit).

When computer hardware developed so that floating point numbers might have 3-digit exponents, the format options were changed to E+dd, E-dd or +0dd, -0dd for 2-digit exponents, and +ddd, -ddd for 3-digit exponents.

That still wasn't enough for some computer hardware (e.g. the Cray supercomputers could represent numbers with 4-digit expoinents) so the format specifier was also given a new option Ew.dEe where the w and d are as before, and e specifies the number of digits printed in the exponent.
You know you're showing your age here? :devil:

220px-FortranCardPROJ039.agr.jpg
 
Mod note: Copied code in attachment to here.
wyosteve said:
here's the code

Code:
program ComputeEB
!
!
implicit none
integer,parameter :: iconst = 6         ! integer used to control the resolution
integer,parameter :: Nz = iconst*5		! half the number of zones in each domain
integer,parameter :: ntot = 3*Nz        ! total number of timesteps
integer,parameter :: printnum = iconst  ! number of timesteps between data printout
integer,parameter :: c = 3E8			! speed of prop in a vacuum
REAL, PARAMETER :: pi = 3.1415927
integer :: i,j,k, n, Nzh, numout
double precision :: x(-Nz:Nz), y(-Nz:Nz), z(-Nz:Nz)
double precision :: Ex(-Nz:Nz), Bx(-Nz:Nz), Ey(-Nz:Nz), By(-Nz:Nz), Ez(-Nz:Nz), Bz(-Nz:Nz) 
double precision :: Exh(-Nz:Nz), Bxh(-Nz:Nz), Eyh(-Nz:Nz), Byh(-Nz:Nz), Ezh(-Nz:Nz), Bzh(-Nz:Nz) 
double precision :: Jx(-Nz:Nz), Jy(-Nz:Nz), Jz(-Nz:Nz)
double precision :: v, L, dt, h, twoh, dth, ed, time, Energy
double precision :: R, rho, omega, Toff, epsilon, mu
character(len=20) :: filenum
!
!
!
! Input parameters and constants
L = 0.1d0			! length of half the domain
h = L/Nz			! length of each zone
twoh = 2.0d0*h 		! 2h
dt = 0.25d0*h/c		! timestep
write(*,*) 'stuff = ', v, h, dt
dth = 0.5d0*dt
Nzh = Nz/2
R = .025d0
rho = 1E10
omega = 1E-3
Toff = 8E-11
epsilon = 8.85E-12
mu = pi*4E-7
!
!  Set up the 3D matrix
do i = -Nz, Nz
  x(i) = i*h
  y(i) = i*h
  z(i) = i*h
enddo
!
! Initial conditions
do i = -Nz, Nz
  Ex(i) = 0.0d0
  Ey(i) = 0.0d0
  Ez(i) = 0.0d0
  Bx(i) = 0.0d0
  By(i) = 0.0d0
  Exh(i) = 0.0d0
  Eyh(i) = 0.0d0
  Ezh(i) = 0.0d0
  Bxh(i) = 0.0d0
  Byh(i) = 0.0d0
  Bzh(i) = 0.0d0
  Jx(i) = 0.0d0
  Jy(i) = 0.0d0
  Jz(i) = 0.0d0
enddo
open(unit=11,file='Ex0')
do i = -Nz, Nz
    write(11,111) x(i), Ex(i) ! write data to file
enddo
close(11)
open(unit=11,file='Ey0')
do i = -Nz, Nz
    write(11,111) y(i), Ey(i) ! write data to file
enddo
close(11)
open(unit=11,file='Ez0')
do i = -Nz, Nz
    write(11,111) z(i), Ez(i) ! write data to file
enddo
close(11)
open(unit=11,file='Bx0')
do i = -Nz, Nz
    write(11,111) x(i), Bx(i) ! write data to file
enddo
close(11)
open(unit=11,file='By0')
do i = -Nz, Nz
    write(11,111) y(i), By(i) ! write data to file
enddo
close(11)
open(unit=11,file='Bz0')
do i = -Nz, Nz
    write(11,111) z(i), Bz(i) ! write data to file
enddo
close(11)
!
! Evolve	
time = 0.0d0
numout = 0
do n = 1, ntot ! Compute E and B
  do i = -Nz+1, Nz-1
    do j = -Nz+1, Nz-1
      do k = -Nz+1, Nz-1
        ! determine if we are within the current
        if (time < Toff .AND. sqrt(x(i)**2+y(j)**2+z(k)**2) < R) then
          Jx(k) = (-y(j)/2)*rho*omega*(1+cos(pi*sqrt(x(i)**2+y(j)**2+z(k)**2)/R))
          Jy(k) = (x(i)/2)*rho*omega*(1+cos(pi*sqrt(x(i)**2+y(j)**2+z(k)**2)/R))
        endif
        ! advance a half timestep
        ! E
        Exh(k) = Ex(k) + (dt/(4*epsilon*mu*h))*(Bz(j+1)-Bz(j-1)-By(k+1)+By(k-1))&
			& - (dt/(2*epsilon))*Jx(k)
        Eyh(k) = Ey(k) + (dt/(4*epsilon*mu*h))*(Bx(k+1)-Bx(k-1)-Bz(i+1)+Bz(i-1))&
			& - (dt/(2*epsilon))*Jy(k)
        Ezh(k) = Ex(k) + (dt/(4*epsilon*mu*h))*(By(i+1)-By(i-1)-Bx(j+1)+Bx(j-1))&
			& - (dt/(2*epsilon))*Jz(k)
        ! B
        Bxh(k) = Bx(k) - (dt/(4*h))*(Ez(j+1)-Ez(j-1)-Ey(k+1)+Ey(k-1))
        Byh(k) = By(k) - (dt/(4*h))*(Ex(k+1)-Ex(k-1)-Ez(i+1)+Ez(i-1))
        Bzh(k) = Bz(k) - (dt/(4*h))*(Ey(i+1)-Ey(i-1)-Ex(j+1)+Ex(j-1))
        ! advance a full timestep
        ! E
        Ex(k) = Ex(k) + (dt/(2*epsilon*mu*h))*(Bzh(j+1)-Bzh(j-1)-Byh(k+1)+Byh(k-1))&
			& - (dt/(2*epsilon))*Jx(k)
        Ey(k) = Ey(k) + (dt/(2*epsilon*mu*h))*(Bxh(k+1)-Bxh(k-1)-Bzh(i+1)+Bzh(i-1))&
			& - (dt/(2*epsilon))*Jy(k)
        Ez(k) = Ex(k) + (dt/(2*epsilon*mu*h))*(Byh(i+1)-Byh(i-1)-Bxh(j+1)+Bxh(j-1))&
			& - (dt/(2*epsilon))*Jz(k)
        ! B
        Bx(k) = Bx(k) - (dt/(2*h))*(Ezh(j+1)-Ezh(j-1)-Eyh(k+1)+Eyh(k-1))
        By(k) = By(k) - (dt/(2*h))*(Exh(k+1)-Exh(k-1)-Ezh(i+1)+Ezh(i-1))
        Bz(k) = Bz(k) - (dt/(2*h))*(Eyh(i+1)-Eyh(i-1)-Exh(j+1)+Exh(j-1))
      enddo
    enddo
  enddo
  time = time + dt
  write(*,*) 'step = ', n, ' time = ', time 
  ! Print out data if n equals a multiple of printnum 
  if (n .eq. (n/printnum)*printnum) then  
    numout = numout + 1                     ! increment numout (number of print-outs)
    write(filenum,*) numout                 ! write integer numout to character filenum
    filenum = adjustl(filenum)              ! remove leading spaces
    open(unit=33,file='Ex'//trim(filenum))	! create file with appropriate filename
    do i = -Nz, Nz
      write(33,111) x(i), Ex(i)         		! write data to file
    enddo
    close(33)
    open(unit=33,file='Ey'//trim(filenum))	! create file with appropriate filename
    do i = -Nz, Nz
      write(33,111) y(i), Ey(i)         		! write data to file
    enddo
    close(33)
    open(unit=33,file='Ez'//trim(filenum))	! create file with appropriate filename
    do i = -Nz, Nz
      write(33,111) z(i), Ez(i)         		! write data to file
    enddo
    close(33)
    open(unit=33,file='Bx'//trim(filenum))	! create file with appropriate filename
    do i = -Nz, Nz
      write(33,111) x(i), Bx(i)         		! write data to file
    enddo
    close(33)
    open(unit=33,file='By'//trim(filenum))	! create file with appropriate filename
    do i = -Nz, Nz
      write(33,111) y(i), By(i)         		! write data to file
    enddo
    close(33)
    open(unit=33,file='Bz'//trim(filenum))	! create file with appropriate filename
    do i = -Nz, Nz
      write(33,111) z(i), Bz(i)         		! write data to file
    enddo
    close(33)
  endif
enddo	
!	 
111 format(2E20.10)
555 format(2E20.10)
999 format(2E20.10)		
end program
 
wyosteve said:
Hi,
I'm writing a program in FORTRAN (my first) to find E and B fields due to a spinning sphere of charge. Anyways when printing out E and B field magnitudes I am getting numbers like this: 0.1773372103+245
What the heck does this mean!? Is it like 0.1773372103 x 10^245?
Thanks for any enlightenment!
If you're getting numbers like these, you are probably printing uninitialized variables.
 
  • #10
yeah I realized that! (along with lots of other issues, haha) thanks
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 20 ·
Replies
20
Views
6K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 11 ·
Replies
11
Views
11K
  • · Replies 22 ·
Replies
22
Views
5K
  • · Replies 19 ·
Replies
19
Views
7K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K