{"id":177,"date":"2017-09-13T10:50:45","date_gmt":"2017-09-13T13:50:45","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=177"},"modified":"2017-09-13T10:50:45","modified_gmt":"2017-09-13T13:50:45","slug":"fall1-f","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/fall1-f\/","title":{"rendered":"fall1.f"},"content":{"rendered":"<pre>c&lt;html&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\r\n      end module constants\r\nc\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\nc&lt;a name=\"alable\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      real(dbl), allocatable :: v(:),z(:),t(:), zreal(:)\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\n      real(dbl) dt\r\n      integer nsteps\r\nc&lt;a name=\"all\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      allocate (v(np),z(np),t(np),zreal(np))\r\nc&lt;\/font&gt;&lt;\/a&gt;\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\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   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\r\n      integer i, nsteps\r\nc\r\nc   Solve the equation for a falling body\r\nc\r\nc     d v                    d z\r\nc     ---    =  - g          ---   =  v\r\nc     d t                    d t\r\nc\r\nc   Set remaining initial conditions:\r\nc\r\n      t(1)=0.\r\n      v(1)=0.\r\nc\r\nc     Now loop through time steps until z goes negative or we run out of space\r\nc\r\n      do 100 i=2,np\r\n         v(i)= v(i-1)-dt*g\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\nc&lt;a name=\"con\"&gt;&lt;font color=\"FF0000\"&gt;\r\n 100     continue\r\nc&lt;\/font&gt;&lt;\/a&gt;\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\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      real(dbl) t(*),z(*),zreal(*)\r\n      integer i,nsteps\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      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),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\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;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 end module constants c program fall use constants implicit none c c Program to calculate the dynamics of a falling body c c John Mahaffy 4\/15\/95 c c Arrays: c v &#8211; velocity at each time integration step c z &#8211; height [&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-177","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/177","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=177"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/177\/revisions"}],"predecessor-version":[{"id":178,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/177\/revisions\/178"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}