| 1 | 14 | jlechner | /* Implementation of the TRANSPOSE intrinsic
 | 
      
         | 2 |  |  |    Copyright 2003, 2005 Free Software Foundation, Inc.
 | 
      
         | 3 |  |  |    Contributed by Tobias Schlüter
 | 
      
         | 4 |  |  |  
 | 
      
         | 5 |  |  | This file is part of the GNU Fortran 95 runtime library (libgfortran).
 | 
      
         | 6 |  |  |  
 | 
      
         | 7 |  |  | Libgfortran is free software; you can redistribute it and/or
 | 
      
         | 8 |  |  | modify it under the terms of the GNU General Public
 | 
      
         | 9 |  |  | License as published by the Free Software Foundation; either
 | 
      
         | 10 |  |  | version 2 of the License, or (at your option) any later version.
 | 
      
         | 11 |  |  |  
 | 
      
         | 12 |  |  | In addition to the permissions in the GNU General Public License, the
 | 
      
         | 13 |  |  | Free Software Foundation gives you unlimited permission to link the
 | 
      
         | 14 |  |  | compiled version of this file into combinations with other programs,
 | 
      
         | 15 |  |  | and to distribute those combinations without any restriction coming
 | 
      
         | 16 |  |  | from the use of this file.  (The General Public License restrictions
 | 
      
         | 17 |  |  | do apply in other respects; for example, they cover modification of
 | 
      
         | 18 |  |  | the file, and distribution when not linked into a combine
 | 
      
         | 19 |  |  | executable.)
 | 
      
         | 20 |  |  |  
 | 
      
         | 21 |  |  | Libgfortran is distributed in the hope that it will be useful,
 | 
      
         | 22 |  |  | but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
      
         | 23 |  |  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
      
         | 24 |  |  | GNU General Public License for more details.
 | 
      
         | 25 |  |  |  
 | 
      
         | 26 |  |  | You should have received a copy of the GNU General Public
 | 
      
         | 27 |  |  | License along with libgfortran; see the file COPYING.  If not,
 | 
      
         | 28 |  |  | write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 | 
      
         | 29 |  |  | Boston, MA 02110-1301, USA.  */
 | 
      
         | 30 |  |  |  
 | 
      
         | 31 |  |  | #include "config.h"
 | 
      
         | 32 |  |  | #include <assert.h>
 | 
      
         | 33 |  |  | #include "libgfortran.h"
 | 
      
         | 34 |  |  |  
 | 
      
         | 35 |  |  | #if defined (HAVE_GFC_COMPLEX_16)
 | 
      
         | 36 |  |  |  
 | 
      
         | 37 |  |  | extern void transpose_c16 (gfc_array_c16 * ret, gfc_array_c16 * source);
 | 
      
         | 38 |  |  | export_proto(transpose_c16);
 | 
      
         | 39 |  |  |  
 | 
      
         | 40 |  |  | void
 | 
      
         | 41 |  |  | transpose_c16 (gfc_array_c16 * ret, gfc_array_c16 * source)
 | 
      
         | 42 |  |  | {
 | 
      
         | 43 |  |  |   /* r.* indicates the return array.  */
 | 
      
         | 44 |  |  |   index_type rxstride, rystride;
 | 
      
         | 45 |  |  |   GFC_COMPLEX_16 *rptr;
 | 
      
         | 46 |  |  |   /* s.* indicates the source array.  */
 | 
      
         | 47 |  |  |   index_type sxstride, systride;
 | 
      
         | 48 |  |  |   const GFC_COMPLEX_16 *sptr;
 | 
      
         | 49 |  |  |  
 | 
      
         | 50 |  |  |   index_type xcount, ycount;
 | 
      
         | 51 |  |  |   index_type x, y;
 | 
      
         | 52 |  |  |  
 | 
      
         | 53 |  |  |   assert (GFC_DESCRIPTOR_RANK (source) == 2);
 | 
      
         | 54 |  |  |  
 | 
      
         | 55 |  |  |   if (ret->data == NULL)
 | 
      
         | 56 |  |  |     {
 | 
      
         | 57 |  |  |       assert (GFC_DESCRIPTOR_RANK (ret) == 2);
 | 
      
         | 58 |  |  |       assert (ret->dtype == source->dtype);
 | 
      
         | 59 |  |  |  
 | 
      
         | 60 |  |  |       ret->dim[0].lbound = 0;
 | 
      
         | 61 |  |  |       ret->dim[0].ubound = source->dim[1].ubound - source->dim[1].lbound;
 | 
      
         | 62 |  |  |       ret->dim[0].stride = 1;
 | 
      
         | 63 |  |  |  
 | 
      
         | 64 |  |  |       ret->dim[1].lbound = 0;
 | 
      
         | 65 |  |  |       ret->dim[1].ubound = source->dim[0].ubound - source->dim[0].lbound;
 | 
      
         | 66 |  |  |       ret->dim[1].stride = ret->dim[0].ubound+1;
 | 
      
         | 67 |  |  |  
 | 
      
         | 68 |  |  |       ret->data = internal_malloc_size (sizeof (GFC_COMPLEX_16) * size0 ((array_t *) ret));
 | 
      
         | 69 |  |  |       ret->offset = 0;
 | 
      
         | 70 |  |  |     }
 | 
      
         | 71 |  |  |  
 | 
      
         | 72 |  |  |   if (ret->dim[0].stride == 0)
 | 
      
         | 73 |  |  |     ret->dim[0].stride = 1;
 | 
      
         | 74 |  |  |   if (source->dim[0].stride == 0)
 | 
      
         | 75 |  |  |     source->dim[0].stride = 1;
 | 
      
         | 76 |  |  |  
 | 
      
         | 77 |  |  |   sxstride = source->dim[0].stride;
 | 
      
         | 78 |  |  |   systride = source->dim[1].stride;
 | 
      
         | 79 |  |  |   xcount = source->dim[0].ubound + 1 - source->dim[0].lbound;
 | 
      
         | 80 |  |  |   ycount = source->dim[1].ubound + 1 - source->dim[1].lbound;
 | 
      
         | 81 |  |  |  
 | 
      
         | 82 |  |  |   rxstride = ret->dim[0].stride;
 | 
      
         | 83 |  |  |   rystride = ret->dim[1].stride;
 | 
      
         | 84 |  |  |  
 | 
      
         | 85 |  |  |   rptr = ret->data;
 | 
      
         | 86 |  |  |   sptr = source->data;
 | 
      
         | 87 |  |  |  
 | 
      
         | 88 |  |  |   for (y=0; y < ycount; y++)
 | 
      
         | 89 |  |  |     {
 | 
      
         | 90 |  |  |       for (x=0; x < xcount; x++)
 | 
      
         | 91 |  |  |         {
 | 
      
         | 92 |  |  |           *rptr = *sptr;
 | 
      
         | 93 |  |  |  
 | 
      
         | 94 |  |  |           sptr += sxstride;
 | 
      
         | 95 |  |  |           rptr += rystride;
 | 
      
         | 96 |  |  |         }
 | 
      
         | 97 |  |  |         sptr += systride - (sxstride * xcount);
 | 
      
         | 98 |  |  |         rptr += rxstride - (rystride * xcount);
 | 
      
         | 99 |  |  |     }
 | 
      
         | 100 |  |  | }
 | 
      
         | 101 |  |  |  
 | 
      
         | 102 |  |  | #endif
 |