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
00039
00040 #include <stdio.h>
00041 #include <mutex.h>
00042 #include <math.h>
00043 #include <ctype.h>
00044 #include <string.h>
00045 #include <cmplrs/fio.h>
00046 #include "fmt.h"
00047 #include "iomode.h"
00048 #include "lio.h"
00049 #include "lread.h"
00050 #include "err.h"
00051 #include "open.h"
00052 #include "nio.h"
00053 #include "util.h"
00054 #include "bcompat.h"
00055
00056
00057
00058
00059
00060
00061
00062 #define BSIZ (unsigned) 50
00063 static char nlrs[] = "namelist read";
00064 static char *getword(unit *, char *, unsigned int, int, int);
00065 #if 11
00066 static int c_nle (cilist64 *pcl, unit **fu);
00067 static int s_wsne64_mp (cilist64 *pnlarg, unit **fu);
00068 #else
00069 static int c_nle (cilist *pcl, unit **fu);
00070 #endif
00071
00072
00073 #define XINT_TYPE int
00074 #define NAMEDims Dims
00075 #define NAMENlentry Nlentry
00076 #define NAMENamelist Namelist
00077
00078 #include "nio_decl.h"
00079
00080 #undef XINT_TYPE
00081 #undef NAMEDims
00082 #undef NAMENlentry
00083 #undef NAMENamelist
00084
00085 #if 11
00086 #define XINT_TYPE XINT
00087 #define NAMEDims Dims64
00088 #define NAMENlentry Nlentry64
00089 #define NAMENamelist Namelist64
00090
00091 #include "nio_decl.h"
00092 #undef XINT_TYPE
00093 #undef NAMEDims
00094 #undef NAMENlentry
00095 #undef NAMENamelist
00096 #endif
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 #define NAMEs_rsNe_work s_rsNe_work
00108 #define NAMEs_wsNe_work s_wsNe_work
00109 #if 11
00110 #define TYPEcilist cilist64
00111 #else
00112 #define TYPEcilist cilist
00113 #endif
00114 #define TYPENamelist Namelist
00115 #define TYPENlentry Nlentry
00116 #define NAMEfindit findit
00117 #define NAMEgetvar getvar
00118
00119 #include "nio_work.h"
00120 #undef NAMEs_rsNe_work
00121 #undef NAMEs_wsNe_work
00122 #undef TYPEcilist
00123 #undef TYPENamelist
00124 #undef TYPENlentry
00125 #undef NAMEfindit
00126 #undef NAMEgetvar
00127
00128
00129 #if 11
00130 #define NAMEs_rsNe_work s_rsNe64_work
00131 #define NAMEs_wsNe_work s_wsNe64_work
00132 #define TYPEcilist cilist64
00133 #define TYPENamelist Namelist64
00134 #define TYPENlentry Nlentry64
00135 #define NAMEfindit findit64
00136 #define NAMEgetvar getvar64
00137
00138 #include "nio_work.h"
00139 #undef NAMEs_rsNe_work
00140 #undef NAMEs_wsNe_work
00141 #undef TYPEcilist
00142 #undef TYPENamelist
00143 #undef TYPENlentry
00144 #undef NAMEfindit
00145 #undef NAMEgetvar
00146
00147 #else
00148
00149
00150
00151
00152 #pragma weak s_rsNe64_work = s_rsNe_work
00153 #pragma weak s_wsNe64_work = s_wsNe_work
00154
00155 #endif
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 int
00189 s_rsne (cilist *pnlarg)
00190 {
00191 Namelist *pnl;
00192 Nlentry *pnlent;
00193
00194 #if 11
00195
00196
00197 cilist64 dst;
00198 get_cilist64(&dst, pnlarg);
00199 #define WORK_ARG &dst
00200 #else
00201 #define WORK_ARG pnlarg
00202 #endif
00203
00204 #ifdef I90OLD
00205
00206
00207 return s_rsNe_work(WORK_ARG, &f77curunit, 1, 1);
00208
00209 #else
00210
00211
00212 pnl = (Namelist *) pnlarg->cinml;
00213 pnlent = pnl->nlvnames;
00214 do {
00215 if (pnlent->type >= 0)
00216 pnlent->type = match_type[pnlent->type];
00217 pnlent++;
00218 } while (strlen (pnlent->varname));
00219 return s_rsNe_work (WORK_ARG, &f77curunit,1,0);
00220 #endif
00221
00222 #undef WORK_ARG
00223 }
00224
00225 int
00226 s_rsNe (cilist *pnlarg)
00227 {
00228 #if 11
00229
00230
00231 cilist64 dst;
00232 get_cilist64(&dst, pnlarg);
00233 #define WORK_ARG &dst
00234 #else
00235 #define WORK_ARG pnlarg
00236 #endif
00237 #ifdef I90OLD
00238 return s_rsNe_work(WORK_ARG, &f77curunit, 0, 0);
00239
00240 #else
00241 return s_rsNe_work(WORK_ARG, &f77curunit, 1, 0);
00242
00243
00244 #endif
00245 #undef WORK_ARG
00246 }
00247
00248
00249 int
00250 s_rsNe_mp (cilist *pnlarg, unit **fu)
00251 {
00252 #if 11
00253
00254
00255 cilist64 dst;
00256 get_cilist64(&dst, pnlarg);
00257 #define WORK_ARG &dst
00258 #else
00259 #define WORK_ARG pnlarg
00260 #endif
00261 #ifdef I90OLD
00262 return s_rsNe_work(WORK_ARG, fu, 0, 0);
00263
00264 #else
00265 return s_rsNe_work(WORK_ARG, fu, 1, 0);
00266
00267
00268 #endif
00269 #undef WORK_ARG
00270 }
00271
00272
00273
00274
00275
00276
00277
00278 static char *getword(unit *ftnunit, char *s, unsigned int n, int skip_newline, int space_is_a_delimiter)
00279 {
00280 int i;
00281 char *p = s;
00282
00283
00284
00285
00286
00287 if (!skip_newline) {
00288 while (isspace(GETC(i))) {
00289 if (i == '\n') {
00290 *p = '\0';
00291 return s;
00292 }
00293 }
00294 UNGETC (i);
00295 }
00296
00297
00298
00299
00300
00301
00302
00303 while ((GETC (i) == '\n') && (GETC (i) && (i == '*' || i == 'C' || i == 'c'))) {
00304 for (UNGETC (i); GETC (i) != '\n' && i != EOF;);
00305 if (i == '\n')
00306 UNGETC (i);
00307 if (i == EOF)
00308 break;
00309 }
00310 UNGETC (i);
00311
00312 for (GETC (i);
00313 isspace (i) || (ispunct (i) && i != '?' && i != '$' && i != '&');
00314 GETC (i)) {
00315
00316
00317
00318
00319
00320 if (i == '!') {
00321 for (UNGETC (i); GETC (i) != '\n' && i != EOF;);
00322 if (i == '\n')
00323 UNGETC (i);
00324 while ((GETC (i) == '\n') && (GETC (i) && (i == '*' || i == 'C' || i == 'c'))) {
00325 for (UNGETC (i); GETC (i) != '\n' && i != EOF;);
00326 if (i == '\n')
00327 UNGETC (i);
00328 if (i == EOF)
00329 break;
00330 }
00331 UNGETC (i);
00332 }
00333
00334 }
00335 if (space_is_a_delimiter) {
00336 while (n--) {
00337 if (i != EOF && i != '=' && !isspace (i) )
00338 *p++ = (isupper (i) ? i + 'a' - 'A' : i);
00339 else
00340 break;
00341 GETC (i);
00342 }
00343 } else {
00344 while (n--) {
00345 if (i != EOF && i != '=' && (!isspace (i) || i == ' ' || i == '\t'))
00346 *p++ = (isupper (i) ? i + 'a' - 'A' : i);
00347 else
00348 break;
00349 GETC (i);
00350 }
00351 }
00352
00353
00354
00355
00356
00357 if (i == '\n')
00358 UNGETC (i);
00359
00360 if (feof (ftnunit->ufd) && p == s)
00361 return NULL;
00362 *p = '\0';
00363 return s;
00364 }
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390 int
00391 s_wsne (cilist *pnlarg)
00392 {
00393 #if 11
00394
00395
00396 cilist64 dst;
00397 get_cilist64(&dst, pnlarg);
00398 #ifdef I90OLD
00399 return s_wsNe_work(&dst, &f77curunit, 1);
00400 #else
00401 return s_wsNe_work(&dst, &f77curunit, 0);
00402 #endif
00403
00404 #else
00405 #ifdef I90OLD
00406 return s_wsNe_work(pnlarg, &f77curunit, 1);
00407 #else
00408 return s_wsNe_work(pnlarg, &f77curunit, 0);
00409 #endif
00410
00411 #endif
00412 }
00413
00414 int
00415 s_wsne_mp (cilist *pnlarg, unit **fu)
00416 {
00417 Namelist *pnl;
00418 Nlentry *pnlent;
00419 #if 11
00420
00421
00422 cilist64 dst;
00423 get_cilist64(&dst, pnlarg);
00424 #define WORK_ARG &dst
00425 #else
00426 #define WORK_ARG pnlarg
00427 #endif
00428
00429 #ifdef I90OLD
00430
00431
00432
00433 return s_wsNe_work(WORK_ARG, fu, 1);
00434
00435 #else
00436
00437
00438 pnl = (Namelist *) pnlarg->cinml;
00439 pnlent = pnl->nlvnames;
00440 do {
00441 if (pnlent->type >= 0)
00442 pnlent->type = match_type[pnlent->type];
00443 pnlent++;
00444 } while (strlen (pnlent->varname));
00445 return s_wsNe_work (WORK_ARG, fu, 0);
00446 #endif
00447
00448 #undef WORK_ARG
00449 }
00450
00451 #if 11
00452 static int
00453 s_wsne64_mp (cilist64 *pnlarg, unit **fu)
00454 {
00455 Namelist *pnl;
00456 Nlentry *pnlent;
00457
00458 #ifdef I90OLD
00459
00460
00461
00462 return s_wsNe_work(pnlarg, fu, 1);
00463
00464 #else
00465
00466
00467 pnl = (Namelist *) pnlarg->cinml;
00468 pnlent = pnl->nlvnames;
00469 do {
00470 if (pnlent->type >= 0)
00471 pnlent->type = match_type[pnlent->type];
00472 pnlent++;
00473 } while (strlen (pnlent->varname));
00474 return s_wsNe_work (pnlarg, fu, 0);
00475 #endif
00476
00477 }
00478 #endif
00479
00480
00481 int
00482 s_wsNe (cilist *pnlarg)
00483 {
00484 #if 11
00485
00486
00487 cilist64 dst;
00488 get_cilist64(&dst, pnlarg);
00489 #define WORK_ARG &dst
00490 #else
00491 #define WORK_ARG pnlarg
00492 #endif
00493 return( s_wsNe_work( WORK_ARG, &f77curunit, 0 ) );
00494 #undef WORK_ARG
00495 }
00496
00497
00498 int
00499 s_wsNe_mp (cilist *pnlarg, unit **fu)
00500 {
00501 #if 11
00502
00503
00504 cilist64 dst;
00505 get_cilist64(&dst, pnlarg);
00506 #define WORK_ARG &dst
00507 #else
00508 #define WORK_ARG pnlarg
00509 #endif
00510 return s_wsNe_work(WORK_ARG, fu, 0);
00511
00512 #undef WORK_ARG
00513 }
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530 static
00531 int
00532 #if 11
00533 c_nle (cilist64 *pcl, unit **fu)
00534 #else
00535 c_nle (cilist *pcl, unit **fu)
00536 #endif
00537 {
00538 unit *ftnunit;
00539
00540 ftnunit = *fu = map_luno (pcl->ciunit);
00541 while (fu != &f77curunit && test_and_set( &ftnunit->lock_unit, 1L ))
00542 ;
00543 if (ftnunit->uconn <= 0 && fk_open (SEQ, FMT, pcl->ciunit)) {
00544 ftnunit->uconn = 0;
00545 errret(pcl->cierr, 102, "namelist io");
00546 }
00547 ftnunit->f77fmtbuf = "namelist io";
00548 ftnunit->f77scale = 0;
00549 ftnunit->f77recpos = 0;
00550 ftnunit->ufd = ftnunit->ufd;
00551
00552 if (!ftnunit->ufmt)
00553 errret(pcl->cierr, 103, "namelist io");
00554 return (0);
00555 }
00556
00557 #pragma weak __kai_s_rsne = s_rsNe
00558 #pragma weak __kai_s_wsne = s_wsNe
00559 #pragma weak __kai_s_rsne_mp = s_rsNe_mp
00560 #pragma weak __kai_s_wsne_mp = s_wsNe_mp
00561
00562
00563 #if 11
00564
00565 int
00566 s_rsNe64(cilist64 *pnlarg)
00567 {
00568 return s_rsNe64_work(pnlarg, &f77curunit, 1, 0);
00569 }
00570
00571 int
00572 s_rsNe64_mp(cilist64 *pnlarg, unit **fu)
00573 {
00574 return s_rsNe64_work(pnlarg, fu, 1, 0);
00575 }
00576
00577 int
00578 s_wsNe64(cilist64 *pnlarg)
00579 {
00580 return( s_wsNe64_work(pnlarg, &f77curunit, 0 ));
00581 }
00582
00583 int
00584 s_wsNe64_mp(cilist64 *pnlarg, unit **fu)
00585 {
00586 return( s_wsNe64_work(pnlarg, fu, 0));
00587 }
00588
00589 #pragma weak __kai_s_rsne64 = s_rsNe64
00590 #pragma weak __kai_s_wsne64 = s_wsNe64
00591 #pragma weak __kai_s_rsne64_mp = s_rsNe64_mp
00592 #pragma weak __kai_s_wsne64_mp = s_wsNe64_mp
00593
00594 #endif