| 1 |
/*=========================================================================== |
| 2 |
Copyright (C) 1995-2007 European Southern Observatory (ESO) |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU General Public License as |
| 6 |
published by the Free Software Foundation; either version 2 of |
| 7 |
the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public |
| 15 |
License along with this program; if not, write to the Free |
| 16 |
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, |
| 17 |
MA 02139, USA. |
| 18 |
|
| 19 |
Correspondence concerning ESO-MIDAS should be addressed as follows: |
| 20 |
Internet e-mail: [email protected] |
| 21 |
Postal address: European Southern Observatory |
| 22 |
Data Management Division |
| 23 |
Karl-Schwarzschild-Strasse 2 |
| 24 |
D 85748 Garching bei Muenchen |
| 25 |
GERMANY |
| 26 |
===========================================================================*/ |
| 27 |
|
| 28 |
/*+++++++++++++++++++++ Module MIDLDB +++++++++++++++++++++++++++++++++++++++ |
| 29 |
.LANGUAGE C |
| 30 |
.IDENTIFICATION Module MIDLDB |
| 31 |
.AUTHOR Klaus Banse ESO - Garching |
| 32 |
.KEYWORDS Local Descriptor Blocks |
| 33 |
.ENVIRONMENT VMS and UNIX |
| 34 |
.COMMENTS |
| 35 |
holds clearLDB, cacheLDB, CRELDB, LDBinfo, RDLDB, WRLDB, RDcLDB |
| 36 |
.VERSIONS |
| 37 |
[1.30] 861110: move from FORTRAN to C |
| 38 |
|
| 39 |
091210 last modif |
| 40 |
------------------------------------------------------------------------*/ |
| 41 |
|
| 42 |
#include <fileexts.h> |
| 43 |
#include <osyparms.h> |
| 44 |
|
| 45 |
|
| 46 |
#define BIT_0 0x1 |
| 47 |
|
| 48 |
#define LDBNO 4 |
| 49 |
|
| 50 |
static int lastout = 0; |
| 51 |
static int chanLDB[LDBNO], blkLDB[LDBNO]; |
| 52 |
static int statLDB[LDBNO]={0,0,0,0,}; |
| 53 |
/* statLDB = 0: free = 1: read LDB = 2: marked for writing */ |
| 54 |
|
| 55 |
static struct LDB_STRUCT KLDB[LDBNO]; |
| 56 |
|
| 57 |
/* |
| 58 |
|
| 59 |
*/ |
| 60 |
|
| 61 |
void clearLDB(chanl) |
| 62 |
|
| 63 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 64 |
.PURPOSE |
| 65 |
.RETURNS |
| 66 |
nothing |
| 67 |
--------------------------------------------------*/ |
| 68 |
|
| 69 |
int chanl; /* IN: I/O channel */ |
| 70 |
|
| 71 |
{ |
| 72 |
register int nr; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
for (nr=0; nr<LDBNO; nr++) |
| 77 |
{ |
| 78 |
if ((statLDB[nr] != 0) && (chanLDB[nr] == chanl)) |
| 79 |
{ |
| 80 |
statLDB[nr] = 0; |
| 81 |
return; |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
/* |
| 87 |
|
| 88 |
*/ |
| 89 |
|
| 90 |
int cacheLDB(flag,chanl,blockno,lp) |
| 91 |
|
| 92 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 93 |
.PURPOSE |
| 94 |
create a local descriptor block (LDB) = 4 virtual blocks |
| 95 |
.ALGORITHM |
| 96 |
create + initialize a LDB for a bulk data frame |
| 97 |
if the present block points to another (LDB_NEXT != 0) then |
| 98 |
one already exists. otherwise, the logical file extent is |
| 99 |
incremented and the file physically extended, if necessary |
| 100 |
.RETURNS |
| 101 |
status: I*4 return status |
| 102 |
--------------------------------------------------*/ |
| 103 |
|
| 104 |
int flag; /* IN: = 1, read |
| 105 |
2, write |
| 106 |
22, create fresh LDB |
| 107 |
3, close out (force writing) */ |
| 108 |
int chanl; /* IN: I/O channel */ |
| 109 |
int blockno; /* IN: virtual block no. */ |
| 110 |
struct LDB_STRUCT **lp; /* OUT: pointer to LDB */ |
| 111 |
|
| 112 |
{ |
| 113 |
int lfree, found, status; |
| 114 |
register int nr, *ireg; |
| 115 |
|
| 116 |
char *cldb; |
| 117 |
|
| 118 |
struct LDB_STRUCT *ldbp; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
lfree = -1; |
| 123 |
|
| 124 |
for (nr=0; nr<LDBNO; nr++) |
| 125 |
{ |
| 126 |
if (statLDB[nr] == 0) |
| 127 |
lfree = nr; /* keep last free entry */ |
| 128 |
|
| 129 |
else /* slot `nr' in use */ |
| 130 |
{ |
| 131 |
if (chanLDB[nr] == chanl) /* and same I/O channel */ |
| 132 |
{ |
| 133 |
*lp = &KLDB[nr]; /* set return pointer to LDB */ |
| 134 |
|
| 135 |
if (blkLDB[nr] == blockno) /* same block no. */ |
| 136 |
{ |
| 137 |
if (flag == 1) /* read same LDB */ |
| 138 |
return ERR_NORMAL; |
| 139 |
else if (flag == 2) /* write same LDB */ |
| 140 |
{ |
| 141 |
statLDB[nr] = 2; /* modify statLDB acc. */ |
| 142 |
return ERR_NORMAL; |
| 143 |
} |
| 144 |
else if (flag == 3) /* force writing */ |
| 145 |
{ |
| 146 |
cldb = (char *) &KLDB[nr]; |
| 147 |
statLDB[nr] = 1; /* modify statLDB acc. */ |
| 148 |
#if vms |
| 149 |
return (OSY_WVB(chanl,cldb,LDB_SIZE,blockno)); |
| 150 |
#else |
| 151 |
return (OSY_WLDB(chanl,cldb,blockno)); |
| 152 |
#endif |
| 153 |
} |
| 154 |
else /* only 22 left ... */ |
| 155 |
{ |
| 156 |
found = nr; |
| 157 |
goto init_LDB; |
| 158 |
} |
| 159 |
} |
| 160 |
else /* different block no. */ |
| 161 |
{ |
| 162 |
cldb = (char *) &KLDB[nr]; |
| 163 |
if (flag == 3) |
| 164 |
{ |
| 165 |
if (blockno != -1) |
| 166 |
{ |
| 167 |
statLDB[nr] = 1; /* modify statLDB acc. */ |
| 168 |
blkLDB[nr] = blockno; /* follow with block no. */ |
| 169 |
} |
| 170 |
else |
| 171 |
statLDB[nr] = 0; /* clear entry */ |
| 172 |
|
| 173 |
#if vms |
| 174 |
return (OSY_WVB(chanl,cldb,LDB_SIZE,blkLDB[nr])); |
| 175 |
#else |
| 176 |
return (OSY_WLDB(chanl,cldb,blkLDB[nr])); |
| 177 |
#endif |
| 178 |
} |
| 179 |
else if (flag == 2) |
| 180 |
return ERR_INPINV; |
| 181 |
|
| 182 |
|
| 183 |
/* write LDB before reading again */ |
| 184 |
|
| 185 |
if (statLDB[nr] > 1) |
| 186 |
{ |
| 187 |
#if vms |
| 188 |
status = OSY_WVB(chanl,cldb,LDB_SIZE,blkLDB[nr]); |
| 189 |
#else |
| 190 |
status = OSY_WLDB(chanl,cldb,blkLDB[nr]); |
| 191 |
#endif |
| 192 |
if (status != ERR_NORMAL) return status; |
| 193 |
} |
| 194 |
blkLDB[nr] = blockno; |
| 195 |
|
| 196 |
if (flag != 22) /* flag = 1 */ |
| 197 |
{ |
| 198 |
statLDB[nr] = 1; |
| 199 |
#if vms |
| 200 |
return (OSY_RVB(chanl,cldb,LDB_SIZE,blockno)); |
| 201 |
#else |
| 202 |
return (OSY_RLDB(chanl,cldb,blockno)); |
| 203 |
#endif |
| 204 |
} |
| 205 |
|
| 206 |
found = nr; /* for flag = 22, go on */ |
| 207 |
goto init_LDB; |
| 208 |
} |
| 209 |
} |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
if (flag == 3) |
| 215 |
return ERR_NORMAL; |
| 216 |
else if (flag == 2) |
| 217 |
return ERR_INPINV; |
| 218 |
|
| 219 |
|
| 220 |
/* here, if we have to create a new entry */ |
| 221 |
|
| 222 |
if (lfree == -1) |
| 223 |
{ /* we have to clear an entry */ |
| 224 |
found = lastout++; |
| 225 |
if (lastout >= LDBNO) lastout = 0; |
| 226 |
|
| 227 |
cldb = (char *) &KLDB[found]; |
| 228 |
if (statLDB[found] > 1) |
| 229 |
{ |
| 230 |
#if vms |
| 231 |
status = OSY_WVB(chanLDB[found],cldb,LDB_SIZE,blkLDB[found]); |
| 232 |
#else |
| 233 |
status = OSY_WLDB(chanLDB[found],cldb,blkLDB[found]); |
| 234 |
#endif |
| 235 |
if (status != ERR_NORMAL) return status; |
| 236 |
} /* statLDB updated below */ |
| 237 |
} |
| 238 |
else |
| 239 |
{ |
| 240 |
found = lfree; /* use free entry */ |
| 241 |
cldb = (char *) &KLDB[found]; |
| 242 |
} |
| 243 |
|
| 244 |
*lp = &KLDB[found]; /* set return pointer to LDB */ |
| 245 |
chanLDB[found] = chanl; |
| 246 |
blkLDB[found] = blockno; |
| 247 |
if (flag == 1) /* only flag = 1 or 22 left */ |
| 248 |
{ |
| 249 |
statLDB[found] = 1; |
| 250 |
#if vms |
| 251 |
return (OSY_RVB(chanl,cldb,LDB_SIZE,blockno)); |
| 252 |
#else |
| 253 |
return (OSY_RLDB(chanl,cldb,blockno)); |
| 254 |
#endif |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
/* create a "fresh" LDB */ |
| 259 |
|
| 260 |
init_LDB: |
| 261 |
statLDB[found] = 2; |
| 262 |
ldbp = *lp; |
| 263 |
ldbp->BLKNUM = blockno; |
| 264 |
ldbp->NEXT = 0; |
| 265 |
ireg = ldbp->LDBWORDS.IWORD; |
| 266 |
for (nr=0; nr<LDB_NDSCRW; nr+=2) /* fill data with 0 */ |
| 267 |
{ |
| 268 |
*ireg++ = 0; |
| 269 |
*ireg++ = 0; |
| 270 |
} |
| 271 |
|
| 272 |
return ERR_NORMAL; |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
/* optional debug section |
| 277 |
|
| 278 |
printf("flag=%d, chanl=%d, block=%d written...\n",flag,chanLDB[nr],blockno); |
| 279 |
|
| 280 |
printf("flag=%d (-1), chanl=%d, block=%d written...\n", |
| 281 |
flag,chanLDB[nr],blkLDB[nr]); |
| 282 |
|
| 283 |
printf("flag=%d, chanl=%d, update block=%d written...\n", |
| 284 |
flag,chanLDB[found],blkLDB[found]); |
| 285 |
|
| 286 |
printf("flag=%d, chanl=%d, block=%d read...\n",flag,chanl,blockno); |
| 287 |
*/ |
| 288 |
|
| 289 |
/* |
| 290 |
|
| 291 |
*/ |
| 292 |
|
| 293 |
int MID_CRELDB(myentry,ldbp) |
| 294 |
|
| 295 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 296 |
.PURPOSE |
| 297 |
create a local descriptor block (LDB) = 4 virtual blocks |
| 298 |
.ALGORITHM |
| 299 |
create + initialize a LDB for a bulk data frame |
| 300 |
if the present block points to another (LDB_NEXT != 0) then |
| 301 |
one already exists. otherwise, the logical file extent is |
| 302 |
incremented and the file physically extended, if necessary |
| 303 |
.RETURNS |
| 304 |
status: I*4 return status |
| 305 |
--------------------------------------------------*/ |
| 306 |
|
| 307 |
int myentry; /* IN: FCT entry number */ |
| 308 |
struct LDB_STRUCT *ldbp; /* IN: points to LDB */ |
| 309 |
|
| 310 |
|
| 311 |
{ |
| 312 |
int lpex, status, blockno, chanl, vbn; |
| 313 |
|
| 314 |
|
| 315 |
struct FCT_STRUCT *fctpntr; |
| 316 |
|
| 317 |
struct FCB_STRUCT *fcbp; |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
fctpntr = FCT.ENTRIES + myentry; /* init */ |
| 325 |
chanl = fctpntr->IOCHAN; |
| 326 |
|
| 327 |
|
| 328 |
/* if another LDB exists, write the present one to disk + read the next */ |
| 329 |
|
| 330 |
if (ldbp->NEXT != 0) |
| 331 |
{ |
| 332 |
vbn = ldbp->BLKNUM; |
| 333 |
status = cacheLDB(2,chanl,vbn,&ldbp); /* save LDB */ |
| 334 |
|
| 335 |
if (status == ERR_NORMAL) |
| 336 |
status = cacheLDB(1,chanl,ldbp->NEXT,&ldbp); /* get next one */ |
| 337 |
|
| 338 |
if (status == ERR_NORMAL) |
| 339 |
return ERR_NORMAL; /* that's it already folks ... */ |
| 340 |
|
| 341 |
goto end_of_it; |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
/* We have to get a new "block" - may be already allocated |
| 346 |
also increment logical file extension. |
| 347 |
If logical ext. greater than physical ext., extend data frame */ |
| 348 |
|
| 349 |
fcbp = fctpntr->FZP; |
| 350 |
blockno = fcbp->LEXBDF + 4; /* 1 LDB = 4 blocks */ |
| 351 |
|
| 352 |
if (fcbp->LEXBDF < fcbp->D1BLOCK) /* no descr after data? */ |
| 353 |
{ |
| 354 |
if (blockno < fcbp->D1BLOCK) goto upda_LEXBDF; |
| 355 |
|
| 356 |
fcbp->LEXBDF = fcbp->PEXBDF; |
| 357 |
blockno = fcbp->LEXBDF + 4; /* thus blockno > PEXBDF */ |
| 358 |
} |
| 359 |
|
| 360 |
|
| 361 |
if (blockno > fcbp->PEXBDF) |
| 362 |
{ /* extend frame for additional descr. blocks (LDBs) */ |
| 363 |
int exalq; |
| 364 |
|
| 365 |
if (chanl < 0) /* we have a "memory file" */ |
| 366 |
{ |
| 367 |
exalq = 32; /* increase by 8 LDBs */ |
| 368 |
status = MID_VMEM(2,exalq,&chanl); /* extend virtual memory */ |
| 369 |
if (status != ERR_NORMAL) |
| 370 |
{ |
| 371 |
MID_ERROR("FSY","MID_CRELDB",status,0); |
| 372 |
return status; /* status = ERR_MEMOUT */ |
| 373 |
} |
| 374 |
fcbp->PEXBDF += exalq; |
| 375 |
} |
| 376 |
|
| 377 |
else |
| 378 |
{ |
| 379 |
exalq = fcbp->PEXBDF + 16; /* increase by 4 LDBs */ |
| 380 |
|
| 381 |
#if vms |
| 382 |
FSY_EXTBDF(fctpntr->FILEIDA,fctpntr->FILEIDB,fctpntr->DEVICE, |
| 383 |
exalq,&lpex,&status); |
| 384 |
if ( (status & BIT_0) == 0 ) |
| 385 |
#else |
| 386 |
status = FSY_EXTBDF(fctpntr->FILEID,exalq,&lpex); |
| 387 |
if (status != 0) |
| 388 |
#endif |
| 389 |
|
| 390 |
{ |
| 391 |
MID_ERROR("FSY","MID_CRELDB/FSY_EXTBDF",status,0); |
| 392 |
return ERR_FRMNAC; |
| 393 |
} |
| 394 |
fcbp->PEXBDF = lpex; |
| 395 |
} |
| 396 |
} |
| 397 |
|
| 398 |
|
| 399 |
/* update existing LDB + write it to disk */ |
| 400 |
|
| 401 |
upda_LEXBDF: |
| 402 |
ldbp->NEXT = fcbp->LEXBDF + 1; |
| 403 |
|
| 404 |
status = cacheLDB(3,chanl,ldbp->BLKNUM,&ldbp); /* force writing */ |
| 405 |
if (status == ERR_NORMAL) /* initialize new LDB */ |
| 406 |
status = cacheLDB(22,chanl,ldbp->NEXT,&ldbp); |
| 407 |
if (status == ERR_NORMAL) |
| 408 |
{ |
| 409 |
fcbp->LEXBDF = blockno; /* update FCB.LEXBDF */ |
| 410 |
fcbp->NOLDB ++; /* and LDB count */ |
| 411 |
return ERR_NORMAL; |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
/* something wrong - report it */ |
| 416 |
|
| 417 |
end_of_it: |
| 418 |
MID_ERROR("MIDAS","MID_CRELDB:",status,0); |
| 419 |
return status; |
| 420 |
} |
| 421 |
|
| 422 |
/* |
| 423 |
|
| 424 |
*/ |
| 425 |
|
| 426 |
void LDBinfo(chanl,ldbp,indx,alen,extens) |
| 427 |
|
| 428 |
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 429 |
.PURPOSE |
| 430 |
Get header info (i.e. next extension) of an atom from the local |
| 431 |
descriptor block, (LDB = 4 virtual blocks) |
| 432 |
.ALGORITHM |
| 433 |
Each atom in the LDB is preceded by a header of 3 longwords. |
| 434 |
The 1. longword holds the no. of data elements in that atom |
| 435 |
The 2. holds the block no.of next extension. If = -1, no extension exists. |
| 436 |
The 3. holds the index of next extension |
| 437 |
|
| 438 |
Ojo: the code must be synchronised with the "header section" of the |
| 439 |
following MID_RDLDB routine !!! |
| 440 |
.RETURNS |
| 441 |
nothing |
| 442 |
-------------------------------------------------------------------------*/ |
| 443 |
|
| 444 |
int chanl /* IN : channel no. of frame */; |
| 445 |
struct LDB_STRUCT *ldbp; /* IN: points to LDB */ |
| 446 |
int indx /* IN : word # in LDB, where atom is to be read */; |
| 447 |
int *alen /* IO : no. of values required, will be set to actual length \ |
| 448 |
of atom starting from pos. 1 specified via first \ |
| 449 |
if = 0, only the header will be returned */; |
| 450 |
int *extens /* OUT: block no. + indx of next extension */; |
| 451 |
|
| 452 |
{ |
| 453 |
|
| 454 |
/* get 1. header longword = actual length */ |
| 455 |
|
| 456 |
*alen = ldbp->LDBWORDS.IWORD[indx]; |
| 457 |
|
| 458 |
|
| 459 |
/* get 2. header longword */ |
| 460 |
|
| 461 |
if (indx >= LDB_NDSCRW1) |
| 462 |
{ |
| 463 |
(void) cacheLDB(1,chanl,ldbp->NEXT,&ldbp); |
| 464 |
indx = -1; /* so indx will be 0 */ |
| 465 |
} |
| 466 |
|
| 467 |
*extens = ldbp->LDBWORDS.IWORD[++indx]; /* that's the next extension */ |
| 468 |
|
| 469 |
|
| 470 |
/* get 3. header longword */ |
| 471 |
|
| 472 |
if (indx >= LDB_NDSCRW1) |
| 473 |
{ |
| 474 |
(void) cacheLDB(1,chanl,ldbp->NEXT,&ldbp); |
| 475 |
indx = -1; /* so indx will be 0 */ |
| 476 |
} |
| 477 |
/* the index of next extension */ |
| 478 |
*(extens+1) = ldbp->LDBWORDS.IWORD[++indx]; |
| 479 |
} |
| 480 |
|
| 481 |
/* |
| 482 |
|
| 483 |
*/ |
| 484 |
|
| 485 |
void MID_RDLDB(chanl,ldbp,indx,typ,iatom,ratom,first,alen,extens) |
| 486 |
|
| 487 |
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 488 |
.PURPOSE |
| 489 |
read an atom from the local descriptor block, LDB = 4 virtual blocks |
| 490 |
.ALGORITHM |
| 491 |
Each atom in the LDB is preceded by a header of 3 longwords. |
| 492 |
The 1. longword holds the no. of data elements in that atom |
| 493 |
The 2. holds the block no.of next extension. If = -1, no extension exists. |
| 494 |
The 3. holds the index of next extension |
| 495 |
|
| 496 |
Ojo: the code of the "header section" must be synchronised with the |
| 497 |
routine LDBinfo above !!! |
| 498 |
.RETURNS |
| 499 |
nothing |
| 500 |
-------------------------------------------------------------------------*/ |
| 501 |
|
| 502 |
int chanl /* IN : channel no. of frame */; |
| 503 |
struct LDB_STRUCT *ldbp; /* IN: points to LDB */ |
| 504 |
int indx /* IN : word # in LDB, where atom is to be read */; |
| 505 |
int typ /* IN : type of atom - 1=I*4, 2=R*4 */; |
| 506 |
int *iatom /* OUT: receives integer atom */; |
| 507 |
float *ratom /* OUT: receives real atom */; |
| 508 |
int first /* IN : 1st position of descriptor data to be accessed */; |
| 509 |
int *alen /* IO : no. of values required, will be set to actual length |
| 510 |
of atom starting from pos. 1 specified via first |
| 511 |
if = 0, only the header will be returned */; |
| 512 |
int *extens /* OUT: block no. + indx of next extension */; |
| 513 |
|
| 514 |
{ |
| 515 |
int rlen, left, from; |
| 516 |
register int nr; |
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
/* get 1. header longword = actual length */ |
| 525 |
|
| 526 |
rlen = *alen; |
| 527 |
*alen = ldbp->LDBWORDS.IWORD[indx]; |
| 528 |
|
| 529 |
|
| 530 |
/* get 2. header longword */ |
| 531 |
|
| 532 |
if (indx >= LDB_NDSCRW1) |
| 533 |
{ |
| 534 |
(void) cacheLDB(1,chanl,ldbp->NEXT,&ldbp); |
| 535 |
indx = -1; /* so indx will be 0 */ |
| 536 |
} |
| 537 |
|
| 538 |
*extens = ldbp->LDBWORDS.IWORD[++indx]; /* that's the next extension */ |
| 539 |
|
| 540 |
|
| 541 |
/* get 3. header longword */ |
| 542 |
|
| 543 |
if (indx >= LDB_NDSCRW1) |
| 544 |
{ |
| 545 |
(void) cacheLDB(1,chanl,ldbp->NEXT,&ldbp); |
| 546 |
indx = -1; /* so indx will be 0 */ |
| 547 |
} |
| 548 |
/* the index of next extension */ |
| 549 |
*(extens+1) = ldbp->LDBWORDS.IWORD[++indx]; |
| 550 |
|
| 551 |
/* this check left in for backwards compatibility and should be |
| 552 |
taken out one day... */ |
| 553 |
if (rlen < 1) return; /* we just wanted the next extension*/ |
| 554 |
|
| 555 |
|
| 556 |
*alen -= (first - 1); |
| 557 |
|
| 558 |
|
| 559 |
/* increment indx + read next LDB, if necessary */ |
| 560 |
|
| 561 |
indx += first; |
| 562 |
while (indx > LDB_NDSCRW1) |
| 563 |
{ |
| 564 |
(void) cacheLDB(1,chanl,ldbp->NEXT,&ldbp); |
| 565 |
indx -= LDB_NDSCRW; |
| 566 |
} |
| 567 |
|
| 568 |
|
| 569 |
/* indx is now in [0,509] - initialize counters */ |
| 570 |
|
| 571 |
if (*alen > rlen) |
| 572 |
*alen = rlen; /* total length to be transmitted */ |
| 573 |
else |
| 574 |
rlen = *alen; |
| 575 |
from = 0; |
| 576 |
|
| 577 |
|
| 578 |
/* branch according to 'typ' */ |
| 579 |
|
| 580 |
more_data: |
| 581 |
left = LDB_NDSCRW - indx ; /* no. of lw's left */ |
| 582 |
if (rlen < left) left = rlen; /* transfer in this blockno */ |
| 583 |
|
| 584 |
if (typ == 1) /* integer atom */ |
| 585 |
{ |
| 586 |
register int *result, *ireg; |
| 587 |
|
| 588 |
result = iatom + from; |
| 589 |
ireg = ldbp->LDBWORDS.IWORD + indx; |
| 590 |
for (nr=0; nr<left; nr++) *result++ = *ireg++; |
| 591 |
} |
| 592 |
|
| 593 |
else /* real atom */ |
| 594 |
{ |
| 595 |
register float *result, *rreg; |
| 596 |
|
| 597 |
result = ratom + from; |
| 598 |
rreg = ldbp->LDBWORDS.RWORD + indx; |
| 599 |
for (nr=0; nr<left; nr++) *result++ = *rreg++; |
| 600 |
} |
| 601 |
|
| 602 |
|
| 603 |
/* read next LDB, if necessary */ |
| 604 |
|
| 605 |
if (rlen > left) |
| 606 |
{ /* if ((indx+left) > LDB_NDSCRW1) always true here! */ |
| 607 |
(void) cacheLDB(1,chanl,ldbp->NEXT,&ldbp); |
| 608 |
indx = 0; |
| 609 |
|
| 610 |
rlen -= left; |
| 611 |
from += left; |
| 612 |
goto more_data; /* get more data */ |
| 613 |
} |
| 614 |
|
| 615 |
} |
| 616 |
|
| 617 |
/* |
| 618 |
|
| 619 |
*/ |
| 620 |
|
| 621 |
void MID_WRLDB(chanl,ldbp,indx,typ,iatom,ratom,catom,conflg,first,alen,extens) |
| 622 |
|
| 623 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 624 |
.PURPOSE |
| 625 |
write into an existing atom in the LDB (only the data is updated) |
| 626 |
and return atom length (in data values) and next extension of atom |
| 627 |
.ALGORITHM |
| 628 |
Each atom in the LDB is preceded by a header of three 4-byte words |
| 629 |
The 1. word holds the length of the atom in data elements, |
| 630 |
the 2. holds the block no. of next extension. If = -1, no extension exists. |
| 631 |
the 3. holds the indx of next extension |
| 632 |
.RETURNS |
| 633 |
nothing |
| 634 |
-------------------------------------------------------------------------*/ |
| 635 |
|
| 636 |
int chanl /* IN : channel no. of frame */; |
| 637 |
struct LDB_STRUCT *ldbp; /* IN: points to LDB */ |
| 638 |
int indx /* IN : index in current LDB */; |
| 639 |
int typ /* IN : type of atom 1=I*4, 2=R*4, 3=character data */; |
| 640 |
int *iatom /* IN : contains integer atom */; |
| 641 |
char *catom /* IN : contains character atom */; |
| 642 |
float *ratom /* IN : contains real atom */; |
| 643 |
int conflg /* IN : constant flag = 1 (yes), 0 = (no) */; |
| 644 |
int first /* IN : position of descriptor data to be accessed */; |
| 645 |
int *alen /* IO : no. of values required will be set to actual no. of \ |
| 646 |
values modified, starting from 1st position specified \ |
| 647 |
via first */; |
| 648 |
int *extens /* IO : returns block + indx of extension */; |
| 649 |
|
| 650 |
{ |
| 651 |
int rlen, fcharm1=0; |
| 652 |
int left, slen, from; |
| 653 |
register int nr; |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
rlen = *alen; |
| 659 |
/* get 1. header 4-byte word = actual length */ |
| 660 |
*alen = ldbp->LDBWORDS.IWORD[indx]; |
| 661 |
|
| 662 |
|
| 663 |
/* get 2. header 4-byte words */ |
| 664 |
|
| 665 |
if (indx >= LDB_NDSCRW1) |
| 666 |
{ |
| 667 |
(void) cacheLDB(1,chanl,ldbp->NEXT,&ldbp); |
| 668 |
indx = -1; /* so indx will be 0 */ |
| 669 |
} |
| 670 |
/* that's the next extension */ |
| 671 |
*extens = ldbp->LDBWORDS.IWORD[++indx]; |
| 672 |
|
| 673 |
|
| 674 |
/* get 3. header 4-byte words */ |
| 675 |
|
| 676 |
if (indx == LDB_NDSCRW1) |
| 677 |
{ |
| 678 |
(void) cacheLDB(1,chanl,ldbp->NEXT,&ldbp); |
| 679 |
indx = -1; /* so indx will be 0 */ |
| 680 |
} |
| 681 |
/* indx of next extension */ |
| 682 |
*(extens+1) = ldbp->LDBWORDS.IWORD[++indx]; |
| 683 |
|
| 684 |
|
| 685 |
/* for character data, split offset into (integer) 4-byte words + bytes */ |
| 686 |
|
| 687 |
nr = first - 1; |
| 688 |
if (typ == 3) |
| 689 |
{ |
| 690 |
fcharm1 = nr % II_SIZE; |
| 691 |
indx += ((nr / II_SIZE) + 1); |
| 692 |
} |
| 693 |
else |
| 694 |
indx += first; |
| 695 |
|
| 696 |
*alen -= nr; |
| 697 |
|
| 698 |
|
| 699 |
/* increment indx + read next LDB, if necessary */ |
| 700 |
|
| 701 |
while (indx > LDB_NDSCRW1) |
| 702 |
{ |
| 703 |
(void) cacheLDB(1,chanl,ldbp->NEXT,&ldbp); |
| 704 |
indx -= LDB_NDSCRW; |
| 705 |
} |
| 706 |
|
| 707 |
|
| 708 |
/* indx is now in [0,509] - initialize counters */ |
| 709 |
|
| 710 |
if (*alen > rlen) |
| 711 |
*alen = rlen; /* total length to be transmitted */ |
| 712 |
else |
| 713 |
rlen = *alen; |
| 714 |
from = 0; |
| 715 |
|
| 716 |
|
| 717 |
/* branch according to data type */ |
| 718 |
|
| 719 |
more_data: |
| 720 |
left = LDB_NDSCRW - indx; /* no. of int's left */ |
| 721 |
|
| 722 |
|
| 723 |
/* check for each type for constant flag */ |
| 724 |
|
| 725 |
if (typ == 1) /* integer atom */ |
| 726 |
{ |
| 727 |
register int *source, *ireg; |
| 728 |
|
| 729 |
if (rlen < left) |
| 730 |
slen = rlen; /* transfer in this blockno */ |
| 731 |
else |
| 732 |
slen = left; |
| 733 |
source = iatom + from; |
| 734 |
ireg = ldbp->LDBWORDS.IWORD + indx; |
| 735 |
|
| 736 |
if (conflg == 1) |
| 737 |
{ |
| 738 |
register int ival; |
| 739 |
|
| 740 |
ival = *source; |
| 741 |
for (nr=0;nr<slen;nr++) *ireg++ = ival; |
| 742 |
} |
| 743 |
else |
| 744 |
{ |
| 745 |
for (nr=0;nr<slen;nr++) *ireg++ = *source++; |
| 746 |
} |
| 747 |
|
| 748 |
indx += slen; /* update pointers */ |
| 749 |
} |
| 750 |
|
| 751 |
else if (typ == 2) /* real atom */ |
| 752 |
{ |
| 753 |
register float *source, *rreg; |
| 754 |
|
| 755 |
if (rlen < left) |
| 756 |
slen = rlen; /* transfer in this blockno */ |
| 757 |
else |
| 758 |
slen = left; |
| 759 |
source = ratom + from; |
| 760 |
rreg = ldbp->LDBWORDS.RWORD + indx; |
| 761 |
if (conflg == 1) |
| 762 |
{ |
| 763 |
register float rval; |
| 764 |
|
| 765 |
rval = *source; |
| 766 |
for (nr=0;nr<slen;nr++) *rreg++ = rval; |
| 767 |
} |
| 768 |
else |
| 769 |
{ |
| 770 |
for (nr=0;nr<slen;nr++) *rreg++ = *source++; |
| 771 |
} |
| 772 |
|
| 773 |
indx += slen; /* update pointers */ |
| 774 |
} |
| 775 |
|
| 776 |
else /* character atom */ |
| 777 |
{ |
| 778 |
register char *cpntra, *cpntrb; |
| 779 |
|
| 780 |
left = left*II_SIZE - fcharm1; |
| 781 |
if (rlen > left) |
| 782 |
slen = left; |
| 783 |
else |
| 784 |
slen = rlen; |
| 785 |
|
| 786 |
cpntra = (char *) &(ldbp->LDBWORDS); |
| 787 |
cpntra += (indx*II_SIZE + fcharm1); /* point to first char. */ |
| 788 |
cpntrb = catom + from; |
| 789 |
|
| 790 |
if (conflg == 1) |
| 791 |
{ |
| 792 |
register char cval; |
| 793 |
|
| 794 |
cval = *cpntrb; |
| 795 |
for (nr=0;nr<slen;nr++) *cpntra++ = cval; |
| 796 |
} |
| 797 |
else |
| 798 |
(void) memcpy(cpntra,cpntrb,(size_t)slen); |
| 799 |
|
| 800 |
fcharm1 = 0; /* now always at a 4-byte word boundary */ |
| 801 |
indx += (slen+(II_SIZE-1))/II_SIZE ; |
| 802 |
} |
| 803 |
|
| 804 |
|
| 805 |
(void) cacheLDB(2,chanl,ldbp->BLKNUM,&ldbp); /* save current LDB */ |
| 806 |
|
| 807 |
if (rlen > slen) |
| 808 |
{ /* if (indx > LDB_NDSCRW1) always true here! */ |
| 809 |
(void) cacheLDB(1,chanl,ldbp->NEXT,&ldbp); |
| 810 |
indx = 0; |
| 811 |
|
| 812 |
rlen -= slen; |
| 813 |
from += slen; |
| 814 |
goto more_data; /* write more data */ |
| 815 |
} |
| 816 |
} |
| 817 |
|
| 818 |
/* |
| 819 |
|
| 820 |
*/ |
| 821 |
|
| 822 |
void MID_RDcLDB(chanl,ldbp,indx,catom,first,alen,extens) |
| 823 |
|
| 824 |
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 825 |
.PURPOSE |
| 826 |
read a character atom from the local descriptor block, LDB = 4 virtual blocks |
| 827 |
.ALGORITHM |
| 828 |
Each atom in the LDB is preceded by a header of 3 longwords. |
| 829 |
The 1. longword holds the no. of data elements in that atom |
| 830 |
The 2. holds the block no.of next extension. If = -1, no extension exists. |
| 831 |
The 3. holds the index of next extension |
| 832 |
|
| 833 |
Ojo: the code of the "header section" must be synchronised with the |
| 834 |
routine LDBinfo above !!! |
| 835 |
.RETURNS |
| 836 |
nothing |
| 837 |
-------------------------------------------------------------------------*/ |
| 838 |
|
| 839 |
int chanl /* IN : channel no. of frame */; |
| 840 |
struct LDB_STRUCT *ldbp; /* IN: points to LDB */ |
| 841 |
int indx /* IN : word # in LDB, where atom is to be read */; |
| 842 |
char *catom /* OUT: receives character atom */; |
| 843 |
int first /* IN : 1st position of descriptor data to be accessed */; |
| 844 |
int *alen /* IO : no. of values required, will be set to actual length |
| 845 |
of atom starting from pos. 1 specified via first |
| 846 |
if = 0, only the header will be returned */; |
| 847 |
int *extens /* OUT: block no. + indx of next extension */; |
| 848 |
|
| 849 |
{ |
| 850 |
int felem, rlen, fcharm1; |
| 851 |
int left, status, mx; |
| 852 |
|
| 853 |
register char *cpntra, *cpntrb; |
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
rlen = *alen; |
| 859 |
|
| 860 |
|
| 861 |
/* get 1. header longword = actual length */ |
| 862 |
|
| 863 |
*alen = ldbp->LDBWORDS.IWORD[indx]; |
| 864 |
|
| 865 |
|
| 866 |
/* get 2. header longword */ |
| 867 |
|
| 868 |
if (indx >= LDB_NDSCRW1) |
| 869 |
{ |
| 870 |
status = cacheLDB(1,chanl,ldbp->NEXT,&ldbp); |
| 871 |
indx = -1; /* so indx will be 0 */ |
| 872 |
} |
| 873 |
|
| 874 |
*extens = ldbp->LDBWORDS.IWORD[++indx]; /* that's the next extension */ |
| 875 |
|
| 876 |
|
| 877 |
/* get 3. header longword */ |
| 878 |
|
| 879 |
if (indx >= LDB_NDSCRW1) |
| 880 |
{ |
| 881 |
status = cacheLDB(1,chanl,ldbp->NEXT,&ldbp); |
| 882 |
indx = -1; /* so indx will be 0 */ |
| 883 |
} |
| 884 |
/* the index of next extension */ |
| 885 |
*(extens+1) = ldbp->LDBWORDS.IWORD[++indx]; |
| 886 |
|
| 887 |
|
| 888 |
/* split offset into longwords + bytes */ |
| 889 |
|
| 890 |
mx = first - 1; |
| 891 |
felem = mx / II_SIZE; /* quotient (integer) */ |
| 892 |
fcharm1 = mx % II_SIZE; /* remainder */ |
| 893 |
felem ++ ; |
| 894 |
|
| 895 |
|
| 896 |
/* increment indx + read next LDB, if necessary */ |
| 897 |
|
| 898 |
indx += felem; |
| 899 |
while (indx > LDB_NDSCRW1) |
| 900 |
{ |
| 901 |
status = cacheLDB(1,chanl,ldbp->NEXT,&ldbp); |
| 902 |
indx -= LDB_NDSCRW; |
| 903 |
} |
| 904 |
|
| 905 |
cpntrb = catom; /* point to output char. buffer */ |
| 906 |
|
| 907 |
|
| 908 |
/* indx is now in [0,509] - loop until we got all data */ |
| 909 |
|
| 910 |
*alen -= mx; |
| 911 |
if (*alen > rlen) |
| 912 |
*alen = rlen; /* total length can be transmitted */ |
| 913 |
else |
| 914 |
rlen = *alen; /* total length is truncated */ |
| 915 |
|
| 916 |
cpntra = (char *)&(ldbp->LDBWORDS); |
| 917 |
cpntra += (indx*II_SIZE + fcharm1); /* point to first char. */ |
| 918 |
|
| 919 |
left = (LDB_NDSCRW - indx)*II_SIZE - fcharm1; /* no. of chars left */ |
| 920 |
|
| 921 |
more_data: |
| 922 |
if (rlen <= left) |
| 923 |
{ |
| 924 |
(void) memcpy(cpntrb,cpntra,(size_t)rlen); |
| 925 |
return; |
| 926 |
} |
| 927 |
|
| 928 |
(void) memcpy(cpntrb,cpntra,(size_t)left); /* get as much as possible */ |
| 929 |
(void) cacheLDB(1,chanl,ldbp->NEXT,&ldbp); /* read next LDB */ |
| 930 |
cpntra = (char *)&(ldbp->LDBWORDS); /* changes after cacheLDB */ |
| 931 |
rlen -= left; /* update remaining size */ |
| 932 |
cpntrb += left; /* and follow with pointer */ |
| 933 |
/* now always at lword boundary */ |
| 934 |
left = LDB_NDSCRW*II_SIZE; /* new no. of chars left */ |
| 935 |
goto more_data; |
| 936 |
} |
| 937 |
|