{"id":179,"date":"2017-09-13T10:51:31","date_gmt":"2017-09-13T13:51:31","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=179"},"modified":"2017-09-13T10:51:31","modified_gmt":"2017-09-13T13:51:31","slug":"fall2-f","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/fall2-f\/","title":{"rendered":"fall2.f"},"content":{"rendered":"<pre>c&lt;html&gt;\r\nc&lt;head&gt;&lt;title&gt;fall2.f&lt;\/title&gt;&lt;\/head&gt;\r\nc&lt;body&gt;\r\nc&lt;pre&gt;\r\n      module constants\r\n         integer, parameter :: np=2000, dbl=selected_real_kind(14,100)\r\n         real(dbl) :: g=9.807,dtmin=.001, kspg=10., mass = 100.0\r\nc\r\nc    np - number of elements available in solution arrays\r\nc    dbl - KIND for real variables\r\nc    g  -  constant of gravitational acceleration\r\nc    dtmin -  minimum allowed time step size\r\nc    kspg  -  spring constant for bungy cord\r\nc    mass -  Mass of the fool jumping off of the bridge\r\nc&lt;a name=\"em\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      end module constants\r\nc&lt;\/a&gt;&lt;\/font&gt;\r\n      program fall\r\n      use constants\r\n      implicit none\r\nc\r\nc   Program to calculate the dynamics of a falling body\r\nc\r\nc   John Mahaffy    4\/15\/95\r\nc\r\nc   Arrays:\r\nc     v   -   velocity at each time integration step\r\nc     z   -   height at  each time integration step\r\nc     t   -   time for each corresponding v and z\r\nc     zreal - Actual height at time t(i) for comparison with computed z\r\nc\r\nc   In this program, I am using allocatate just to save space in the\r\nc   executable program file (a.out).  No attempt is made to estimate a size.\r\nc   Module \"constants\" communicates between subroutines.\r\nc\r\n      real(dbl), allocatable :: v(:),z(:),t(:), zreal(:)\r\n      real(dbl) dt\r\n      integer nsteps\r\nc\r\n      allocate (v(np),z(np),t(np),zreal(np))\r\n      call input(z,dt)\r\n      call odesolve(v,z,t,dt,nsteps)\r\n      call realans(t,z,nsteps,zreal)\r\n      call output (t,z,zreal,v,nsteps)\r\n      stop\r\n      end\r\nc\r\n      subroutine input (z,dt)\r\n      use constants\r\n      implicit none\r\nc\r\nc   Obtain user input for initial height and time step\r\nc\r\nc   John Mahaffy    4\/15\/95\r\nc\r\nc  Output Arguments:\r\nc     z(1)   -  initial height\r\nc     dt     -  integration time step\r\nc\r\n      real(dbl) z(*),dt\r\nc\r\n      write(6,'(a)',advance='no') ' Initial height (meters): '\r\n      read *, z(1)\r\n      write(6,'(a)',advance='no') 'Time step size (seconds): '\r\n      read *, dt\r\n      if(dt.le.0.) dt=dtmin\r\n      return\r\n      end\r\nc\r\n      subroutine odesolve(v,z,t,dt,nsteps)\r\n      use constants\r\n      implicit none\r\nc\r\nc   Solve the Ordinary Differential Equation of motion for the body\r\nc\r\nc    John Mahaffy   5\/16\/95\r\nc\r\nc   Arguments:\r\nc   Input\r\nc     dt     -   timestep size\r\nc   Output:\r\nc     v    -   velocity\r\nc     z    -   height\r\nc     t    -   time\r\nc     nsteps - last step in the integration\r\nc\r\n      real(dbl) v(*),z(*),t(*),dt, c0, c1\r\n      integer i,nsteps\r\nc\r\nc     g  -  gravitational acceleration\r\nc     dtmin - time step selected if 0.0 is entered\r\nc     kspg - spring constant\r\nc     mass - mass of falling body\r\nc\r\nc\r\nc   Solve the equation for a falling body on a spring\r\nc\r\nc     d v              k                      d z\r\nc     ---    =  - g + --- ( z0 - z ) ,         ---   =  v\r\nc     d t              m                      d t\r\nc\r\nc\r\nc   Set remaining initial conditions:\r\nc\r\n      t(1)=0.\r\n      v(1)=0.\r\nc\r\nc   Set some useful constants\r\nc\r\n      c1=dt*kspg\/mass\r\n      c0= c1*z(1)-g*dt\r\nc\r\nc     Now loop through time steps until z goes negative or we run out of space\r\nc     This time integration is FIRST ORDER accurate (error proportional to dt)\r\nc\r\n      do 100 i=2,np\r\n         v(i)= v(i-1)+c0-c1*z(i-1)\r\n         z(i)= z(i-1)+dt*.5*(v(i)+v(i-1))\r\n         t(i)=t(i-1)+dt\r\n         if(z(i).lt.0.) go to 200\r\n 100     continue\r\n      write(6,*) 'Ran out of space to continue integration'\r\n      write(6,*) ' Last height was ',z(np),' meters'\r\n      i=np\r\n 200  nsteps=i\r\nc     return\r\n      end\r\nc\r\n      subroutine realans(t,z,nsteps,zreal)\r\n      use constants\r\n      implicit none\r\nc\r\nc     Get the values of the analytic solution to the differential equation\r\nc     for each time point to check the numerical accuracy.\r\nc\r\nc     John Mahaffy 5\/16\/95\r\nc\r\nc     g  -  gravitational acceleration\r\nc     dtmin - time step selected if 0.0 is entered\r\nc     kspg - spring constant\r\nc     mass - mass of falling body\r\nc\r\n      real(dbl) t(*),z(*),zreal(*),c1,c2\r\n      integer i,nsteps\r\n      c1=g*mass\/kspg\r\nc     &lt;a name=2&gt;&lt;font color=FF0000&gt;\r\n      c2=sqrt(kspg\/mass)\r\nc      &lt;\/font&gt;  &lt;\/a&gt;\r\n      do 10 i=1,nsteps\r\nc     &lt;a name=1&gt;&lt;font color=FF0000&gt;\r\n  10  zreal(i)=c1*cos(c2*t(i)) + z(1)-c1\r\nc      &lt;\/font&gt;  &lt;\/a&gt;\r\n      return\r\n      end\r\nc\r\n      subroutine output(t,z,zreal,v,nsteps)\r\n      use constants, only : dbl\r\n      implicit none\r\nc\r\nc   Outputs the full results of the time integration\r\nc\r\nc   John Mahaffy    4\/15\/95\r\nc\r\n      real(dbl) v(*),z(*),t(*), zreal(*)\r\n      integer nsteps,i\r\n      print *, 'Results are in fall.output'\r\n      open (11,file='fall.output')\r\n      write(11,2000)\r\n      do 300 i=1,nsteps\r\n      write(11,2001) t(i),z(i),zreal(i),z(i)-zreal(i)\r\n 300  continue\r\n 2000 format (21x,'Computed',8x,'Actual',\/,\r\n     &amp;        6x,'Time',12x,'Height',9x,'Height',9x,'Error')\r\n 2001 format (1x,1p,4e15.7)\r\n      return\r\n      end\r\nc&lt;\/pre&gt;\r\nc&lt;\/body&gt;\r\nc&lt;\/html&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>c&lt;html&gt; c&lt;head&gt;&lt;title&gt;fall2.f&lt;\/title&gt;&lt;\/head&gt; c&lt;body&gt; c&lt;pre&gt; module constants integer, parameter :: np=2000, dbl=selected_real_kind(14,100) real(dbl) :: g=9.807,dtmin=.001, kspg=10., mass = 100.0 c c np &#8211; number of elements available in solution arrays c dbl &#8211; KIND for real variables c g &#8211; constant of gravitational acceleration c dtmin &#8211; minimum allowed time step size c kspg &#8211; spring [&hellip;]<\/p>\n","protected":false},"author":22,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[],"tags":[],"class_list":["post-179","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/comments?post=179"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/179\/revisions"}],"predecessor-version":[{"id":180,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/179\/revisions\/180"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}