Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
s2uz.c
Go to the documentation of this file.
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 
00038 #pragma ident "@(#) libf/fio/s2uz.c     92.1    06/18/99 18:41:02"
00039 #include <fortran.h>
00040 #include <cray/fmtconv.h>
00041 #include <cray/portdefs.h>
00042 
00043 #define MXBITS  64              /* Number of bits in a hexadecimal value */
00044 #define MXDGTS  16              /* Number of digits in one hex word     */
00045 #define MXSIZE  (MXDGTS + 1)    /* Size of one hex word plus blank      */
00046 #define DGSIZE  4               /* Size of one hex digit (in bits)      */
00047 
00048 #define UNDP    (MODEUN | MODEDP)
00049 
00050 extern oc_func _S2UZ;           /* Interface must match oc_func prototype */
00051 
00052 /*
00053  *      _S2UZ() Convert Fortran integer variable to hex format.
00054  *
00055  *      Entry:
00056  *              value   Address of logical variable
00057  *              fca     Address of first unpacked character
00058  *              mode    Address of mode bits
00059  *              width   Address of field width
00060  *              digits  Address of digits field
00061  *              exp     Unused
00062  *              scale   Unused
00063  *
00064  *      Exit:
00065  *              result  Points to end of output field
00066  *
00067  *      Note:   This routine has the same parameters as S2UI, etc. in
00068  *              libc.  It does CRAYs implementation of the Z edit
00069  *              descriptor (automatically masks the field down to the
00070  *              size specified by the edit descriptor and always does
00071  *              leading zeroes if the digits field is not set by the
00072  *              user (digits is 1 and MODE77)).  It also handles double-
00073  *              precision values via two calls to _s2uz if the field
00074  *              width is large enough.
00075  */
00076 
00077 long *
00078 _S2UZ(
00079 const void      *value,
00080 long            *fca,
00081 const long      *mode,
00082 const long      *width,
00083 const long      *digits,
00084 const long      *exp,
00085 const long      *scale
00086 )
00087 {
00088         int64   datum;
00089 #ifdef  _F_INT4
00090         int32   datum32;
00091 #if     defined(_F_INT2) && defined(__mips)
00092         _f_int2 datum16;
00093         _f_int1 datum8;
00094 #endif  /* _F_INT2 and mips */
00095 #endif  /* _F_INT4 */
00096         long    fd, fw, m77, nfd, *ptr;
00097 
00098         fd      = *digits;
00099         fw      = *width;
00100 
00101 #ifdef  _F_INT4
00102         if ((*mode & MODEHP) != 0)
00103                 datum   = *(_f_int4 *)value;
00104         else
00105 #if     defined(_F_INT2) && defined(__mips)
00106         if ((*mode & MODEWP) != 0)
00107                 datum   = *(_f_int2 *)value;
00108         else
00109         if ((*mode & MODEBP) != 0)
00110                 datum   = *(_f_int1 *)value;
00111         else
00112 #endif  /* _F_INT2 and mips */
00113 #endif  /* _F_INT4 */
00114                 datum   = *(_f_int8 *)value;
00115 
00116         ptr     = fca;
00117         m77     = (*mode & MODE77);     /* Fortran 77 mode */
00118 
00119         /* Check if double-precision value and field is large enough. */
00120 
00121         if ((*mode & UNDP) == UNDP && fw > MXSIZE) {
00122 
00123                 if (fd == 1 && m77 != 0)
00124                         fd      = fw;
00125 
00126                 fw     -= MXSIZE;
00127                 nfd     = fd - MXDGTS;
00128 
00129                 if (nfd < 0)
00130                         nfd     = 0;
00131                 else
00132                         if (nfd > fw)
00133                                 nfd     = fw;
00134 
00135                 if (m77 != 0) { /* If Fortran 77 mode */
00136                         long    mask, temp;
00137 
00138                         temp    = fw * DGSIZE;
00139                         mask    = (temp < MXBITS) ? ((1 << temp) - 1) : ~0;
00140                         datum   = datum & mask;
00141                 }
00142 
00143                 ptr     = _s2uz(&datum, ptr, mode, &fw, &nfd, exp, scale);
00144 
00145                 datum   = *((int64 *)value + 1);
00146                 fw      = MXSIZE;
00147 
00148                 if (fd > MXDGTS)
00149                         fd      = MXDGTS;
00150         }
00151         else
00152                 if (fd == 1 && m77 != 0)
00153                         fd      = (fw > MXDGTS) ? MXDGTS : fw;
00154 
00155         if (m77 != 0) { /* If Fortran 77 mode */
00156                 long    mask, temp;
00157 
00158                 temp    = fw * DGSIZE;
00159                 mask    = (temp < MXBITS) ? ((1 << temp) - 1) : ~0;
00160                 datum   = datum & mask;
00161         }
00162 
00163 #ifdef  _F_INT4
00164         if ((*mode & MODEHP) != 0) {
00165                 datum32 = datum;
00166                 value   = &datum32;
00167         }
00168         else
00169 #if     defined(_F_INT2) && defined(__mips)
00170         if ((*mode & MODEWP) != 0) {
00171                 datum16 = datum;
00172                 value   = &datum16;
00173         }
00174         else
00175         if ((*mode & MODEBP) != 0) {
00176                 datum8  = datum;
00177                 value   = &datum8;
00178         }
00179         else
00180 #endif  /* _F_INT2 and mips */
00181 #endif  /* _F_INT4 */
00182                 value   = &datum;
00183 
00184         return( _s2uz(value, ptr, mode, &fw, &fd, exp, scale) );
00185 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines