00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #pragma ident "@(#) libf/fio/wnly.c 92.1 06/21/99 10:37:55"
00039
00040
00041
00042
00043
00044 #include <stdio.h>
00045 #include <errno.h>
00046 #include <fortran.h>
00047 #include <memory.h>
00048 #include <stdlib.h>
00049 #include <liberrno.h>
00050 #include <cray/fmtconv.h>
00051 #include "fio.h"
00052 #include "fmt.h"
00053 #include "lio.h"
00054 #include "rnl.h"
00055
00056 extern void _memwcpy (long *_S1, long *_S2, int _N);
00057
00058
00059
00060
00061
00062
00063
00064 #define YMP80 (_dreal8 == DREAL8_YMP80)
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 struct BUFFERS {
00077 long *outbuff;
00078 long *outptr;
00079 int outcnt;
00080 long *f_lbuf;
00081 long *f_lbufptr;
00082 int f_lbufcnt;
00083 int lcomma;
00084 };
00085
00086 static char *char_rep(char *_P, int _Cn, unsigned int _Ln, int *_Lc,
00087 struct BUFFERS *_Bp);
00088
00089 static long *find_rep(long *_P, int _Cn, int _In, int _Ty, int *_Lc,
00090 struct BUFFERS *_Bp);
00091
00092 static int l_write(FIOSPTR css, unit *cup, void *dptr, unsigned elsize,
00093 int count, int inc, int type, long recsize, int errf,
00094 struct BUFFERS *bptr);
00095
00096 static int lw_A(FIOSPTR css, char *_P, int _Cl, long _Rc, unit *_Cu,
00097 int _Er, struct BUFFERS *_Bp);
00098
00099 static void writ_rep(long repcnt, struct BUFFERS *buffers);
00100
00101
00102
00103
00104
00105 #define NLPUT(x) { \
00106 *(bptr->outptr)++ = (long) x; \
00107 bptr->outcnt--; \
00108 }
00109
00110 #define NLPUTS(string) { \
00111 s = string; \
00112 while (c = *s++) { \
00113 NLPUT(c); \
00114 } \
00115 }
00116
00117
00118
00119
00120
00121 #define LPUT(x) { \
00122 (*(bptr->f_lbufptr)++ = (long) x); \
00123 bptr->f_lbufcnt++; \
00124 }
00125
00126 #define LPUTS(string) { \
00127 s = string; \
00128 while (c = *s++) { \
00129 LPUT(c); \
00130 } \
00131 }
00132
00133
00134
00135
00136
00137 #define NLINE() { \
00138 bptr->lcomma = 0; \
00139 if (OUT_LINE) { \
00140 REPFLUSH(); \
00141 } \
00142 }
00143
00144
00145
00146
00147
00148
00149
00150 #define REPFLUSH() { \
00151 if (_fwch(cup, bptr->outbuff, recsize - bptr->outcnt, 1) < 0)\
00152 RERR(css, errno); \
00153 bptr->outptr = bptr->outbuff;\
00154 *bptr->outptr++ = (long) ' '; \
00155 *bptr->outptr++ = (long) ' '; \
00156 bptr->outcnt = recsize - 2; \
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 int
00174 @WNL(
00175 _f_int *unump,
00176 Namelist *nl,
00177 int errf
00178 )
00179 {
00180 unum_t unum;
00181 int errn;
00182 int n, ss;
00183 void *vaddr;
00184 unsigned elsize;
00185 long recsize;
00186
00187 char c;
00188 char *s;
00189 unit *cup;
00190 Nlentry *nlent;
00191 FIOSPTR css;
00192 struct BUFFERS wnlbuffers;
00193 struct BUFFERS *bptr;
00194 bptr = &wnlbuffers;
00195 bptr->f_lbuf = NULL;
00196
00197 unum = *unump;
00198
00199 GET_FIOS_PTR(css);
00200 STMT_BEGIN(unum, 0, T_WNL, NULL, css, cup);
00201
00202 if (cup == NULL) {
00203 cup = _imp_open77(css, SEQ, FMT, unum, errf, &errn);
00204
00205
00206
00207
00208 if (cup == NULL)
00209 RERR(css, errn);
00210 }
00211
00212
00213
00214 cup->uflag = (errf != 0 ? _UERRF : 0);
00215 cup->ulineptr = cup->ulinebuf;
00216 cup->uwrt = 1;
00217
00218
00219
00220 css->u.fmt.nonl = 0;
00221
00222
00223 if (cup->useq == 0)
00224 RERR(css, FESEQTIV);
00225
00226 if (!cup->ufmt)
00227 RERR(css, FEFMTTIV);
00228
00229 if ((cup->uaction & OS_WRITE) == 0)
00230 RERR(css, FENOWRIT);
00231
00232 bptr = &wnlbuffers;
00233 bptr->lcomma = 0;
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 recsize = cup->uldwsize;
00248
00249 if (cup->urecl == 0 && _wnlrecsiz > 0)
00250 recsize = MIN(cup->urecsize, _wnlrecsiz);
00251
00252 bptr->outcnt = recsize - 1;
00253 bptr->outbuff = cup->ulinebuf;
00254 bptr->outptr = bptr->outbuff;
00255 *bptr->outptr++ = OUT_ECHO;
00256 bptr->f_lbuf = (long *) malloc((recsize + 1) * sizeof(long));
00257
00258 if (bptr->f_lbuf == NULL)
00259 RERR(css, FENOMEMY);
00260
00261
00262
00263 NLPUT(OUT_CHAR);
00264 NLPUTS(nl->nlname);
00265 NLPUT(' ');
00266 NLPUT(' ');
00267 NLINE();
00268
00269 nlent = nl->nlvnames;
00270
00271 do {
00272 int ntype;
00273
00274 ntype = _old_namelist_to_f77_type_cnvt[nlent->na.type];
00275
00276
00277
00278
00279
00280
00281
00282
00283 bptr->f_lbufptr = bptr->f_lbuf;
00284 bptr->f_lbufcnt = 0;
00285
00286 LPUTS(nlent->varname);
00287 LPUT(' ');
00288 LPUT(OUT_EQ);
00289
00290
00291 n = (nlent->na.offdim) ? nlent->na.nels : 1;
00292
00293 if (ntype == DT_CHAR) {
00294 _fcd f;
00295 f = *(_fcd *)(((unsigned long) nlent->va.varaddr +
00296 (long *)nl));
00297 vaddr = _fcdtocp(f);
00298 elsize = _fcdlen(f);
00299 }
00300 else {
00301 vaddr = (void *)nlent->va.varaddr;
00302 elsize = 0;
00303 }
00304
00305 LPUT(' ');
00306
00307
00308
00309 ss = l_write(css, cup, vaddr, elsize, n, 1, ntype, recsize,
00310 errf, bptr);
00311
00312 if (ss != 0) {
00313 RERR(css, ss);
00314 }
00315
00316 NLINE();
00317
00318 nlent++;
00319
00320 } while (nlent->varname[0]);
00321
00322 if (bptr->outcnt < 6) {
00323 REPFLUSH();
00324 bptr->outptr--;
00325 bptr->outcnt++;
00326 }
00327
00328 NLPUT(OUT_CHAR);
00329 NLPUTS("END");
00330 REPFLUSH();
00331 ret:
00332
00333 STMT_END(cup, T_WNL, NULL, css);
00334
00335 if (bptr->f_lbuf != NULL)
00336 free(bptr->f_lbuf);
00337
00338 return(CFT77_RETVAL(ss));
00339 }
00340
00341
00342
00343
00344
00345 static int
00346 l_write(
00347 FIOSPTR css,
00348 unit *cup,
00349 void *dptr,
00350 unsigned elsize,
00351 int count,
00352 int inc,
00353 int type,
00354 long recsize,
00355 int errf,
00356 struct BUFFERS *bptr
00357 )
00358 {
00359 unsigned int len77;
00360 char *cp;
00361 long *ptr;
00362 long ugly[ITEMBUFSIZ];
00363 long dig;
00364 long exp;
00365 long mod;
00366 long scl;
00367 long ss;
00368 long wid;
00369 long *ib_ptr;
00370 long *newp;
00371 int lcount;
00372 oc_func *gcf;
00373 ftype_t f90type;
00374
00375 if (type == DT_CHAR) {
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385 cp = dptr;
00386 len77 = elsize;
00387
00388 for (; count > 0; count-- ) {
00389
00390 bptr->lcomma = 0;
00391
00392 if (count > 1) {
00393
00394
00395
00396
00397 cp = char_rep(cp, count, len77, &lcount,
00398 bptr);
00399 count = count - (lcount - 1);
00400 }
00401
00402
00403
00404 ss = lw_A(css, cp, len77, recsize, cup, errf, bptr);
00405
00406 if (ss != 0) {
00407 RERR(css, ss);
00408 }
00409
00410 cp = cp + len77;
00411 }
00412
00413 return(0);
00414
00415 }
00416
00417
00418
00419 ptr = (long *)dptr;
00420 f90type = _f77_to_f90_type_cnvt[type];
00421
00422 if ((type == DT_DBLE) || (type == DT_CMPLX))
00423 inc = inc + inc;
00424
00425 for (; count > 0; count--, ptr += inc) {
00426
00427 if (count > 1) {
00428
00429 ptr = find_rep(ptr, count, inc, type, &lcount,
00430 bptr);
00431
00432 count = count - (lcount - 1);
00433 }
00434
00435 ib_ptr = bptr->f_lbufptr;
00436
00437 switch (type) {
00438
00439 case DT_NONE:
00440 gcf = _s2uo; mod = MODEUN; wid = WOCTWRD;
00441 dig = WOCTWRD; exp = 0; scl = 0;
00442 break;
00443
00444 case DT_SINT:
00445 case DT_INT:
00446 gcf = _s2ui; mod = 0; wid = WINT;
00447 dig = 1; exp = 0; scl = 0;
00448 break;
00449
00450 case DT_REAL:
00451 case DT_CMPLX:
00452 gcf = _sd2uge; mod = 0; wid = WREAL8;
00453 dig = _dreal8; exp = DEXP8; scl = 1;
00454 if (YMP80) dig = 9;
00455 break;
00456
00457 case DT_DBLE:
00458
00459
00460
00461
00462
00463
00464 gcf = _sd2udee; mod = MODEDP; wid = WREAL16;
00465 dig = _dreal16-1; exp = DEXP16; scl = 1;
00466 if (YMP80) dig = 25;
00467 break;
00468 }
00469
00470
00471
00472
00473
00474 switch (type) {
00475
00476 default:
00477
00478 #if _F_REAL16 == 1
00479 if (YMP80 && !cup->uft90 && type == DT_DBLE &&
00480 *(_f_dble *)ptr == 0.0) {
00481
00482 static const char *zero_dp = "0.0E+00";
00483 ib_ptr += _unpack(zero_dp, ib_ptr,
00484 strlen(zero_dp), -1);
00485 break;
00486 }
00487 #endif
00488
00489 newp = gcf(ptr, ugly, &mod, &wid, &dig, &exp, &scl);
00490
00491 if (type == DT_NONE)
00492 *newp++ = 'B';
00493
00494 ib_ptr = ib_ptr + _wnl_beautify(f90type, ugly, newp,
00495 ib_ptr, cup->uft90);
00496 break;
00497
00498 case DT_CMPLX:
00499
00500 *ib_ptr++ = '(';
00501
00502 newp = gcf(ptr, ugly, &mod, &wid, &dig, &exp, &scl);
00503
00504 ib_ptr = ib_ptr + _wnl_beautify(f90type, ugly, newp,
00505 ib_ptr, cup->uft90);
00506
00507 *ib_ptr++ = COMMA;
00508
00509 newp = gcf((_f_real *)ptr + 1, ugly,
00510 &mod, &wid, &dig, &exp, &scl);
00511
00512 ib_ptr = ib_ptr + _wnl_beautify(f90type, ugly, newp,
00513 ib_ptr, cup->uft90);
00514
00515 *ib_ptr++ = ')';
00516
00517 break;
00518
00519 case DT_LOG:
00520 *ib_ptr++ = _lvtob(*(_f_log8 *)ptr)? 'T':'F';
00521 break;
00522 }
00523
00524
00525
00526
00527 bptr->f_lbufcnt += ib_ptr - bptr->f_lbufptr;
00528 bptr->f_lbufptr = ib_ptr;
00529
00530 LPUT(OUT_SEP);
00531 LPUT(' ');
00532 LPUT(' ');
00533
00534 if (bptr->outcnt <= bptr->f_lbufcnt) {
00535
00536
00537
00538
00539
00540
00541 REPFLUSH();
00542 }
00543
00544 bptr->f_lbufptr = bptr->f_lbuf;
00545
00546 _memwcpy(bptr->outptr, bptr->f_lbufptr, bptr->f_lbufcnt);
00547
00548 bptr->outptr += bptr->f_lbufcnt;
00549 bptr->outcnt -= bptr->f_lbufcnt;
00550 bptr->f_lbufptr = bptr->f_lbuf;
00551 bptr->f_lbufcnt = 0;
00552 }
00553
00554 return(0);
00555
00556 ret:
00557 return(ss);
00558 }
00559
00560
00561
00562
00563
00564
00565
00566 static long *
00567 find_rep(
00568 long *ptr,
00569 int count,
00570 int inc,
00571 int type,
00572 int *lcount,
00573 struct BUFFERS *bptr
00574 )
00575 {
00576 int i;
00577 long *p1, *p2, *q1, *q2;
00578
00579 p1 = ptr;
00580 q1 = ptr + inc;
00581
00582 if (type == DT_CMPLX || type == DT_DBLE) {
00583
00584 p2 = p1 + 1;
00585 q2 = q1 + 1;
00586
00587 for (i = 1; i < count; i++) {
00588
00589 if ((*p1 != *q1) || (*p2 != *q2)) {
00590 break;
00591 }
00592 else {
00593 p1 = q1;
00594 p2 = p1 + 1;
00595 q1 = q1 + inc;
00596 q2 = q1 + 1;
00597 }
00598 }
00599 }
00600 else {
00601 for (i = 1; i < count; i++) {
00602
00603 if (*p1 != *q1) {
00604 break;
00605 }
00606 else {
00607 p1 = q1;
00608 q1 = q1 + inc;
00609 }
00610 }
00611 }
00612
00613 *lcount = (long) i;
00614
00615 if (i > 1)
00616 writ_rep(i, bptr);
00617
00618 return(p1);
00619 }
00620
00621 static void
00622 writ_rep(
00623 long repcnt,
00624 struct BUFFERS *bptr
00625 )
00626 {
00627 long mode;
00628 long wid;
00629 long dig;
00630 long zero = 0;
00631 long *newp;
00632 long *q;
00633 long buf[WINT];
00634
00635 mode = 0;
00636 wid = WINT;
00637 dig = 0;
00638
00639 newp = _s2ui((long*)&repcnt, buf, &mode, &wid, &dig, &zero, &zero);
00640
00641 for (q = buf; q < newp; q++)
00642 if ((char)*q != ' ')
00643 break;
00644
00645 while (q < newp) {
00646 *bptr->f_lbufptr++ = *q++;
00647 bptr->f_lbufcnt++;
00648 }
00649
00650 *bptr->f_lbufptr++ = (long) '*';
00651 bptr->f_lbufcnt++;
00652 }
00653
00654
00655
00656
00657
00658
00659
00660 static char *
00661 char_rep(
00662 char *ptr,
00663 int count,
00664 unsigned int len77,
00665 int *lcount,
00666 struct BUFFERS *bptr
00667 )
00668 {
00669 int i;
00670 char *qptr;
00671
00672 qptr = ptr + len77;
00673
00674 for (i = 1; i < count; i++) {
00675
00676 if (memcmp(ptr, qptr, len77))
00677 break;
00678
00679 qptr = qptr + len77;
00680 }
00681
00682 *lcount = (long)i;
00683
00684 if (i > 1)
00685 writ_rep(i, bptr);
00686
00687 return(ptr + (*lcount - 1) * len77);
00688 }
00689
00690
00691
00692
00693
00694 static int
00695 lw_A(
00696 FIOSPTR css,
00697 char *ptr,
00698 int charlen,
00699 long recsize,
00700 unit *cup,
00701 int errf,
00702 struct BUFFERS *bptr
00703 )
00704 {
00705 int m;
00706 char *aposptr;
00707 int ss;
00708 int fflag;
00709 int recmax;
00710
00711
00712
00713
00714
00715
00716
00717 fflag = 0;
00718 *bptr->f_lbufptr++ = (long) '\'';
00719 bptr->f_lbufcnt++;
00720
00721 for (; charlen > 0; ) {
00722
00723 if (fflag == 0) {
00724 recmax = recsize - 2;
00725 m = MIN(charlen, recmax - bptr->f_lbufcnt);
00726 }
00727 else {
00728 recmax = recsize - 1;
00729 m = MIN(charlen, recmax - bptr->f_lbufcnt);
00730 }
00731
00732
00733
00734 aposptr = memchr(ptr, '\'', m);
00735
00736 if (aposptr != 0) {
00737
00738 m = aposptr + 1 - ptr;
00739
00740
00741 (void) _unpack(ptr, bptr->f_lbufptr, m, -1);
00742
00743 *(bptr->f_lbufptr + m) = '\'';
00744 ptr = ptr + m;
00745 charlen = charlen - m;
00746 m++;
00747 }
00748 else {
00749
00750
00751 (void) _unpack(ptr, bptr->f_lbufptr, m, -1);
00752
00753 ptr = ptr + m;
00754 charlen = charlen - m;
00755 }
00756
00757 bptr->f_lbufptr += m;
00758 bptr->f_lbufcnt += m;
00759
00760
00761
00762
00763
00764 if (bptr->f_lbufcnt >= recmax) {
00765 if (bptr->outcnt <= bptr->f_lbufcnt) {
00766 REPFLUSH();
00767
00768
00769
00770 if (fflag == 1) {
00771 bptr->outptr--;
00772 bptr->outcnt++;
00773 }
00774 fflag = 1;
00775 }
00776 bptr->f_lbufptr = bptr->f_lbuf;
00777
00778 _memwcpy(bptr->outptr, bptr->f_lbufptr,
00779 bptr->f_lbufcnt);
00780
00781 bptr->outptr += bptr->f_lbufcnt;
00782 bptr->outcnt -= bptr->f_lbufcnt;
00783 bptr->f_lbufptr = bptr->f_lbuf;
00784 bptr->f_lbufcnt = 0;
00785 }
00786 }
00787
00788 *bptr->f_lbufptr++ = (long) '\'';
00789 bptr->f_lbufcnt++;
00790
00791 LPUT(OUT_SEP);
00792 LPUT(' ');
00793 LPUT(' ');
00794
00795 bptr->lcomma = 1;
00796
00797 if (bptr->outcnt <= bptr->f_lbufcnt) {
00798
00799
00800
00801
00802 REPFLUSH();
00803
00804
00805 if (fflag == 1) {
00806 bptr->outptr--;
00807 bptr->outcnt++;
00808 }
00809 }
00810
00811 bptr->f_lbufptr = bptr->f_lbuf;
00812
00813 _memwcpy(bptr->outptr, bptr->f_lbufptr, bptr->f_lbufcnt);
00814
00815 bptr->outptr += bptr->f_lbufcnt;
00816 bptr->outcnt -= bptr->f_lbufcnt;
00817 bptr->f_lbufptr = bptr->f_lbuf;
00818 bptr->f_lbufcnt = 0;
00819
00820 return(0);
00821
00822 ret:
00823 return(ss);
00824 }
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842 int
00843 _wnl_beautify(
00844 ftype_t typ90,
00845 long *ugly,
00846 long *p_limit,
00847 long *pretty,
00848 unsigned isf90)
00849
00850 {
00851 int ret;
00852
00853 ret = _beautify(typ90, ugly, p_limit, pretty, isf90);
00854
00855
00856
00857
00858
00859 if (YMP80 && !isf90 && typ90 == DVTYPE_REAL || typ90 == DVTYPE_COMPLEX){
00860 if (pretty[ret - 1] == '.')
00861 pretty[ret++] = '0';
00862 }
00863
00864 return (ret);
00865 }