I would like to solve following task: I have got a grid (nCellsY, nCellsZ). Each grid cell can contain no fiber, one fiber ore more fibers. I know in which cell the fibers are. I need to know the indices of the fibers which are in one cell. For example a short list of fibers: fiberInCellY = (/1,5,3,5,4,3,1/) fiberInCellZ = (/1,4,6,1,2,5,1/) I would like to get following: Cell Index of fiber Index of fiber
GridFibers(1,1) 1 7 GridFibers(5,1) 4 GridFibers(4,2) 5 GridFibers(5,4) 2
...and so on...
but with my following code it shows me no index:
PROGRAM run IMPLICIT NONE INTEGER, DIMENSION(7) :: fiberInCellY, fiberInCellZ INTEGER i, j, k, nCellsY, nCellsZ type :: indFibInCell integer, allocatable, dimension(:) :: ind end type indFibInCell type (indFibInCell), allocatable, dimension(:,:) :: Gridfibers fiberInCellY = (/1,5,3,5,4,3,1/) fiberInCellZ = (/1,4,6,1,2,5,1/) nCellsY = 6 nCellsZ = 6 allocate(GridFibers(nCellsY,nCellsZ)) do j=1, nCellsZ do i=1, nCellsY do k=1, 7 if (i == fiberInCellY(k) .and. j == fiberInCellZ(k)) then Gridfibers(i,j)%ind = k print *, "Gridfibers(",i, "," ,j, ")", Gridfibers(i,j)%ind end if end do end do end do END PROGRAM run