{"id":69,"date":"2017-09-11T15:08:51","date_gmt":"2017-09-11T18:08:51","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=69"},"modified":"2017-09-11T15:08:51","modified_gmt":"2017-09-11T18:08:51","slug":"array3a-f","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/array3a-f\/","title":{"rendered":"array3a.f"},"content":{"rendered":"<pre>PROGRAM ARRAY3\r\nc\r\nc    What if I don't know how much array space I will need when I first\r\nc    write my Fortran Program\r\nc\r\nc    John Mahaffy   2\/3\/95\r\nc\r\n      IMPLICIT NONE\r\n      INTEGER I,J,IERR,N,NDAT\r\nc\r\nc    Declare A, B, and C to be arrays to be ALLOCATABLE\r\nc\r\n      REAL, ALLOCATABLE :: A(:),B(:),C(:)\r\n      REAL CSUM,CMAX,CMIN,AVERAGE,DUMMY\r\nc\r\nc   One way to decide on how much space you need is to count information\r\nc   in the input.  Be sure to include options for error conditions.\r\nc\r\n      OPEN(11,FILE='array3a.in',ERR=400)\r\n      NDAT=0\r\n  10  READ(11,*,END=20) DUMMY\r\n      NDAT=NDAT+1\r\n      GO TO 10\r\n  20  CONTINUE\r\n      IF(NDAT.EQ.0) go to 400\r\nc\r\nc    Having gone through Unit 11, I need to reposition it at the beginning\r\nc\r\n      REWIND(11)\r\nc\r\nc   I've dropped the STAT optional argument this time.  The program will\r\nc   stop at the ALLOCATE statement if any problems develop.\r\nc\r\n      ALLOCATE (A(1:NDAT),B(NDAT),C(NDAT))\r\n      PRINT *, 'ERROR FLAG =', IERR\r\nc\r\nc   Set values of A and B\r\nc\r\n      DO 30 I=1,NDAT\r\n      READ(11,*) A(I), B(I)\r\n  30  CONTINUE\r\nc\r\nc   Process as before\r\nc\r\n      C(1:NDAT)=A(1:NDAT)+B(1:NDAT)\r\n      CSUM=SUM(C(1:NDAT))\r\n      CMIN=MINVAL(C(1:NDAT))\r\n      CMAX=MAXVAL(C(1:NDAT))\r\nC\r\n      AVERAGE=CSUM\/NDAT\r\n      WRITE(*,'(\/\/,'' RESULTS FOR ELEMENTS 1 THROUGH '',I3,'' OF C'')')\r\n     &amp; NDAT\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\n      WRITE(6,2003) C(1:NDAT)\r\n 2003 FORMAT(' C = ',\/,(1P,8E10.2))\r\nc\r\n      STOP\r\n 400  PRINT *,' Empty or missing input file: array3a.in'\r\n      STOP\r\n      END<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>PROGRAM ARRAY3 c c What if I don&#8217;t know how much array space I will need when I first c write my Fortran Program c c John Mahaffy 2\/3\/95 c IMPLICIT NONE INTEGER I,J,IERR,N,NDAT c c Declare A, B, and C to be arrays to be ALLOCATABLE c REAL, ALLOCATABLE :: A(:),B(:),C(:) REAL CSUM,CMAX,CMIN,AVERAGE,DUMMY c [&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-69","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/69","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=69"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/69\/revisions"}],"predecessor-version":[{"id":70,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/69\/revisions\/70"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}