1 /* Generic implementation of the RESHAPE intrinsic
2 Copyright 2002 Free Software Foundation, Inc.
3 Contributed by Paul Brook <paul@nowt.org>
5 This file is part of the GNU Fortran 95 runtime library (libgfor).
7 Libgfor is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 Ligbfor is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with libgfor; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 #include "libgfortran.h"
29 __pack (const gfc_array_char
* ret
, const gfc_array_char
* array
,
30 const gfc_array_l4
* mask
, const gfc_array_char
* vector
)
32 /* r.* indicates the return array. */
35 /* s.* indicates the source array. */
36 index_type sstride
[GFC_MAX_DIMENSIONS
];
39 /* m.* indicates the mask array. */
40 index_type mstride
[GFC_MAX_DIMENSIONS
];
42 const GFC_LOGICAL_4
*mptr
;
44 index_type count
[GFC_MAX_DIMENSIONS
];
45 index_type extent
[GFC_MAX_DIMENSIONS
];
51 size
= GFC_DESCRIPTOR_SIZE (array
);
52 dim
= GFC_DESCRIPTOR_RANK (array
);
53 for (n
= 0; n
< dim
; n
++)
56 extent
[n
] = array
->dim
[n
].ubound
+ 1 - array
->dim
[n
].lbound
;
57 sstride
[n
] = array
->dim
[n
].stride
* size
;
58 mstride
[n
] = mask
->dim
[n
].stride
;
65 rstride0
= ret
->dim
[0].stride
* size
;
68 sstride0
= sstride
[0];
69 mstride0
= mstride
[0];
74 /* Use the same loop for both logical types. */
75 if (GFC_DESCRIPTOR_SIZE (mask
) != 4)
77 if (GFC_DESCRIPTOR_SIZE (mask
) != 8)
78 runtime_error ("Funny sized logical array");
79 for (n
= 0; n
< dim
; n
++)
82 mptr
= GFOR_POINTER_L8_TO_L4 (mptr
);
87 /* Test this element. */
91 memcpy (rptr
, sptr
, size
);
94 /* Advance to the next element. */
99 while (count
[n
] == extent
[n
])
101 /* When we get to the end of a dimension, reset it and increment
102 the next dimension. */
104 /* We could precalculate these products, but this is a less
105 frequently used path so proabably not worth it. */
106 sptr
-= sstride
[n
] * extent
[n
];
107 mptr
-= mstride
[n
] * extent
[n
];
111 /* Break out of the loop. */
124 /* Add any remaining elements from VECTOR. */
127 n
= vector
->dim
[0].ubound
+ 1 - vector
->dim
[0].lbound
;
128 nelem
= ((rptr
- ret
->data
) / rstride0
);
131 sstride0
= vector
->dim
[0].stride
* size
;
135 sptr
= vector
->data
+ sstride0
* nelem
;
139 memcpy (rptr
, sptr
, size
);