{"id":97,"date":"2017-09-13T10:03:34","date_gmt":"2017-09-13T13:03:34","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=97"},"modified":"2017-09-13T10:03:34","modified_gmt":"2017-09-13T13:03:34","slug":"dual-interface-f","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/dual-interface-f\/","title":{"rendered":"dual-interface.f"},"content":{"rendered":"<pre>c&lt;html&gt;\r\nc&lt;body&gt;\r\nc&lt;pre&gt;\r\n      program interface\r\nc\r\nc    Example of the use of the INTERFACE structure to\r\nc    create a generic function interface.  No function\r\nc    named \"saxpy\" actually exists, but the INTERFACE\r\nc    lets Fortran chose between \"rsaxpy\" and \"isaxpy\"\r\nc    depending upon argument types.\r\nc\r\nc     John Mahaffy  4\/3\/96\r\nc\r\n      implicit none\r\n      integer i\r\nc&lt;a name=\"dim\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      real, dimension(10) :: z,y,x=(\/(i,i=1,10)\/)\r\n      integer, dimension(10) :: m,l,k=(\/(i,i=1,10)\/)\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\n      data y \/5*1,5*2\/\r\n      data l \/5*1,5*2\/\r\nc\r\nc   interface block to permit a vector valued\r\nc   function named saxpy\r\nc\r\n      interface saxpy\r\nc\r\nc       interface to the REAL version of the function\r\nc\r\n         function rsaxpy (a,x,y)\r\n            real x(:),y(:),a\r\n            real rsaxpy(size(x))\r\nc\r\nc    Declare x,y,a as input to saxpy, a good compiler\r\nc    should warn you if they are undefined\r\nc\r\n            intent (in) x,y,a\r\n         end function rsaxpy\r\nc\r\nc       interface to the INTEGER version of the function\r\nc\r\n         function isaxpy (a,x,y)\r\nc&lt;a name=\"intent\"&gt;&lt;font color=\"FF0000\"&gt;\r\n            integer, intent(in) :: x(:),y(:),a\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\n            integer isaxpy(size(x))\r\n         end function isaxpy\r\nc&lt;a name=\"end\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      end interface\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\nc\r\nc\r\nc   Begin  Executable Statements\r\nc\r\nc   The next use of \"saxpy\" will actually  be using\r\nc   \"rsaxpy\"\r\nc\r\n      z = saxpy(2.,x,y)\r\n      write (*,2001)'a', 2.0\r\n      write(*,2001) 'x', x\r\n      write(*,2001) 'y', y\r\n      write(*,*) ' For z = a x + y '\r\n      write(*,2001) 'z',z\r\nc\r\nc   The next use of \"saxpy\" will actually  be using\r\nc   \"isaxpy\"\r\nc\r\n      m = saxpy(2 ,k,l)\r\n      write (*,2002)'a', 2\r\n      write(*,2002) 'k', k\r\n      write(*,2002) 'l', l\r\n      write(*,*) ' For m = a k + l '\r\n      write(*,2002) 'm',m\r\n      stop\r\n 2001 format (\/, 1x,a,' = ', 5f8.1,\/, (5x,5f8.1))\r\n 2002 format (\/, 1x,a,' = ', 5i5,\/, (5x,5i5))\r\n      end\r\nc\r\n      function rsaxpy(a,x,y)\r\nc\r\nc   Multply all contents of an array \"x\" by the scalar \"a\"\r\nc   then add the result to the array \"y\"\r\nc\r\nc   John Mahaffy    4\/3\/96\r\nc\r\nc\r\n      implicit none\r\n      real, dimension (:) :: x,y\r\n      real a, rsaxpy(size(x))\r\nc\r\nc   The next line combined with a good compiler should\r\nc   prevent you from accidently redefining a, x, or y\r\nc   within the subprogram.  Silly here, but not so far-\r\nc   fetched if the subprogram drags on for a 1000 lines\r\nc\r\n      intent (in) a,x,y\r\nc\r\n      rsaxpy =  a*x + y\r\n      return\r\n      end\r\nc\r\n      function isaxpy(a,x,y)\r\nc\r\nc   Multply all contents of an array \"x\" by the scalar \"a\"\r\nc   then add the result to the array \"y\"\r\nc\r\nc   John Mahaffy    4\/3\/96\r\nc\r\n      implicit none\r\n      integer, dimension (:), intent(in) :: x,y\r\n      integer, intent(in) :: a\r\n      integer isaxpy(size(x))\r\n      isaxpy =  a*x + y\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; program interface c c Example of the use of the INTERFACE structure to c create a generic function interface. No function c named &#8220;saxpy&#8221; actually exists, but the INTERFACE c lets Fortran chose between &#8220;rsaxpy&#8221; and &#8220;isaxpy&#8221; c depending upon argument types. c c John Mahaffy 4\/3\/96 c implicit none integer i [&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-97","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/97","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=97"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/97\/revisions"}],"predecessor-version":[{"id":98,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/97\/revisions\/98"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=97"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=97"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=97"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}