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

  • Context: Fortran 
  • Thread starter Thread starter shipman
  • Start date Start date
  • Tags Tags
    Error Fortran
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
4 replies · 4K views
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
 
Physics 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?
 
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