Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2.1 of the GNU Lesser General Public License 00007 as published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU Lesser General Public 00021 License along with this program; if not, write the Free Software 00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 00023 USA. 00024 00025 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00026 Mountain View, CA 94043, or: 00027 00028 http://www.sgi.com 00029 00030 For further information regarding this notice, see: 00031 00032 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00033 00034 */ 00035 00036 00037 #pragma ident "@(#) libfi/array/size.c 92.2 07/07/99 15:52:02" 00038 #include <liberrno.h> 00039 #include <stddef.h> 00040 #include <cray/dopevec.h> 00041 00042 /* 00043 * SIZE Returns the extent of an array along a specified dimension 00044 * or the total number of elements in the array. 00045 * If source pointer/allocatable array is not 00046 * associated/allocated, return an error. 00047 * If DIM not present, return the total number of elements in 00048 * array. Otherwise, return extent of Dim specified. 00049 */ 00050 00051 _f_int 00052 _SIZE (DopeVectorType * source, 00053 _f_int *dimptr) 00054 { 00055 int iresult; 00056 int dim; 00057 int rank; 00058 int loopj; 00059 00060 /* If source is a pointer/allocatable array, it must be 00061 * associated/allocated. */ 00062 if (source->p_or_a && !source->assoc) 00063 _lerror (_LELVL_ABORT, FENMPTAR, "SIZE"); 00064 00065 rank = source->n_dim; 00066 if (dimptr == NULL) { 00067 iresult = 1; 00068 /* Retrieve product of extents */ 00069 for (loopj = 0; loopj < rank; loopj++) 00070 iresult = iresult * source->dimension[loopj].extent; 00071 } 00072 else { 00073 /* argument DIM must be within source array rank */ 00074 dim = *dimptr - 1; 00075 if (dim < 0 || dim >= rank) 00076 _lerror (_LELVL_ABORT, FENMSCDM, "SIZE"); 00077 00078 /* Return extent */ 00079 iresult = source->dimension[dim].extent; 00080 } 00081 00082 return(iresult); 00083 } 00084 00085 /* 00086 * SIZE_4 Returns the extent of an array along a specified dimension 00087 * or the total number of elements in the array. 00088 * If source pointer/allocatable array is not 00089 * associated/allocated, return an error. 00090 * If DIM not present, return the total number of elements in 00091 * array. Otherwise, return extent of Dim specified. 00092 */ 00093 00094 #if defined (_UNICOS) 00095 #pragma duplicate _SIZE_4 as _SIZE_2 00096 #pragma duplicate _SIZE_4 as _SIZE_1 00097 #endif 00098 00099 _f_int4 00100 _SIZE_4 (DopeVectorType * source, 00101 _f_int *dimptr) 00102 { 00103 _f_int4 iresult; 00104 int dim; 00105 int rank; 00106 int loopj; 00107 00108 /* If source is a pointer/allocatable array, it must be 00109 * associated/allocated. */ 00110 if (source->p_or_a && !source->assoc) 00111 _lerror (_LELVL_ABORT, FENMPTAR, "SIZE"); 00112 00113 rank = source->n_dim; 00114 if (dimptr == NULL) { 00115 iresult = 1; 00116 /* Retrieve product of extents */ 00117 for (loopj = 0; loopj < rank; loopj++) 00118 iresult = iresult * source->dimension[loopj].extent; 00119 } 00120 else { 00121 /* argument DIM must be within source array rank */ 00122 dim = *dimptr - 1; 00123 if (dim < 0 || dim >= rank) 00124 _lerror (_LELVL_ABORT, FENMSCDM, "SIZE"); 00125 00126 /* Return extent */ 00127 iresult = source->dimension[dim].extent; 00128 } 00129 00130 return(iresult); 00131 } 00132 00133 /* 00134 * SIZE_8 Returns the extent of an array along a specified dimension 00135 * or the total number of elements in the array. 00136 * If source pointer/allocatable array is not 00137 * associated/allocated, return an error. 00138 * If DIM not present, return the total number of elements in 00139 * array. Otherwise, return extent of Dim specified. 00140 */ 00141 00142 _f_int8 00143 _SIZE_8 (DopeVectorType * source, 00144 _f_int *dimptr) 00145 { 00146 _f_int8 iresult; 00147 int dim; 00148 int rank; 00149 int loopj; 00150 00151 /* If source is a pointer/allocatable array, it must be 00152 * associated/allocated. */ 00153 if (source->p_or_a && !source->assoc) 00154 _lerror (_LELVL_ABORT, FENMPTAR, "SIZE"); 00155 00156 rank = source->n_dim; 00157 if (dimptr == NULL) { 00158 iresult = 1; 00159 /* Retrieve product of extents */ 00160 for (loopj = 0; loopj < rank; loopj++) 00161 iresult = iresult * source->dimension[loopj].extent; 00162 } 00163 else { 00164 /* argument DIM must be within source array rank */ 00165 dim = *dimptr - 1; 00166 if (dim < 0 || dim >= rank) 00167 _lerror (_LELVL_ABORT, FENMSCDM, "SIZE"); 00168 00169 /* Return extent */ 00170 iresult = source->dimension[dim].extent; 00171 } 00172 00173 return(iresult); 00174 }