| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020, 2023 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
|
| 9 |
/* |
| 10 |
* This routine is here for the purpose of assigning a replacement |
| 11 |
* file name thus overriding the default, machine dependent, FORTRAN |
| 12 |
* I/O file assignments. For example, on the VAX, under VAX |
| 13 |
* FORTRAN, an OPEN(n) statement writes the data to the file |
| 14 |
* FOR00n.DAT in the default directory. One can override this |
| 15 |
* filename by ASSIGN'ing the logical name FOR0NN to a filename |
| 16 |
* before executing the image. Sadly, the CRAY version of FORTRAN |
| 17 |
* does not allow for such an eventuality. So, to affect the |
| 18 |
* changes, one must manually check for the file name via this |
| 19 |
* routine which tests for the existence of a execution line string |
| 20 |
* of the form "tapen=filename". Furthermore, one must test the |
| 21 |
* return filename length to see if such a string does exist and |
| 22 |
* loop to the appropriate form of OPEN() statement. (Note that for |
| 23 |
* the time being, this capability under CTSS is *NOT* part of this |
| 24 |
* module. Maybe it can be fixed later.) For example, consider the |
| 25 |
* following code segment: |
| 26 |
* |
| 27 |
* CALL EXNAME( 7, FILENM, LN ) |
| 28 |
* IF( LN .EQ. 0 ) THEN ! Then just take the default |
| 29 |
* OPEN( 7 ) |
| 30 |
* ELSE ! I've found a file name, use it. |
| 31 |
* OPEN( 7, FILE=FILENM ) |
| 32 |
* ENDIF |
| 33 |
* |
| 34 |
* In fact, the same sort of thing happens in the UNIX world. |
| 35 |
* To provide as least some compatibility with the VAX world, we test |
| 36 |
* for the ENVIRONMENT variables of the form FOR0NN. |
| 37 |
* |
| 38 |
*/ |
| 39 |
#include "fortranc.h" |
| 40 |
#include <stdio.h> |
| 41 |
#include <stdlib.h> /* getenv */ |
| 42 |
#include <string.h> /* strlen */ |
| 43 |
|
| 44 |
#define TRUE 1 |
| 45 |
#define FALSE 0 |
| 46 |
|
| 47 |
#define INSYMBOL "FOR0" |
| 48 |
#define EXSYMBOL "EXT" |
| 49 |
|
| 50 |
static char *copy_string(char *dest, char const *source, long int elements) |
| 51 |
{ |
| 52 |
char *d; |
| 53 |
for (d = dest; d + 1 < dest + elements && *source; d++, source++) { |
| 54 |
*d = *source; |
| 55 |
} |
| 56 |
*d = '\0'; |
| 57 |
return d; |
| 58 |
} |
| 59 |
|
| 60 |
#if defined(ADDC_) |
| 61 |
void exname_(FTNINT *iunit, char *name, FTNINT *ln, long int nlen) |
| 62 |
#else |
| 63 |
void exname(FTNINT *iunit, char *name, FTNINT *ln, long int nlen) |
| 64 |
#endif |
| 65 |
{ |
| 66 |
char string[3]; |
| 67 |
char symbol[7]; |
| 68 |
int ExtSymbol; |
| 69 |
|
| 70 |
char *darg; |
| 71 |
|
| 72 |
if (*iunit > -100 && *iunit < 100) { |
| 73 |
#if Build64 |
| 74 |
snprintf(string, 3, "%02ld", labs(*iunit)); |
| 75 |
#else |
| 76 |
snprintf(string, 3, "%02d", abs(*iunit)); |
| 77 |
#endif |
| 78 |
|
| 79 |
if (*iunit > 0) { |
| 80 |
ExtSymbol = FALSE; |
| 81 |
snprintf(symbol, 7, "%s%s", INSYMBOL, string); |
| 82 |
} |
| 83 |
else { |
| 84 |
ExtSymbol = TRUE; |
| 85 |
snprintf(symbol, 7, "%s%s", EXSYMBOL, string); |
| 86 |
} |
| 87 |
|
| 88 |
if ((darg = (char *)getenv(symbol)) != (char *)NULL) { |
| 89 |
unsigned int DargLen = strlen(darg); |
| 90 |
/* We need this to give us the length of the ENVIRONMENT |
| 91 |
* variable while calling strlen() only once. |
| 92 |
*/ |
| 93 |
copy_string(name, darg, DargLen + 1); |
| 94 |
*ln = DargLen; |
| 95 |
} |
| 96 |
else if (!ExtSymbol) { |
| 97 |
#if Build64 |
| 98 |
snprintf(name, nlen, "fort.%ld", labs(*iunit)); |
| 99 |
#else |
| 100 |
snprintf(name, nlen, "fort.%d", abs(*iunit)); |
| 101 |
#endif |
| 102 |
*ln = strlen(name); |
| 103 |
} |
| 104 |
else { |
| 105 |
/* Then I have referenced an external symbol that has not been |
| 106 |
* defined... |
| 107 |
*/ |
| 108 |
*name = '\0'; |
| 109 |
*ln = 0; |
| 110 |
} |
| 111 |
} |
| 112 |
else { |
| 113 |
#if Build64 |
| 114 |
fprintf(stderr, |
| 115 |
"ERROR: SUPES exname - invalid unit number %ld. Must be between -100 and 100.\n", |
| 116 |
*iunit); |
| 117 |
#else |
| 118 |
fprintf(stderr, |
| 119 |
"ERROR: SUPES exname - invalid unit number %d. Must be between -100 and 100.\n", |
| 120 |
*iunit); |
| 121 |
#endif |
| 122 |
} |
| 123 |
} |
| 124 |
/* |
| 125 |
************************************************************************ |
| 126 |
C DESCRIPTION: |
| 127 |
C This routine returns either a valid file name for a logical unit |
| 128 |
C number or the value of a symbol. If IUNIT .GT. 0, the returned |
| 129 |
C name may be used as the value for the FILE specification in an |
| 130 |
C OPEN statement. If IUNIT .LE. 0, the returned name is the value of |
| 131 |
C a system symbol. It is assumed that the unit/file name or symbol |
| 132 |
C linkage will be passed to this routine during program execution. |
| 133 |
C A null string (LN = 0) will be returned if no name is available. |
| 134 |
|
| 135 |
C FORMAL PARAMETERS: |
| 136 |
C IUNIT INTEGER Logical Unit Number ( >0 ) |
| 137 |
C or Symbol ID ( = -IUNIT ) |
| 138 |
C NAME CHARACTER File Name |
| 139 |
C LN INTEGER Length of File Name |
| 140 |
|
| 141 |
************************************************************************ |
| 142 |
*/ |