/* nag_matop_real_tri_matmul_inplace (f01dgc) Example Program.
*
* Copyright 2023 Numerical Algorithms Group.
*
* Mark 29.1, 2023.
*/
#include <nag.h>
#include <stdio.h>
int main(void) {
/* Scalars */
double alpha;
Integer exit_status, i, j, n, pda, pdb;
/* Arrays */
double *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;
Nag_MatrixType matrix;
#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_real_tri_matmul_inplace (f01dgc) Example Program Results");
printf("\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%*[^\n] ", &alpha);
if (n > 0) {
/* Allocate memory */
if (!(a = NAG_ALLOC(n * n, double)) || !(b = NAG_ALLOC(n * n, double))) {
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) {
matrix = Nag_UpperMatrix;
for (i = 0; i < n; i++) {
for (j = i; j < n; j++) {
scanf("%lf", &A(i, j));
}
}
} else {
matrix = Nag_LowerMatrix;
for (i = 0; i < n; i++) {
for (j = 0; j <= i; j++) {
scanf("%lf", &A(i, j));
}
}
}
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", &B(i, j));
}
}
} else { /* B is lower triangular */
for (i = 0; i < n; i++) {
for (j = 0; j <= i; j++) {
scanf("%lf", &B(i, j));
}
}
}
scanf("%*[^\n] ");
/* nag_matop_real_tri_matmul_inplace (f01dgc).
*
*/
nag_matop_real_tri_matmul_inplace(side, uplo, transa, n, alpha, a, pda, b,
pdb, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_matop_real_tri_matmul_inplace (f01dgc).\n%s\n",
fail.message);
exit_status = 2;
goto END;
}
/* Print the updated matrix B */
/* nag_file_print_matrix_real_gen (x04cac).
* Print real general matrix (easy-to-use)
*/
fflush(stdout);
if (transa == Nag_Trans)
matrix = Nag_GeneralMatrix;
nag_file_print_matrix_real_gen(order, matrix, Nag_NonUnitDiag, n, n, b, pdb,
"Solution matrix B", 0, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_file_print_matrix_real_gen (x04cac).\n%s\n",
fail.message);
exit_status = 3;
goto END;
}
END:
NAG_FREE(a);
NAG_FREE(b);
return exit_status;
}