program derived_types_03
! AST only
do nn = 1, ndiag
    ing = diag(nn)%len
    allocate(diag(nn)%cell_id(ing), STAT=ierr)
    if (ierr /= 0) then
        return
    end if
    ndpwds = ndpwds + SIZE(diag(nn)%cell_id)
end do

do k = 1, nz
    do j = 1, ny
        do i = 1, ichunk
            nn = i + j + k - 2
            indx(nn) = indx(nn) + 1
            ing = indx(nn)
            diag(nn)%cell_id(ing)%ic = i
            diag(nn)%cell_id(ing)%j = j
            diag(nn)%cell_id(ing)%k = k
        end do
    end do
end do
end program derived_types_03
