program htcoef2 c c John Mahaffy, Penn State University, CmpSc 201 Example c 1/26/96 c implicit none real k,D,h,Re,Pr real htc real anum c c Calculate an approximation for heat transfer coefficients c in a 1 inch pipe for several different Reynolds numbers c c h - heat transfer coefficient ( w/m**2/K)' c k - conductivity ( w/m/K)' c D - hydraulic diameter (m) c Re - Reynolds number c data k,D,Pr/0.617,0.0254,1.0/ c c Just to prove a point, I'm going to initialize the variable c called anum to 100 here. Watch what happens to the value c of the variable with the same name in the function htc, c the subroutine output, and here. c anum=100. c c Calculate and print Heat Transfer Coefficients for several c Reynolds numbers. c Re=10. h=htc(Re,D,k,Pr) call output (Re,h) c c Notice that I can use constants as arguments to subprograms c h=htc(100.,D,k,Pr) call output( 100., h) c c I can also use functions within the arguments to subprograms c call output (1000.,htc(1000.,D,k,Pr)) c c Watch what happens if the data type of my argument in the calling c sequence doesn't match the data type of the corresponding element c of the subprogram's argument list. c (I'm incorrectly using integer "10000" instead of 1.0e4 or 10000.0) c h=htc(10000,D,k,Pr) call output(10000,h) c c Although I set the value of variables called "anum" within htc and c output, the value of "anum" in the main program remains unchanged c The name "anum" represents a different memory location in each section c of the program. c c print *,' In main program anum = ',anum c stop end c function htc(Re,Hd,k,Pr) c c Calculate a heat transfer coefficient based on the maximum of the c Laminar and Turbulent coefficients. The turbulent coefficient is c obtained from a Dittus-Boelter correlation c c Notice that the variable names within the function do not have to c match the argument names in the calling sequence where the function c is used. Unless you take special measures, the Fortran compiler c makes no connection between variable names in the main program c and in functions or subroutines. At this point the only way that you c can get the main program and subprograms to agree that two variable c names represent the same location in computer memory is by alligning c those names in the same position in appropriate calling sequences and c subprogram argument lists. c c implicit none real Re,k,Hd,Pr,htc,Nulam,Nuturb real anum c c htc - heat transfer coefficient ( w/m**2/K)' c Nulam - laminar Nusselt number c Nuturb - Turbulent Nusselt number (Dittus-Boelter correlation) c k - conductivity ( w/m/K)' c Hd - hydraulic diameter (m) c Re - Reynolds number c Pr - Prandl number c data Nulam / 4.0/ c c Just to prove a point, I'm going to initialize the variable c called anum to 1 within this function. Watch what happens to the c value of the variable with the same name in the main program and c the subroutine output. c data anum/1.0/ c Nuturb=0.023*Re**0.8*Pr**0.4 htc=k/Hd*max(Nulam,Nuturb) c print *,' In function htc anum = ',anum c return end c subroutine output ( Re, h) c Print results to the screen c implicit none real Re, h real anum c c Re - Reynolds Number c h - Heat Transfer Coefficient c print *, 'For Reynolds Number = ',Re print *, 'Heat Transfer Coefficient is ',h,' w/m**2/K' c c Just to prove a point, I'm going to set the value of a variable c called anum to 3 within this subroutine. Watch what happens to the c value of the variable with the same name in the main program and c the function htc. c anum=3 print *,' In Subroutine output anum = ',anum c return end