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/getdcparam.c 92.6 10/07/99 13:07:09"
00039
00040 #include <fortran.h>
00041 #include <cray/nassert.h>
00042 #include <cray/dopevec.h>
00043 #include "fio.h"
00044
00045 #define DT_SPECREAL 8
00046
00047
00048
00049
00050
00051
00052 #define INTEGER_SZ (sizeof(_f_int) << 3)
00053 #define REAL_SZ (sizeof(_f_real) << 3)
00054 #define DOUBLE_SZ (sizeof(_f_dble) << 3)
00055 #define COMPLEX_SZ (sizeof(_f_comp) << 3)
00056 #define LOGICAL_SZ (sizeof(_f_log) << 3)
00057
00058
00059
00060
00061
00062 static void
00063 _gdc_abort(FIOSPTR css, unit *cup, struct f90_type ts);
00064
00065 #ifdef KEY
00066 static int
00067 #else
00068 int
00069 #endif
00070 _gdc_dflt2len(int ncindex, struct f90_type ts, short dp);
00071
00072 int
00073 _gdc_kind2len(int ncindex, struct f90_type ts);
00074
00075 int
00076 _gdc_star2len(int ncindex, struct f90_type ts);
00077
00078
00079
00080
00081
00082
00083
00084
00085 int
00086 _get_dc_param(
00087 FIOSPTR css,
00088 unit *cup,
00089 struct f90_type ts,
00090 type_packet *tip)
00091 {
00092 register ftype_t type90;
00093 register short type77;
00094 register short cvtype;
00095 register short newkind;
00096 register short dpflag;
00097 register int forlen;
00098 register int natlen;
00099 register int ncindex;
00100
00101
00102
00103 assert ( ts.type >= DVTYPE_TYPELESS && ts.type <= DVTYPE_ASCII );
00104
00105 type90 = tip->type90;
00106 type77 = tip->type77;
00107 natlen = tip->intlen;
00108 forlen = 0;
00109 cvtype = -1;
00110 dpflag = (ts.dpflag || (ts.kind_or_star == DVD_KIND_DOUBLE)) ? 1 : 0;
00111
00112 if (type90 == DVTYPE_ASCII)
00113 ncindex = _charset_cnvt[cup->ucharset];
00114 else
00115 ncindex = cup->unumcvrt;
00116
00117 if (ncindex == 0)
00118 goto done;
00119
00120 newkind = __fndc_ncfunc[ncindex].new_style_func;
00121
00122 if ( !newkind && type77 == -1) {
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 type77 = _f90_to_f77_type_cnvt[type90];
00136
00137 switch (ts.kind_or_star) {
00138
00139 case DVD_DEFAULT:
00140 case DVD_KIND_DOUBLE:
00141
00142
00143
00144
00145
00146
00147 if (type77 == DT_REAL && dpflag)
00148 type77 = DT_DBLE;
00149 break;
00150
00151 case DVD_STAR:
00152 case DVD_KIND_CONST:
00153
00154
00155
00156
00157
00158
00159
00160
00161 if (type77 == DT_INT && (ts.dec_len << 3) <
00162 __fndc_f77sz[ncindex]->typlen[DT_INT])
00163 type77 = DT_SINT;
00164 break;
00165
00166 default:
00167 break;
00168 }
00169 }
00170
00171 #ifdef DEBUG_FDC
00172 printf("\n");
00173 switch (ts.type) {
00174 case DVTYPE_TYPELESS: printf("declaration: typeless"); break;
00175 case DVTYPE_INTEGER: printf("declaration: INTEGER"); break;
00176 case DVTYPE_REAL: printf("declaration: REAL"); break;
00177 case DVTYPE_COMPLEX: printf("declaration: COMPLEX"); break;
00178 case DVTYPE_LOGICAL: printf("declaration: LOGICAL"); break;
00179 case DVTYPE_ASCII: printf("declaration: CHARACTER"); break;
00180 }
00181 if (ts.dpflag)
00182 printf(", dpflag (DOUBLE) set\n");
00183 else
00184 printf("\n");
00185 switch (ts.kind_or_star) {
00186 case DVD_DEFAULT: printf("KIND type: DEFAULT\n"); break;
00187 case DVD_KIND: printf("KIND type: KIND=expression\n"); break;
00188 case DVD_STAR: printf("KIND type: *%d (bytes)\n", ts.dec_len); break;
00189 case DVD_KIND_CONST: printf("KIND type: KIND=%d\n", ts.dec_len); break;
00190 case DVD_KIND_DOUBLE: printf("KIND type: KIND DOUBLE\n"); break;
00191 }
00192 printf(" Internal length = %d bits\n", ts.int_len);
00193 #endif
00194
00195 switch (ts.kind_or_star) {
00196
00197 case DVD_DEFAULT:
00198
00199
00200
00201 if (newkind) {
00202 forlen = _gdc_dflt2len(ncindex, ts, dpflag);
00203
00204 if (forlen != 0)
00205 cvtype = type90;
00206 }
00207 else {
00208 cvtype = type77;
00209 forlen = __fndc_f77sz[ncindex]->typlen[cvtype];
00210 }
00211 break;
00212
00213 case DVD_KIND_DOUBLE:
00214
00215
00216
00217
00218
00219
00220
00221 if (newkind) {
00222 forlen = _gdc_dflt2len(ncindex, ts, 1);
00223
00224 if (forlen != 0)
00225 cvtype = type90;
00226 }
00227 else
00228 if (type90 == DVTYPE_REAL) {
00229 cvtype = DT_DBLE;
00230 forlen = __fndc_f77sz[ncindex]->typlen[cvtype];
00231 }
00232 break;
00233
00234 case DVD_STAR:
00235
00236
00237
00238
00239
00240 forlen = _gdc_star2len(ncindex, ts);
00241
00242 if (newkind) {
00243 cvtype = type90;
00244
00245 if (forlen == 0)
00246 forlen = ts.dec_len << 3;
00247 }
00248 else {
00249 cvtype = type77;
00250
00251 if (forlen == 0)
00252 forlen = __fndc_f77sz[ncindex]->typlen[cvtype];
00253 }
00254 break;
00255
00256 case DVD_KIND_CONST:
00257
00258
00259
00260
00261
00262
00263
00264
00265 forlen = _gdc_kind2len(ncindex, ts);
00266
00267 if (newkind) {
00268 cvtype = type90;
00269
00270 if (forlen == 0) {
00271
00272 forlen = ts.dec_len << 3;
00273
00274 if (cvtype == DVTYPE_COMPLEX)
00275 forlen = forlen << 1;
00276 }
00277 }
00278 else {
00279 cvtype = type77;
00280
00281 if (forlen == 0)
00282 forlen = __fndc_f77sz[ncindex]->typlen[cvtype];
00283 }
00284 break;
00285
00286 case DVD_KIND:
00287
00288
00289
00290
00291
00292
00293
00294
00295 break;
00296 }
00297
00298 #ifdef DEBUG_FDC
00299 printf(" Foreign length = %d bits\n", forlen);
00300 #endif
00301
00302
00303
00304
00305
00306
00307
00308 if (type90 == DVTYPE_INTEGER && forlen == natlen &&
00309 __fndc_ncfunc[ncindex].cray_int_compat ) {
00310 ncindex = 0;
00311 goto done;
00312 }
00313
00314 #ifdef __mips
00315
00316
00317
00318
00319 if (ncindex == NCV_IEG &&
00320 forlen == natlen &&
00321 !(type90 == DVTYPE_REAL && natlen == (REAL_SZ << 1)) &&
00322 !(type90 == DVTYPE_COMPLEX && natlen == (COMPLEX_SZ << 1)) ) {
00323 ncindex = 0;
00324 goto done;
00325 }
00326 #endif
00327
00328 #if !defined(__mips) && !defined(_LITTLE_ENDIAN)
00329
00330
00331
00332
00333
00334
00335
00336
00337 if ( !newkind && forlen != __fndc_f77sz[ncindex]->typlen[cvtype]) {
00338 register int oldcvt = cvtype;
00339 cvtype = -1;
00340 if (oldcvt == DT_INT) {
00341 if (forlen == __fndc_f77sz[ncindex]->typlen[DT_SINT])
00342 cvtype = DT_SINT;
00343 }
00344 else if (oldcvt == DT_REAL) {
00345 if (__fndc_f77sz[ncindex]->numtypes > DT_SPECREAL &&
00346 forlen == __fndc_f77sz[ncindex]->typlen[DT_SPECREAL])
00347 cvtype = DT_SPECREAL;
00348
00349
00350
00351
00352
00353 if (ts.int_len !=
00354 (_f77_type_len[(cvtype == DT_SPECREAL) ? DT_REAL : cvtype] << 3))
00355 cvtype = -1;
00356
00357 }
00358 }
00359 #endif
00360
00361 done:
00362 #ifdef DEBUG_FDC
00363 printf(" Conversion type = %d (%s conversion function type)\n", cvtype,
00364 newkind ? "new" : "old f77");
00365 printf(" Conversion index = %d\n", ncindex);
00366 #endif
00367
00368 if (ncindex > 0) {
00369
00370 tip->extlen = forlen;
00371 tip->cnvindx = ncindex;
00372 tip->newfunc = newkind;
00373 tip->cnvtype = cvtype;
00374
00375 if (cup->uwrt)
00376 tip->cnvfunc = __fndc_ncfunc[ncindex].to_foreign;
00377 else
00378 tip->cnvfunc = __fndc_ncfunc[ncindex].to_native;
00379
00380 if (cvtype < 0) {
00381 if (ABORT_ON_ERROR)
00382 _gdc_abort(css, cup, ts);
00383
00384 return(FENCNV90);
00385 }
00386 }
00387
00388 return(0);
00389 }
00390
00391
00392
00393
00394
00395 #ifdef KEY
00396 static int
00397 #else
00398 int
00399 #endif
00400 _gdc_dflt2len(
00401 int ncindex,
00402 struct f90_type ts,
00403 short dpflag)
00404 {
00405 register int forlen;
00406
00407 forlen = 0;
00408
00409 switch (ncindex) {
00410
00411 case NCV_T3D:
00412 forlen = ts.int_len;
00413
00414 if (ts.type == DVTYPE_COMPLEX)
00415 forlen = 128;
00416 else
00417 if (ts.type > DVTYPE_TYPELESS && ts.type < DVTYPE_ASCII)
00418 forlen = 64;
00419 break;
00420
00421 case NCV_CRAY:
00422 case NCV_IEL:
00423 switch (ts.type) {
00424
00425 case DVTYPE_INTEGER:
00426 case DVTYPE_LOGICAL:
00427 forlen = 64;
00428 break;
00429
00430 case DVTYPE_REAL:
00431 forlen = (ts.int_len <= REAL_SZ) ? 64 : 128;
00432 break;
00433
00434 case DVTYPE_COMPLEX:
00435 forlen = (ts.int_len <= COMPLEX_SZ) ? 128 : 256;
00436 break;
00437
00438 case DVTYPE_TYPELESS:
00439 case DVTYPE_ASCII:
00440 forlen = ts.int_len;
00441 break;
00442 }
00443
00444 break;
00445
00446 case NCV_IBM:
00447 case NCV_IEG:
00448 case NCV_IEU:
00449 case NCV_MIPS:
00450 case NCV_VMS:
00451 #ifdef _CRAY
00452
00453
00454
00455
00456 if (ts.type != DVTYPE_TYPELESS && ts.type != DVTYPE_ASCII)
00457 forlen = ts.int_len >> 1;
00458 else
00459 forlen = ts.int_len;
00460 #else
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472 switch (ts.type) {
00473
00474 case DVTYPE_INTEGER:
00475 case DVTYPE_LOGICAL:
00476
00477 assert ( INTEGER_SZ == LOGICAL_SZ );
00478
00479 #ifdef KEY
00480 forlen = ts.int_len;
00481 #else
00482 forlen = MIN(ts.int_len, INTEGER_SZ);
00483 #endif
00484 break;
00485
00486 case DVTYPE_REAL:
00487 #ifdef KEY
00488 forlen = ts.int_len;
00489 #else
00490 forlen = MIN(ts.int_len, (REAL_SZ << dpflag));
00491 #endif
00492 break;
00493
00494 case DVTYPE_COMPLEX:
00495 #ifdef KEY
00496 forlen = ts.int_len;
00497 #else
00498 forlen = MIN(ts.int_len, (COMPLEX_SZ << dpflag));
00499 #endif
00500 break;
00501
00502 case DVTYPE_TYPELESS:
00503 case DVTYPE_ASCII:
00504 forlen = ts.int_len;
00505 break;
00506 }
00507 #endif
00508 break;
00509
00510 case NCV_IED:
00511 #ifdef _CRAY
00512 if (ts.type == DVTYPE_INTEGER || ts.type == DVTYPE_LOGICAL)
00513 forlen = ts.int_len >> 1;
00514 else
00515 #endif
00516 forlen = ts.int_len;
00517 break;
00518
00519 default:
00520 break;
00521 }
00522
00523 return(forlen);
00524 }
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541 int
00542 _gdc_star2len(
00543 int ncindex,
00544 struct f90_type ts)
00545 {
00546 register int forlen;
00547
00548 forlen = 0;
00549
00550 switch (ncindex) {
00551
00552 case NCV_CDC:
00553 if (ts.type == DVTYPE_INTEGER &&
00554 (ts.dec_len == 2 || ts.dec_len == 4))
00555 forlen = 60;
00556
00557 else if (ts.type == DVTYPE_REAL && ts.dec_len == 8)
00558 forlen = 60;
00559
00560 else if (ts.type == DVTYPE_COMPLEX && ts.dec_len == 16)
00561 forlen = 120;
00562
00563 break;
00564
00565 case NCV_NVE:
00566 if (ts.type == DVTYPE_INTEGER &&
00567 (ts.dec_len == 2 || ts.dec_len == 4))
00568 forlen = 64;
00569 break;
00570
00571 case NCV_IEL:
00572 case NCV_CRAY:
00573 if (ts.type == DVTYPE_INTEGER || ts.type == DVTYPE_LOGICAL ||
00574 (ts.type == DVTYPE_REAL && ts.dec_len < 8))
00575 forlen = 64;
00576
00577 if (ts.type == DVTYPE_COMPLEX && ts.dec_len < 16)
00578 forlen = 128;
00579 break;
00580
00581 case NCV_T3D:
00582 if ((ts.type == DVTYPE_INTEGER || ts.type == DVTYPE_LOGICAL) &&
00583 ts.dec_len < 4)
00584 forlen = 32;
00585
00586 if (ts.type == DVTYPE_REAL && ts.dec_len > 8)
00587 forlen = 64;
00588
00589 if (ts.type == DVTYPE_COMPLEX && ts.dec_len > 16)
00590 forlen = 128;
00591 break;
00592
00593 default:
00594 break;
00595 }
00596
00597 return(forlen);
00598 }
00599
00600 int
00601 _gdc_kind2len(
00602 int ncindex,
00603 struct f90_type ts)
00604 {
00605 register int forlen;
00606
00607 forlen = 0;
00608
00609
00610
00611 switch (ncindex) {
00612
00613 case NCV_CRAY:
00614 case NCV_IEL:
00615 if (ts.type == DVTYPE_INTEGER || ts.type == DVTYPE_LOGICAL ||
00616 (ts.type == DVTYPE_REAL && ts.dec_len < 8))
00617 forlen = 64;
00618
00619 if (ts.type == DVTYPE_COMPLEX && ts.dec_len < 8)
00620 forlen = 128;
00621 break;
00622
00623 case NCV_T3D:
00624 if ((ts.type == DVTYPE_INTEGER || ts.type == DVTYPE_LOGICAL) &&
00625 ts.dec_len < 4)
00626 forlen = 32;
00627
00628 if (ts.type == DVTYPE_REAL && ts.dec_len > 8)
00629 forlen = 64;
00630
00631 if (ts.type == DVTYPE_COMPLEX && ts.dec_len > 8)
00632 forlen = 128;
00633 break;
00634
00635 default:
00636 break;
00637 }
00638
00639 return(forlen);
00640 }
00641
00642
00643
00644
00645
00646
00647
00648 static void
00649 _gdc_abort(
00650 FIOSPTR css,
00651 unit *cup,
00652 struct f90_type ts)
00653 {
00654 char *tn;
00655 char txt_decl[30];
00656 char *txt_dp;
00657
00658 if (ts.kind_or_star == DVD_STAR)
00659 tn = "%s*%d";
00660 else if (ts.kind_or_star == DVD_KIND)
00661 tn = "%s(KIND=%d)";
00662 else if (ts.kind_or_star == 3)
00663 tn = "%s*%d";
00664 else
00665 tn = "%s";
00666
00667 (void) sprintf(txt_decl, tn, _f90_type_name[ts.type], ts.dec_len);
00668
00669 txt_dp = "";
00670
00671 if (ts.dpflag && ts.int_len == sizeof(_f_real) << 3)
00672 txt_dp = "\n which was mapped to single precision with the -dp compiler option\n";
00673
00674 _ferr(css, FENCNV90, txt_decl, txt_dp);
00675
00676 return;
00677 }