{"id":175,"date":"2017-09-13T10:49:11","date_gmt":"2017-09-13T13:49:11","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=175"},"modified":"2017-09-13T10:49:11","modified_gmt":"2017-09-13T13:49:11","slug":"fall-f","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/fall-f\/","title":{"rendered":"fall.f"},"content":{"rendered":"<pre>c&lt;html&gt;\r\nc&lt;body&gt;\r\nc&lt;pre&gt;\r\n      program fall\r\n      implicit none\r\nc\r\nc   Program to calculate the dynamics of a falling body\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    John Mahaffy  4\/15\/95\r\nc\r\n      integer np\r\n      parameter (np=2000)\r\nc\r\nc   In this program, I am using blank common just to save space in the\r\nc   executable program file (a.out).  It only appears in the main program\r\nc   Named common \"const\" communicates between subroutines.  By using the\r\nc   \"common\/const\/...\" statement in the main routine, I insure that some\r\nc   machines do not lose values in that common block when the first\r\nc   subroutine containing \"common\/const\/...\" is exited.\r\nc\r\nc&lt;a name=\"com\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      common v(np),z(np),t(np), zreal(np)\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\n      real v,z,t,zreal\r\n      common\/const\/dtmin,g\r\n      real dtmin,g\r\n      real dt\r\n      integer nsteps\r\nc\r\n      call input(z,dt)\r\n      call odesolve(v,z,t,dt,np,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\nc&lt;a name=\"bdata\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      block data cons\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\nc\r\nc    Initialize various constants\r\nc\r\nc    John Mahaffy  4\/15\/95\r\nc\r\nc     g  -  gravitational acceleration\r\nc     dtmin - time step selected if 0.0 is entered\r\nc\r\n      common\/const\/dtmin,g\r\n      real dtmin,g\r\n      data dtmin,g\/.001,9.807\/\r\nc&lt;a name=\"ebd\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      end block data cons\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\n      subroutine input (z,dt)\r\nc\r\nc   Obtain user input for initial height and solution 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 z(*)\r\n      common\/const\/dtmin,g\r\n      real dtmin,g\r\nc\r\n      write(6,*) ' What is the initial height (meters)?'\r\n      read *, z(1)\r\n      write(6,*) ' What time step size do you want (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,np,nsteps)\r\nc\r\nc   Solve the Ordinary Differential Equation of motion for the body\r\nc\r\nc    John Mahaffy  4\/15\/95\r\nc\r\nc   Arguments:\r\nc   Input\r\nc     dt     -   timestep size\r\nc     np     -   size of v,z, and t arrays\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 v(*),z(*),t(*),dt,rdt\r\n      common\/const\/dtmin,g\r\n      real dtmin,g\r\nc\r\nc   Solve the equation for a falling body\r\nc\r\nc      2\r\nc     d z\r\nc     ---2   =  - g\r\nc     d t\r\nc\r\nc    NOTE:  When you try this you will see that solving this for of the\r\nc           equation will result in the amplification of machine round-off\r\nc           error.  Never use this approach for this type equation.\r\nc\r\nc   Set remaining initial conditions:\r\nc\r\n      t(1)=0.\r\n      v(1)=0.\r\nc\r\nc    For the first step we need to fold in the initial velocity condition\r\nc    v(1)=(z(2)-z(0))\/(2*dt)  giving z(0)=z(1) - 2*dt*v(1)\r\nc    Substituting this value of z(0) into the equation at t=0 gives:\r\nc\r\n      z(2) = z(1) - .5*g*dt**2\r\n      t(2) = dt\r\nc\r\nc     Now loop through time steps until z goes negative or we run out of space\r\nc\r\n      rdt=.5\/dt\r\n      do 100 i=2,np-1\r\n         z(i+1)= 2*z(i)-z(i-1)-dt**2*g\r\n         v(i)=(z(i+1) - z(i-1)) * rdt\r\n         t(i+1)=t(i)+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\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  4\/15\/95\r\nc\r\n      common\/const\/dtmin,g\r\n      real dtmin,g\r\n      real t(*),z(*),zreal(*)\r\nc\r\n      do 10 i=1,nsteps\r\n  10  zreal(i)=z(1)-.5*g*t(i)**2\r\n      return\r\n      end\r\nc\r\n      subroutine output(t,z,zreal,v,nsteps)\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 v(*),z(*),t(*), zreal(*)\r\n      integer nsteps,i\r\n      print *, 'Look in the file fall.output for detailed results'\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),v(i),z(i),zreal(i)\r\n 300  continue\r\n 2000 format (33x,'Computed',8x,'Actual',\/,\r\n     &amp;        6x,'Time',9x,'Velocity', 8x,'Height',8x,'Height')\r\n 2001 format (1x,1p,4e15.7)\r\n      return\r\nc&lt;a name=\"1\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      end subroutine output\r\nc&lt;\/font&gt;&lt;\/a&gt;\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;body&gt; c&lt;pre&gt; program fall implicit none c c Program to calculate the dynamics of a falling body c c Arrays: c v &#8211; velocity at each time integration step c z &#8211; height at each time integration step c t &#8211; time for each corresponding v and z c zreal &#8211; Actual height at [&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-175","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/175","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=175"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/175\/revisions"}],"predecessor-version":[{"id":176,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/175\/revisions\/176"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}