Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
ru.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/ru.c       92.2    06/21/99 10:37:55"
00039 
00040 #include <errno.h>
00041 #include <liberrno.h>
00042 #include <fortran.h>
00043 #include "fio.h"
00044 #ifdef  _CRAYMPP
00045 #include <stdarg.h>
00046 #endif
00047 
00048 #ifdef  _UNICOS 
00049 #pragma _CRI duplicate _RUI as $RUI
00050 #pragma _CRI duplicate _RUF as $RUF
00051 #endif
00052 
00053 int     _RUF();
00054 
00055 #define ERROR0(cond, n) {               \
00056         if (!(cond))                    \
00057                 _ferr(css, n);          \
00058         else                            \
00059                 goto error;             \
00060 }
00061 
00062 #define ERROR1(cond, n, p) {            \
00063         if (!(cond))                    \
00064                 _ferr(css, (n), p);     \
00065         else                            \
00066                 goto error;             \
00067 }
00068 
00069 /*
00070  *      $RUI - read unformatted initialization Fortran-77 I/O interface
00071  *
00072  *      CALL    $RUI,(funit, _arg2, err, end, iostat, rec)
00073  *
00074  *              funit   Address of Fortran unit designator (integer unit
00075  *                      number)
00076  *              _arg2   Unused
00077  *              err     Address of error address (ERR=label)
00078  *              end     Address of end address (END=label)
00079  *              iostat  Address of I/O status variable (integer variable)
00080  *              rec     Address of integer record number (NULL implies
00081  *                      sequential I/O)
00082  *
00083  *      $RUI calls:
00084  *
00085  *              _imp_open77(), _ferr(), _unit_seek()
00086  */
00087 
00088 #ifdef  _CRAYMPP
00089 int
00090 _RUI(
00091 _fcd            _Unitid,        /* Pointer to unit identifier           */
00092 ...)
00093 #else
00094 int
00095 _RUI(
00096 _fcd            _Unitid,        /* Pointer to unit identifier           */
00097 _fcd            _arg2,          /* Unused                               */
00098 long            *err,           /* Address of error processing address  */
00099 long            *end,           /* Address of end processing address    */
00100 _f_int          *iostat,        /* Address of IOSTAT variable           */
00101 _f_int          *rec            /* Address of direct access record no.  */
00102 #ifndef _UNICOS
00103 ,FIOSPTR        cssa            /* Statement state structure            */
00104 #endif
00105 )
00106 #endif
00107 {
00108         register int    errf;           /* Error processing flag        */
00109         register int    errn;           /* Error number                 */
00110         register int    iost;           /* I/O statement type           */
00111         register int    iotp;           /* I/O type                     */
00112         register recn_t recn;           /* Direct access record number  */
00113         register unum_t unum;           /* Actual unit number           */
00114         unit            *cup;           /* Pointer to unit table entry  */
00115         FIOSPTR         css;            /* Statement state structure    */
00116 #ifdef  _CRAYMPP
00117         va_list         args;
00118         _fcd            _arg2;          /* Unused */
00119         long            *err;           /* Address of error processing address*/
00120         long            *end;           /* Address of end processing address */
00121         _f_int          *iostat;        /* Address of IOSTAT variable */
00122         _f_int          *rec;           /* Address of direct access record no.*/
00123 #endif
00124 
00125 #ifdef  _UNICOS
00126         GET_FIOS_PTR(css);
00127 
00128         /* Check if recursive triple-call I/O */
00129 
00130         if (css->f_iostmt != 0)
00131                 _ferr(css, FEIOACTV);
00132 #else
00133         css     = cssa;
00134 #endif
00135 
00136 #ifdef  _CRAYMPP
00137         va_start(args, _Unitid);
00138         _arg2   = va_arg(args, _fcd);
00139         err     = va_arg(args, long *);
00140         end     = va_arg(args, long *);
00141         iostat  = va_arg(args, _f_int *);
00142         rec     = va_arg(args, _f_int *);
00143         va_end(args);
00144 #endif
00145         errn    = 0;
00146 
00147         /* Establish error processing options */
00148 
00149         if (iostat != NULL)
00150                 *iostat = 0;            /* Clear IOSTAT variable, if extant */
00151 
00152         errf    = ((err != NULL) || (iostat != NULL));
00153         iost    = T_RSU;
00154         iotp    = SEQ;                  /* Assume sequential */
00155         unum    = **(_f_int **)&_Unitid;
00156 
00157         if (rec != NULL) {      /* If direct access */
00158                 iost    = T_RDU;        /* Set direct unformatted read */
00159                 iotp    = DIR;
00160                 recn    = *rec;
00161         }
00162 
00163         STMT_BEGIN(unum, 0, iost, NULL, css, cup);
00164 
00165         if (cup == NULL) {      /* if not connected */
00166                 int     stat;
00167 
00168                 cup     = _imp_open77(css, iotp, UNF, unum, errf, &stat);
00169 
00170                 if (cup == NULL) {
00171                         errn    = stat;
00172                         goto error;
00173                 }
00174         }
00175 
00176         /* Record error processing options in the unit */
00177 
00178         cup->uiostat    = iostat;
00179         cup->uflag      = (err    != NULL ?  _UERRF : 0) |
00180                           (end    != NULL ?  _UENDF : 0) |
00181                           (iostat != NULL ? _UIOSTF : 0);
00182 
00183         /* Perform error checking */
00184 
00185         if (cup->ufs == FS_AUX) {
00186                 errn    = FEMIXAUX;     /* Can't mix auxiliary and Fortran I/O */
00187                 ERROR0(errf, errn);
00188         }
00189 
00190         if ((cup->uaction & OS_READ) == 0) {
00191                 errn    = FENOREAD;     /* No read permission */
00192                 ERROR0(errf, errn);
00193         }
00194 
00195         if (cup->ufmt) {        /* If unformatted attempted on formatted file */
00196                 errn    = FEUNFMIV;             /* Unformatted not allowed */
00197                 ERROR0(errf, errn);
00198         }
00199 
00200         /* If sequential and writing, disallow read after write */
00201 
00202         if (cup->useq && cup->uwrt != 0) {
00203                 errn    = FERDAFWR;             /* Read after write */
00204                 ERROR0(errf, errn);
00205         }
00206 
00207         /* Preset fields in unit table */
00208 
00209         cup->ueor_found = NO;                   /* Clear EOR */
00210         cup->uwrt       = 0;
00211         cup->ulastyp    = DVTYPE_TYPELESS;
00212 
00213         if (iotp == DIR) {      /* If direct access */
00214 
00215                 if (cup->useq)          /* If direct attempted on seq. file */
00216                         errn    = FEDIRTIV;     /* Direct access not allowed */
00217                 else
00218                         errn    = _unit_seek(cup, recn, iost);
00219 
00220                 if (errn != 0) {
00221                         ERROR1(errf, errn, recn);
00222                 }
00223         }
00224         else {          /* Else sequential access */
00225 
00226                 if (cup->useq == 0) {   /* If seq. attempted on direct file */
00227                         errn    = FESEQTIV;     /* Sequential not allowed */
00228                         ERROR0(errf, errn);
00229                 }
00230 
00231 #if     PURE_ENABLED
00232                 if (cup->upure && cup->upuretype != P_RDWR) {
00233                         /*
00234                          * Set the upuretype field to P_RDWR mode unless it has
00235                          * previously been set to P_BUFIO by a BUFFER IN/OUT 
00236                          * statement.  This check prevents the intermixing of 
00237                          * READ/WRITE I/O with BUFFER IN/BUFFER OUT I/O when
00238                          * '-s pure' is assigned.
00239                          */
00240                         if (cup->upuretype == P_BUFIO) {
00241                                 errn    = FEMIXBUF;
00242                                 ERROR0(errf, errn);
00243                         }
00244                         cup->upuretype  = P_RDWR;
00245                 }
00246 #endif
00247 
00248         }
00249 
00250         if (errn != 0)
00251                 ERROR0(errf, errn);
00252 
00253         return(CFT77_RETVAL(IO_OKAY));
00254 
00255 error:
00256         if (iostat != NULL)
00257                 *iostat = errn;         /* Set IOSTAT variable to error */
00258 
00259         if (cup != NULL)                /* If we have a unit */
00260                 cup->uflag      |= (errn > 0) ? _UERRC : _UENDC;/* Set status */
00261 
00262 #ifdef  _UNICOS
00263         return(CFT77_RETVAL(_RUF()));
00264 #else
00265         return(CFT77_RETVAL(_RUF(css)));
00266 #endif
00267 
00268 }
00269 
00270 #ifdef  _UNICOS
00271 
00272 /*
00273  *      Definition of inlined function _inline_rdunf()
00274  */
00275 #define INLINE
00276 #include "rdunf.c"
00277 
00278 /*
00279  *      $RUA$ - read unformatted transfer Fortran-77 I/O interface 
00280  *
00281  *      CALL    $RUA$,(fwa, count, inc, type)
00282  *
00283  *              fwa     First word address of datum (may be a Fortran
00284  *                      character descriptor)
00285  *              count   Number of data items
00286  *              stride  Stride between data items
00287  *              type    Type of data
00288  *
00289  *      $RUA$ calls:
00290  *
00291  *              _ferr(), _RUF()
00292  */
00293 
00294 int
00295 $RUA$(
00296         _fcd    fwa,            /* Address of first word of data        */
00297         long    *count,         /* Address of count of data items       */
00298         long    *stride,        /* Address of stride between data items */
00299         long    *type           /* Address of data type                 */
00300 )
00301 {
00302         register short  type77;         /* Fortran 77 data type */
00303         register int    errn;           /* Error number */
00304         type_packet     tip;            /* Type information packet */
00305         struct f90_type ts;             /* F90 type structure */
00306         void            *dptr;
00307         unit            *cup;           /* Pointer to unit table entry  */
00308         FIOSPTR         css;
00309 
00310         GET_FIOS_PTR(css);
00311 
00312         cup     = css->f_cu;
00313         type77  = *type & 017;
00314 
00315         CREATE_F90_INFO(ts, tip, type77);
00316 
00317         tip.count       = *count;
00318         tip.stride      = *stride;
00319 
00320         if (type77 == DT_CHAR) {
00321                 dptr            = (void *) _fcdtocp(fwa);
00322                 tip.elsize      = tip.elsize * _fcdlen(fwa);
00323         }
00324         else
00325                 dptr            = *(void **)&fwa;
00326 
00327 #if     NUMERIC_DATA_CONVERSION_ENABLED
00328 
00329         if (cup->unumcvrt || cup->ucharset) {
00330 
00331                 errn    = _get_dc_param(css, cup, ts, &tip);
00332 
00333                 if (errn != 0)
00334                         goto error;
00335         }
00336 #endif
00337 
00338 #pragma _CRI inline _inline_rdunf
00339         errn    = _inline_rdunf(css, cup, dptr, &tip, 0);
00340 
00341         if (errn == 0)
00342                 return(CFT77_RETVAL(IO_OKAY));
00343 
00344 error:
00345         if (cup->uiostat != NULL)
00346                 *(cup->uiostat) = errn;
00347 
00348         cup->uflag      |= (errn > 0) ? _UERRC : _UENDC;        /* Set status */
00349 
00350         if (cup->uflag & (_UIOSTF | _UERRF | _UENDF))
00351                 return(CFT77_RETVAL(_RUF()));
00352 
00353         _ferr(css, FEINTUNK);           /* Deep weeds */
00354 }
00355 
00356 #endif  /* _UNICOS */
00357 
00358 /*
00359  *      _RUF - read unformatted finalization Fortran-77 I/O interface
00360  *
00361  *      CALL    _RUF,()
00362  *
00363  *      _RUF calls:
00364  *
00365  *              _ferr()
00366  */
00367 
00368 int
00369 _RUF(
00370 #ifndef _UNICOS
00371 FIOSPTR cssa            /* Statement state structure    */
00372 #endif
00373 )
00374 {
00375         register int    errn;           /* Error number                 */
00376         register long   flag;           /* Error flag                   */
00377         unit            *cup;           /* Pointer to unit table entry  */
00378         FIOSPTR         css;            /* Statement state structure    */
00379 
00380 #ifdef  _UNICOS
00381         GET_FIOS_PTR(css);
00382 #else
00383         css     = cssa;
00384 #endif
00385         cup     = css->f_cu;
00386 
00387         if (cup == NULL) {              /* If unit not opened */
00388                 /*
00389                  * If unit not connected, assume we are catching errors with
00390                  * ERR= or IOSTAT= and that _RUF is being called from $RUI or
00391                  * $RUA$.
00392                  */
00393                 flag    = _UERRC | _UERRF;
00394                 goto finished;
00395         }
00396 
00397         cup->ulrecl     = cup->urecpos;
00398         cup->urecpos    = 0;
00399 
00400 #ifdef  _CRAYMPP
00401         if (css->f_shrdput) {
00402                 css->f_shrdput  = 0;
00403                 _remote_write_barrier();
00404         }
00405 #endif
00406         if ((cup->uflag & (_UERRC | _UENDC)) == 0) {    /* If no error or EOF */
00407 
00408                 errn    = 0;
00409 
00410                 switch (cup->ufs) {
00411 
00412                 case FS_FDC:
00413                         /*
00414                          * Do a full record read to advance to the
00415                          * end of the record for sequential access.
00416                          */
00417                         if (cup->useq)  /* If sequential */
00418                                 if (cup->ublkd && !cup->ueor_found) {
00419                                         int             ubc = 0;
00420                                         char            dummy;
00421                                         struct ffsw     fst;    /* FFIO status block */
00422 
00423                                         (void) XRCALL(cup->ufp.fdc, readrtn)
00424                                                 cup->ufp.fdc,
00425                                                 CPTR2BP(&dummy), 0,
00426                                                 &fst, FULL, &ubc);
00427 
00428                                         switch (fst.sw_stat) {
00429                                         case FFERR:
00430                                                 errn            = fst.sw_error;
00431                                                 break;
00432 
00433                                         case FFEOF:
00434                                                 cup->uend       = PHYSICAL_ENDFILE;
00435                                                 errn            = FERDPEOF;
00436                                                 break;
00437 
00438                                         case FFEOD:
00439                                                 if (cup->uend == BEFORE_ENDFILE) {
00440                                                         cup->uend       = LOGICAL_ENDFILE;
00441                                                         errn            = FERDPEOF;
00442                                                 }
00443                                                 else
00444                                                         errn            = FERDENDR;
00445                                                 break;
00446                                         }
00447                                 }
00448                         break;
00449 
00450                 default:
00451                         break;
00452                 } /* switch */
00453 
00454                 if (errn != 0) {
00455 
00456                         if (cup->uiostat != NULL)
00457                                 *(cup->uiostat) = errn;
00458 
00459                         flag    = (_UIOSTF | ((errn < 0) ? _UENDF : _UERRF));
00460 
00461                         if ((cup->uflag & flag) == 0)
00462                                 _ferr(css, errn);
00463                         else    /* Set status */
00464                                 cup->uflag      |= (errn < 0) ? _UENDC : _UERRC;
00465                 }
00466 
00467         }
00468 
00469         flag    = cup->uflag;   /* Save status */
00470 
00471 finished:
00472         STMT_END(cup, TF_READ, NULL, css);      /* Unlock unit */
00473 
00474         if ((flag & (_UERRC | _UENDC)) == 0)    /* If no error or EOF */
00475                 return(CFT77_RETVAL(IO_OKAY));
00476         else
00477                 if ((flag & _UERRC) != 0) {     /* If error */
00478 
00479                         if ((flag & (_UIOSTF | _UERRF)) != 0)
00480                                 return(CFT77_RETVAL(IO_ERR));
00481                 }
00482                 else                            /* Else EOF */
00483                         if ((flag & (_UIOSTF | _UENDF)) != 0)
00484                                 return(CFT77_RETVAL(IO_END));
00485 
00486         _ferr(css, FEINTUNK);           /* Deep weeds */
00487 
00488         return(CFT77_RETVAL(IO_ERR));   /* MIPS compiler requires this return */
00489 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines