/* nag_matop_complex_tri_matmul_inplace (f01duc) Example Program.
*
* Copyright 2023 Numerical Algorithms Group.
*
* Mark 29.2, 2023.
*/
#include <nag.h>
#include <stdio.h>
int main(void) {
/* Scalars */
Complex alpha;
Integer exit_status, i, j, n, pda, pdb;
/* Arrays */
Complex *a = 0, *b = 0;
char nag_enum_arg[40];
/* Nag Types */
Nag_OrderType order = Nag_ColMajor;
NagError fail;
Nag_SideType side;
Nag_UploType uplo;
Nag_TransType transa;
#define A(I, J) a[J * pda + I]
#define B(I, J) b[J * pdb + I]
exit_status = 0;
INIT_FAIL(fail);
printf("nag_matop_complex_tri_matmul_inplace (f01duc) Example Program \
Results\n\n");
/* Skip heading in data file. */
scanf("%*[^\n]");
/* Read the problem dimensions */
scanf("%" NAG_IFMT "%*[^\n]", &n);
pda = n;
pdb = n;
/* Read side */
scanf("%39s%*[^\n] ", nag_enum_arg);
/* nag_enum_name_to_value (x04nac).
* Converts NAG enum member name to value
*/
side = (Nag_SideType)nag_enum_name_to_value(nag_enum_arg);
/* Read uplo */
scanf("%39s%*[^\n] ", nag_enum_arg);
/* nag_enum_name_to_value (x04nac), see above. */
uplo = (Nag_UploType)nag_enum_name_to_value(nag_enum_arg);
/* Read transa */
scanf("%39s%*[^\n] ", nag_enum_arg);
/* nag_enum_name_to_value (x04nac), see above. */
transa = (Nag_TransType)nag_enum_name_to_value(nag_enum_arg);
/* Read scalar parameters */
scanf(" ( %lf , %lf ) %*[^\n]", &alpha.re, &alpha.im);
if (n > 0) {
/* Allocate memory */
if (!(a = NAG_ALLOC(n * n, Complex)) || !(b = NAG_ALLOC(n * n, Complex))) {
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
} else {
printf("Invalid n\n");
exit_status = 1;
return exit_status;
}
/* Read A from data file */
if (uplo == Nag_Upper) { /* A is upper triangular */
for (i = 0; i < n; i++) {
for (j = i; j < n; j++) {
scanf(" ( %lf , %lf ) ", &A(i, j).re, &A(i, j).im);
}
}
} else { /* A is lower triangular */
for (i = 0; i < n; i++) {
for (j = 0; j <= i; j++) {
scanf(" ( %lf , %lf ) ", &A(i, j).re, &A(i, j).im);
}
}
}
scanf("%*[^\n] ");
/* Read B from data file */
if (uplo == Nag_Upper) { /* B is upper triangular */
for (i = 0; i < n; i++) {
for (j = i; j < n; j++) {
scanf(" ( %lf , %lf ) ", &B(i, j).re, &B(i, j).im);
}
}
} else { /* B is lower triangular */
for (i = 0; i < n; i++) {
for (j = 0; j <= i; j++) {
scanf(" ( %lf , %lf ) ", &B(i, j).re, &B(i, j).im);
}
}
}
scanf("%*[^\n] ");
/* nag_matop_complex_tri_matmul_inplace (f01duc).
*
*/
nag_matop_complex_tri_matmul_inplace(side, uplo, transa, n, alpha, a, pda, b,
pdb, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_matop_complex_tri_matmul_inplace (f01duc).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}
/* Print the updated matrix B */
/* nag_file_print_matrix_complex_gen (x04dac).
* Print complex general matrix (easy-to-use)
*/
fflush(stdout);
if (transa == Nag_NoTrans)
nag_file_print_matrix_complex_gen(
order, (uplo == Nag_Upper ? Nag_UpperMatrix : Nag_LowerMatrix),
Nag_NonUnitDiag, n, n, b, pdb, "Solution matrix B", 0, &fail);
else
nag_file_print_matrix_complex_gen(order, Nag_GeneralMatrix, Nag_NonUnitDiag,
n, n, b, pdb, "Solution matrix B", 0,
&fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_file_print_matrix_complex_gen (x04dac).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}
END:
NAG_FREE(a);
NAG_FREE(b);
return exit_status;
}