| 1 |
/* |
| 2 |
* Copyright(C) 1999-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 |
/* ifdef.h - ifdef file for cdr routines |
| 9 |
* This file is used to define the system dependent ways C is |
| 10 |
* called from FORTRAN. Underscores are used by default. |
| 11 |
* |
| 12 |
* SUN DEC/ULTRIX ALLIANT : C routines must have underscores |
| 13 |
* SGI CONVEX : C routines must have underscores |
| 14 |
* |
| 15 |
* VAX HP IBM/aix : C routines do not have underscores |
| 16 |
* |
| 17 |
* CRAY/UNICOS : C routines must be capitalized, |
| 18 |
* and no underscores |
| 19 |
* |
| 20 |
* This include file is used by all cdr routines |
| 21 |
*/ |
| 22 |
|
| 23 |
#include <stdlib.h> |
| 24 |
#include <unistd.h> |
| 25 |
|
| 26 |
#if defined(ADDC_) |
| 27 |
#endif |
| 28 |
#if !defined(CRAY) && !defined(ADDC_) && !defined(COUGAR) |
| 29 |
#define cdrcom_ cdrcom |
| 30 |
#define cdrcm2_ cdrcm2 |
| 31 |
#define cdrunx_ cdrunx |
| 32 |
#define vcjob_ vcjob |
| 33 |
#define vconod_ vconod |
| 34 |
#define cdr1ch_ cdr1ch |
| 35 |
#define cdr1pk_ cdr1pk |
| 36 |
#define cdr2cm_ cdr2cm |
| 37 |
#define cdra2c_ cdra2c |
| 38 |
#define cdrbit_ cdrbit |
| 39 |
#define cdrbtr_ cdrbtr |
| 40 |
#define cdrc2a_ cdrc2a |
| 41 |
#define cdrc2h_ cdrc2h |
| 42 |
#define cdrcfs_ cdrcfs |
| 43 |
#define cdrcvt_ cdrcvt |
| 44 |
#define cdrela_ cdrela |
| 45 |
#define cdrgnm_ cdrgnm |
| 46 |
#define cdri2c_ cdri2c |
| 47 |
#define cdrinp_ cdrinp |
| 48 |
#define cdrjob_ cdrjob |
| 49 |
#define cdrlwr_ cdrlwr |
| 50 |
#define cdrmon_ cdrmon |
| 51 |
#define cdroab_ cdroab |
| 52 |
#define cdrof3_ cdrof3 |
| 53 |
#define cdroff_ cdroff |
| 54 |
#define cdrofs_ cdrofs |
| 55 |
#define cdrono_ cdrono |
| 56 |
#define cdrout_ cdrout |
| 57 |
#define cdrpak_ cdrpak |
| 58 |
#define cdrrfs_ cdrrfs |
| 59 |
#define cdrrvt_ cdrrvt |
| 60 |
#define cdrstd_ cdrstd |
| 61 |
#define cdrtbk_ cdrtbk |
| 62 |
#define cdrtim_ cdrtim |
| 63 |
#define cdrtod_ cdrtod |
| 64 |
#define cdrupk_ cdrupk |
| 65 |
#define cdrupr_ cdrupr |
| 66 |
#define cdrwfs_ cdrwfs |
| 67 |
#endif |
| 68 |
#if defined(CRA) |
| 69 |
#define cdrcom_ CDRCOM |
| 70 |
#define cdrcm2_ CDRCM2 |
| 71 |
#define cdrunx_ CDRUNX |
| 72 |
#define vcjob_ VCJOB |
| 73 |
#define vconod_ VCONOD |
| 74 |
#define cdr1ch_ CDR1CH |
| 75 |
#define cdr1pk_ CDR1PK |
| 76 |
#define cdr2cm_ CDR2CM |
| 77 |
#define cdra2c_ CDRA2C |
| 78 |
#define cdrbit_ CDRBIT |
| 79 |
#define cdrbtr_ CDRBTR |
| 80 |
#define cdrc2a_ CDRC2A |
| 81 |
#define cdrc2h_ CDRC2H |
| 82 |
#define cdrcfs_ CDRCFS |
| 83 |
#define cdrcvt_ CDRCVT |
| 84 |
#define cdrela_ CDRELA |
| 85 |
#define cdrgnm_ CDRGNM |
| 86 |
#define cdri2c_ CDRI2C |
| 87 |
#define cdrinp_ CDRINP |
| 88 |
#define cdrjob_ CDRJOB |
| 89 |
#define cdrlwr_ CDRLWR |
| 90 |
#define cdrmon_ CDRMON |
| 91 |
#define cdroab_ CDROAB |
| 92 |
#define cdrof3_ CDROF3 |
| 93 |
#define cdroff_ CDROFF |
| 94 |
#define cdrofs_ CDROFS |
| 95 |
#define cdrono_ CDRONO |
| 96 |
#define cdrout_ CDROUT |
| 97 |
#define cdrpak_ CDRPAK |
| 98 |
#define cdrrfs_ CDRRFS |
| 99 |
#define cdrrvt_ CDRRVT |
| 100 |
#define cdrstd_ CDRSTD |
| 101 |
#define cdrtbk_ CDRTBK |
| 102 |
#define cdrtim_ CDRTIM |
| 103 |
#define cdrtod_ CDRTOD |
| 104 |
#define cdrupk_ CDRUPK |
| 105 |
#define cdrupr_ CDRUPR |
| 106 |
#define cdrwfs_ CDRWFS |
| 107 |
#endif |
| 108 |
/* end ifdef.h */ |
| 109 |
|
| 110 |
/* Structures used to communicate with FORTRAN common blocks. |
| 111 |
* On all systems, except CRAY/UNICOS, structures must be declared |
| 112 |
* external. On UNICOS, the structures are not external. |
| 113 |
*/ |
| 114 |
#if defined(CRA) |
| 115 |
|
| 116 |
/* cdrcm2_u.h */ |
| 117 |
struct cdr2 |
| 118 |
{ |
| 119 |
char KGNAME[80]; |
| 120 |
} cdrcm2_; |
| 121 |
|
| 122 |
/* cdrcom.h */ |
| 123 |
struct cdr |
| 124 |
{ |
| 125 |
int KWRTFL; |
| 126 |
int KRDFL; |
| 127 |
int KOUTFL; |
| 128 |
int KINFL; |
| 129 |
int KWRDSZ; |
| 130 |
int KBYTEL; |
| 131 |
int KCPW; |
| 132 |
int KBAUD; |
| 133 |
int KCOMTP; |
| 134 |
} cdrcom_; |
| 135 |
|
| 136 |
/* cdrunx.h */ |
| 137 |
struct unx |
| 138 |
{ |
| 139 |
int KUNTFD[1000]; |
| 140 |
} cdrunx_; |
| 141 |
|
| 142 |
/* vcjob.h */ |
| 143 |
struct job |
| 144 |
{ |
| 145 |
int KIDSIZ; |
| 146 |
int KJOBID[4]; |
| 147 |
int KUSRSZ; |
| 148 |
int KUSRID[4]; |
| 149 |
int KSZROU; |
| 150 |
int KJROUT[4]; |
| 151 |
int KSECUR; |
| 152 |
int KJTIME[4]; |
| 153 |
int KJDATE[4]; |
| 154 |
int MACHIN[3]; |
| 155 |
int MACLEN; |
| 156 |
} vcjob_; |
| 157 |
|
| 158 |
/* for now, hard code this stuff in: */ |
| 159 |
#if defined(SECURITY_CODE) |
| 160 |
#undef SECURITY_CODE |
| 161 |
#endif |
| 162 |
#define SECURITY_CODE 0 |
| 163 |
|
| 164 |
#if defined(CDR_MACHINE) |
| 165 |
#undef CDR_MACHINE |
| 166 |
#endif |
| 167 |
#define CDR_MACHINE "UNICOS" |
| 168 |
|
| 169 |
#if defined(ROUTE) |
| 170 |
#undef ROUTE |
| 171 |
#endif |
| 172 |
#define ROUTE "BX 603" |
| 173 |
|
| 174 |
/* vconod.h */ |
| 175 |
struct onode |
| 176 |
{ |
| 177 |
int ONODE; |
| 178 |
} vconod_; |
| 179 |
|
| 180 |
#else |
| 181 |
|
| 182 |
/* cdrcm2.h */ |
| 183 |
extern struct cdr2 |
| 184 |
{ |
| 185 |
char KGNAME[80]; |
| 186 |
} cdrcm2_; |
| 187 |
|
| 188 |
/* cdrcom.h */ |
| 189 |
extern struct cdr |
| 190 |
{ |
| 191 |
int KWRTFL; |
| 192 |
int KRDFL; |
| 193 |
int KOUTFL; |
| 194 |
int KINFL; |
| 195 |
int KWRDSZ; |
| 196 |
int KBYTEL; |
| 197 |
int KCPW; |
| 198 |
int KBAUD; |
| 199 |
int KCOMTP; |
| 200 |
} cdrcom_; |
| 201 |
|
| 202 |
/* cdrunx.h */ |
| 203 |
extern struct unx |
| 204 |
{ |
| 205 |
int KUNTFD[1000]; |
| 206 |
} cdrunx_; |
| 207 |
|
| 208 |
/* vcjob.h */ |
| 209 |
extern struct job |
| 210 |
{ |
| 211 |
int KIDSIZ; |
| 212 |
int KJOBID[4]; |
| 213 |
int KUSRSZ; |
| 214 |
int KUSRID[4]; |
| 215 |
int KSZROU; |
| 216 |
int KJROUT[4]; |
| 217 |
int KSECUR; |
| 218 |
int KJTIME[3]; |
| 219 |
int KJDATE[3]; |
| 220 |
int MACHIN[3]; |
| 221 |
int MACLEN; |
| 222 |
} vcjob_; |
| 223 |
|
| 224 |
/* for now, hard code this stuff in: */ |
| 225 |
#if defined(SECURITY_CODE) |
| 226 |
#undef SECURITY_CODE |
| 227 |
#endif |
| 228 |
#define SECURITY_CODE 0 |
| 229 |
|
| 230 |
#if defined(CDR_MACHINE) |
| 231 |
#undef CDR_MACHINE |
| 232 |
#endif |
| 233 |
#define CDR_MACHINE "UNIX" |
| 234 |
|
| 235 |
#if defined(ROUTE) |
| 236 |
#undef ROUTE |
| 237 |
#endif |
| 238 |
#define ROUTE "BX 603" |
| 239 |
|
| 240 |
/* vconod.h */ |
| 241 |
extern struct onode |
| 242 |
{ |
| 243 |
int ONODE; |
| 244 |
} vconod_; |
| 245 |
|
| 246 |
#endif |
| 247 |
|
| 248 |
/* System includes */ |
| 249 |
#include <ctype.h> |
| 250 |
#if !defined(__CYGWIN__) |
| 251 |
#include <pwd.h> |
| 252 |
#endif |
| 253 |
#include <signal.h> |
| 254 |
#include <stdio.h> |
| 255 |
#include <string.h> |
| 256 |
|
| 257 |
#if defined(CRA) |
| 258 |
#include <fcntl.h> |
| 259 |
#include <sys/types.h> |
| 260 |
#endif |
| 261 |
#include <sys/file.h> |
| 262 |
|
| 263 |
#if defined(CRA) || defined(interix) || defined(linux) |
| 264 |
#include <time.h> |
| 265 |
#else |
| 266 |
#include <sys/time.h> |
| 267 |
#endif |
| 268 |
#if defined(sun) && (defined(SYSV) || defined(SVR4)) |
| 269 |
#include <fcntl.h> |
| 270 |
#include <sys/stat.h> |
| 271 |
#include <sys/types.h> |
| 272 |
#endif |
| 273 |
|
| 274 |
/* *** CDR1CH *** |
| 275 |
|
| 276 |
Copy the Nth KBYTEL-width character of STRING to the |
| 277 |
lowest order character field of NUCHAR. |
| 278 |
|
| 279 |
Parameters: |
| 280 |
n - IN - character position, counted from the left, of |
| 281 |
the character to be extracted from STRING |
| 282 |
string - IN - word from which to copy the character |
| 283 |
nuchar - OUT - word in which to place the character |
| 284 |
|
| 285 |
*/ |
| 286 |
|
| 287 |
void cdr1ch_(int *n, unsigned *string, unsigned *nuchar) |
| 288 |
{ |
| 289 |
if (*n > cdrcom_.KCPW) { |
| 290 |
return; |
| 291 |
} |
| 292 |
*nuchar = (*string >> (cdrcom_.KWRDSZ - *n * cdrcom_.KBYTEL) & ~(~0u << cdrcom_.KBYTEL)); |
| 293 |
} |
| 294 |
|
| 295 |
/* *** CDR1PK *** |
| 296 |
|
| 297 |
Copy the KBYTEL-width character of INCHAR (right-justified) to |
| 298 |
the Nth KBYTEL-width character position of BUFFER. |
| 299 |
|
| 300 |
Parameters: |
| 301 |
n - IN - character position, counted from the left, at which |
| 302 |
the KBYTEL-width character is copied |
| 303 |
inchar - IN - word containing one KBYTEL-width character, right |
| 304 |
adjusted, zero-filled |
| 305 |
buffer - OUT - word into which the character is copied. |
| 306 |
|
| 307 |
*/ |
| 308 |
|
| 309 |
void cdr1pk_(int *n, unsigned *inchar, unsigned *buffer) |
| 310 |
{ |
| 311 |
int i; |
| 312 |
unsigned temp, mask; |
| 313 |
|
| 314 |
if (*n > cdrcom_.KCPW) { |
| 315 |
return; |
| 316 |
} |
| 317 |
temp = *inchar << (i = cdrcom_.KWRDSZ - (*n * cdrcom_.KBYTEL)); |
| 318 |
mask = ~(~0u << cdrcom_.KBYTEL) << i; |
| 319 |
*buffer = ((mask & temp) | (~mask & *buffer)); |
| 320 |
} |
| 321 |
/* *** CDR2CM *** |
| 322 |
|
| 323 |
Bitwise complement, used for 2's complement. |
| 324 |
|
| 325 |
Parameters: |
| 326 |
in - IN - integer to complement |
| 327 |
iout - OUT - complemented integer |
| 328 |
|
| 329 |
*/ |
| 330 |
|
| 331 |
void cdr2cm_(int *in, int *iout) { *iout = ~(*in) + 1; } |
| 332 |
|
| 333 |
/* *** CDRPAK *** |
| 334 |
|
| 335 |
Pack the IWIDTH lower order bits from NEXT into IBUF, starting at |
| 336 |
bit position IBUF(IWORD) + IBITLC. Bits are counted left to right. |
| 337 |
IWORD and IBITLC are updated to reflect the new position in IBUF. |
| 338 |
|
| 339 |
Parameters: |
| 340 |
next - IN - word containing bits to pack into ibuf |
| 341 |
iwidth - IN - number of bits to get from NEXT |
| 342 |
iword - IN/OUT -word in buffer to put the bits |
| 343 |
ibitlc - IN/OUT -number of bits currently used in IBUF(IWORD) |
| 344 |
ibuf - OUT - the array in which to put the bits |
| 345 |
|
| 346 |
*/ |
| 347 |
|
| 348 |
void cdrpak_(unsigned *next, int *iwidth, int *iword, int *ibitlc, unsigned *ibuf) |
| 349 |
{ |
| 350 |
int idx, i; |
| 351 |
unsigned temp, mask; |
| 352 |
|
| 353 |
/* check boundaries */ |
| 354 |
if (*iwidth > cdrcom_.KWRDSZ) { |
| 355 |
return; |
| 356 |
} |
| 357 |
|
| 358 |
/* if bitlc is bigger than the word size, increment */ |
| 359 |
if (*ibitlc >= cdrcom_.KWRDSZ) { |
| 360 |
*ibitlc = 0; |
| 361 |
(*iword)++; |
| 362 |
} |
| 363 |
|
| 364 |
/* "C" start arrays at 0 */ |
| 365 |
idx = *iword - 1; |
| 366 |
|
| 367 |
if (*ibitlc + *iwidth > cdrcom_.KWRDSZ) { |
| 368 |
|
| 369 |
/* word overflow - break into parts */ |
| 370 |
|
| 371 |
temp = *next >> (i = *iwidth + *ibitlc - cdrcom_.KWRDSZ); |
| 372 |
mask = ~0u << (cdrcom_.KWRDSZ - *ibitlc); |
| 373 |
ibuf[idx] = ((~mask & temp) | (mask & ibuf[idx])); |
| 374 |
*ibitlc = i; |
| 375 |
(*iword)++; |
| 376 |
idx++; |
| 377 |
temp = *next << (i = cdrcom_.KWRDSZ - *ibitlc); |
| 378 |
mask = ~0u << i; |
| 379 |
ibuf[idx] = ((mask & temp) | (~mask & ibuf[idx])); |
| 380 |
} |
| 381 |
else { |
| 382 |
|
| 383 |
/* it fits all in one word */ |
| 384 |
|
| 385 |
temp = *next << (i = cdrcom_.KWRDSZ - *ibitlc - *iwidth); |
| 386 |
mask = ~(~0u << *iwidth) << i; |
| 387 |
ibuf[idx] = ((mask & temp) | (~mask & ibuf[idx])); |
| 388 |
*ibitlc += *iwidth; |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
/* *** CDRA2C *** |
| 393 |
|
| 394 |
Convert from ascii to character |
| 395 |
|
| 396 |
Parameters: |
| 397 |
asci - IN - integer representing an ascii character |
| 398 |
charac - OUT - the character represented by asci |
| 399 |
|
| 400 |
*/ |
| 401 |
|
| 402 |
void cdra2c_(int *asci, char *charac) { charac[0] = (char)*asci; } |
| 403 |
/* *** CDRBIT *** |
| 404 |
|
| 405 |
This is a dummy routine to satisfy externals. See CDRPAK |
| 406 |
|
| 407 |
Parameters: |
| 408 |
next - IN - |
| 409 |
iwidth - IN - |
| 410 |
iword - IN/OUT - |
| 411 |
ibitlc - IN/OUT - |
| 412 |
ibuf - OUT - |
| 413 |
|
| 414 |
*/ |
| 415 |
|
| 416 |
void cdrbit_(unsigned *next, int *iwidth, int *iword, int *ibitlc, unsigned *ibuf) |
| 417 |
{ |
| 418 |
cdrpak_(next, iwidth, iword, ibitlc, ibuf); |
| 419 |
} |
| 420 |
|
| 421 |
/* *** CDRUPK *** |
| 422 |
|
| 423 |
Copy IWIDTH bits from IBUF,starting at bit position IBUF(IWORD) + |
| 424 |
IBITLC, into low order of NEXT. Bits are counted left to right. |
| 425 |
IWORD and IBITLC are updated to reflect the new position in IBUF. |
| 426 |
|
| 427 |
Parameters: |
| 428 |
ibuf - IN - the array containing the bits to copy into next |
| 429 |
iword - IN/OUT - word in buffer from which to get the bits |
| 430 |
ibitlc - IN/OUT - number of bits already retrieved from IBUF(IWORD) |
| 431 |
iwidth - IN - number of bits to get from IBUF |
| 432 |
next - OUT - word to put the bits in, right justified, zero filled |
| 433 |
|
| 434 |
*/ |
| 435 |
|
| 436 |
void cdrupk_(unsigned *ibuf, int *iword, int *ibitlc, int *iwidth, unsigned *next) |
| 437 |
{ |
| 438 |
int idx, i; |
| 439 |
unsigned temp, mask; |
| 440 |
#if defined(DEC) || defined(linux) || defined(interix) |
| 441 |
unsigned char *p_temp, ctemp; |
| 442 |
#endif |
| 443 |
/* check boundaries */ |
| 444 |
if (*iwidth > cdrcom_.KWRDSZ) { |
| 445 |
return; |
| 446 |
} |
| 447 |
|
| 448 |
/* if ibitlc is bigger than word size, increment */ |
| 449 |
if (*ibitlc >= cdrcom_.KWRDSZ) { |
| 450 |
*ibitlc = 0; |
| 451 |
(*iword)++; |
| 452 |
} |
| 453 |
|
| 454 |
/* "C" arrays start at 0 */ |
| 455 |
idx = *iword - 1; |
| 456 |
|
| 457 |
if (*ibitlc + *iwidth > cdrcom_.KWRDSZ) { |
| 458 |
|
| 459 |
/* crosses word boundary - break it up */ |
| 460 |
|
| 461 |
temp = ibuf[idx]; |
| 462 |
#if defined(DEC) || defined(linux) || defined(interix) |
| 463 |
/* swap byte order around */ |
| 464 |
p_temp = (unsigned char *)(&temp); |
| 465 |
ctemp = *p_temp; |
| 466 |
*p_temp = *(p_temp + 3); |
| 467 |
*(p_temp + 3) = ctemp; |
| 468 |
ctemp = *(p_temp + 1); |
| 469 |
*(p_temp + 1) = *(p_temp + 2); |
| 470 |
*(p_temp + 2) = ctemp; |
| 471 |
#endif |
| 472 |
temp = temp << (i = *iwidth + *ibitlc - cdrcom_.KWRDSZ); |
| 473 |
mask = ~(~0u << (cdrcom_.KWRDSZ - *ibitlc)) << i; |
| 474 |
*next = (mask & temp); |
| 475 |
*ibitlc = i; |
| 476 |
(*iword)++; |
| 477 |
idx++; |
| 478 |
temp = ibuf[idx]; |
| 479 |
#if defined(DEC) || defined(linux) || defined(interix) |
| 480 |
/* swap byte order around */ |
| 481 |
p_temp = (unsigned char *)(&temp); |
| 482 |
ctemp = *p_temp; |
| 483 |
*p_temp = *(p_temp + 3); |
| 484 |
*(p_temp + 3) = ctemp; |
| 485 |
ctemp = *(p_temp + 1); |
| 486 |
*(p_temp + 1) = *(p_temp + 2); |
| 487 |
*(p_temp + 2) = ctemp; |
| 488 |
#endif |
| 489 |
temp = temp >> (cdrcom_.KWRDSZ - *ibitlc); |
| 490 |
mask = ~(~0u << *ibitlc); |
| 491 |
*next = ((mask & temp) | *next); |
| 492 |
} |
| 493 |
else { |
| 494 |
|
| 495 |
/* doesn't cross word boundary */ |
| 496 |
|
| 497 |
temp = ibuf[idx]; |
| 498 |
#if defined(DEC) || defined(linux) || defined(interix) |
| 499 |
/* swap byte order around */ |
| 500 |
p_temp = (unsigned char *)(&temp); |
| 501 |
ctemp = *p_temp; |
| 502 |
*p_temp = *(p_temp + 3); |
| 503 |
*(p_temp + 3) = ctemp; |
| 504 |
ctemp = *(p_temp + 1); |
| 505 |
*(p_temp + 1) = *(p_temp + 2); |
| 506 |
*(p_temp + 2) = ctemp; |
| 507 |
#endif |
| 508 |
temp = temp >> (cdrcom_.KWRDSZ - *ibitlc - *iwidth); |
| 509 |
mask = ~(~0u << *iwidth); |
| 510 |
*next = mask & temp; |
| 511 |
*ibitlc += *iwidth; |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
/* *** CDRBTR *** |
| 516 |
|
| 517 |
This is a dummy routine to satisfy externals. See CDRUPK |
| 518 |
|
| 519 |
Parameters: |
| 520 |
ibuf - IN - |
| 521 |
iword - IN/OUT - |
| 522 |
ibitlc - IN/OUT - |
| 523 |
iwidth - IN - |
| 524 |
next - OUT - |
| 525 |
|
| 526 |
*/ |
| 527 |
|
| 528 |
void cdrbtr_(unsigned ibuf[], int *iword, int *ibitlc, int *iwidth, unsigned *next) |
| 529 |
{ |
| 530 |
cdrupk_(ibuf, iword, ibitlc, iwidth, next); |
| 531 |
} |
| 532 |
/* *** CDRC2A *** |
| 533 |
|
| 534 |
Convert from character to ASCII |
| 535 |
|
| 536 |
Parameters: |
| 537 |
charac - IN - the character represented by asci |
| 538 |
asci - OUT - integer representing an ASCII character |
| 539 |
|
| 540 |
*/ |
| 541 |
|
| 542 |
void cdrc2a_(char *charac, int *asci) { *asci = (int)charac[0]; } |
| 543 |
|
| 544 |
/* *** CDRC2H *** |
| 545 |
|
| 546 |
Convert character to hollerith. TITLE will contain at least |
| 547 |
LENGTH characters, and ITITLE will be dimensioned one larger |
| 548 |
in order to append the zero word that is required by Hollerith |
| 549 |
rules. |
| 550 |
|
| 551 |
Notes and Revisions: |
| 552 |
This routine just copies the input to the output and appends a |
| 553 |
zero word, the C/FORTRAN parameter passing handles the rest. |
| 554 |
|
| 555 |
Parameters: |
| 556 |
title - IN - character string of any length |
| 557 |
length - IN - length of title |
| 558 |
ititle - OUT - hollerith equivalent of title |
| 559 |
|
| 560 |
*/ |
| 561 |
|
| 562 |
void cdrc2h_(unsigned *title, int *length, unsigned *ititle) |
| 563 |
{ |
| 564 |
int i, ilen; |
| 565 |
|
| 566 |
ilen = *length / cdrcom_.KCPW; |
| 567 |
for (i = 0; i < ilen; i++) { |
| 568 |
ititle[i] = title[i]; |
| 569 |
} |
| 570 |
ititle[ilen + 1] = 0; |
| 571 |
} |
| 572 |
|
| 573 |
/* *** CDRCFS *** |
| 574 |
|
| 575 |
Close file sequential. |
| 576 |
|
| 577 |
Notes and Revisions: |
| 578 |
This routine uses the array KUNTFD, in the FORTRAN common and |
| 579 |
the C external structure, cdrunx, to translate from FORTRAN |
| 580 |
unit number to UNIX/C file descriptors. |
| 581 |
|
| 582 |
Parameters: |
| 583 |
ifilcd - IN - FORTRAN unit number of the sequential file to close |
| 584 |
eof - IN - end-of-file request flag. If eof=1, an end of file |
| 585 |
marker is written on the end of the file. |
| 586 |
|
| 587 |
*/ |
| 588 |
|
| 589 |
void cdrcfs_(int *ifilcd, int *eof) |
| 590 |
{ |
| 591 |
/* translate fortran unit number to file descriptor */ |
| 592 |
int fd = cdrunx_.KUNTFD[*ifilcd]; |
| 593 |
|
| 594 |
/* if eof = 1 then write eof on file */ |
| 595 |
if (*eof == 1) { |
| 596 |
char buf[4]; |
| 597 |
*buf = EOF; |
| 598 |
if (write(fd, buf, 4) == -1) { |
| 599 |
perror("CDRCFS error:"); |
| 600 |
} |
| 601 |
} |
| 602 |
|
| 603 |
/* close the file */ |
| 604 |
close(fd); |
| 605 |
} |
| 606 |
/* *** CDRCVT *** |
| 607 |
|
| 608 |
Convert from internal character set to ASCII character set. |
| 609 |
|
| 610 |
Notes and Revisions: |
| 611 |
This routine is here to satisfy the call, since the internal |
| 612 |
character set is ASCII. |
| 613 |
|
| 614 |
Parameters: |
| 615 |
in - IN - character to be converted, in host internal format |
| 616 |
iout - OUT - character converted to ASCII |
| 617 |
|
| 618 |
*/ |
| 619 |
|
| 620 |
void cdrcvt_(int *in, int *iout) { *iout = *in; } |
| 621 |
/* *** CDRELA *** |
| 622 |
|
| 623 |
Collect CPU time. This is a dummy routine to satisfy calls from |
| 624 |
VDMONI. Monitoring isn't done on this system |
| 625 |
|
| 626 |
Parameters: |
| 627 |
icode - IN - 0 = initialize timer, 1 = save timer |
| 628 |
|
| 629 |
*/ |
| 630 |
void cdrela_(int *icode) {} |
| 631 |
|
| 632 |
/* *** CDRGNM *** |
| 633 |
|
| 634 |
Name graphics output file or the post processor input file |
| 635 |
|
| 636 |
Notes and Revisions: |
| 637 |
This routine is called by VDGNAM (if the user called VDGNAM), |
| 638 |
and VBPKG. Whoever gets here first, wins. |
| 639 |
|
| 640 |
Parameters: |
| 641 |
gname - IN - file name to call graphics output file |
| 642 |
glen - IN - length of file name |
| 643 |
*/ |
| 644 |
|
| 645 |
void cdrgnm_(char gname[], int *glen) |
| 646 |
{ |
| 647 |
/* make sure name hasn't already been set */ |
| 648 |
char blank = ' '; |
| 649 |
if (cdrcm2_.KGNAME[0] != blank) { |
| 650 |
return; |
| 651 |
} |
| 652 |
|
| 653 |
/* store it in the external (and common) variables */ |
| 654 |
for (int i = 0; i < *glen; i++) { |
| 655 |
cdrcm2_.KGNAME[i] = gname[i]; |
| 656 |
} |
| 657 |
|
| 658 |
/* append a backslash and an endofstring character */ |
| 659 |
char bslash = '\\'; |
| 660 |
cdrcm2_.KGNAME[*glen] = bslash; |
| 661 |
cdrcm2_.KGNAME[*glen + 1] = '\0'; |
| 662 |
} |
| 663 |
|
| 664 |
/* *** CDRI2C *** |
| 665 |
|
| 666 |
Convert positive integer to decimal character string equivalent |
| 667 |
|
| 668 |
Parameters: |
| 669 |
intp - IN - positive integer to be converted |
| 670 |
ndigit - IN - number of digits to be produced in string form |
| 671 |
(pad left with zeros) |
| 672 |
string - OUT - character string of at least ndigit characters |
| 673 |
|
| 674 |
*/ |
| 675 |
|
| 676 |
void cdri2c_(int *intp, int *ndigit, char string[]) |
| 677 |
{ |
| 678 |
int inbr = *intp; |
| 679 |
|
| 680 |
for (int i = (*ndigit - 1); i >= 0; i--) { |
| 681 |
string[i] = inbr % 10 + '0'; |
| 682 |
inbr = inbr / 10; |
| 683 |
} |
| 684 |
} |
| 685 |
#define CDR_MAXLEN 512 |
| 686 |
|
| 687 |
/* *** CDRINP *** |
| 688 |
|
| 689 |
Send the prompt, IPROMPT, to the terminal, and read ICOUNT |
| 690 |
characters from the terminal into buffer IBUFFER. |
| 691 |
|
| 692 |
Parameters: |
| 693 |
icount - IN - number of characters to be accepted from the |
| 694 |
terminal |
| 695 |
ibuffer - OUT - buffer into which the characters are read |
| 696 |
iprompt - iN - prompt sequence to output to the terminal |
| 697 |
|
| 698 |
*/ |
| 699 |
|
| 700 |
void cdrinp_(int *icount, int *ibuffer, int *iprompt) |
| 701 |
{ |
| 702 |
char buffer[CDR_MAXLEN]; |
| 703 |
int istat, actcnt = 0; |
| 704 |
|
| 705 |
/* check the input */ |
| 706 |
int icnt = *icount; |
| 707 |
if (*icount > CDR_MAXLEN) { |
| 708 |
icnt = CDR_MAXLEN; |
| 709 |
} |
| 710 |
|
| 711 |
/* if prompt count is greater than 0, output the prompt */ |
| 712 |
if (iprompt[0] > 0) { |
| 713 |
char prompt[CDR_MAXLEN]; |
| 714 |
for (int i = 1; i <= iprompt[0]; i++) { |
| 715 |
prompt[i - 1] = (char)iprompt[i]; |
| 716 |
} |
| 717 |
|
| 718 |
if ((istat = write(1, prompt, iprompt[0])) == -1) { |
| 719 |
perror("CDRINP error:"); |
| 720 |
} |
| 721 |
} |
| 722 |
|
| 723 |
/* read from the terminal */ |
| 724 |
if ((istat = read(1, buffer, icnt)) == -1) { |
| 725 |
perror("CDRINP error:"); |
| 726 |
} |
| 727 |
else { |
| 728 |
/* strip off newline if there is one */ |
| 729 |
if (buffer[istat - 1] == '\n') { |
| 730 |
actcnt = istat - 1; |
| 731 |
} |
| 732 |
else { |
| 733 |
actcnt = istat; |
| 734 |
} |
| 735 |
} |
| 736 |
|
| 737 |
/* load user's buffer */ |
| 738 |
for (int i = 0; i < actcnt; i++) { |
| 739 |
ibuffer[i] = (int)buffer[i]; |
| 740 |
} |
| 741 |
|
| 742 |
/* zero fill left over buffer space */ |
| 743 |
if (actcnt < icnt) { |
| 744 |
for (int i = actcnt; i < icnt; i++) { |
| 745 |
ibuffer[i] = 0; |
| 746 |
} |
| 747 |
|
| 748 |
/* if there wasn't a newline, flush input */ |
| 749 |
if (buffer[istat - 1] != '\n') { |
| 750 |
read(1, buffer, CDR_MAXLEN); |
| 751 |
} |
| 752 |
} |
| 753 |
} |
| 754 |
|
| 755 |
/* *** CDRJOB *** |
| 756 |
|
| 757 |
Get job information and set the vars in the vcjob common block: |
| 758 |
process id - max 12 chars |
| 759 |
length of process id |
| 760 |
user name - max 12 chars |
| 761 |
length of user name |
| 762 |
routing info - max 12 chars |
| 763 |
length of routing |
| 764 |
security classification |
| 765 |
date 86-12-15 |
| 766 |
time 12:23:59 |
| 767 |
machine - max 12 chars |
| 768 |
length of machine |
| 769 |
*/ |
| 770 |
|
| 771 |
void cdrjob_(void) {} |
| 772 |
|
| 773 |
/* *** CDRLWR *** |
| 774 |
|
| 775 |
Convert character string to all lower case |
| 776 |
|
| 777 |
Notes and Revisions: |
| 778 |
Only converts characters |
| 779 |
|
| 780 |
Parameters: |
| 781 |
in - IN - character string to be converted |
| 782 |
iout - OUT - character string converted to all lower case |
| 783 |
inlen - IN - length of character string in |
| 784 |
|
| 785 |
*/ |
| 786 |
|
| 787 |
void cdrlwr_(char in[], char iout[], int *inlen) |
| 788 |
{ |
| 789 |
for (int i = 0; i <= *inlen - 1; i++) { |
| 790 |
if (isupper(in[i])) { |
| 791 |
iout[i] = tolower(in[i]); |
| 792 |
} |
| 793 |
else { |
| 794 |
iout[i] = in[i]; |
| 795 |
} |
| 796 |
} |
| 797 |
} |
| 798 |
/* *** CDRMON *** |
| 799 |
|
| 800 |
Write out monitoring information. This is a dummy routine to |
| 801 |
satisfy calls from VDMONI. Monitoring isn't done on this system. |
| 802 |
|
| 803 |
Parameters: |
| 804 |
mdev - IN - |
| 805 |
mpkg - IN - |
| 806 |
mpage - IN - |
| 807 |
|
| 808 |
*/ |
| 809 |
|
| 810 |
void cdrmon_(int *mdev, int *mpkg, int *mpages) {} |
| 811 |
|
| 812 |
/* *** CDROFS *** |
| 813 |
|
| 814 |
Open a file for sequential access. |
| 815 |
|
| 816 |
Notes and Revisions: |
| 817 |
This routine uses the array KUNTFD, in the FORTRAN common and |
| 818 |
the C external structure, cdrunx, to translate from FORTRAN |
| 819 |
unit number to UNIX/C file descriptors. |
| 820 |
|
| 821 |
Parameters: |
| 822 |
ifilcd - IN - the FORTRAN unit number of the file to open |
| 823 |
|
| 824 |
*/ |
| 825 |
|
| 826 |
void cdrofs_(int *ifilcd) |
| 827 |
{ |
| 828 |
/* check for graphics output file. file name is stored in KGNAME |
| 829 |
from external (common) cdrcm2. if file hasn't been named, or |
| 830 |
unit isn't KOUTFL, default to file{unit} */ |
| 831 |
|
| 832 |
char symbol[1024]; |
| 833 |
char blank = ' '; |
| 834 |
if (*ifilcd == cdrcom_.KOUTFL && cdrcm2_.KGNAME[0] != blank) { |
| 835 |
int i = 0; |
| 836 |
int j = 0; |
| 837 |
char bslash = '\\'; |
| 838 |
while (cdrcm2_.KGNAME[i] != bslash) { |
| 839 |
symbol[i++] = cdrcm2_.KGNAME[j++]; |
| 840 |
} |
| 841 |
symbol[i] = '\0'; |
| 842 |
} |
| 843 |
else { |
| 844 |
snprintf(symbol, 1024, "file%d", *ifilcd); |
| 845 |
} |
| 846 |
|
| 847 |
/* check the environment to see if a file name has been assigned */ |
| 848 |
char *env = getenv(symbol); |
| 849 |
if (env != NULL && strlen(env) < 1024) { |
| 850 |
snprintf(symbol, 1024, "%s", env); |
| 851 |
} |
| 852 |
|
| 853 |
/* open the file - if it doesn't exist, create it with mode 664 */ |
| 854 |
int fd; |
| 855 |
if ((fd = open(symbol, (O_CREAT | O_RDWR), 0664)) == -1) { |
| 856 |
int errnum = 722; |
| 857 |
int errsev = 10; |
| 858 |
char err[50]; |
| 859 |
snprintf(err, 50, "SVDI ERROR NUMBER %d SEVERITY CODE %d", errnum, errsev); |
| 860 |
perror(err); |
| 861 |
} |
| 862 |
else { |
| 863 |
|
| 864 |
/* associate fortran unit number with file descriptor */ |
| 865 |
cdrunx_.KUNTFD[*ifilcd] = fd; |
| 866 |
} |
| 867 |
} |
| 868 |
|
| 869 |
/* *** CDROAB *** |
| 870 |
|
| 871 |
Open file for the Abekas |
| 872 |
|
| 873 |
*/ |
| 874 |
|
| 875 |
void cdroab_(int *ifilcd, int *frame) |
| 876 |
{ |
| 877 |
char ic[5]; |
| 878 |
int len; |
| 879 |
|
| 880 |
/* can't call cdrgnm, because it only lets you name |
| 881 |
the file once, so set the name in the common block */ |
| 882 |
|
| 883 |
len = 4; |
| 884 |
cdri2c_(frame, &len, ic); |
| 885 |
ic[len] = '\0'; |
| 886 |
snprintf(cdrcm2_.KGNAME, 80, "%s.RGB", ic); |
| 887 |
|
| 888 |
cdrofs_(ifilcd); |
| 889 |
} |
| 890 |
/* *** CDROF3 *** |
| 891 |
|
| 892 |
Open a file for sequential access, fixed length, formatted |
| 893 |
|
| 894 |
Notes and Revisions: |
| 895 |
C file structures don't have the concept of record structure. |
| 896 |
This routine calls CDROFS |
| 897 |
|
| 898 |
Parameters: |
| 899 |
ifilcd - IN - the FORTRAN unit number of the file to open |
| 900 |
idum - IN - originally used for record length |
| 901 |
|
| 902 |
*/ |
| 903 |
|
| 904 |
void cdrof3_(int *ifilcd, int *idum) { cdrofs_(ifilcd); } |
| 905 |
/* *** CDROFF *** |
| 906 |
|
| 907 |
Open a file for sequential access, fixed length, formatted |
| 908 |
|
| 909 |
Notes and Revisions: |
| 910 |
C file structures don't have the concept of record structure. |
| 911 |
This routine calls CDROFS |
| 912 |
|
| 913 |
Parameters: |
| 914 |
ifilcd - IN - the FORTRAN unit number of the file to open |
| 915 |
|
| 916 |
*/ |
| 917 |
|
| 918 |
void cdroff_(int *ifilcd) { cdrofs_(ifilcd); } |
| 919 |
|
| 920 |
/* *** CDRONO *** |
| 921 |
|
| 922 |
Set flag to designate this file is going to the output node |
| 923 |
|
| 924 |
Parameters: |
| 925 |
setono - IN - logical value |
| 926 |
|
| 927 |
*/ |
| 928 |
|
| 929 |
void cdrono_(int *setono) { vconod_.ONODE = *setono; } |
| 930 |
#define MAXBUFFER 512 |
| 931 |
|
| 932 |
/* *** CDROUT *** |
| 933 |
|
| 934 |
Transmit ICOUNT words from BUFFER to the terminal |
| 935 |
|
| 936 |
Parameters: |
| 937 |
ICOUNT - IN - number of characters to be sent to the terminal |
| 938 |
BUFFER - IN - integer array containing the characters |
| 939 |
|
| 940 |
*/ |
| 941 |
|
| 942 |
void cdrout_(int *icount, int *buffer) |
| 943 |
{ |
| 944 |
int count = *icount; |
| 945 |
int j = 0; |
| 946 |
while (count > 0) { |
| 947 |
int c_count = (count > MAXBUFFER) ? MAXBUFFER : count; |
| 948 |
count = count - c_count; |
| 949 |
|
| 950 |
char c_buffer[MAXBUFFER]; |
| 951 |
for (int i = 0; i < c_count; i++) { |
| 952 |
c_buffer[i] = (char)buffer[j++]; |
| 953 |
} |
| 954 |
|
| 955 |
/* write to standard output */ |
| 956 |
if (write(1, c_buffer, c_count) == -1) { |
| 957 |
perror("CDROUT error"); |
| 958 |
} |
| 959 |
} |
| 960 |
} |
| 961 |
|
| 962 |
/* *** CDRRFS *** |
| 963 |
|
| 964 |
Try to read LENGTH words from the file. Return the actual number |
| 965 |
of words read. |
| 966 |
|
| 967 |
Notes and Revisions: |
| 968 |
This routine uses the array KUNTFD, in the FORTRAN common and |
| 969 |
the C external structure, cdrunx, to translate from FORTRAN |
| 970 |
unit number to UNIX/C file descriptors. |
| 971 |
read() will not read beyond EOF. read() returns the actual |
| 972 |
number of bytes read, or -1 for fail. |
| 973 |
|
| 974 |
Parameters: |
| 975 |
ifilcd - IN - FORTRAN unit number of file to read |
| 976 |
length - IN - number of words to try to read |
| 977 |
buffer - OUT - array of size LENGTH into which the data is read |
| 978 |
istat - OUT - status indicator: 0 = end of file; |
| 979 |
>0 = actual number of words read; |
| 980 |
<0 = error |
| 981 |
|
| 982 |
*/ |
| 983 |
|
| 984 |
void cdrrfs_(int *ifilcd, int *length, char *buffer, int *istat) |
| 985 |
{ |
| 986 |
/* translate fortran unit number to file descriptor */ |
| 987 |
int fd = cdrunx_.KUNTFD[*ifilcd]; |
| 988 |
|
| 989 |
/* if the file hasn't been opened, open it */ |
| 990 |
if (fd == 0) { |
| 991 |
cdrofs_(ifilcd); |
| 992 |
fd = cdrunx_.KUNTFD[*ifilcd]; |
| 993 |
} |
| 994 |
|
| 995 |
/* read the data as a byte stream */ |
| 996 |
if ((*istat = read(fd, buffer, (*length * cdrcom_.KCPW))) != -1) { |
| 997 |
*istat = *istat / cdrcom_.KCPW; |
| 998 |
} |
| 999 |
} |
| 1000 |
/* *** CDRRVT *** |
| 1001 |
|
| 1002 |
Convert from ASCII character set to internal character set. |
| 1003 |
|
| 1004 |
Notes and Revisions: |
| 1005 |
This routine is here to satisfy the call, since the internal |
| 1006 |
character set is ASCII. |
| 1007 |
|
| 1008 |
Parameters: |
| 1009 |
in - IN - character to be converted in ASCII |
| 1010 |
iout - OUT - character converted to internal format |
| 1011 |
|
| 1012 |
*/ |
| 1013 |
|
| 1014 |
void cdrrvt_(int *in, int *iout) { *in = *iout; } |
| 1015 |
|
| 1016 |
/* *** CDRSTD *** |
| 1017 |
|
| 1018 |
Copy the left-most N characters from the input character string |
| 1019 |
to the output word. |
| 1020 |
|
| 1021 |
Parameters: |
| 1022 |
n - IN - number of characters to copy from string |
| 1023 |
string - IN - input character string |
| 1024 |
nuchar - OUT - word in which to put the n characters |
| 1025 |
|
| 1026 |
*/ |
| 1027 |
|
| 1028 |
void cdrstd_(int *n, unsigned *string, unsigned *nuchar) |
| 1029 |
{ |
| 1030 |
if (*n > cdrcom_.KCPW) { |
| 1031 |
return; |
| 1032 |
} |
| 1033 |
*nuchar = (*string >> (cdrcom_.KWRDSZ - *n * cdrcom_.KBYTEL) & ~(~0u << (*n * cdrcom_.KBYTEL))); |
| 1034 |
} |
| 1035 |
/* *** CDRTBK *** |
| 1036 |
Generate a traceback. This is a dummy routine to satisfy |
| 1037 |
externals calls. |
| 1038 |
*/ |
| 1039 |
void cdrtbk_(void) {} |
| 1040 |
|
| 1041 |
/* *** CDRTIM *** |
| 1042 |
Pause TIM seconds. (dummy) |
| 1043 |
*/ |
| 1044 |
|
| 1045 |
void cdrtim_(float *tim) {} |
| 1046 |
|
| 1047 |
void cdrtod_(void) |
| 1048 |
{ |
| 1049 |
snprintf((char *)vcjob_.KJTIME, sizeof(vcjob_.KJTIME), "%02d:%02d:%02d\\", 11, 11, 11); |
| 1050 |
snprintf((char *)vcjob_.KJDATE, sizeof(vcjob_.KJDATE), "%02d-%02d-%02d\\", 5, 5, 5); |
| 1051 |
} |
| 1052 |
|
| 1053 |
/* *** CDRUPR *** |
| 1054 |
|
| 1055 |
Convert character string to all upper case |
| 1056 |
|
| 1057 |
Parameters: |
| 1058 |
in - IN - character string to be converted |
| 1059 |
iout - OUT - character string converted to all upper case |
| 1060 |
inlen - IN - length of character string in |
| 1061 |
|
| 1062 |
*/ |
| 1063 |
|
| 1064 |
void cdrupr_(char in[], char iout[], int *inlen) |
| 1065 |
{ |
| 1066 |
for (int i = 0; i <= *inlen; i++) { |
| 1067 |
if (islower(in[i])) { |
| 1068 |
iout[i] = toupper(in[i]); |
| 1069 |
} |
| 1070 |
} |
| 1071 |
} |
| 1072 |
|
| 1073 |
/* *** CDRWFS *** |
| 1074 |
|
| 1075 |
Write LENGTH words from BUFFER to the file. |
| 1076 |
|
| 1077 |
Parameters: |
| 1078 |
ifilcd - IN - FORTRAN unit number of file to write |
| 1079 |
length - IN - number of words to be written |
| 1080 |
buffer - IN - array containing the words of data to be written |
| 1081 |
istat - OUT - status indicator. 0 = no error; 1 = error |
| 1082 |
|
| 1083 |
*/ |
| 1084 |
|
| 1085 |
void cdrwfs_(int *ifilcd, int *length, char *buffer, int *istat) |
| 1086 |
{ |
| 1087 |
/* translate fortran unit number to file descriptor */ |
| 1088 |
int fd = cdrunx_.KUNTFD[*ifilcd]; |
| 1089 |
|
| 1090 |
/* if the file hasn't been opened, open it */ |
| 1091 |
if (fd == 0) { |
| 1092 |
cdrofs_(ifilcd); |
| 1093 |
fd = cdrunx_.KUNTFD[*ifilcd]; |
| 1094 |
} |
| 1095 |
|
| 1096 |
/* write out the data as a byte stream. */ |
| 1097 |
if ((*istat = write(fd, buffer, (*length * cdrcom_.KCPW))) == -1) { |
| 1098 |
*istat = 1; |
| 1099 |
} |
| 1100 |
else { |
| 1101 |
*istat = 0; |
| 1102 |
} |
| 1103 |
} |