        implicit real*8 (a-h,o-z)
        character(100) a
        dimension mtani(10000000),nhi(100000000),na1(10000000),
     &  na2(10000000),na3(10000000),nb1(100000000),nb2(10000000),
     &  nc1(10000000),nd1(10000000),nd2(100000000),nd3(10000000),
     &  ne1(10000000),ne2(10000000),ne3(100000000),nf1(10000000),
     &  nf2(10000000)
!       dimension kamo(1000),tani(1000), syuu(1000),kamoku(10000000)
        open(7,file='moku0.csv')
        read(7,*) a
         nkamoku=394 ! moku0.csvの全科目数 
        do i=1,nkamoku
        read(7,*) j,mtanii,nhii,na1i,na2i,na3i,
     &  nb1i,nb2i,nc1i,nd1i,nd2i,nd3i,ne1i,ne2i,
     &  ne3i,nf1i,nf2i
!
        mtani(j)=mtanii; nhi(j)=nhii; na1(j)=na1i; na2(j)=na2i 
        na3(j)=na3i; nb1(j)=nb1i; nb2(j)=nb2i; nc1(j)=nc1i; nd1(j)=nd1i
        nd2(j)=nd2i; nd3(j)=nd3i; ne1(j)=ne1i; ne2(j)=ne2i; ne3(j)=ne3i
        nf1(j)=nf1i; nf2(j)=nf2i
!
! moku0.csvに空欄があると、前回読み込み値が引き継がれるので、ここで初期化。 
         mtanii=0; nhii=0; na1i=0; na2i=0 
         na3i=0; nb1i=0; nb2i=0; nc1i=0; nd1i=0
         nd2i=0; nd3i=0; ne1i=0; ne2i=0; ne3i=0
         nf1i=0; nf2i=0
!
        end do
!
!
        open(8,file='souka02.tex')
        write(8,*) '\\documentclass[a4j]{jsarticle}'
        write(8,*) '\\begin{document}'
!
        open(9,file='tassei02.tex')
        write(9,*) '\\documentclass[a4j]{jsarticle}'
        write(9,*) '\\begin{document}'
        write(9,*) '\\begin{table}[h]'
        write(9,*) '\\vspace{-20mm}'
        write(9,*) '\\begin{tabular}'
        write(9,*) '{|r|c|r|r|r|r|r|r|r|r|r|r|r|r|r|c|}'
        write(9,*) '\\hline'
      write(9,*) '学籍番号',' &','◎/○',' &','A1',' &','A2',' &','A31',
     & ' &','B1',' &','B2',' &','C1',' &','D1',' &','D2',' &',
     &   'E1',' &','E2',' &','E3',' &','F1',' &','F2',' &  \\\\'
        write(9,*) '\\hline'
!
        read(*,*) m
        do i=1,m
        read(*,*) num
!
!
        read(*,*) kamsuu
!
        nhia12=0; nhia11=0; na12=0; na11=0
        nhia22=0; nhia21=0; na22=0; na21=0
        nhia32=0; nhia31=0; na32=0; na31=0
        nhib12=0; nhib11=0; nb12=0; nb11=0
        nhib22=0; nhib21=0; nb22=0; nb21=0
        nhic12=0; nhic11=0; nc12=0; nc11=0
        nhid12=0; nhid11=0; nd12=0; nd11=0
        nhid22=0; nhid21=0; nd22=0; nd21=0
        nhid32=0; nhid31=0; nd32=0; nd31=0
        nhie12=0; nhie11=0; ne12=0; ne11=0
        nhie22=0; nhie21=0; ne22=0; ne21=0
        nhie32=0; nhie31=0; ne32=0; ne31=0
        nhif12=0; nhif11=0; nf12=0; nf11=0
        nhif22=0; nhif21=0; nf22=0; nf21=0
!
        do j=1,kamsuu
         read*, k, tanij, syuuj
! A-1
         if((nhi(k)==20).and.(na1(k)==2)) nhia12=nhia12+mtani(k)
         if((nhi(k)==20).and.(na1(k)==1)) nhia11=nhia11+mtani(k)
         if((nhi(k)/=20).and.(na1(k)==2)) na12=na12+mtani(k)
         if((nhi(k)/=20).and.(na1(k)==1)) na11=na11+mtani(k)
! A-2
         if((nhi(k)==20).and.(na2(k)==2)) nhia22=nhia22+mtani(k)
         if((nhi(k)==20).and.(na2(k)==1)) nhia21=nhia21+mtani(k)
         if((nhi(k)/=20).and.(na2(k)==2)) na22=na22+mtani(k)
         if((nhi(k)/=20).and.(na2(k)==1)) na21=na21+mtani(k)
! A-3
         if((nhi(k)==20).and.(na3(k)==2)) nhia32=nhia32+mtani(k)
         if((nhi(k)==20).and.(na3(k)==1)) nhia31=nhia31+mtani(k)
         if((nhi(k)/=20).and.(na3(k)==2)) na32=na32+mtani(k)
         if((nhi(k)/=20).and.(na3(k)==1)) na31=na31+mtani(k)
! B-1
         if((nhi(k)==20).and.(nb1(k)==2)) nhib12=nhib12+mtani(k)
         if((nhi(k)==20).and.(nb1(k)==1)) nhib11=nhib11+mtani(k)
         if((nhi(k)/=20).and.(nb1(k)==2)) nb12=nb12+mtani(k)
         if((nhi(k)/=20).and.(nb1(k)==1)) nb11=nb11+mtani(k)
! B-2
         if((nhi(k)==20).and.(nb2(k)==2)) nhib22=nhib22+mtani(k)
         if((nhi(k)==20).and.(nb2(k)==1)) nhib21=nhib21+mtani(k)
         if((nhi(k)/=20).and.(nb2(k)==2)) nb22=nb22+mtani(k)
         if((nhi(k)/=20).and.(nb2(k)==1)) nb21=nb21+mtani(k)
! C-1
         if((nhi(k)==20).and.(nc1(k)==2)) nhic12=nhic12+mtani(k)
         if((nhi(k)==20).and.(nc1(k)==1)) nhic11=nhic11+mtani(k)
         if((nhi(k)/=20).and.(nc1(k)==2)) nc12=nc12+mtani(k)
         if((nhi(k)/=20).and.(nc1(k)==1)) nc11=nc11+mtani(k)
! D-1
         if((nhi(k)==20).and.(nd1(k)==2)) nhid12=nhid12+mtani(k)
         if((nhi(k)==20).and.(nd1(k)==1)) nhid11=nhid11+mtani(k)
         if((nhi(k)/=20).and.(nd1(k)==2)) nd12=nd12+mtani(k)
         if((nhi(k)/=20).and.(nd1(k)==1)) nd11=nd11+mtani(k)
! D-2
         if((nhi(k)==20).and.(nd2(k)==2)) nhid22=nhid22+mtani(k)
         if((nhi(k)==20).and.(nd2(k)==1)) nhid21=nhid21+mtani(k)
         if((nhi(k)/=20).and.(nd2(k)==2)) nd22=nd22+mtani(k)
         if((nhi(k)/=20).and.(nd2(k)==1)) nd21=nd21+mtani(k)
! D-3
         if((nhi(k)==20).and.(nd3(k)==2)) nhid32=nhid32+mtani(k)
         if((nhi(k)==20).and.(nd3(k)==1)) nhid31=nhid31+mtani(k)
         if((nhi(k)/=20).and.(nd3(k)==2)) nd32=nd32+mtani(k)
         if((nhi(k)/=20).and.(nd3(k)==1)) nd31=nd31+mtani(k)
! E-1
         if((nhi(k)==20).and.(ne1(k)==2)) nhie12=nhie12+mtani(k)
         if((nhi(k)==20).and.(ne1(k)==1)) nhie11=nhie11+mtani(k)
         if((nhi(k)/=20).and.(ne1(k)==2)) ne12=ne12+mtani(k)
         if((nhi(k)/=20).and.(ne1(k)==1)) ne11=ne11+mtani(k)
! E-2
         if((nhi(k)==20).and.(ne2(k)==2)) nhie22=nhie22+mtani(k)
         if((nhi(k)==20).and.(ne2(k)==1)) nhie21=nhie21+mtani(k)
         if((nhi(k)/=20).and.(ne2(k)==2)) ne22=ne22+mtani(k)
         if((nhi(k)/=20).and.(ne2(k)==1)) ne21=ne21+mtani(k)
! E-3
         if((nhi(k)==20).and.(ne3(k)==2)) nhie32=nhie32+mtani(k)
         if((nhi(k)==20).and.(ne3(k)==1)) nhie31=nhie31+mtani(k)
         if((nhi(k)/=20).and.(ne3(k)==2)) ne32=ne32+mtani(k)
         if((nhi(k)/=20).and.(ne3(k)==1)) ne31=ne31+mtani(k)
! F-1
         if((nhi(k)==20).and.(nf1(k)==2)) nhif12=nhif12+mtani(k)
         if((nhi(k)==20).and.(nf1(k)==1)) nhif11=nhif11+mtani(k)
         if((nhi(k)/=20).and.(nf1(k)==2)) nf12=nf12+mtani(k)
         if((nhi(k)/=20).and.(nf1(k)==1)) nf11=nf11+mtani(k)
! F-2
         if((nhi(k)==20).and.(nf2(k)==2)) nhif22=nhif22+mtani(k)
         if((nhi(k)==20).and.(nf2(k)==1)) nhif21=nhif21+mtani(k)
         if((nhi(k)/=20).and.(nf2(k)==2)) nf22=nf22+mtani(k)
         if((nhi(k)/=20).and.(nf2(k)==1)) nf21=nf21+mtani(k)
!
        end do
!
        nhan=0 !未達成項目があるたびに1が足される。つまり0のみ達成
!
        write(8,*) '\\begin{table}[h]'
        write(8,*) '\\vspace{-20mm}'
        write(8,*) '\\begin{tabular}{crrrc}'
        write(8,*) num,' \\\\'
!
!
        write(8,*) '学習・教育目標 & 必修 & 選択 & 取得単位 & 未/了\\\\'
!
        write(8,*) '(A-1) 基礎知識 & & & & \\\\'
        call maru2(30,28,nhia12,2,na12,ia12,nhan)
        call maru1(35,31,nhia11,4,na11,ia11,nhan)
!
        write(8,*) '(A-2) 基礎知識 & & & & \\\\'
        call maru2(10, 6,nhia22,4,na22,ia22,nhan)
        call maru1(30,24,nhia21,6,na21,ia21,nhan)
!
        write(8,*) '(A-3) 基礎知識 & & & & \\\\'
        call maru2( 6, 4,nhia32,2,na32,ia32,nhan)
        call maru1(22,18,nhia31,4,na31,ia31,nhan)
!
        write(8,*) '(B-1) 基礎知識 & & & & \\\\'
        call maru2( 8, 2,nhib12,6,nb12,ib12,nhan)
        call maru1(30,26,nhib11,4,nb11,ib11,nhan)
!
        write(8,*) '(B-2) 基礎知識 & & & & \\\\'
        call maru2( 4, 0,nhib22,4,nb22,ib22,nhan)
        call maru1(16,12,nhib21,4,nb21,ib21,nhan)
!
        write(8,*) '(C-1) 基礎知識 & & & & \\\\'
        call maru2(25,21,nhic12,4,nc12,ic12,nhan)
        call maru1(18,14,nhic11,4,nc11,ic11,nhan)
!
        write(8,*) '(D-1) 基礎知識 & & & & \\\\'
        call maru2(25,25,nhid12,0,nd12,id12,nhan)
        call maru1(13, 7,nhid11,6,nd11,id11,nhan)
!
        write(8,*) '(D-2) 基礎知識 & & & & \\\\'
        call maru2( 5, 1,nhid22,4,nd22,id22,nhan)
        call maru1(10,10,nhid21,0,nd21,id21,nhan)
!
        write(8,*) '(D-3) 基礎知識 & & & & \\\\'
        call maru2(23,17,nhid32,6,nd32,id32,nhan)
        call maru1(11, 7,nhid31,4,nd31,id31,nhan)
!
        write(8,*) '(E-1) 基礎知識 & & & & \\\\'
        call maru2(12, 8,nhie12,4,ne12,ie12,nhan)
        call maru1(17,13,nhie11,4,ne11,ie11,nhan)
!
        write(8,*) '(E-2) 基礎知識 & & & & \\\\'
        call maru2(10, 8,nhie22,2,ne22,ie22,nhan)
        call maru1( 9, 7,nhie21,2,ne21,ie21,nhan)
!
        write(8,*) '(E-3) 基礎知識 & & & & \\\\'
        call maru2( 7, 5,nhie32,2,ne32,ie32,nhan)
        call maru1( 2, 2,nhie31,0,ne31,ie31,nhan)
!
        write(8,*) '(F-1) 基礎知識 & & & & \\\\'
        call maru2( 2, 2,nhif12,0,nf12,if12,nhan)
        call maru1(15,15,nhif11,0,nf11,if11,nhan)
!
        write(8,*) '(F-2) 基礎知識 & & & & \\\\'
        call maru2( 8, 8,nhif22,0,nf22,if22,nhan)
        call maru1( 7, 7,nhif21,0,nf21,if21,nhan)
!
!
        write(8,*) '\\end{tabular}'
        write(8,*) '\\end{table}'
        write(8,*) '\\clearpage'
!
        if(nhan==0) then
        write(9,*) num,' &','◎',' &',ia12,' &',ia22,' &',ia32,' &',
     & ib12,' &',ib22,' &',ic12,' &',id12,' &',id22,' &',
     &   ie12,' &',ie22,' &',ie32,' &',if12,' &',if22,' & ○ \\\\'
        write(9,*) '\\cline{1-15}'
        write(9,*) num,' &','○',' &',ia11,' &',ia21,' &',ia31,' &',
     & ib11,' &',ib21,' &',ic11,' &',id11,' &',id21,' &',
     &   ie11,' &',ie21,' &',ie31,' &',if11,' &',if21,' &  \\\\'
        write(9,*) '\\hline'
       else
        write(9,*) num,' &','◎',' &',ia12,' &',ia22,' &',ia32,' &',
     & ib12,' &',ib22,' &',ic12,' &',id12,' &',id22,' &',
     &   ie12,' &',ie22,' &',ie32,' &',if12,' &',if22,' & - \\\\'
        write(9,*) '\\cline{1-15}'
        write(9,*) num,' &','○',' &',ia11,' &',ia21,' &',ia31,' &',
     & ib11,' &',ib21,' &',ic11,' &',id11,' &',id21,' &',
     &   ie11,' &',ie21,' &',ie31,' &',if11,' &',if21,' &  \\\\'
        write(9,*) '\\hline'
         end if
!
         ngyou=ngyou+2
         if(ngyou==40) then !1ページ何行ずつの表にするか
        write(9,*) '\\end{tabular}'
        write(9,*) '\\end{table}'
        write(9,*) '\\clearpage'
        write(9,*) '\\begin{table}[h]'
        write(9,*) '\\vspace{-20mm}'
        write(9,*) '\\begin{tabular}'
        write(9,*) '{|r|c|r|r|r|r|r|r|r|r|r|r|r|r|r|c|}'
        write(9,*) '\\hline'
      write(9,*) '学籍番号',' &','◎/○',' &','A1',' &','A2',' &','A31',
     & ' &','B1',' &','B2',' &','C1',' &','D1',' &','D2',' &',
     &   'E1',' &','E2',' &','E3',' &','F1',' &','F2',' &  \\\\'
        write(9,*) '\\hline'
        ngyou=0
         end if
!
!
        end do
        write(8,*) '\\end{document}'
        close(8)
!
        write(9,*) '\\end{tabular}'
        write(9,*) '\\end{table}'
        write(9,*) '\\end{document}'
        close(9)
!
!
        end
!
        subroutine maru2(nkei,nhihi,nhisyu,nhi,nsyu,ngou,nhan)
        ngou=nhisyu+nsyu
        if(ngou>=nkei) then
                write(8,*) '◎',nkei,'単位 &',nhisyu,'/',nhihi,' &',
     &          nsyu,'/',nhi,' &', ngou,'/',nkei,' &','了 \\\\'
        else
                nhan=nhan+1
                write(8,*) '◎',nkei,'単位 &',nhisyu,'/',nhihi,' &',
     &          nsyu,'/',nhi,' &', ngou,'/',nkei,' &','■未■ \\\\'
        end if
        return
        end
!
!
        subroutine maru1(nkei,nhihi,nhisyu,nhi,nsyu,ngou,nhan)
        ngou=nhisyu+nsyu
        if(ngou>=nkei) then
                write(8,*) '◯',nkei,'単位 &',nhisyu,'/',nhihi,' &',
     &          nsyu,'/',nhi,' &', ngou,'/',nkei,' &','了 \\\\'
        else
                nhan=nhan+1
                write(8,*) '◯',nkei,'単位 &',nhisyu,'/',nhihi,' &',
     &          nsyu,'/',nhi,' &', ngou,'/',nkei,' &','■未■ \\\\'
        end if
        return
        end
!
!
!
!

