{"id":101,"date":"2017-09-13T10:05:54","date_gmt":"2017-09-13T13:05:54","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=101"},"modified":"2017-09-13T10:05:54","modified_gmt":"2017-09-13T13:05:54","slug":"format-f","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/format-f\/","title":{"rendered":"format.f"},"content":{"rendered":"<pre>c&lt;html&gt;\r\nc&lt;head&gt;&lt;title&gt;format.f&lt;\/title&gt;&lt;\/head&gt;\r\nc&lt;body&gt;\r\nc&lt;pre&gt;\r\n      program format\r\nc\r\nc    Examples of various uses of the Format Statement, and a small\r\nc    warning about precision of constants.\r\nc\r\nc    John Mahaffy  2\/26\/96\r\nc\r\n      integer n\r\n      parameter (n=5)\r\n      real r,cv,t(n),p(n),rho(n),u(n),tc(n),tf(n)\r\nc&lt;a name=\"dp\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      double precision rd,cvd,td,pd,rhod\r\n      double precision rd1\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\n      parameter (r=287.0478,cv=1004.832-r)\r\nc\r\nc    Watch the output to see what happens when I casually move\r\nc    single precision numbers into double precision parameters\r\nc    (or constants).  The computer is pretty causual about what\r\nc    it fills into the extra digits of precision.\r\nc\r\n      parameter (rd1=r)\r\nc\r\nc    Here I carefully define constants as DOUBLE PRECISION\r\nc\r\n      parameter (rd=287.0478d0,cvd=1.004832d3-r)\r\nc\r\nc    In Fortran90 I could have used a different notation in conjuction\r\nc    with KIND.  Comment out old code and uncomment the following to try.\r\nc\r\nc     integer, parameter :: r8=selected_real_kind(15,30)\r\nc     real (r8) rd,cvd,td,pd,rhod,ud\r\nc     parameter (rd=287.0478_r8, cvd=1.004832e3_r8)\r\nc\r\n      data p,t \/n*1.e5,n*300.\/\r\n      data pd,td\/1.d5,3.d2\/\r\n      open(11,file='format.out')\r\n      print *, ' Casual  Definition of Double Precision Gas Constant ='\r\n     &amp;  ,rd1\r\n      print *, ' Careful Definition of Double Precision Gas Constant ='\r\n     &amp;  ,rd\r\nc\r\n      print *\r\nc\r\n      print 2222\r\n 2222 format ('Look what I''ve got to do to include a single quote')\r\nc\r\n      print *\r\nc\r\n      rho(1)= p(1)\/(r*t(1))\r\n      rhod=pd\/(rd*td)\r\nc\r\nc    Start by writing a header\r\nc\r\n      write(*,1000)\r\n 1000 format(14x,' Pressure',13x,'Temperature',17x,'Density')\r\n      write(*,2000) p(1),t(1),rho(1)\r\n      write(*,2001) pd,td,rhod\r\n      write(*,2002) pd,td,rhod\r\nc\r\nc  Note how numbers in the following are right justified in the output\r\nc\r\n 2000 format(1p,3(1x,e23.7))\r\n 2001 format(1p,3(1x,d23.15))\r\nc\r\nc   You can get away with \"e\" edit descriptor on DOUBLE PRECISION\r\nc\r\n 2002 format(1p,3(1x,e23.15))\r\n      tc(1)=t(1)-273.16\r\n      tf(1)=32.+1.8*tc(1)\r\n      u(1)=cv*t(1)\r\n      rho(1)=p(1)\/(r*t(1))\r\n      do 100 i=2,n\r\n         t(i)=t(i-1)+100.\r\n         tc(i)=t(i)-273.16\r\n         tf=32.+1.8*tc(i)\r\n         p(i)=p(i-1)+1.e4\r\n         u(i)=cv*t(i)\r\n 100     rho(i)=p(i)\/(r*t(i))\r\n      write(11,2020)    2005\r\n      write(11,2004)\r\n 2004 format(\/\/,63x,'Internal',\/,\r\n     &amp;  1x,'Cell',3(5x,'Temp '), 7x,'P',8x,'Density',6x,'Energy',\r\n     &amp;  \/,2x,'Num',6x,'(K)',7x,'(C)',7x,'(F)',6x,'(Pa)',6x,\r\n     &amp;  '(kg\/m**3)',5x,'(J\/kg)' )\r\n      write(11,2005) (i,t(i),tc(i),tf(i),p(i),rho(i),u(i),i=1,n)\r\n 2005 format(1x,i4,0p,3f10.1,1p,3e12.3)\r\nc\r\nc   Watch What gets reused in the 2006 FORMAT\r\nc\r\n      write(11,2020)    2006\r\n      write(11,2004)\r\n      write(11,2006) (i,t(i),tc(i),tf(i),p(i),rho(i),u(i),i=1,n)\r\n 2006 format(71('-'),\/,(1x,i4,0p,3f10.1,1p,3e12.3))\r\nc\r\nc   Watch What gets reused in the 2007 FORMAT, containing an extra\r\nc   bounding parentheses, and a repeat factor on the main interior\r\nc   block of the FORMAT\r\nc\r\n      write(11,2020)    2007\r\n      write(11,2004)\r\n      write(11,2007) (i,t(i),tc(i),tf(i),p(i),rho(i),u(i),i=1,n)\r\n 2007 format((71('-'),\/,1(1x,i4,0p,3f10.1,1p,3e12.3)))\r\nc\r\nc   Next I get fancy with Repeat Operators and some vertical lines\r\nc\r\n      write(11,2020)    2008\r\n      write(11,2004)\r\n      write(11,2008) (i,t(i),tc(i),tf(i),p(i),rho(i),u(i),i=1,n)\r\n 2008 format((1x,i4,0p,3(2x,'|',2x,f5.1),1p, 3(1x,'|',1x,e9.3)))\r\nc\r\n      write(11,2020)    2009\r\n      write(11,2004)\r\nc\r\nc   Look how the seemingly harmless drop of one pair of parentheses\r\nc   can totally wreck the pattern of reuse in the FORMAT\r\nc\r\n      write(11,2009) (i,t(i),tc(i),tf(i),p(i),rho(i),u(i),i=1,n)\r\n 2009 format(1x,i4,0p,3(2x,'|',2x,f5.1),1p, 3(1x,'|',1x,e9.3))\r\nc\r\nc   Try replacing the above failed format with one that produces a\r\nc   table containing both vertical and horizontal bounding lines.\r\nc\r\n 2020 format(\/\/,'  Format Number ',i4)\r\n      stop\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;format.f&lt;\/title&gt;&lt;\/head&gt; c&lt;body&gt; c&lt;pre&gt; program format c c Examples of various uses of the Format Statement, and a small c warning about precision of constants. c c John Mahaffy 2\/26\/96 c integer n parameter (n=5) real r,cv,t(n),p(n),rho(n),u(n),tc(n),tf(n) c&lt;a name=&#8221;dp&#8221;&gt;&lt;font color=&#8221;FF0000&#8243;&gt; double precision rd,cvd,td,pd,rhod double precision rd1 c&lt;\/font&gt;&lt;\/a&gt; parameter (r=287.0478,cv=1004.832-r) c c Watch the output to [&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-101","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/101","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=101"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/101\/revisions"}],"predecessor-version":[{"id":102,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/101\/revisions\/102"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}