Fortran Why am I getting a NaN Error when Running my Fortran Program?

  • Thread starter Thread starter shipman
  • Start date Start date
  • Tags Tags
    Error Fortran
AI Thread Summary
The discussion revolves around troubleshooting a Fortran program designed to calculate bubble radius using the RP model. The user encountered a NaN (Not a Number) error during execution. Key points include the user's initial setup, which involved defining constants and variables for the simulation, and the iterative loop for calculating bubble pressure and radius. The user sought clarification on the NaN error, prompting responses that highlighted potential causes, such as division by zero. After making adjustments to the code, including changing the time step and modifying line continuations, the user successfully ran the program and confirmed that the NaN error was linked to mathematical errors in the calculations. The conversation emphasizes the importance of debugging and understanding error messages in programming.
shipman
Messages
3
Reaction score
0
Hi to everyone,

I am quite new to forum and fortran. Basically, i am trying to calculate the bubble radius using RP model and this is my code:
Code:
	IMPLICIT DOUBLE PRECISION (A-H,O-Z)
	IMPLICIT INTEGER (I-N)
C	! Declare local constant Pi
	REAL, PARAMETER :: Pi = 3.1415927D0	

C	*************************************************************
C	*    OUTPUT VARIABLES                                        *
C	*************************************************************
	OPEN (10,FILE='DT12.csv',STATUS='UNKNOWN')

C	************INPUT   VARIABLES**************
      DT=1.0D-12	!time step
	TEND=8.0D-4 ! ENDTIME
      DIN= 8.0D-4    !Initial BUBle Dia ometer  
      
C	********   SOME   VARIABLE DATA*****************
      ROL  =1.0D3  ! DENSITY   [LIQUID] kg/m-3
      DMYUL=1.002D-3 ! VISCOSITY [LIQUID]
     	PV=2.3D3    ! SATURATION PRESSURE 
	SIGMA=7.277D-2 ! SURFACE TENSION 
	BETA=1.4D0    ! pressure parameter
	VO=4.78D-9 !constant bubble volume 
	PO=1.00072D5 !used in pres. calculation 
      
	RO=0.5D0*DIN   ! BUBBLE RADIUS AT OLD TIME STEP
	R =0.5D0*DIN !0.5D0*1.07D-3  ! CURRENT BUBBLE RADIUS

	! Initial bubble volume

	VB= 4.0D0*Pi*(RO**3.0D0)/3.0D0 
	
	PG = PO*(VB/VO)**BETA ! PRESSURE OF NON-CONDENSING GAS

	PBUB  =PG +PV !bubble pressure
	
	PSUR=1.01325D5 !enviroment pressure=constant 

	TP    =0.0D0
	N     =0

C	************OUT PUT  INFOMATION*******************************

      NDATA=INT(TEND/DT)
      WRITE(*,100) DIN*1.0D3
      WRITE(*,300) NDATA

C	**************************************************************
C	 ***************LOOP 1  START*********************************
C	**************************************************************
10    TP=TP+DT

      N=N+1
	


	! Solving RP equation

      RR=(PBUB-PSUR
     &    -4.0D0*DMYUL/DT*(R-RO)/R
     &    -2.0D0*SIGMA/R)/ROL
      RNE=2.0D0*R-RO-1.5D0*(R-RO)**2.0D0/R+DT*DT*RR/R
	    
		
	 ! BUBBLE RADIUS AT NEW TIME STEP
      
	IF(RNE*2.0D0.LE.0)   RNE= 0.5d0*DIN
	IF(RNE*2.0D0.GE.2.0d-3)   RNE= 2.0d-3
      
	
	VB= 4.0D0*Pi*(RNE**3.0D0)/3.0D0 
	
	PG = PO*(VB/VO)**BETA ! PRESSURE OF NON-CONDENSING GAS

	PBUB  =PG+PV !bubble pressure

      DRDT=(RNE-R)/DT


	RO =R
	R  =RNE
	RNE=0.0D0

     
C	 *************************************************************
C	*						 OUTPUT                              *
C	*********************WRITE( *,400)*****************************************
     
      
	IF (MOD(N,NDATA/10000).EQ.1) THEN  !screen display data
       WRITE( *,400) N,TP,((3.0D0*VB)/(4.0d0*Pi))**(1.0d0/3.0D0)*1.0D3,
     & PG/1.0d6,DRDT
	end if
	
	if (MOD(N,NDATA/10000).EQ.1) THEN  !csv.data
	  WRITE( *,400) N,TP,((3.0D0*VB)/(4.0d0*Pi))**(1.0d0/3.0D0)*1.0D3,
     & PG/1.0d6,DRDT
      END IF
     
     	IF (TP.LT.TEND) GOTO 10  !time iteration

	
	goto 101
	
	
C *************************************************************
C *    LOOP END                                               *
C *************************************************************
C
101   write(*,*)RNE
  
  100 FORMAT('INITIAL DIAMETER(um)='F6.2)
  200 FORMAT('LIQUID PRESSURE(kPa)='F6.2)
  300 FORMAT('CYCLE NUMBER='8X,I16)
  400 FORMAT(I13,4(1X,1H,E13.6))
 
	CLOSE(10)

	
	
	STOP
	END

could someone tell me that why i get NaN error when i run the program?

Best Regards
 
Technology news on Phys.org
Could you provide some more detail about how the program informs you that the NaN error has occurred?

What is the exact wording of the NaN error message?
 
Do you know what NaN means?
 
took the source
saved the file as *.f90
replaced all "C" in first column for "!"
removed continuation marks "&" and simply glued lines back together...there is room
increased time step from e-12 to e-8, for good measure
compiled program
run it

First few lines:
Code:
INITIAL DIAMETER(um)=  0.80
CYCLE NUMBER=                   79999
            1 , 0.100000E-07 , 0.400000E+00 , 0.177292E-02 ,-0.291038E-02
            1 , 0.100000E-07 , 0.400000E+00 , 0.177292E-02 ,-0.291038E-02
            8 , 0.800000E-07 , 0.399999E+00 , 0.177290E-02 ,-0.232831E-01
            8 , 0.800000E-07 , 0.399999E+00 , 0.177290E-02 ,-0.232831E-01
           15 , 0.150000E-06 , 0.399996E+00 , 0.177286E-02 ,-0.436557E-01
           15 , 0.150000E-06 , 0.399996E+00 , 0.177286E-02 ,-0.436557E-01
           22 , 0.220000E-06 , 0.399993E+00 , 0.177278E-02 ,-0.640284E-01
           22 , 0.220000E-06 , 0.399993E+00 , 0.177278E-02 ,-0.640284E-01

Last few lines:
Code:
        79927 , 0.799872E-03 , 0.200000E+01 , 0.152885E+01 , 0.000000E+00
        79927 , 0.799872E-03 , 0.200000E+01 , 0.152885E+01 , 0.000000E+00
        79934 , 0.799942E-03 , 0.200000E+01 , 0.152885E+01 , 0.000000E+00
        79934 , 0.799942E-03 , 0.200000E+01 , 0.152885E+01 , 0.000000E+00
   0.00000000
 
Thank you so much for your all kind replies. Yeah "gsal" finally i could run the program correctly. I found that NaN shows mathematical error which can be derived from dividing by zero...Thank you
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top