This is so trivial that there is no need to write a routine to do it. For a matrix of size n, all you need to do is to set
IA = [1, 3, 6, 9, ..., 3n-3; 3n-1]
JA = [1,2, 3,4,5, 6,7,8, ,...,3n-3, 3n-2]
and A to the 3n-2 values, arranged by rows.
Furthermore, why do you want to use the more general CSR representation for a tridiagonal matrix?
elmeliegy, abdelrahman wrote:
I am going to assemble the tridiagonal matrix into csr/coo format and then use PARDISO linear solver routines.
Why do that? That would be wasted effort, since the "Thomas Algorithm" for solving tridiagonal equations can be coded in 10 to 20 lines of code.