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 00038 #pragma ident "@(#) libf/fio/impopen.c 92.1 06/21/99 10:37:55" 00039 00040 #include <cray/nassert.h> 00041 #include "fio.h" 00042 00043 /* 00044 * _ll_implicit_open 00045 * _imp_open 00046 * _imp_open77 00047 * 00048 * Performs an implicit open for a unit which was not mentioned 00049 * in an OPEN statement before its first I/O (Cray extension). 00050 * Upon successful completion, the unit is open and locked. 00051 * Since another task might sneak in and open this unit while 00052 * _imp_open is being called, the unit should be validated 00053 * for proper form and access in the calling routine after return 00054 * from _imp_open. 00055 * 00056 * Side effect: 00057 * Stores its return value in css->f_cu 00058 * 00059 * Return value: 00060 * The unit pointer on success. 00061 * NULL if error, with error status returned in *errstat. 00062 */ 00063 00064 unit * 00065 _ll_implicit_open( 00066 FIOSPTR css, /* Fortran I/O statement state */ 00067 int acc, /* SEQ or DIR */ 00068 int form, /* FMT or UNF */ 00069 unum_t unum, /* Unit number */ 00070 int errflag, /* Set if error recovery */ 00071 int *errstat, /* Gets error status if error recovery. 00072 May be NULL if errflag == 0 */ 00073 int isf90) /* =0 iff cf77 style I/O is requested */ 00074 { 00075 int errn; 00076 olist a; 00077 unit *cup; 00078 00079 OPENLOCK(); /* prevent any other OPENs or CLOSEs now */ 00080 00081 errn = 0; 00082 cup = NULL; 00083 00084 if (acc == DIR) { 00085 errn = FECONNDA; 00086 goto done; 00087 } 00088 00089 if (!GOOD_UNUM(unum)) { 00090 errn = FEIVUNIT; 00091 goto done; 00092 } 00093 00094 cup = _get_cup(unum); 00095 00096 /* 00097 * If the unit is connected, another task must have opened it while 00098 * _imp_open was being called, and before _openlock was locked. 00099 * Skip the open processing if the unit is already open. 00100 */ 00101 if (cup == NULL) { 00102 00103 a.oerr = errflag; /* Set error recovery */ 00104 a.ounit = unum; /* Fortran unit number */ 00105 a.ofile = NULL; /* No file name */ 00106 a.ofilelen = 0; /* or length */ 00107 a.ostatus = OS_UNKNOWN; 00108 a.oaccess = OS_SEQUENTIAL; 00109 a.oform = (form == FMT) ? OS_FORMATTED : OS_UNFORMATTED; 00110 a.orecl = 0; 00111 a.oposition = OS_ASIS; 00112 a.oaction = OS_ACTION_UNSPECIFIED; 00113 a.oblank = OS_NULL; 00114 a.odelim = OS_NONE; 00115 a.opad = OS_YES; 00116 00117 errn = _f_open(css, &cup, &a, isf90); 00118 } 00119 00120 done: 00121 00122 OPENUNLOCK(); 00123 00124 if (errn != 0) { /* Handle an error condition */ 00125 if (cup != NULL) 00126 _release_cup(cup); 00127 00128 if (errflag) { 00129 *errstat = errn; 00130 return(NULL); 00131 } 00132 00133 _ferr(css, errn, unum); /* FEIVUNIT needs unum as 2nd arg */ 00134 } 00135 00136 css->f_cu = cup; 00137 return(cup); 00138 } 00139 00140 /* 00141 * _implicit_open will be phased out in favor of _imp_open and _imp_open77 00142 */ 00143 unit * 00144 _implicit_open(int acc, int form, unum_t unum, int errflag, int *errstat) 00145 { 00146 FIOSPTR css; 00147 GET_FIOS_PTR(css); 00148 return(_ll_implicit_open(css, acc, form, unum, errflag, errstat, 1) ); 00149 } 00150 00151 /* 00152 * _imp_open implicitly opens a unit which by default uses Fortran 90 00153 * style formatted I/O. 00154 */ 00155 unit * 00156 _imp_open(FIOSPTR css, int acc, int form, unum_t unum, int errflag, 00157 int *errstat) 00158 { 00159 return(_ll_implicit_open(css, acc, form, unum, errflag, errstat, 1) ); 00160 } 00161 00162 /* 00163 * _imp_open77 implicitly opens a unit which by default uses cf77 00164 * style formatted I/O. 00165 */ 00166 unit * 00167 _imp_open77(FIOSPTR css, int acc, int form, unum_t unum, int errflag, 00168 int *errstat) 00169 { 00170 return(_ll_implicit_open(css, acc, form, unum, errflag, errstat, 0) ); 00171 }