!Fortran Final project
!Written By: Nicole Kessler

!file 4: file = bodyheights, Nicole Kessler, height aprox 5'3''
!another file = bodyheights2, Zach Schmitt, height aprox 5'9''
!other files have same name but 3-10 instead of 2 at the end of the name.

!Affects of Posture on Arterial Blood Pressures

!jc  A little longer summary of program here would be nice

PROGRAM pressure

  IMPLICIT NONE

   !variables with S at the end signify the data when the person is standing, L when the person is lying down
  !define vairables
  REAL:: co_visc, rho, conversion
  CHARACTER (LEN=35):: nameS, nameL
  CHARACTER (LEN = 10), DIMENSION(:), ALLOCATABLE:: body_part
  INTEGER :: num_pts, i, g, Pheart, hi
  REAL, DIMENSION(:), ALLOCATABLE :: heightS, heightL, PbodypartS, PbodypartL, hS, hL,x  !height is from ground (cm)
  INTEGER:: ier
  INTEGER, EXTERNAL:: pgbeg
  

  co_visc = 0.04 !vicosity of blood
  Pheart = 100  !mmHg, mean pressure at heart level
  g = 980      !cm/sec^2
  rho = 1.05  !g/cm^3, density of blood
  conversion = 7.5028E-4  !mmHg = 7.5028 E -04 dynes/cm^2

!jc  Why cgs units?  Are they standard in the references you looked at?

  OPEN(4, FILE= 'bodyheights', ACTION = 'READ', STATUS = 'OLD')

  !!READ(4, FILE= 'name of file', ACTION = 'READ', STATUS = 'OLD')
  READ(4,'(2A35)') nameS, nameL
  READ(4, '(I2)') num_pts
  
 Print*, nameS, nameL, num_pts

 ALLOCATE(heightS(num_pts), heightL(num_pts), body_part(num_pts), PbodypartS(num_pts), PbodypartL(num_pts))
 ALLOCATE(hS(num_pts), hL(num_pts), x(num_pts))

!jc  Don't indent the DO - indent inside the DO loop

    DO i = 1, num_pts          !this causes the loop to go through all of the data points
      READ(4, *) body_part(i), heightS(i), heightL(i)   !heights are measured in cm
      PRINT*, body_part(i), heightS(i), heightL(i), i
    ENDDO 

    DO i = 1, num_pts

!jc  You could use array syntax here:  hS = heightS(3)-heightS
    x(i) = i

       hS(i)=heightS(3)-heightS(i)
       hL(i)=heightL(3)-heightL(i)
      PRINT*, hS(i), hL(i)

       PbodypartS(i) = Pheart + (rho*g*hS(i))*conversion	!hS(L) is the distance of the body part below heart level (in cm)
       PbodypartL(i) = Pheart + (rho*g*hL(i))*conversion       ! rho*g*hS(L) is in dynes per cm^2, need to convert to mmHg.
      PRINT*,  PbodypartS(i), PbodypartL(i)
    END DO



  PRINT*, 'The aprox blood pressures (mmHG) standing,then lying flat are: '
  !jc  A llop would be nice here ....
  PRINT*, body_part(1), PbodypartS(1), PbodypartL(1)
  PRINT*, body_part(2), PbodypartS(2), PbodypartL(2)
  PRINT*, body_part(3), PbodypartS(3), PbodypartL(3)
  PRINT*, body_part(4), PbodypartS(4), PbodypartL(4)
  PRINT*, body_part(5), PbodypartS(5), PbodypartL(5)
  PRINT*, body_part(6), PbodypartS(6), PbodypartL(6)
  PRINT*, body_part(7), PbodypartS(7), PbodypartL(7)
  PRINT*, body_part(8), PbodypartS(8), PbodypartL(8)
  PRINT*, body_part(9), PbodypartS(9), PbodypartL(9)

  CLOSE(4)



!Initialize plot.  Using PGBIN to make a histogram/bar graph to show the blood pressure levels at the various places along the body. 
!Making one graph for both Standing and Lying down so viewer can see the immediate difference in blood pressure.

!jc  Nice work on the plots - I know it took a bit to get this working.

	ier = pgbeg(0, '/xserve',1,1)

	CALL pgenv (0.5, 9.5, 0., 200., 0, 1)

	CALL pglab('', 'Blood Pressure (mmHg)', 'Affects of Posture on Pressure in Different Areas of the Body')

	CALL pgsci(5)   !use the color to specify standing

	CALL pgbin(9, x(1:9), PbodypartS(1:9), .true. )

	CALL pgptxt(2., 175., 0.0, 0.0, nameS)

	CALL pgsci(7)  !another color to specify lying down

	CALL pgbin(9, x(1:9), PbodypartL(1:9), .true. )

	CALL pgptxt(6., 40., 0.0, 0.0, nameL)

	CALL pgsci(1)

	CALL pgpt (1, x(3), PbodypartS(3), 8) !this will represent the overlap of blood pressures at the heart

	CALL pgsci(1)

	CALL pgmtxt ('B', 2.5, 0.0, 0.0, "  1:Eyes,  2:Shoulders, 3:Heart,  4:Waist, 5:Hips,  6:Mid Thigh, 7:Knee,  8:Mid Calf, 9:Feet")
	
	CALL pgmtxt ('B', 3.5, 3.0, 0.0, "Body Parts by Number")
	CALL pgend



 DEALLOCATE (heightS, heightL, body_part, PbodypartS, PbodypartL, hL, hS, x)

END PROGRAM pressure

!jc  OK program.  While the calculations are not particularly taxing,
!jc  the program did them well.
