Actual source code: zsortsof.c
1: #include <petsc/private/fortranimpl.h>
2: #include <petscsys.h>
4: #if defined(PETSC_HAVE_FORTRAN_CAPS)
5: #define petsctimsort_ PETSCTIMSORT
6: #define petsctimsortwitharray_ PETSCTIMSORTWITHARRAY
7: #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
8: #define petsctimsort_ petsctimsort
9: #define petsctimsortwitharray_ petsctimsortwitharray
10: #endif
12: struct fc_c {
13: void (*fcmp)(const void *a, const void *b, void *c, int *res);
14: void *fctx;
15: } fc_c;
17: int cmp_via_fortran(const void *a, const void *b, void *ctx)
18: {
19: int result;
20: struct fc_c *fc = (struct fc_c *)ctx;
21: fc->fcmp(a, b, fc->fctx, &result);
22: return result;
23: }
25: PETSC_EXTERN void petsctimsort_(PetscInt *n, void *arr, size_t *size, void (*cmp)(const void *, const void *, void *, int *), void *ctx, PetscErrorCode *ierr)
26: {
27: struct fc_c fc = {cmp, ctx};
28: *ierr = PetscTimSort(*n, arr, *size, cmp_via_fortran, &fc);
29: }
31: PETSC_EXTERN void petsctimsortwitharray_(PetscInt *n, void *arr, size_t *asize, void *barr, size_t *bsize, void (*cmp)(const void *, const void *, void *, int *), void *ctx, PetscErrorCode *ierr)
32: {
33: struct fc_c fc = {cmp, ctx};
34: *ierr = PetscTimSortWithArray(*n, arr, *asize, barr, *bsize, cmp_via_fortran, &fc);
35: }