{"id":155,"date":"2017-09-13T10:35:57","date_gmt":"2017-09-13T13:35:57","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=155"},"modified":"2017-09-13T10:35:57","modified_gmt":"2017-09-13T13:35:57","slug":"plot2-f","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/plot2-f\/","title":{"rendered":"plot2.f"},"content":{"rendered":"<pre>c&lt;html&gt;\r\nc&lt;head&gt;&lt;title&gt;plot2.f&lt;\/title&gt;&lt;\/head&gt;\r\nc&lt;body&gt;\r\nc&lt;pre&gt;\r\n\r\n      program plotit\r\nc\r\nc    Program to provide plots of Sin(x)\r\nc    Ascii Character plots go to terminal and file 'pplot.out'\r\nc\r\nc     John Mahaffy   2\/1\/95\r\nc\r\n      implicit none\r\nc\r\nc    The following line tells Fortran that \"func\" is a function or subroutine\r\nc    and not a variable\r\nc\r\nc&lt;a name=\"ex\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      external func\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\nc\r\nc   The next line is necessary to pass the location of the intrinsic sin\r\nc   function as an argument to a subprogram\r\nc\r\nc&lt;a name=\"intrinsic\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      intrinsic sin\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\nc\r\n      call pplot(func,0.,6.)\r\n      print *, 'Hit the Enter key to continue'\r\nc&lt;a name=\"pause\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      pause\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\n      call gnuplot('x','y','sin(x)',func,0.0,6.0)\r\n      call gnuplot('x','y','Intrinsic sin(x)',sin,0.0,6.0)\r\n      stop\r\n      end\r\n      subroutine pplot(f,xmin,xmax)\r\nc\r\nc   Generate ASCII character plot to screen and file 'pplot.out'\r\nc\r\n      implicit none\r\n      character line*72\r\n      real x, f , xmin , xmax\r\n      integer ip,i,imax\r\nc\r\nc    The following line tells Fortran that f is a function or subroutine\r\nc    and not a variable\r\nc\r\n      external f\r\nc\r\nc   INPUT Arguments\r\nc\r\nc   f       -   function to be ploted\r\nc   xmin    -   minimum x value\r\nc   xmax    -   maximum x value\r\nc\r\nc   OTHER key variables\r\nc\r\nc   line    -   Character string loaded with a line of output\r\nc   ip      -   Position in line for a function value\r\nc\r\n      open (11,file='pplot.out')\r\nc\r\nc   Label values of the y axis\r\nc\r\n      line=' '\r\n      line(14:15)='-1'\r\n      line(65:65)='1'\r\n      write(*,*) line\r\n      write(11,*) line\r\n      line=' '\r\n      write(line(10:13),'(f4.1)') xmin\r\nc\r\nc   Draw the y axis\r\nc\r\n      line(15:40)='+----+----+----+----+----+'\r\n      line(41:65)=line(16:40)\r\nc\r\nc   Plot the value at x=0\r\nc\r\n      ip= nint(25*f(0.0))+40\r\n      line(ip:ip)='*'\r\n      write(*,*) line\r\n      write(11,*) line\r\n      line=' '\r\n      imax=nint((xmax-xmin)*10)\r\nc\r\nc     Limit output\r\nc\r\n      imax=min(1000,imax)\r\nc\r\nc    Loop through and plot points for other x values\r\nc\r\n      do 50 i=1,imax\r\n         x=.1*i\r\n         ip=nint(25*f(x))+40\r\nc \r\n         if(mod(i,10).eq.0) then\r\n            write(line(10:13),'(f4.1)') x\r\n            line(40:40)='+'\r\nc&lt;a name=\"else\"&gt;&lt;font color=\"FF0000\"&gt;\r\n         else\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\n            line(10:13)=' '\r\n            line(40:40)='|'\r\n         endif\r\n         line(ip:ip)='*'\r\n         write(*,*) line\r\n         write(11,*) line\r\n 50      line(ip:ip)=' '\r\nc&lt;a name=\"close\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      close (11)\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\n      return\r\n      end\r\n      subroutine gnuplot(xlabel,ylabel,title,f,xmin,xmax)\r\nc\r\nc   Ship data to the public domain program \"gnuplot\" for plotting\r\nc\r\n      implicit none\r\n      character line*72,sq*1\r\n      real x,f,xmin,xmax,fx\r\n      character*(*) xlabel,ylabel,title\r\n      integer i,imax,lc\r\n      external f\r\n      data sq\/''''\/\r\nc\r\nc   INPUT Arguments\r\nc\r\nc   f       -   function to be ploted\r\nc   xmin    -   minimum x value\r\nc   xmax    -   maximum x value\r\nc   xlabel  -   Contains a label for the x-axis\r\nc   ylabel  -   Contains a label for the y-axis\r\nc   title   -   Contains a title for the plot\r\nc\r\nc   OTHER key variables\r\nc\r\nc   line   -   Contains a line of character data\r\nc\r\nc   Drive a separate true graphics program (gnuplot)\r\nc\r\nc   First set up the command file for gnuplot\r\nc   Run gnuplot interactively and use the \"help\" command to learn more\r\nc   about what I am doing.\r\nc\r\n      open (12,file='gnuxy')\r\nc\r\nc  UnComment the next line if you are on a NCSA\/BYU Telnet Session\r\nc\r\nc     write(12,*) 'set terminal tek40xx'\r\nc\r\n      write(12,*) 'set data style lines'\r\nc     &lt;a name=1&gt;&lt;font color=FF0000&gt;\r\n      lc=len(xlabel)\r\nc     &lt;\/font&gt;\r\n      line='set xlabel '''\/\/xlabel(1:lc)\/\/sq\r\n      write(12,*)line\r\nc\r\nc   You don't really need to calculate the character variable length\r\nc   here.  The following works just fine because of the character*(*)\r\nc\r\n      line='set ylabel '''\/\/ylabel\/\/sq\r\n      write(12,*)line\r\n      line='set title '''\/\/title\/\/sq\r\n      write(12,*)line\r\n      write(12,*)'set nokey'\r\n      write(12,2000) xmin,xmax\r\n 2000 format('set xrange [',f3.0,':',f3.0,']')\r\n      write(12,*) 'plot ''dataxy'' using 1:2'\r\n      write(12,*) 'pause 10'\r\n      close(12)\r\nc\r\nc   Generate x-y pairs for the graph\r\nc\r\n      open (12,file='dataxy')\r\n      imax=nint((xmax-xmin)*10)\r\nc\r\nc     Limit output\r\nc\r\n      imax=min(1000,imax)\r\nc\r\n      do 100 i=0,imax\r\n         x=.1*i\r\n         fx=f(x)\r\n         write(12,*) x,fx\r\n  100 continue\r\n      close(12)\r\nc\r\nc   Tell the system to run the program gnuplot\r\nc   This call works on either IBM RS6000 or Sun, but is not part of\r\nc   the Fortran standard.\r\nc   Comment out the line if you aren't at a terminal with graphics\r\nc\r\n      call system('gnuplot gnuxy')\r\nc&lt;a name=\"10\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      return\r\nc&lt;\/a&gt;&lt;\/font&gt;\r\n      end\r\nc&lt;a name=\"fun\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      real function func(x)\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\n      func=sin(x)\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;plot2.f&lt;\/title&gt;&lt;\/head&gt; c&lt;body&gt; c&lt;pre&gt; program plotit c c Program to provide plots of Sin(x) c Ascii Character plots go to terminal and file &#8216;pplot.out&#8217; c c John Mahaffy 2\/1\/95 c implicit none c c The following line tells Fortran that &#8220;func&#8221; is a function or subroutine c and not a variable c c&lt;a name=&#8221;ex&#8221;&gt;&lt;font color=&#8221;FF0000&#8243;&gt; [&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-155","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/155","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=155"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/155\/revisions"}],"predecessor-version":[{"id":156,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/155\/revisions\/156"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}