{"id":52,"date":"2017-09-11T13:11:30","date_gmt":"2017-09-11T16:11:30","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=52"},"modified":"2017-09-11T13:11:30","modified_gmt":"2017-09-11T16:11:30","slug":"array1-f","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/array1-f\/","title":{"rendered":"array1.f"},"content":{"rendered":"<pre>c&lt;html&gt;\r\nc&lt;head&gt;&lt;title&gt;array1.f&lt;\/title&gt;&lt;\/head&gt;\r\nc&lt;body&gt;\r\nc&lt;pre&gt;\r\nc&lt;a name=\"program\"&gt;&lt;font color=\"FF0000\"&gt;\r\n\r\n      PROGRAM ARRAY1\r\nc&lt;\/a&gt;&lt;\/font&gt;\r\nc\r\nc    Simple exercises in using arrays for data analysis using Fortran 77\r\nc\r\nc    John Mahaffy   12\/27\/94\r\nc\r\n      IMPLICIT NONE\r\nc\r\nc    Declare A, B, and C to be arrays each containing 10 elements\r\nc\r\n      REAL A(10),B(10),C(10)\r\n      INTEGER I\r\nc\r\nc    A, B, and C could have been declared arrays in the REAL statement\r\nc    below  as \"      REAL CSUM,CMAX,CMIN,AVERAGE,A(10),B(10),C(10)\"\r\nc\r\n      REAL CSUM,CMAX,CMIN,AVERAGE\r\nc\r\nc    I've introduced the DATA statement below as a way of initializing\r\nc    A and B.  Note that the values are loaded into A and B at Compile\r\nc    time, and involve no computational work when the program is executed.\r\nc\r\n      DATA  A\/1.,2.,3.,4.,5.,6.,7.,8.,9.,10.\/,B\/3*1.,4*2.,3*3.\/\r\nc\r\nc    Now we set up a loop to set each element of C to be the sum of the\r\nc    corresponding elements in A and B.  At the same time we will be summing\r\nc    the elements in C to get an average value, and obtaining the maximum\r\nc    and minimum values of all elements in C.\r\nc\r\n      CSUM=0.\r\n      CMAX=-1.E38\r\n      CMIN=1.E38\r\n      DO 100 I=1,10\r\n         C(I)=A(I)+B(I)\r\nc     &lt;a name=1&gt;&lt;font color=FF0000&gt;\r\n         CMAX=MAX(C(I),CMAX)\r\nc     &lt;\/font&gt;\r\nc     &lt;a name=2&gt;&lt;font color=ff00ff&gt;\r\n         CMIN=MIN(C(I),CMIN)\r\nc     &lt;\/font&gt;\r\n 100     CSUM=CSUM+C(I)\r\nC\r\n      AVERAGE=CSUM\/10\r\nC\r\nc    The next write statement illustrates use of * for the unit number.\r\nc    It represents the default unit, which is the terminal.\r\nc\r\n      WRITE(*,*) ' RESULTS FOR FULL C ARRAY'\r\nc\r\nc    The format associated with the following write spreads the output\r\nc    of the three values (AVERAGE, CMIN, and CMAX) over 3 output lines.\r\nc\r\n      WRITE(6,2000)AVERAGE,CMIN,CMAX\r\nc&lt;a name=\"format\"&gt;&lt;font color=\"FF0000\"&gt;\r\n 2000 FORMAT(' AVERAGE OF ALL ELEMENTS IN C = ', F8.3,\/,\r\n     &amp;       ' MINIMUM OF ALL ELEMENTS IN C = ', F8.3,\/,\r\n     &amp;       ' MAXIMUM OF ALL ELEMENTS IN C = ', F8.3)\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\nc\r\nc   Look carefully at the results of the following formatted write.  After\r\nc   the first 8 elements of C are printed on one line, the end of the format\r\nc   specification is reached, so a new line is started.  Format information\r\nc   for the remaining 2 elements is obtained by looping back to the last left\r\nc   parenthesis and in this case reusing the 8E10.2 format.  Fortran is\r\nc   undisturbed by the fact that you run out of elements in C before you use\r\nc   all of the 8E10.2.  It just stops writing, and moves on to the next\r\nc   statement in the program.\r\nc\r\n      WRITE(6,2001) C\r\n 2001 FORMAT(' C = ',\/,(8E10.2))\r\nC\r\nC    Often you do not want to work with all elements of an array.  This is\r\nc    simple for our case.  The bounds on \"I\" are simply altered in the DO\r\nc    statement.\r\nc\r\n      CSUM=0.\r\n      CMAX=-1.E38\r\n      CMIN=1.E38\r\n      C(1)=0.\r\n      C(10)=0.\r\n      DO 200 I=2,9\r\n         C(I)=A(I)+B(I)\r\n         CMAX=MAX(C(I),CMAX)\r\n         CMIN=MIN(C(I),CMIN)\r\n 200     CSUM=CSUM+C(I)\r\nc    \r\n      AVERAGE=CSUM\/8\r\nc\r\nc    Below is another example of imbedding a format in a WRITE statement.\r\nc    Note the effect of the double slashes (\/\/).  Also note the doubled\r\nc    single quotes surrounding the character string \"RESULTS FOR EL...\".\r\nc    This practice is necessary when using a quoted character string within\r\nc    another quoted string.\r\nc\r\n      WRITE(*,'(\/\/,'' RESULTS FOR ELEMENTS 2 THROUGH 9 OF C'')')\r\nc\r\n      WRITE(6,2002)AVERAGE,CMIN,CMAX\r\n 2002 FORMAT(' AVERAGE OF SELECTED ELEMENTS IN C = ', F8.3,\/,\r\n     &amp;       ' MINIMUM OF SELECTED ELEMENTS IN C = ', F8.3,\/,\r\n     &amp;       ' MAXIMUM OF SELECTED ELEMENTS IN C = ', F8.3)\r\nc\r\nc  The write below is an example of the use of what is called an implied\r\nc  do loop.  In this case it is equivalent to using:\r\nc   WRITE(6,2003)C(1),C(2),C(3),C(4),C(5),C(6),C(7),C(8),C(9)\r\nc  I've included a \"1P\" here, but didn't the first time we printed C.  Note\r\nc  the difference.\r\nc\r\n      WRITE(6,2003) (C(I),I=2,9)\r\n 2003 FORMAT(' C = ',\/,(1P,8E10.2))\r\nc\r\nc   Very frequently it is necessary to take special action depending on the\r\nc   value of an array elements.  No real surprises here, but take a look at\r\nc   how this is handled in \"array2.f\".\r\nc   To see what Fortran does if you replace \"LOG(A(I))\" with \"LOG(I)\".\r\nc   For intrinsic functions it warns you if you mess up argument types.\r\nc\r\n      A(4)=-1.0\r\n      DO 300 I=1,10\r\n         IF(A(I).GT.1.0) THEN\r\n                C(I)=LOG(A(I))\r\n         ELSE\r\n            C(I)=0.\r\n         ENDIF\r\n  300    CONTINUE\r\nc\r\nc   Another way to get a blank line is given below.\r\nc\r\n      PRINT *\r\n      WRITE(6,*) ' RESULTS OF LOG(A)'\r\n      WRITE(6,2004) C\r\n 2004 FORMAT(' C = ',\/,(1P,8E10.2))\r\n      STOP\r\nc&lt;a name=\"end\"&gt;&lt;font color=\"FF0000\")\r\n      END\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;head&gt;&lt;title&gt;array1.f&lt;\/title&gt;&lt;\/head&gt; c&lt;body&gt; c&lt;pre&gt; c&lt;a name=&#8221;program&#8221;&gt;&lt;font color=&#8221;FF0000&#8243;&gt; PROGRAM ARRAY1 c&lt;\/a&gt;&lt;\/font&gt; c c Simple exercises in using arrays for data analysis using Fortran 77 c c John Mahaffy 12\/27\/94 c IMPLICIT NONE c c Declare A, B, and C to be arrays each containing 10 elements c REAL A(10),B(10),C(10) INTEGER I c c A, B, and [&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-52","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/52","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=52"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/52\/revisions"}],"predecessor-version":[{"id":53,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/52\/revisions\/53"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}