/* nag_matop_real_tri_matmul (f01dfc) Example Program.
*
* Copyright 2024 Numerical Algorithms Group.
*
* Mark 30.2, 2024.
*/
#include <nag.h>
#include <stdio.h>
int main(void) {
/* Scalars */
double alpha, beta;
Integer exit_status, i, j, n, pda, pdb, pdc, lu, lta, ltb;
/* Arrays */
double *a = 0, *b = 0, *c = 0;
char nag_enum_arg[40];
/* Nag Types */
Nag_OrderType order = Nag_ColMajor;
NagError fail;
Nag_UploType uplo;
Nag_TransType transa, transb;
#define A(I, J) a[J * pda + I]
#define B(I, J) b[J * pdb + I]
#define C(I, J) c[J * pdc + I]
exit_status = 0;
INIT_FAIL(fail);
printf("nag_matop_real_tri_matmul (f01dfc) 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;
pdc = n;
/* 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);
lu = (uplo == Nag_Lower ? 0 : 1);
/* 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);
lta = (transa == Nag_Trans ? 0 : 1);
/* Read transb */
scanf("%39s%*[^\n] ", nag_enum_arg);
/* nag_enum_name_to_value (x04nac), see above. */
transb = (Nag_TransType)nag_enum_name_to_value(nag_enum_arg);
ltb = (transb == Nag_Trans ? 0 : 1);
/* Read scalar parameters */
scanf("%lf%*[^\n] ", &alpha);
scanf("%lf%*[^\n] ", &beta);
if (n > 0) {
/* Allocate memory */
if (!(a = NAG_ALLOC(n * n, double)) || !(b = NAG_ALLOC(n * n, double)) ||
!(c = 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 (lu == lta) {
/* A is upper triangular */
for (i = 0; i < n; i++) {
for (j = i; j < n; j++) {
scanf("%lf", &A(i, j));
}
}
} else {
/* A is lower triangular */
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 (lu == ltb) {
/* 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] ");
/* Read C from data file */
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
scanf("%lf", &C(i, j));
}
}
scanf("%*[^\n] ");
/* nag_matop_real_tri_matmul (f01dfc).
*
*/
nag_matop_real_tri_matmul(uplo, transa, transb, n, alpha, a, pda, b, pdb,
beta, c, pdc, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_matop_real_tri_matmul (f01dfc).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}
/* Print the updated matrix C */
/* nag_gen_real_mat_print (x04cac).
* Print real general matrix (easy-to-use)
*/
fflush(stdout);
nag_gen_real_mat_print(order, Nag_GeneralMatrix, Nag_NonUnitDiag, n, n, c,
pdc, "Solution matrix C", 0, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_gen_real_mat_print (x04cac).\n%s\n", fail.message);
exit_status = 1;
goto END;
}
END:
NAG_FREE(a);
NAG_FREE(b);
NAG_FREE(c);
return exit_status;
}