i77vers.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. char
  2. _libi77_version_f2c[] = "\n@(#) LIBI77 VERSION (f2c) pjw,dmg-mods 20030321\n";
  3. /*
  4. 2.01 $ format added
  5. 2.02 Coding bug in open.c repaired
  6. 2.03 fixed bugs in lread.c (read * with negative f-format) and lio.c
  7. and lio.h (e-format conforming to spec)
  8. 2.04 changed open.c and err.c (fopen and freopen respectively) to
  9. update to new c-library (append mode)
  10. 2.05 added namelist capability
  11. 2.06 allow internal list and namelist I/O
  12. */
  13. /*
  14. close.c:
  15. allow upper-case STATUS= values
  16. endfile.c
  17. create fort.nnn if unit nnn not open;
  18. else if (file length == 0) use creat() rather than copy;
  19. use local copy() rather than forking /bin/cp;
  20. rewind, fseek to clear buffer (for no reading past EOF)
  21. err.c
  22. use neither setbuf nor setvbuf; make stderr buffered
  23. fio.h
  24. #define _bufend
  25. inquire.c
  26. upper case responses;
  27. omit byfile test from SEQUENTIAL=
  28. answer "YES" to DIRECT= for unopened file (open to debate)
  29. lio.c
  30. flush stderr, stdout at end of each stmt
  31. space before character strings in list output only at line start
  32. lio.h
  33. adjust LEW, LED consistent with old libI77
  34. lread.c
  35. use atof()
  36. allow "nnn*," when reading complex constants
  37. open.c
  38. try opening for writing when open for read fails, with
  39. special uwrt value (2) delaying creat() to first write;
  40. set curunit so error messages don't drop core;
  41. no file name ==> fort.nnn except for STATUS='SCRATCH'
  42. rdfmt.c
  43. use atof(); trust EOF == end-of-file (so don't read past
  44. end-of-file after endfile stmt)
  45. sfe.c
  46. flush stderr, stdout at end of each stmt
  47. wrtfmt.c:
  48. use upper case
  49. put wrt_E and wrt_F into wref.c, use sprintf()
  50. rather than ecvt() and fcvt() [more accurate on VAX]
  51. */
  52. /* 16 Oct. 1988: uwrt = 3 after write, rewind, so close won't zap the file. */
  53. /* 10 July 1989: change _bufend to buf_end in fio.h, wsfe.c, wrtfmt.c */
  54. /* 28 Nov. 1989: corrections for IEEE and Cray arithmetic */
  55. /* 29 Nov. 1989: change various int return types to long for f2c */
  56. /* 30 Nov. 1989: various types from f2c.h */
  57. /* 6 Dec. 1989: types corrected various places */
  58. /* 19 Dec. 1989: make iostat= work right for internal I/O */
  59. /* 8 Jan. 1990: add rsne, wsne -- routines for handling NAMELIST */
  60. /* 28 Jan. 1990: have NAMELIST read treat $ as &, general white
  61. space as blank */
  62. /* 27 Mar. 1990: change an = to == in rd_L(rdfmt.c) so formatted reads
  63. of logical values reject letters other than fFtT;
  64. have nowwriting reset cf */
  65. /* 14 Aug. 1990: adjust lread.c to treat tabs as spaces in list input */
  66. /* 17 Aug. 1990: adjust open.c to recognize blank='Z...' as well as
  67. blank='z...' when reopening an open file */
  68. /* 30 Aug. 1990: prevent embedded blanks in list output of complex values;
  69. omit exponent field in list output of values of
  70. magnitude between 10 and 1e8; prevent writing stdin
  71. and reading stdout or stderr; don't close stdin, stdout,
  72. or stderr when reopening units 5, 6, 0. */
  73. /* 18 Sep. 1990: add component udev to unit and consider old == new file
  74. iff uinode and udev values agree; use stat rather than
  75. access to check existence of file (when STATUS='OLD')*/
  76. /* 2 Oct. 1990: adjust rewind.c so two successive rewinds after a write
  77. don't clobber the file. */
  78. /* 9 Oct. 1990: add #include "fcntl.h" to endfile.c, err.c, open.c;
  79. adjust g_char in util.c for segmented memories. */
  80. /* 17 Oct. 1990: replace abort() and _cleanup() with calls on
  81. sig_die(...,1) (defined in main.c). */
  82. /* 5 Nov. 1990: changes to open.c: complain if new= is specified and the
  83. file already exists; allow file= to be omitted in open stmts
  84. and allow status='replace' (Fortran 90 extensions). */
  85. /* 11 Dec. 1990: adjustments for POSIX. */
  86. /* 15 Jan. 1991: tweak i_ungetc in rsli.c to allow reading from
  87. strings in read-only memory. */
  88. /* 25 Apr. 1991: adjust namelist stuff to work with f2c -i2 */
  89. /* 26 Apr. 1991: fix some bugs with NAMELIST read of multi-dim. arrays */
  90. /* 16 May 1991: increase LEFBL in lio.h to bypass NeXT bug */
  91. /* 17 Oct. 1991: change type of length field in sequential unformatted
  92. records from int to long (for systems where sizeof(int)
  93. can vary, depending on the compiler or compiler options). */
  94. /* 14 Nov. 1991: change uint to Uint in fmt.h, rdfmt.c, wrtfmt.c. */
  95. /* 25 Nov. 1991: change uint to Uint in lwrite.c; change sizeof(int) to
  96. sizeof(uioint) in fseeks in sue.c (missed on 17 Oct.). */
  97. /* 1 Dec. 1991: uio.c: add test for read failure (seq. unformatted reads);
  98. adjust an error return from EOF to off end of record */
  99. /* 12 Dec. 1991: rsli.c: fix bug with internal list input that caused
  100. the last character of each record to be ignored.
  101. iio.c: adjust error message in internal formatted
  102. input from "end-of-file" to "off end of record" if
  103. the format specifies more characters than the
  104. record contains. */
  105. /* 17 Jan. 1992: lread.c, rsne.c: in list and namelist input,
  106. treat "r* ," and "r*," alike (where r is a
  107. positive integer constant), and fix a bug in
  108. handling null values following items with repeat
  109. counts (e.g., 2*1,,3); for namelist reading
  110. of a numeric array, allow a new name-value subsequence
  111. to terminate the current one (as though the current
  112. one ended with the right number of null values).
  113. lio.h, lwrite.c: omit insignificant zeros in
  114. list and namelist output. To get the old
  115. behavior, compile with -DOld_list_output . */
  116. /* 18 Jan. 1992: make list output consistent with F format by
  117. printing .1 rather than 0.1 (introduced yesterday). */
  118. /* 3 Feb. 1992: rsne.c: fix namelist read bug that caused the
  119. character following a comma to be ignored. */
  120. /* 19 May 1992: adjust iio.c, ilnw.c, rdfmt.c and rsli.c to make err=
  121. work with internal list and formatted I/O. */
  122. /* 18 July 1992: adjust rsne.c to allow namelist input to stop at
  123. an & (e.g. &end). */
  124. /* 23 July 1992: switch to ANSI prototypes unless KR_headers is #defined ;
  125. recognize Z format (assuming 8-bit bytes). */
  126. /* 14 Aug. 1992: tweak wrt_E in wref.c to avoid -NaN */
  127. /* 23 Oct. 1992: Supply missing l_eof = 0 assignment to s_rsne() in rsne.c
  128. (so end-of-file on other files won't confuse namelist
  129. reads of external files). Prepend f__ to external
  130. names that are only of internal interest to lib[FI]77. */
  131. /* 1 Feb. 1993: backspace.c: fix bug that bit when last char of 2nd
  132. buffer == '\n'.
  133. endfile.c: guard against tiny L_tmpnam; close and reopen
  134. files in t_runc().
  135. lio.h: lengthen LINTW (buffer size in lwrite.c).
  136. err.c, open.c: more prepending of f__ (to [rw]_mode). */
  137. /* 5 Feb. 1993: tweaks to NAMELIST: rsne.c: ? prints the namelist being
  138. sought; namelists of the wrong name are skipped (after
  139. an error message; xwsne.c: namelist writes have a
  140. newline before each new variable.
  141. open.c: ACCESS='APPEND' positions sequential files
  142. at EOF (nonstandard extension -- that doesn't require
  143. changing data structures). */
  144. /* 9 Feb. 1993: Change some #ifdef MSDOS lines to #ifdef NON_UNIX_STDIO.
  145. err.c: under NON_UNIX_STDIO, avoid close(creat(name,0666))
  146. when the unit has another file descriptor for name. */
  147. /* 4 March 1993: err.c, open.c: take declaration of fdopen from rawio.h;
  148. open.c: always give f__w_mode[] 4 elements for use
  149. in t_runc (in endfile.c -- for change of 1 Feb. 1993). */
  150. /* 6 March 1993: uio.c: adjust off-end-of-record test for sequential
  151. unformatted reads to respond to err= rather than end=. */
  152. /* 12 March 1993: various tweaks for C++ */
  153. /* 6 April 1993: adjust error returns for formatted inputs to flush
  154. the current input line when err=label is specified.
  155. To restore the old behavior (input left mid-line),
  156. either adjust the #definition of errfl in fio.h or
  157. omit the invocation of f__doend in err__fl (in err.c). */
  158. /* 23 June 1993: iio.c: fix bug in format reversions for internal writes. */
  159. /* 5 Aug. 1993: lread.c: fix bug in handling repetition counts for
  160. logical data (during list or namelist input).
  161. Change struct f__syl to struct syl (for buggy compilers). */
  162. /* 7 Aug. 1993: lread.c: fix bug in namelist reading of incomplete
  163. logical arrays. */
  164. /* 9 Aug. 1993: lread.c: fix bug in namelist reading of an incomplete
  165. array of numeric data followed by another namelist
  166. item whose name starts with 'd', 'D', 'e', or 'E'. */
  167. /* 8 Sept. 1993: open.c: protect #include "sys/..." with
  168. #ifndef NON_UNIX_STDIO; Version date not changed. */
  169. /* 10 Nov. 1993: backspace.c: add nonsense for #ifdef MSDOS */
  170. /* 8 Dec. 1993: iio.c: adjust internal formatted reads to treat
  171. short records as though padded with blanks
  172. (rather than causing an "off end of record" error). */
  173. /* 22 Feb. 1994: lread.c: check that realloc did not return NULL. */
  174. /* 6 June 1994: Under NON_UNIX_STDIO, use binary mode for direct
  175. formatted files (avoiding any confusion regarding \n). */
  176. /* 5 July 1994: Fix bug (introduced 6 June 1994?) in reopening files
  177. under NON_UNIX_STDIO. */
  178. /* 6 July 1994: wref.c: protect with #ifdef GOOD_SPRINTF_EXPONENT an
  179. optimization that requires exponents to have 2 digits
  180. when 2 digits suffice.
  181. lwrite.c wsfe.c (list and formatted external output):
  182. omit ' ' carriage-control when compiled with
  183. -DOMIT_BLANK_CC . Off-by-one bug fixed in character
  184. count for list output of character strings.
  185. Omit '.' in list-directed printing of Nan, Infinity. */
  186. /* 12 July 1994: wrtfmt.c: under G11.4, write 0. as " .0000 " rather
  187. than " .0000E+00". */
  188. /* 3 Aug. 1994: lwrite.c: do not insert a newline when appending an
  189. oversize item to an empty line. */
  190. /* 12 Aug. 1994: rsli.c rsne.c: fix glitch (reset nml_read) that kept
  191. ERR= (in list- or format-directed input) from working
  192. after a NAMELIST READ. */
  193. /* 7 Sept. 1994: typesize.c: adjust to allow types LOGICAL*1, LOGICAL*2,
  194. INTEGER*1, and (under -DAllow_TYQUAD) INTEGER*8
  195. in NAMELISTs. */
  196. /* 6 Oct. 1994: util.c: omit f__mvgbt, as it is never used. */
  197. /* 2 Nov. 1994: add #ifdef ALWAYS_FLUSH logic. */
  198. /* 26 Jan. 1995: wref.c: fix glitch in printing the exponent of 0 when
  199. GOOD_SPRINTF_EXPONENT is not #defined. */
  200. /* 24 Feb. 1995: iio.c: z_getc: insert (unsigned char *) to allow
  201. internal reading of characters with high-bit set
  202. (on machines that sign-extend characters). */
  203. /* 14 March 1995:lread.c and rsfe.c: adjust s_rsle and s_rsfe to
  204. check for end-of-file (to prevent infinite loops
  205. with empty read statements). */
  206. /* 26 May 1995: iio.c: z_wnew: fix bug in handling T format items
  207. in internal writes whose last item is written to
  208. an earlier position than some previous item. */
  209. /* 29 Aug. 1995: backspace.c: adjust MSDOS logic. */
  210. /* 6 Sept. 1995: Adjust namelist input to treat a subscripted name
  211. whose subscripts do not involve colons similarly
  212. to the name without a subscript: accept several
  213. values, stored in successive elements starting at
  214. the indicated subscript. Adjust namelist output
  215. to quote character strings (avoiding confusion with
  216. arrays of character strings). Adjust f_init calls
  217. for people who don't use libF77's main(); now open and
  218. namelist read statements invoke f_init if needed. */
  219. /* 7 Sept. 1995: Fix some bugs with -DAllow_TYQUAD (for integer*8).
  220. Add -DNo_Namelist_Comments lines to rsne.c. */
  221. /* 5 Oct. 1995: wrtfmt.c: fix bug with t editing (f__cursor was not
  222. always zeroed in mv_cur). */
  223. /* 11 Oct. 1995: move defs of f__hiwater, f__svic, f__icptr from wrtfmt.c
  224. to err.c */
  225. /* 15 Mar. 1996: lread.c, rsfe.c: honor END= in READ stmt with empty iolist */
  226. /* 13 May 1996: add ftell_.c and fseek_.c */
  227. /* 9 June 1996: Adjust rsli.c and lread.c so internal list input with
  228. too few items in the input string will honor end= . */
  229. /* 12 Sept. 1995:fmtlib.c: fix glitch in printing the most negative integer. */
  230. /* 25 Sept. 1995:fmt.h: for formatted writes of negative integer*1 values,
  231. make ic signed on ANSI systems. If formatted writes of
  232. integer*1 values trouble you when using a K&R C compiler,
  233. switch to an ANSI compiler or use a compiler flag that
  234. makes characters signed. */
  235. /* 9 Dec. 1996: d[fu]e.c, err.c: complain about non-positive rec=
  236. in direct read and write statements.
  237. ftell_.c: change param "unit" to "Unit" for -DKR_headers. */
  238. /* 26 Feb. 1997: ftell_.c: on systems that define SEEK_SET, etc., use
  239. SEEK_SET, SEEK_CUR, SEEK_END for *whence = 0, 1, 2. */
  240. /* 7 Apr. 1997: fmt.c: adjust to complain at missing numbers in formats
  241. (but still treat missing ".nnn" as ".0"). */
  242. /* 11 Apr. 1997: err.c: attempt to make stderr line buffered rather
  243. than fully buffered. (Buffering is needed for format
  244. items T and TR.) */
  245. /* 27 May 1997: ftell_.c: fix typo (that caused the third argument to be
  246. treated as 2 on some systems). */
  247. /* 5 Aug. 1997: lread.c: adjust to accord with a change to the Fortran 8X
  248. draft (in 1990 or 1991) that rescinded permission to elide
  249. quote marks in namelist input of character data; compile
  250. with -DF8X_NML_ELIDE_QUOTES to get the old behavior.
  251. wrtfmt.o: wrt_G: tweak to print the right number of 0's
  252. for zero under G format. */
  253. /* 16 Aug. 1997: iio.c: fix bug in internal writes to an array of character
  254. strings that sometimes caused one more array element than
  255. required by the format to be blank-filled. Example:
  256. format(1x). */
  257. /* 16 Sept. 1997:fmt.[ch] rdfmt.c wrtfmt.c: tweak struct syl for machines
  258. with 64-bit pointers and 32-bit ints that did not 64-bit
  259. align struct syl (e.g., Linux on the DEC Alpha). */
  260. /* 19 Jan. 1998: backspace.c: for b->ufmt==0, change sizeof(int) to
  261. sizeof(uiolen). On machines where this would make a
  262. difference, it is best for portability to compile libI77 with
  263. -DUIOLEN_int (which will render the change invisible). */
  264. /* 4 March 1998: open.c: fix glitch in comparing file names under
  265. -DNON_UNIX_STDIO */
  266. /* 17 March 1998: endfile.c, open.c: acquire temporary files from tmpfile(),
  267. unless compiled with -DNON_ANSI_STDIO, which uses mktemp().
  268. New buffering scheme independent of NON_UNIX_STDIO for
  269. handling T format items. Now -DNON_UNIX_STDIO is no
  270. longer be necessary for Linux, and libf2c no longer
  271. causes stderr to be buffered -- the former setbuf or
  272. setvbuf call for stderr was to make T format items work.
  273. open.c: use the Posix access() function to check existence
  274. or nonexistence of files, except under -DNON_POSIX_STDIO,
  275. where trial fopen calls are used. */
  276. /* 5 April 1998: wsfe.c: make $ format item work: this was lost in the
  277. changes of 17 March 1998. */
  278. /* 28 May 1998: backspace.c dfe.c due.c iio.c lread.c rsfe.c sue.c wsfe.c:
  279. set f__curunit sooner so various error messages will
  280. correctly identify the I/O unit involved. */
  281. /* 17 June 1998: lread.c: unless compiled with
  282. ALLOW_FLOAT_IN_INTEGER_LIST_INPUT #defined, treat
  283. floating-point numbers (containing either a decimal point
  284. or an exponent field) as errors when they appear as list
  285. input for integer data. */
  286. /* 7 Sept. 1998: move e_wdfe from sfe.c to dfe.c, where it was originally.
  287. Why did it ever move to sfe.c? */
  288. /* 2 May 1999: open.c: set f__external (to get "external" versus "internal"
  289. right in the error message if we cannot open the file).
  290. err.c: cast a pointer difference to (int) for %d.
  291. rdfmt.c: omit fixed-length buffer that could be overwritten
  292. by formats Inn or Lnn with nn > 83. */
  293. /* 3 May 1999: open.c: insert two casts for machines with 64-bit longs. */
  294. /* 18 June 1999: backspace.c: allow for b->ufd changing in t_runc */
  295. /* 27 June 1999: rsne.c: fix bug in namelist input: a misplaced increment */
  296. /* could cause wrong array elements to be assigned; e.g., */
  297. /* "&input k(5)=10*1 &end" assigned k(5) and k(15..23) */
  298. /* 15 Nov. 1999: endfile.c: set state to writing (b->uwrt = 1) when an */
  299. /* endfile statement requires copying the file. */
  300. /* (Otherwise an immediately following rewind statement */
  301. /* could make the file appear empty.) Also, supply a */
  302. /* missing (long) cast in the sprintf call. */
  303. /* sfe.c: add #ifdef ALWAYS_FLUSH logic, for formatted I/O: */
  304. /* Compiling libf2c with -DALWAYS_FLUSH should prevent losing */
  305. /* any data in buffers should the program fault. It also */
  306. /* makes the program run more slowly. */
  307. /* 20 April 2000: rsne.c, xwsne.c: tweaks that only matter if ftnint and */
  308. /* ftnlen are of different fundamental types (different numbers */
  309. /* of bits). Since these files will not compile when this */
  310. /* change matters, the above VERSION string remains unchanged. */
  311. /* 4 July 2000: adjustments to permit compilation by C++ compilers; */
  312. /* VERSION string remains unchanged. */
  313. /* 5 Dec. 2000: lread.c: under namelist input, when reading a logical array, */
  314. /* treat Tstuff= and Fstuff= as new assignments rather than as */
  315. /* logical constants. */
  316. /* 22 Feb. 2001: endfile.c: adjust to use truncate() unless compiled with */
  317. /* -DNO_TRUNCATE (or with -DMSDOS). */
  318. /* 1 March 2001: endfile.c: switch to ftruncate (absent -DNO_TRUNCATE), */
  319. /* thus permitting truncation of scratch files on true Unix */
  320. /* systems, where scratch files have no name. Add an fflush() */
  321. /* (surprisingly) needed on some Linux systems. */
  322. /* 11 Oct. 2001: backspac.c dfe.c due.c endfile.c err.c fio.h fmt.c fmt.h */
  323. /* inquire.c open.c rdfmt.c sue.c util.c: change fseek and */
  324. /* ftell to FSEEK and FTELL (#defined to be fseek and ftell, */
  325. /* respectively, in fio.h unless otherwise #defined), and use */
  326. /* type OFF_T (#defined to be long unless otherwise #defined) */
  327. /* to permit handling files over 2GB long where possible, */
  328. /* with suitable -D options, provided for some systems in new */
  329. /* header file sysdep1.h (copied from sysdep1.h0 by default). */
  330. /* 15 Nov. 2001: endfile.c: add FSEEK after FTRUNCATE. */
  331. /* 28 Nov. 2001: fmt.h lwrite.c wref.c and (new) signbit.c: on IEEE systems, */
  332. /* print -0 as -0 when compiled with -DSIGNED_ZEROS. See */
  333. /* comments in makefile or (better) libf2c/makefile.* . */
  334. /* 6 Sept. 2002: rsne.c: fix bug with multiple repeat counts in reading */
  335. /* namelists, e.g., &nl a(2) = 3*1.0, 2*2.0, 3*3.0 / */
  336. /* 21 March 2003: err.c: before writing to a file after reading from it, */
  337. /* f_seek(file, 0, SEEK_CUR) to make writing legal in ANSI C. */