{"id":111,"date":"2017-09-13T10:10:49","date_gmt":"2017-09-13T13:10:49","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=111"},"modified":"2017-09-13T10:10:49","modified_gmt":"2017-09-13T13:10:49","slug":"grades1-f","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/grades1-f\/","title":{"rendered":"grades1.f"},"content":{"rendered":"<pre>c &lt;html&gt;\r\nc &lt;head&gt;&lt;title&gt;&lt;\/title&gt;&lt;\/head&gt;\r\nc &lt;body&gt;\r\nc &lt;pre&gt;\r\nc\r\n      program grades\r\nc\r\nc    Program to provide information about a Class Grade distribution\r\nc\r\nc    This program starts to look like a serious structured program\r\nc    The main program only acts as a broad outline calling various key\r\nc    tasks in subprograms.  Specific classes of tasks are isolated in\r\nc    their own subprograms.\r\nc\r\n      implicit none \r\n      integer nstmx, nst\r\n      parameter (nstmx=30)\r\n      real final(nstmx)\r\n      real t1(nstmx),t2(nstmx),t3(nstmx),t4(nstmx),t5(nstmx)\r\n      character*16 names(nstmx)\r\n      character*2 grds(nstmx)\r\n      real temp(nstmx)\r\n      integer ind(nstmx) , i\r\nc   nstmx  - maximum class size\r\nc   nst  -  number of students found\r\nc   t1   -  array of grades for test1\r\nc   t2   -  array of grades for test2\r\nc   t3   -  array of grades for test3\r\nc   t4   -  array of grades for test4\r\nc   t5   -  array of grades for test5\r\nc   names - array containing names of students\r\nc   final - final score obtained from a weighted average of tests\r\nc   grds  - letter grades assigned to each student\r\nc   temp  - temporary score array used for determining ranking\r\nc   ind   - array containing index references to students listed from\r\nc           highest to lowest class score.\r\nc\r\nc   Initialize ind\r\nc\r\n      do 10 i=1,nstmx\r\n  10  ind(i)=i\r\nc\r\nc     Open an output file to record all information\r\nc\r\n      open (12,file='grades.out')\r\nc\r\nc    Read in test data\r\nc&lt;a name=\"call\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      call input(t1,t2,t3,t4,t5,names,nst,nstmx)\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\nc\r\nc    Calculate  the Final avrag score for all students\r\nc\r\n      call mean (t1,t2,t3,t4,t5,nst,final)\r\nc\r\nc   Generate output of processed information\r\nc\r\n      call output(t1,t2,t3,t4,t5,final,nst,names,grds,temp,ind)\r\nc\r\n      stop\r\n      end\r\nc\r\nc\r\n      subroutine input(t1,t2,t3,t4,t5,names,nst,nstmx)\r\nc\r\nc     Reads grades from 5 tests and associated student name\r\nc\r\n      implicit none\r\nc\r\nc   Use of the * in the array dimensioning says that the actual dimension\r\nc   is the problem of the calling routine\r\nc\r\n      real t1(*),t2(*),t3(*),t4(*),t5(*)\r\n      character*(*) names(*)\r\n      character*32 fname\r\n      character*8 answer\r\n      integer nst,nstmx, i\r\n      logical fexist\r\nc\r\nc   Arguments\r\nc\r\nc   Input -\r\nc   nstmax - maximum number of students that can be processed\r\nc\r\nc   Output -\r\nc   nst  -  number of students found\r\nc   t1   -  array of grades for test1\r\nc   t2   -  array of grades for test2\r\nc   t3   -  array of grades for test3\r\nc   t4   -  array of grades for test4\r\nc   t5   -  array of grades for test5\r\nc   names - array containing names of students\r\nc\r\nc   Begin executable code by opening the I\/O   units\r\nc\r\n   5  write(*,1000)\r\n 1000 format ( 'Provide name of file with student information:')\r\n      read *, fname\r\nc &lt;a name=\"inquire\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      inquire (file=fname,exist=fexist)\r\nc &lt;\/font&gt;&lt;\/a&gt;\r\n      if (.not.fexist) then\r\n         print  *,  fname,' does not exist'\r\n         print *, 'Do you want to quit (yes or no)?'\r\n         read *, answer\r\n         if (answer(1:1).eq.'y'.or.answer(1:1).eq.'Y') stop\r\n         go to 5\r\n      endif\r\nc &lt;a name=\"open\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      open (11,file='grades.in',status='old',err=600)\r\nc &lt;\/font&gt;&lt;\/a&gt;\r\nc c\r\n      i=1\r\n   20 read (11,*,end=40) t1(i),t2(i),t3(i),t4(i),t5(i),names(i)\r\n      i=i+1\r\n      go to 20\r\n   40 nst=i-1\r\nc&lt;a name=\"12\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      if(nst.gt.nstmx) then\r\n         print *, 'Insufficient Space to Process this Class'\r\n         print *, 'Set nstmax = ', nst,' in the PARAMETER statement'\r\n         stop\r\n         endif\r\nc&lt;\/a&gt;&lt;\/font&gt;\r\n      return\r\nc\r\n  600 print *,'Problem opening file: ', fname\r\n      stop\r\n      end             \r\nc\r\nc\r\n      subroutine mean (t1,t2,t3,t4,t5,nst,final)\r\n      implicit none\r\nc\r\nc     average the results of 5 tests to produce final scores\r\nc\r\n      real t1(*),t2(*),t3(*),t4(*),t5(*), final(*)\r\n      real w(5),wa(5),wsum\r\nc\r\n      integer nst,i\r\nc\r\nc   Set relative weighting factors for exams\r\nc\r\n      data w\/ 5*1.\/\r\nc\r\nc   Arguments\r\nc\r\nc   Input -\r\nc   nst - number of students\r\nc   nst  -  number of students found\r\nc   t1   -  array of grades for test1\r\nc   t2   -  array of grades for test2\r\nc   t3   -  array of grades for test3\r\nc   t4   -  array of grades for test4\r\nc   t5   -  array of grades for test5\r\nc\r\nc   Output -\r\nc   final - array containing final averaged score\r\nc\r\nc    Other variables:\r\nc    w -   relative weights of tests\r\nc    wsum - sum of relative weights\r\nc    wa -  absolute weights of tests\r\nc\r\nc    Calculate absolute weight factors\r\nc\r\n      wsum=0.\r\n      do 10 i=1,5\r\n  10  wsum = wsum+ w(i)\r\nc\r\nc    The next line saves computer time in the following do loop\r\nc\r\n      wsum=1.\/wsum\r\n      do 20 i=1,5\r\n  20  wa(i)=w(i)*wsum\r\n      do 30 i=1,nst\r\n  30  final(i)=wa(1)*t1(i)+wa(2)*t2(i)+wa(3)*t3(i)+wa(4)*t4(i)\r\n     &amp;        +wa(5)*t5(i)\r\n      return\r\n      end\r\nc\r\nc\r\n      subroutine output(t1,t2,t3,t4,t5,final,nst,names,grds,temp,ind)\r\nc\r\nc    Output Scoring information\r\nc\r\n      implicit none \r\n      integer  nst\r\n      real final(*)\r\n      real t1(*),t2(*),t3(*),t4(*),t5(*)\r\n      real scmin,scmax,avrag,stdev\r\n      character*16 names(*)\r\n      character*2 grds(*)\r\n      integer igtot(10)\r\n      real temp(*)\r\n      integer ind(*) , i, j\r\nc\r\nc   nst  -  number of students found\r\nc   t1   -  array of grades for test1\r\nc   t2   -  array of grades for test2\r\nc   t3   -  array of grades for test3\r\nc   t4   -  array of grades for test4\r\nc   t5   -  array of grades for test5\r\nc   names - array containing names of students\r\nc   final - final score obtained from a weighted average of tests\r\nc\r\nc    The following three arrays are passed in the argument list simply\r\nc    to permit a single point for assigning space in the main program\r\nc    we will learn other ways of providing this flexibility later.\r\nc\r\nc   grds  - letter grades assigned to each student\r\nc   temp  - temporary score array used for determining ranking\r\nc   ind   - array containing index references to students listed from\r\nc           highest to lowest class score.  ind(1) points to the scores\r\nc           and name for the one with the highest final score, etc.\r\nc\r\nc   Initialize ind\r\nc\r\n      do 10 i=1,nst\r\n  10  ind(i)=i\r\nc\r\nc    Generate statistics on all tests and the final exam\r\nc\r\n      write(6,*) 'Test 1'\r\n      write(12,*) 'Test 1'\r\n      call stats (t1,nst,scmax,scmin,avrag,stdev)\r\n      write(6,*) 'Test 2'\r\n      write(12,*) 'Test 2'\r\n      call stats (t2,nst,scmax,scmin,avrag,stdev)\r\n      write(6,*) 'Test 3'\r\n      write(12,*) 'Test 3'\r\n      call stats (t3,nst,scmax,scmin,avrag,stdev)\r\n      write(6,*) 'Test 4'\r\n      write(12,*) 'Test 4'\r\n      call stats (t4,nst,scmax,scmin,avrag,stdev)\r\n      write(6,*) 'Test 5'\r\n      write(12,*) 'Test 5'\r\n      call stats (t5,nst,scmax,scmin,avrag,stdev)\r\n      write(6,*) 'Final Scores'\r\n      write(12,*) 'Final Scores'\r\n      call stats (final,nst,scmax,scmin,avrag,stdev)\r\nc\r\nc  In the above calls note that I never use the values returned for the\r\nc  last four arguments.  The subroutine was taken from another application\r\nc  and I have chosed to leave the calling sequence unaltered to preserve\r\nc  future flexibility within this program.  If blinding speed were a question\r\nc  I would have cleaned this up.\r\nc\r\nc\r\nc     Assign and tally grades\r\nc\r\n      call grade (final,avrag,nst,igtot,grds)\r\nc\r\nc   Establish the final grade ranking\r\nc\r\n      do 30 i=1,nst\r\n   30 temp(i)=final(i)\r\n      call ssort(temp,ind,nst,-2)\r\n      write(12,2221)\r\n      do 40 i=1,nst\r\n      j=ind(i)\r\n      write(12,2222) names(j),final(j),grds(j)\r\n   40 continue     \r\n 2221 format(\/\/,'Class Grades',\/)\r\n 2222 format(1x,a,3x,f5.1,5x,a)\r\n      return\r\n      end\r\nc\r\nc\r\n      subroutine stats (scores,nst,scmax,scmin,avrag,stdev)\r\nc\r\nc    Compute Mean, Standard, minimum, and maximum for a set of scores\r\nc\r\nc\r\n      implicit none\r\n      real scores(*),scmax, scmin,avrag,stdev,sqm\r\n      integer nst,i, nused\r\nc\r\nc   Arguments\r\nc   Input -\r\nc     scores  -  array containing scores for all students\r\nc     nst     -  number of students\r\nc   Output -\r\nc     scmax - Maximum of all scores\r\nc     scmin - minimum of all scores\r\nc     avrag - avrag of all scores\r\nc     stdev  - standard deviation of scores\r\nc\r\nc    You can't initialize items in the argument list with a data statement\r\nc\r\n      avrag=0.\r\n      sqm=0.\r\n      scmax=-1.e38\r\n      scmin=1.e38\r\n      nused=0\r\nc\r\n      do 50 i=1,nst\r\n         nused=nused+1\r\n         scmax=max(scores(i),scmax)\r\n         scmin=min(scores(i),scmin)\r\n         sqm=sqm+scores(i)**2\r\n         avrag=avrag+scores(i)\r\n  50     continue\r\n      avrag=avrag\/nused\r\n      stdev=sqrt((sqm-nused*avrag**2)\/(nused-1))\r\n      write(6,2002) avrag,stdev,scmin,scmax\r\n      write(12,2002) avrag,stdev,scmin,scmax\r\n 2002 format(5x,'Mean Score=',F5.1,', Standard Deviation =',F5.1,\/,\r\n     &amp;  2x, 'Minimum Score =',F5.1,', Maximum Score =',F5.1)\r\n      return\r\n      end\r\nc\r\nc\r\n      subroutine grade (x,xm,ntot,itgrds,grds)\r\n      implicit none\r\n      integer ngrds,ngrdp\r\nc\r\nc   Assign a grade to match a score and tally total number of each grade\r\nc\r\n      parameter (ngrds=8, ngrdp=ngrds+1)\r\n      real x(*),xm\r\n      character*2 grds(*)\r\n      character letgrd(ngrdp)*2\r\n      integer itgrds(*),ntot,i,j\r\n      real grdbnds(ngrds)\r\nc &lt;a href=\"data\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      data grdbnds\/95,90.,87.,84.,80.,73.,60.,50.\/\r\n      data letgrd\/'A ','A-','B+','B ','B-','C+','C ','D ','F '\/\r\nc &lt;\/font&gt;&lt;\/a&gt;\r\nc\r\nc  Arguments\r\nc\r\nc  Input\r\n\r\nc    x    -    array containing scores\r\nc    xm   -    mean value of contents of x\r\nc    ntot -    total number of scores in x\r\nc\r\nc  Output\r\nc    itgrds  -  total number of students receiving each grade\r\nc    grds    -  letter grade corresponding to each element in x\r\nc\r\nc   Note:  The loops below are brute force.  Faster methods exist for\r\nc          covering large class sizes.  Try rewriting taking advantage of\r\nc          presorted x\r\nc\r\n      do 60 i=1,ngrdp\r\n   60 \titgrds(i)=0\r\n      do 100 i=1,ntot\r\n     \t do 70 j=1,ngrds\r\n            if(x(i).ge.grdbnds(j)) go to 80\r\n   70       continue\r\n         itgrds(ngrdp)=itgrds(ngrdp)+1\r\n         grds(i)=letgrd(ngrdp)\r\n         go to 100\r\n   80    itgrds(j)=itgrds(j)+1\r\n         grds(i)=letgrd(j)\r\n  100 continue\r\nc\r\nc    Output the distribution of grades\r\nc\r\n      call distrb(x,xm,ntot,itgrds,ngrds,grdbnds)\r\n      return\r\n      end             \r\nc\r\nc\r\n      subroutine distrb(x,xm,ntot,igtot,ngrds,xlbgrds)\r\n      implicit none\r\nc\r\nc    Give an ascii plot of grade distributions.  Note that there are some\r\nc    hidden assumptions in here about maximum number of students with a\r\nc    given score.\r\nc\r\nc    The following is a doubly dimensioned array more about these\r\nc    when we get to linear equations\r\nc\r\n      character *1  scr(80,20)\r\n      character*80 baseline\r\n      real x,xm,xlbgrds\r\n      integer i,ii, iscr1, itot,igtot,im,j,ntot, ngrds\r\n      dimension x(*),itot(0:100),igtot(*),xlbgrds(*)\r\nc\r\nc  Arguments\r\nc\r\nc  Input\r\nc    x    -    array containing scores\r\nc    xm   -    mean value of contents of x\r\nc    ntot -    total number of scores in x\r\nc   igtot -    total number of each grade\r\nc   ngrds -    total number of possible grades\r\nc  xlbgrds -   lowest score permitted for each grade catigory above F\r\nc\r\nc\r\n      do 5 i=0,100\r\n    5    itot(i)=0\r\nc\r\nc    Tally scores\r\nc     \r\n      do 10 i=1,ntot\r\n         ii=int(x(i))\r\n   10    itot(ii)=itot(ii)+1\r\nc\r\nc    Put count for all less than 21 in itot(21)\r\nc         \r\n      do 12 i=1,20\r\n   12 itot(21)=itot(21)+itot(i)              \r\nc\r\nc    Load screen display array\r\nc   \r\n      iscr1=20\r\n      do 40 i=1,20\r\n         do 40 j=1,80\r\n           if(itot(j+20).lt.i) then\r\n              scr(j,21-i)=' '\r\n           else\r\n              iscr1=min0(iscr1,21-i)\r\n              scr(j,21-i)='*'\r\n           endif\r\n   40 continue                                     \r\n      iscr1=iscr1-1\r\nc\r\nc   Write bar chart\r\nc\r\n      write (6,'(80a1)') ((scr(i,j),i=1,80),j=iscr1,20)\r\n      write (12,'(80a1)') ((scr(i,j),i=1,80),j=iscr1,20)\r\nc\r\n\r\nc   The following 3 writes are poor programming practice.  I should have\r\nc   passed the array letgrd in and automatically generated \"baseline\" and\r\nc   the associated grade labels using character string manipulations an the\r\nc   information in letgrd and xlbgrds.  To get a feeling for the power of\r\nc   character variable manipulations you should rewrite these in a general\r\nc   form so that the grading system can be changed without requiring a\r\nc   rewrite of the output generation.\r\nc                 \r\n\r\nc   Write baseline\r\nc                 \r\n      baseline=\r\n     &amp;       '---------+---------+---------|---------|---------+--|----'\r\n     &amp; \/\/'--|---|--|--|----|----+'\r\n      im=nint(xm)-20\r\n      baseline(im:im)='^'\r\n      write(6,'(a)') baseline\r\n      write(12,'(a)') baseline\r\nc\r\nc   Write Label Line:  This is a poor programming example.  I should have\r\nc   passed the array letgrd in and automatically generated a format based\r\nc   on letgrd and xlbgrds.  If you are feeling ambitious, try a general\r\nc   form for this write.\r\nc                 \r\n      write(6,2001)\r\n      write(12,2001)\r\n 2001 format('             F                     D          C        C+'\r\n     &amp; ,  '   B-  B  B+  A-    A  ')\r\n                     \r\nc\r\nc   Write Grade Totals\r\nc                 \r\n      write(6,2003) (igtot(i),i=(ngrds+1),1,-1)\r\n      write(12,2003) (igtot(i),i=(ngrds+1),1,-1)\r\n\r\n 2003 format('            ',i2,'                    ',i2,'         '\r\n     &amp; ,i2,'       ',i2,'   ',i2,'  ',i2,' ',i2,'  ',i2,'    ',i2)\r\nc      write(6,2002) xm\r\nc      write(12,2002) xm\r\n 2002 format(2x,'Mean =',F5.1)\r\n      return\r\n      end\r\n      SUBROUTINE SSORT (X, Y, N, KFLAG)\r\nC***BEGIN PROLOGUE  SSORT\r\nC***PURPOSE  Sort an array and make the same interchanges in\r\nC            an auxiliary array.  The array is sorted in\r\nC            decreasing order.\r\nC            What algorithm is used?\r\nC***TYPE      SINGLE PRECISION\r\nC***KEYWORDS  SORT, SORTING\r\nC\r\nC   Description of Parameters\r\nC      X - array of values to be sorted   (usually abscissas)\r\nC      Y - array to be carried with X (all swaps of X elements are\r\nC          matched in Y\r\nC      N - number of values in array X to be sorted\r\nC      KFLAG - Not used in this implementation\r\nC\r\nC***REVISION HISTORY  (YYMMDD)\r\nC   950310  DATE WRITTEN\r\nC   John Mahaffy\r\nC***END PROLOGUE  SSORT\r\nC     .. Scalar Arguments ..\r\n      INTEGER KFLAG, N, Y(*)\r\nC     .. Array Arguments ..\r\n      REAL X(*)\r\nC     .. Local Scalars ..\r\n      REAL TEMP\r\n      INTEGER I, J, JMIN, JMAX, JSWAP, ITEMP\r\nC     .. External Subroutines ..\r\nC     None\r\nC     .. Intrinsic Functions ..\r\nC     None\r\nC***FIRST EXECUTABLE STATEMENT  SSORT\r\nC\r\n      JMAX=N\r\n      DO 200 I=1,N-1\r\n         JSWAP=I\r\n         JMIN=I+1\r\n         DO 100 J=JMIN,JMAX\r\n            IF(X(J).GT.X(JSWAP)) JSWAP=J\r\n  100    CONTINUE\r\n         IF(JSWAP.NE.I) THEN\r\n            TEMP=X(I)\r\n            X(I)=X(JSWAP)\r\n            X(JSWAP)=TEMP\r\n            ITEMP=Y(I)\r\n            Y(I)=Y(JSWAP)\r\n            Y(JSWAP)=ITEMP\r\n         ENDIF\r\n  200 CONTINUE\r\n      RETURN\r\n      END\r\nc &lt;\/pre&gt;\r\nc &lt;\/body&gt;\r\nc &lt;\/html&gt;\r\nc<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>c &lt;html&gt; c &lt;head&gt;&lt;title&gt;&lt;\/title&gt;&lt;\/head&gt; c &lt;body&gt; c &lt;pre&gt; c program grades c c Program to provide information about a Class Grade distribution c c This program starts to look like a serious structured program c The main program only acts as a broad outline calling various key c tasks in subprograms. Specific classes of tasks [&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-111","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/111","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=111"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/111\/revisions"}],"predecessor-version":[{"id":112,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/111\/revisions\/112"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}