implicit real*8 (a-h, o-z)
dimension w(3000000),x(3000000),y(3000000),z(3000000),&
&         mesh(1000000,8),narabi(10000,10000)
integer :: j,n
open(7,file='yousosuu2.txt') !yousosuu2.fで数えた要素数ファイル
read(7,*) n,m !周方向、高さ方向の分割数の読み込み
!データ入力
read*, nset !節点数の読み込み
do i=1,nset
read*, mesh(i,1),x(i),y(i),z(i)!各節点の座標値の読み込み
end do
!
!----------------------------------------------------------------------------------------
!
read*, nyou !節点数の読み込み
do i=1,nyou
read*, mesh(i,2),mesh(i,3),mesh(i,4),mesh(i,5),mesh(i,6),mesh(i,7),mesh(i,8)!各要素の読み込み
end do
!-----------------------------------------------------------------------------------------
!
!
!
!
do i=1,nset
print *, mesh(i,1),",",x(i),",",y(i),",",z(i)
end do
!
!--------------------------------------------------------------------------------------------------
!
print *,30*n*m-6*n*(m-1)+1,",",x(6),",",y(6),",",z(6)
print *,30*n*m-6*n*(m-1)+2,",",x(4),",",y(4),",",z(4)
!
!--------------------------------------------------------------------------------------------------
!
do i=1,m/2
print *,30*n*m-6*n*(m-1)-1+4*i,",",x(12*n*i-6*n+2),","&
&,y(12*n*i-6*n+2),",",z(12*n*i-6*n+2)
print *,30*n*m-6*n*(m-1)+4*i,",",x(12*n*i-3*n+2),","&
&,y(12*n*i-3*n+2),",",z(12*n*i-3*n+2)
print *,30*n*m-6*n*(m-1)+1+4*i,",",x(12*n*i+3),","&
&,y(12*n*i+3),",",z(12*n*i+3)
print *,30*n*m-6*n*(m-1)+2+4*i,",",x(12*n*i+3*n+2),","&
&,y(12*n*i+3*n+2),",",z(12*n*i+3*n+2)
end do
!
!-----------------------------------------------------------------------------------------------------
!
print*,30*n*m-6*n*(m-1)+m*2+2,",",x(6*m*n+3*n+7),","&
&,y(6*m*n+3*n+7),",",z(6*m*n+3*n+7)
!
!------------------------------------------------------------------------------------------------------
!
do i=1,m/2
print *,30*n*m-6*n*(m-1)+m*2-1+4*i,",",x(36*n*i+6*m*n-21*n+1),","&
&,y(36*n*i+6*m*n-21*n+1),",",z(36*n*i+6*m*n-21*n+1)
print *,30*n*m-6*n*(m-1)+m*2+4*i,",",x(36*n*i+6*m*n-12*n+2),","&
&,y(36*n*i+6*m*n-12*n+2),",",z(36*n*i+6*m*n-12*n+2)
print *,30*n*m-6*n*(m-1)+m*2+1+4*i,",",x(36*n*i+6*m*n-3*n+2),","&
&,y(36*n*i+6*m*n-3*n+2),",",z(36*n*i+6*m*n-3*n-1+2)
print *,30*n*m-6*n*(m-1)+m*2+2+4*i,",",x(36*n*i+6*m*n+6*n+1),","&
&,y(36*n*i+6*m*n+6*n+1),",",z(36*n*i+6*m*n+6*n+1)
end do
!
!---------------------------------------------------------------------------------------------------------
!
!いらない要素を消す(切れ目の入る片方の要素)
print *,"*ELEMENT, TYPE=S6, ELSET=Eall"
 i=1
print *,mesh(i,2),",",mesh(i,3),",",mesh(i,4),","&
&,mesh(i,5),",",mesh(i,6),",",mesh(i,7),",",mesh(i,8)
!
do i=4,6*n
print *,mesh(i,2),",",mesh(i,3),",",mesh(i,4),","&
&,mesh(i,5),",",mesh(i,6),",",mesh(i,7),",",mesh(i,8)
end do
!-----------------------------------------------------------------------------
!ここからループ
do k=1,n*m
do i=(24*k-18)*n+2,(24*k-18)*n+2+6*n-3
print *,mesh(i,2),",",mesh(i,3),",",mesh(i,4),","&
&,mesh(i,5),",",mesh(i,6),",",mesh(i,7),","&
&,mesh(i,8)
end do

do i=(24*k-12)*n+1,(24*k-12)*n+1+6*n-3
print *,mesh(i,2),",",mesh(i,3),",",mesh(i,4),","&
&,mesh(i,5),",",mesh(i,6),",",mesh(i,7),","&
&,mesh(i,8)
end do

do i=(24*k-6)*n+1,(24*k-6)*n+1+6*n-3
print *,mesh(i,2),",",mesh(i,3),",",mesh(i,4),","&
&,mesh(i,5),",",mesh(i,6),",",mesh(i,7),",",mesh(i,8)
end do

do i=24*k*n+2,24*k*n+2+6*n-3
print *,mesh(i,2),",",mesh(i,3),",",mesh(i,4),","&
&,mesh(i,5),",",mesh(i,6),",",mesh(i,7),",",mesh(i,8)
end do
end do
print *,"ABC"
!
!-----------------------------------------------------------------------------------------------------------
!
!新しい要素をつくる工程の部分
print*,2,",",mesh(2,3),",",mesh(2,4),",",30*m*n-6*n*(m-1)+2,",",&
&mesh(2,6),",",mesh(2,7),",",mesh(2,8)

print*,3,",",mesh(3,3),",",30*m*n-6*n*(m-1)+1,",",30*m*n-6*n*(m-1)+2,",",&
&mesh(3,6),",",30*m*n-6*n*(m-1)+2+m*2,",",mesh(3,8)
!ここからループ
!1列目
do k=1,m/2
print*,(24*k-18)*n+2+6*n-2,",",mesh((24*k-18)*n+2+6*n-2,3),",",mesh((24*k-18)*n+2+6*n-2,4)&
&,",",30*m*n-6*n*(m-1)-1+4*k,",",mesh((24*k-18)*n+2+6*n-2,6),",",mesh((24*k-18)*n+2+6*n-2,7)&
&,",",mesh((24*k-18)*n+2+6*n-2,8)

print*,24*n*k-18*n+1,",",mesh(24*n*k-18*n+1,3),",",30*m*n-6*n*(m-1)-2+4*k,","&
&,30*m*n-6*n*(m-1)-1+4*k,",",mesh(24*n*k-18*n+1,6),",",30*m*n-6*n*(m-1)-1+m*2+4*k,","&
&,mesh(24*n*k-18*n+1,8)
!
!
!2列目
print*,24*n*k-6*n-1,",",mesh(24*n*k-6*n-1,3),",",30*m*n-6*n*(m-1)-1+4*k,","&
&,mesh(24*n*k-6*n-1,5),",",mesh(24*n*k-6*n-1,6),",",mesh(24*n*k-6*n-1,7),",",mesh(24*n*k-6*n-1,8)

print*,24*n*k-6*n,",",mesh(24*n*k-6*n,3),",",30*m*n-6*n*(m-1)-1+4*k,","&
&,30*m*n-6*n*(m-1)+4*k,",",mesh(24*n*k-6*n,6),",",30*m*n-6*n*(m-1)+m*2+4*k,",",mesh(24*n*k-6*n,8)
!
!
!3列目
print*,24*n*k-1,",",mesh(24*n*k-1,3),",",30*m*n-6*n*(m-1)+4*k,",",mesh(24*n*k-1,5)&
&,",",mesh(24*n*k-1,6),",",mesh(24*n*k-1,7),",",mesh(24*n*k-1,8)

print*,24*n*k,",",mesh(24*n*k,3),",",30*m*n-6*n*(m-1)+4*k,",",30*m*n-6*n*(m-1)+1+4*k&
&,",",mesh(24*n*k,6),",",30*m*n-6*n*(m-1)+1+m*2+4*k,",",mesh(24*n*k,8)
!
!
!4列目
print*,24*k*n+2+6*n-2,",",mesh(24*k*n+2+6*n-2,3),",",mesh(24*k*n+2+6*n-2,4),","&
&,30*m*n-6*n*(m-1)+2+4*k,",",mesh(24*k*n+2+6*n-2,6),",",mesh(24*k*n+2+6*n-2,7),","&
&,mesh(24*k*n+2+6*n-2,8)

print*,24*n*k+1,",",mesh(24*n*k+1,3),",",30*m*n-6*n*(m-1)+1+4*k,","&
&,30*m*n-6*n*(m-1)+2+4*k,",",mesh(24*n*k+1,6),",",30*m*n-6*n*(m-1)+2+m*2+4*k,","&
&,mesh(24*n*k+1,8)
end do
end
