| 1 |
/*=========================================================================== |
| 2 |
Copyright (C) 1995-2010 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 |
/*++++++++++++++++++++++++++ SC interface module SCDA +++++++++++++++++++++++ |
| 29 |
.LANGUAGE C |
| 30 |
.IDENTIFICATION Module SCDA |
| 31 |
.AUTHOR K. Banse ESO - Garching |
| 32 |
.KEYWORDS standard interfaces, descriptors |
| 33 |
.ENVIRONMENT VMS and UNIX |
| 34 |
.COMMENTS |
| 35 |
holds YSCDCOP |
| 36 |
|
| 37 |
.VERSION [1.00] 920211: pulled out from scd.c |
| 38 |
|
| 39 |
100816 last modif |
| 40 |
----------------------------------------------------------------------------*/ |
| 41 |
|
| 42 |
#include <fileexts.h> |
| 43 |
#include <stdlib.h> |
| 44 |
#include <stdio.h> |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
#define DATA_ISIZE 2048 /* 2048 int's */ |
| 49 |
#define DATA_CSIZE DATA_ISIZE*II_SIZE /* in bytes */ |
| 50 |
#define DATA_DSIZE DATA_CSIZE/DD_SIZE /* no. of double's */ |
| 51 |
#define DATA_SSIZE DATA_CSIZE/SS_SIZE /* no. of size_t's */ |
| 52 |
|
| 53 |
|
| 54 |
static int mapdat = -1; |
| 55 |
static int maxdim[5] = {DATA_ISIZE,DATA_ISIZE,DATA_CSIZE-1,DATA_DSIZE,DATA_SSIZE}; |
| 56 |
|
| 57 |
|
| 58 |
static char *datpntr; |
| 59 |
|
| 60 |
static char stand0[] = "NAXIS"; |
| 61 |
static char stand1[] = "NPIX"; |
| 62 |
static char stand2[] = "START"; |
| 63 |
static char stand3[] = "STEP"; |
| 64 |
static char stand4[] = "CUNIT"; |
| 65 |
static char stand5[] = "IDENT"; |
| 66 |
static char stand6[] = "LHCUTS"; |
| 67 |
static char stand7[] = "DISPLAY_DATA"; |
| 68 |
static char stand8[] = "HIST_BINS"; |
| 69 |
static char stand9[] = "HISTOGRAM"; |
| 70 |
static char stand10[] = "STATISTIC"; |
| 71 |
static char stand11[] = "WINDOW_TO"; |
| 72 |
static char stand12[] = "WINDOW_FROM"; |
| 73 |
|
| 74 |
static char *stand[13] = {stand0,stand1,stand2,stand3,stand4,stand5,stand6, |
| 75 |
stand7,stand8,stand9,stand10,stand11,stand12}; |
| 76 |
static char tstand0[] = "TBLENGTH"; |
| 77 |
static char tstand1[] = "TBLOFFST"; |
| 78 |
static char tstand2[] = "TBLCONTR"; |
| 79 |
static char tstand3[] = "TSELTABL"; |
| 80 |
|
| 81 |
static char *tstand[4] = {tstand0,tstand1,tstand2,tstand3}; |
| 82 |
/* |
| 83 |
|
| 84 |
*/ |
| 85 |
|
| 86 |
int YSCDCOP(from,to,mask,dsc) |
| 87 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 88 |
.PURPOSE |
| 89 |
Copy descriptors from one frame to another |
| 90 |
.ALGORITHM |
| 91 |
Depending on 'mask' the relevant descriptors are read from |
| 92 |
the source frame + written to the destination frame. |
| 93 |
.REMARKS |
| 94 |
mask for copying: = 1 , copy all descriptors |
| 95 |
= 2 , copy only standard desc. |
| 96 |
= 3 , copy all but standard descriptors |
| 97 |
= 4 , copy descriptors specified by DSClist (max. 8) |
| 98 |
= 5 , copy all but extended list of standard descriptors |
| 99 |
|
| 100 |
= 6 , copy all descriptors except descr specified by DSClist |
| 101 |
= 7 , copy standard descriptors, except DSClist |
| 102 |
= 8 , copy all but standard descriptors, except DSClist |
| 103 |
= 10, copy all but extended list of standard descriptors, |
| 104 |
except descr from.DSClist |
| 105 |
= 100 + mask as described above indicates, that we want |
| 106 |
to clear existing descr's completely before being |
| 107 |
overwritten with (shorter) source descr's |
| 108 |
= 200 + mask as described above indicates, that we do not |
| 109 |
overwrite existing descriptors |
| 110 |
.RETURNS |
| 111 |
return status ( 0 = o.k. ) |
| 112 |
--------------------------------------------------*/ |
| 113 |
|
| 114 |
int from; /* IN: no. of source frame */ |
| 115 |
int to; /* IN: no. of destination frame */ |
| 116 |
int mask; /* IN: copy_mask */ |
| 117 |
char *dsc; /* IN: DSClist = names of descr. to copy |
| 118 |
separated by comma */ |
| 119 |
|
| 120 |
{ |
| 121 |
int iav, nval, nfr, no_elem, byt_elem, cleanem, ncleanem; |
| 122 |
int total, dblock, dindx, dunit, status, mm, e_c, e_l; |
| 123 |
int chanl, nullo, stuff_read, dsc_count, hnc, hno_elem, dsc_exist; |
| 124 |
int tcount, diroff, dirlen, copied_once; |
| 125 |
int fcbDFILLED, fcbPTRLDB, fcbDIREXT; |
| 126 |
int back_err, patflag, patlen=0, pat1flag=0, pat1len=0, *ibuf; |
| 127 |
int bby, nno, ddu, ddb, ddi, ii; |
| 128 |
register int nr; |
| 129 |
static int mapdscdir = -1; |
| 130 |
|
| 131 |
float *rbuf, rr; |
| 132 |
double *dbuf; |
| 133 |
size_t *sbuf; |
| 134 |
|
| 135 |
char *cbuf, dtype[4], filty, descr[88], help[72], htxt[72]; |
| 136 |
char realdescr[52], cc; |
| 137 |
char *zdscpntr, *dscptr[8], *dscbptr=NULL; |
| 138 |
register char *cpt, *dpt; |
| 139 |
static char *dscdir; |
| 140 |
|
| 141 |
|
| 142 |
struct FCT_STRUCT *fctfrom, *fctto; |
| 143 |
|
| 144 |
struct FCB_STRUCT *fcbp; |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
fctfrom = FCT.ENTRIES + from; |
| 150 |
fctto = FCT.ENTRIES + to; |
| 151 |
|
| 152 |
filty = fctfrom->CATALOG[0]; /* get file type */ |
| 153 |
chanl = fctfrom->IOCHAN; |
| 154 |
fcbp = fctfrom->FZP; |
| 155 |
|
| 156 |
|
| 157 |
status = ERR_INPINV; |
| 158 |
e_c = ERRO_CONT; ERRO_CONT = 1; |
| 159 |
e_l = ERRO_LOG; ERRO_LOG = 0; |
| 160 |
|
| 161 |
back_err = total = 1; |
| 162 |
copied_once = patflag = 0; |
| 163 |
dsc_exist = 1; /* default => SCDWRz */ |
| 164 |
|
| 165 |
|
| 166 |
if (mask > 99) |
| 167 |
{ |
| 168 |
if (mask > 199) /* only copy "new" descr. */ |
| 169 |
{ |
| 170 |
cleanem = 2; |
| 171 |
mask -= 200; |
| 172 |
} |
| 173 |
else /* overwrite, but clean first */ |
| 174 |
{ |
| 175 |
cleanem = 1; |
| 176 |
mask -= 100; |
| 177 |
} |
| 178 |
} |
| 179 |
else /* just copy */ |
| 180 |
cleanem = 0; |
| 181 |
|
| 182 |
|
| 183 |
if (mask > 5) |
| 184 |
{ |
| 185 |
tcount = (int) strlen(dsc); |
| 186 |
mask -= 5; |
| 187 |
} |
| 188 |
else |
| 189 |
tcount = 0; |
| 190 |
|
| 191 |
|
| 192 |
switch (mask) /* sort out mask business, */ |
| 193 |
{ /* set tcount as necessary */ |
| 194 |
case 1: |
| 195 |
case 3: |
| 196 |
case 5: |
| 197 |
break; |
| 198 |
|
| 199 |
case 2: |
| 200 |
if (filty == 'T') |
| 201 |
total = 4; |
| 202 |
else |
| 203 |
total = 7; |
| 204 |
break; |
| 205 |
|
| 206 |
case 4: /* pass DSClist */ |
| 207 |
tcount = (int) strlen(dsc); |
| 208 |
if (tcount < 1) /* we need a descr name */ |
| 209 |
goto end0; |
| 210 |
break; |
| 211 |
|
| 212 |
default: |
| 213 |
mask = 1; |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
if (tcount > 0) /* we got descriptors in DSClist */ |
| 218 |
{ |
| 219 |
for (nr=0; nr<tcount; nr++) |
| 220 |
{ |
| 221 |
if (dsc[nr] == ' ') /* cut off trailing blanks (FORTRAN...) */ |
| 222 |
{ |
| 223 |
tcount = nr; |
| 224 |
if (tcount < 1) goto end_of_it; |
| 225 |
break; |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
mm = CGN_INDEXC(dsc,'|'); /* do we have incl-patt|excl-patt? */ |
| 230 |
if (mm > 1) /* only considered for mask=4 ... */ |
| 231 |
{ |
| 232 |
dscptr[0] = (char *)malloc((size_t)tcount); |
| 233 |
dscptr[1] = (char *)malloc((size_t)tcount); |
| 234 |
|
| 235 |
if (dsc[0] == '*') |
| 236 |
{ |
| 237 |
if (dsc[mm-1] == '*') /* we have 1. pattern `*abc*' */ |
| 238 |
{ |
| 239 |
patflag = 11; |
| 240 |
patlen = mm - 2; |
| 241 |
} |
| 242 |
else /* we have 1. pattern `*abc ' */ |
| 243 |
{ |
| 244 |
patflag = 12; |
| 245 |
patlen = mm - 1; |
| 246 |
} |
| 247 |
if (patlen < 1) goto patt_end; |
| 248 |
|
| 249 |
(void) CGN_UPCOPY(dscptr[0],dsc+1,patlen); /* copy in upper case */ |
| 250 |
*(dscptr[0]+patlen) = '\0'; |
| 251 |
} |
| 252 |
else if (dsc[mm-1] == '*') /* we have 1. pattern ` abc*' */ |
| 253 |
{ |
| 254 |
patflag = 13; |
| 255 |
patlen = mm - 1; |
| 256 |
if (patlen < 1) goto patt_end; |
| 257 |
|
| 258 |
(void) CGN_UPCOPY(dscptr[0],dsc,patlen); |
| 259 |
*(dscptr[0]+patlen) = '\0'; |
| 260 |
} |
| 261 |
|
| 262 |
mm ++; /* point to excl-pattern */ |
| 263 |
if (dsc[mm] == '*') |
| 264 |
{ |
| 265 |
if (dsc[tcount-1] == '*') /* we have 2. pattern `*abc*' */ |
| 266 |
{ |
| 267 |
pat1flag = 1; |
| 268 |
pat1len = tcount - mm - 2; |
| 269 |
} |
| 270 |
else /* we have 2. pattern `*abc ' */ |
| 271 |
{ |
| 272 |
pat1flag = 2; |
| 273 |
pat1len = tcount - mm - 1; |
| 274 |
} |
| 275 |
if (pat1len < 1) goto patt_end; |
| 276 |
|
| 277 |
(void) CGN_UPCOPY(dscptr[1],dsc+mm+1,pat1len); |
| 278 |
*(dscptr[1]+pat1len) = '\0'; |
| 279 |
} |
| 280 |
else if (dsc[tcount-1] == '*') /* we have 2. pattern ` abc*' */ |
| 281 |
{ |
| 282 |
pat1flag = 3; |
| 283 |
pat1len = tcount - mm - 1; |
| 284 |
if (pat1len < 1) goto patt_end; |
| 285 |
|
| 286 |
(void) CGN_UPCOPY(dscptr[1],dsc,pat1len); |
| 287 |
*(dscptr[1]+pat1len) = '\0'; |
| 288 |
} |
| 289 |
|
| 290 |
tcount = 2; /* we use two pointers */ |
| 291 |
goto do_FCB_stuff; |
| 292 |
|
| 293 |
patt_end: /* problems, problems, ... */ |
| 294 |
free (dscptr[0]); |
| 295 |
free (dscptr[1]); |
| 296 |
goto end0; |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
if (dsc[0] == '*') |
| 301 |
{ |
| 302 |
if (dsc[tcount-1] == '*') /* we have a pattern `*abc*' */ |
| 303 |
{ |
| 304 |
patflag = 1; |
| 305 |
patlen = tcount - 2; |
| 306 |
} |
| 307 |
else /* we have a pattern `*abc ' */ |
| 308 |
{ |
| 309 |
patflag = 2; |
| 310 |
patlen = tcount - 1; |
| 311 |
} |
| 312 |
if (patlen < 1) goto end_of_it; |
| 313 |
dscptr[0] = malloc((size_t)(patlen+1)); |
| 314 |
(void) CGN_UPCOPY(dscptr[0],dsc+1,patlen); /* in upper case to 1. ptr */ |
| 315 |
*(dscptr[0]+patlen) = '\0'; |
| 316 |
tcount = 1; |
| 317 |
} |
| 318 |
|
| 319 |
else if (dsc[tcount-1] == '*') /* we have a pattern ` abc*' */ |
| 320 |
{ |
| 321 |
patflag = 3; |
| 322 |
patlen = tcount - 1; |
| 323 |
if (patlen < 1) goto end_of_it; |
| 324 |
dscptr[0] = malloc((size_t)(patlen+1)); |
| 325 |
(void) CGN_UPCOPY(dscptr[0],dsc,patlen); /* in upper case to 1. ptr */ |
| 326 |
*(dscptr[0]+patlen) = '\0'; |
| 327 |
tcount = 1; |
| 328 |
} |
| 329 |
|
| 330 |
else |
| 331 |
{ /* list of up to 8 descrs' */ |
| 332 |
dscptr[0] = malloc((size_t)(tcount+1)); |
| 333 |
(void) CGN_UPCOPY(dscptr[0],dsc,tcount); /* in upper case to 1. ptr */ |
| 334 |
*(dscptr[0]+tcount) = '\0'; |
| 335 |
|
| 336 |
cpt = dscptr[0]; |
| 337 |
tcount = 1; /* use as counter of dscptr[] */ |
| 338 |
for (nr=1; nr<8; nr++) |
| 339 |
{ |
| 340 |
mm = CGN_INDEXC(cpt,','); |
| 341 |
if (mm > 0) |
| 342 |
{ |
| 343 |
*(dscptr[nr-1]+mm) = '\0'; |
| 344 |
tcount++; |
| 345 |
cpt += (mm+1); |
| 346 |
dscptr[nr] = malloc((size_t)80); |
| 347 |
(void) CGN_UPCOPY(dscptr[nr],cpt,80); |
| 348 |
*(dscptr[nr]+79) = '\0'; |
| 349 |
} |
| 350 |
} |
| 351 |
if (mask == 4) total = tcount; |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
do_FCB_stuff: |
| 358 |
status = ERR_NORMAL; |
| 359 |
fcbDFILLED = fcbp->DFILLED; |
| 360 |
if (fcbp->DFILLED > fcbp->DIREXT) |
| 361 |
fcbDIREXT = fcbp->DFILLED; |
| 362 |
else |
| 363 |
fcbDIREXT = fcbp->DIREXT; |
| 364 |
fcbPTRLDB = fcbp->PTRLDB; |
| 365 |
|
| 366 |
|
| 367 |
/* allocate working buffer for descr. directory and data */ |
| 368 |
|
| 369 |
if (mapdscdir < 0) /* buffer for descr. directory */ |
| 370 |
{ |
| 371 |
dscdir = (char *) malloc((size_t)fcbDIREXT); |
| 372 |
mapdscdir = 1; /* at least 2500 */ |
| 373 |
} |
| 374 |
zdscpntr = (char *) &YDSCDIR_ENTRY; |
| 375 |
|
| 376 |
if (mapdat < 0) /* buffer for descr. data */ |
| 377 |
{ |
| 378 |
datpntr = malloc((size_t)DATA_CSIZE); |
| 379 |
mapdat = 1; |
| 380 |
} |
| 381 |
|
| 382 |
cbuf = datpntr; |
| 383 |
ibuf = (int *) datpntr; |
| 384 |
rbuf = (float *) datpntr; |
| 385 |
dbuf = (double *) datpntr; |
| 386 |
sbuf = (size_t *) datpntr; |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
/* main loop - read descriptor name + copy, if name o.k. */ |
| 391 |
|
| 392 |
|
| 393 |
if (mask == 5) |
| 394 |
{ |
| 395 |
register int mr; |
| 396 |
|
| 397 |
(void) XSCDINF(fctto->IOCHAN,to,tcount,99,descr,10,&dsc_count); |
| 398 |
dtype[3] = '\0'; |
| 399 |
status = SCDRDX(to,1,descr,dtype,&byt_elem,&no_elem,&hnc); |
| 400 |
dscbptr = malloc((size_t) (dsc_count*50)); /* holds all descrs */ |
| 401 |
dpt = dscbptr; /* in destination frame */ |
| 402 |
nval = dsc_count; |
| 403 |
|
| 404 |
for (mr=0; mr<nval; mr++) |
| 405 |
{ |
| 406 |
status = SCDRDX(to,10,dpt,dtype,&byt_elem,&no_elem,&hnc); |
| 407 |
|
| 408 |
if (filty == 'T') /* compare with descriptors which */ |
| 409 |
{ /* are not copied */ |
| 410 |
for (nr=0; nr<4; nr++) |
| 411 |
{ |
| 412 |
if ((strcmp(dpt,tstand[nr]) == 0) || (strncmp(dpt,"TLABL",5) == 0)) |
| 413 |
{ |
| 414 |
dsc_count --; |
| 415 |
dpt -= 50; /* overwrite dsc name again */ |
| 416 |
break; |
| 417 |
} |
| 418 |
} |
| 419 |
} |
| 420 |
else |
| 421 |
{ |
| 422 |
for (nr=0; nr<13; nr++) |
| 423 |
{ |
| 424 |
if (strcmp(dpt,stand[nr]) == 0) |
| 425 |
{ |
| 426 |
dsc_count --; |
| 427 |
dpt -= 50; /* overwrite dsc name again */ |
| 428 |
break; |
| 429 |
} |
| 430 |
} |
| 431 |
} |
| 432 |
|
| 433 |
dpt += 50; /* for next dsc name */ |
| 434 |
} |
| 435 |
|
| 436 |
status = SCDRDX(to,0,descr,dtype,&byt_elem,&no_elem,&hnc); /* free space */ |
| 437 |
} |
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
diroff = 0; |
| 442 |
nullo = -1; |
| 443 |
dirlen = fcbDFILLED; |
| 444 |
|
| 445 |
(void) MID_RDSCRC(chanl,fcbPTRLDB,0,1,dirlen,dscdir,&nullo); |
| 446 |
cpt = dscdir; /* first read gives us descr. directory */ |
| 447 |
cpt += fcbp->DIRENTRY; /* skip descr. directory */ |
| 448 |
stuff_read = fcbp->DIRENTRY; |
| 449 |
dtype[1] = dtype[2] = ' '; dtype[3] = '\0'; |
| 450 |
|
| 451 |
read_next_entry: |
| 452 |
if (stuff_read < dirlen) |
| 453 |
{ |
| 454 |
stuff_read += fcbp->DIRENTRY; |
| 455 |
if (*cpt != '\0') |
| 456 |
{ /* get a dir. entry */ |
| 457 |
(void) memcpy(zdscpntr,cpt,(size_t)fcbp->DIRENTRY); |
| 458 |
cpt += fcbp->DIRENTRY; |
| 459 |
|
| 460 |
(void) memcpy(descr,YDSC_PNTR->NAMESTR,(size_t)(YDSC_PNTR->NAMELEN+1)); |
| 461 |
dtype[0] = YDSC_PNTR->TYPE; |
| 462 |
byt_elem = (int) YDSC_PNTR->BYTELEM; |
| 463 |
hno_elem = (int) YDSC_PNTR->HELPLEN; |
| 464 |
if (hno_elem > 0) |
| 465 |
{ |
| 466 |
mm = YDSC_PNTR->NAMELEN + 1; /* offset of help string */ |
| 467 |
(void) memcpy(htxt,YDSC_PNTR->NAMESTR+mm,(size_t)(hno_elem+1)); |
| 468 |
} |
| 469 |
else |
| 470 |
htxt[0] = '\0'; |
| 471 |
dunit = (int) YDSC_PNTR->UNIT; |
| 472 |
no_elem = YDSC_PNTR->NOELEM; |
| 473 |
dblock = YDSC_PNTR->START; |
| 474 |
dindx = YDSC_PNTR->INDEX -1; |
| 475 |
/* |
| 476 |
printf("descr: %s, dblock = %d, dindx = %d, noelem = %d\n", |
| 477 |
YDSC_PNTR->NAMESTR, dblock,dindx,no_elem); |
| 478 |
*/ |
| 479 |
|
| 480 |
goto check_mask; |
| 481 |
} |
| 482 |
else |
| 483 |
{ |
| 484 |
cpt += fcbp->DIRENTRY; |
| 485 |
goto read_next_entry; |
| 486 |
} |
| 487 |
} |
| 488 |
|
| 489 |
if (mask == 4) |
| 490 |
{ |
| 491 |
if ((total > 0) && (back_err == 1)) |
| 492 |
status = ERR_DSCNPR; /* catch bad dscr of dscr-list */ |
| 493 |
} |
| 494 |
|
| 495 |
goto end_of_it; /* we're finished */ |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
/* if 'mask' = 4, compare descriptor with dscptr[0],[1],... */ |
| 501 |
|
| 502 |
check_mask: |
| 503 |
if (mask == 4) |
| 504 |
{ |
| 505 |
if (patflag != 0) /* test for pattern match */ |
| 506 |
{ |
| 507 |
back_err = 0; |
| 508 |
if (patflag == 3) |
| 509 |
{ |
| 510 |
if (strncmp(descr,dscptr[0],patlen) == 0) goto find_descr; |
| 511 |
} |
| 512 |
else if (patflag == 2) |
| 513 |
{ |
| 514 |
mm = (int) strlen(descr) - patlen; |
| 515 |
if (mm > -1) |
| 516 |
{ |
| 517 |
if (strcmp(descr+mm,dscptr[0]) == 0) goto find_descr; |
| 518 |
} |
| 519 |
} |
| 520 |
else if (patflag == 1) |
| 521 |
{ |
| 522 |
if (CGN_INDEXS(descr,dscptr[0]) > -1) goto find_descr; |
| 523 |
} |
| 524 |
|
| 525 |
else |
| 526 |
{ /* patflag 11, 12, 13 */ |
| 527 |
if (patflag == 13) |
| 528 |
{ |
| 529 |
if (strncmp(descr,dscptr[0],patlen) == 0) goto test_excl_pat; |
| 530 |
} |
| 531 |
else if (patflag == 12) |
| 532 |
{ |
| 533 |
mm = (int) strlen(descr) - patlen; |
| 534 |
if (mm > -1) |
| 535 |
{ |
| 536 |
if (strcmp(descr+mm,dscptr[0]) == 0) goto test_excl_pat; |
| 537 |
} |
| 538 |
} |
| 539 |
else |
| 540 |
{ |
| 541 |
if (CGN_INDEXS(descr,dscptr[0]) > -1) goto test_excl_pat; |
| 542 |
} |
| 543 |
goto read_next_entry; /* descr not in incl-pattern */ |
| 544 |
|
| 545 |
test_excl_pat: |
| 546 |
if (pat1flag == 3) |
| 547 |
{ |
| 548 |
if (strncmp(descr,dscptr[1],pat1len) == 0) goto read_next_entry; |
| 549 |
} |
| 550 |
else if (pat1flag == 2) |
| 551 |
{ |
| 552 |
mm = (int) strlen(descr) - pat1len; |
| 553 |
if (mm > -1) |
| 554 |
{ |
| 555 |
if (strcmp(descr+mm,dscptr[1]) == 0) goto read_next_entry; |
| 556 |
} |
| 557 |
} |
| 558 |
else |
| 559 |
{ |
| 560 |
if (CGN_INDEXS(descr,dscptr[1]) > -1) goto read_next_entry; |
| 561 |
} |
| 562 |
goto find_descr; /* descr not in excl-pattern */ |
| 563 |
} |
| 564 |
} |
| 565 |
|
| 566 |
else |
| 567 |
{ |
| 568 |
for (nr=0; nr<tcount; nr++) |
| 569 |
{ |
| 570 |
if (strcmp(dscptr[nr],descr) == 0) |
| 571 |
{ |
| 572 |
total --; |
| 573 |
goto find_descr; |
| 574 |
} |
| 575 |
} |
| 576 |
} |
| 577 |
goto read_next_entry; |
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
/* for all other options check for excluded descrs' */ |
| 582 |
|
| 583 |
if (patflag != 0) /* test for pattern match */ |
| 584 |
{ |
| 585 |
if (patflag == 3) |
| 586 |
{ |
| 587 |
if (strncmp(descr,dscptr[0],patlen) == 0) goto read_next_entry; |
| 588 |
} |
| 589 |
else if (patflag == 2) |
| 590 |
{ |
| 591 |
mm = (int) strlen(descr) - patlen; |
| 592 |
if (mm > -1) |
| 593 |
{ |
| 594 |
if (strcmp(descr+mm,dscptr[0]) == 0) goto find_descr; |
| 595 |
} |
| 596 |
} |
| 597 |
else |
| 598 |
{ |
| 599 |
if (CGN_INDEXS(descr,dscptr[0]) > -1) goto read_next_entry; |
| 600 |
} |
| 601 |
} |
| 602 |
|
| 603 |
else |
| 604 |
{ |
| 605 |
for (nr=0; nr<tcount; nr++) |
| 606 |
{ |
| 607 |
if (strcmp(dscptr[nr],descr) == 0) goto read_next_entry; |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
/* if mask = 2, compare descriptor with list of standard descriptors |
| 613 |
and only copy these */ |
| 614 |
|
| 615 |
if (mask == 2) |
| 616 |
{ |
| 617 |
if (filty == 'T') |
| 618 |
{ |
| 619 |
for (nr=0; nr<4; nr++) |
| 620 |
{ |
| 621 |
if (strcmp(descr,tstand[nr]) == 0) |
| 622 |
{ |
| 623 |
total --; |
| 624 |
goto find_descr; |
| 625 |
} |
| 626 |
} |
| 627 |
} |
| 628 |
else |
| 629 |
{ |
| 630 |
for (nr=0; nr<7; nr++) |
| 631 |
{ |
| 632 |
if (strcmp(descr,stand[nr]) == 0) |
| 633 |
{ |
| 634 |
total --; |
| 635 |
goto find_descr; |
| 636 |
} |
| 637 |
} |
| 638 |
} |
| 639 |
goto read_next_entry; |
| 640 |
} |
| 641 |
|
| 642 |
|
| 643 |
/* mask = 3, compare descriptor with list of standard descriptors |
| 644 |
to exclude them from copying */ |
| 645 |
|
| 646 |
if (mask == 3) |
| 647 |
{ |
| 648 |
if (filty == 'T') |
| 649 |
{ |
| 650 |
for (nr=0; nr<4; nr++) |
| 651 |
{ |
| 652 |
if ((strcmp(descr,tstand[nr]) == 0) || |
| 653 |
(strncmp(descr,"TLABL",5) == 0)) goto read_next_entry; |
| 654 |
} |
| 655 |
} |
| 656 |
else |
| 657 |
{ |
| 658 |
for (nr=0; nr<7; nr++) |
| 659 |
{ |
| 660 |
if (strcmp(descr,stand[nr]) == 0) goto read_next_entry; |
| 661 |
} |
| 662 |
} |
| 663 |
} |
| 664 |
|
| 665 |
|
| 666 |
/* if mask = 5, exclude descriptors of extended list of stand. descrs' |
| 667 |
from copying, and copy all others */ |
| 668 |
|
| 669 |
if (mask == 5) |
| 670 |
{ |
| 671 |
if (filty == 'T') |
| 672 |
{ |
| 673 |
for (nr=0; nr<4; nr++) |
| 674 |
{ |
| 675 |
if ((strcmp(descr,tstand[nr]) == 0) || |
| 676 |
(strncmp(descr,"TLABL",5) == 0)) goto read_next_entry; |
| 677 |
} |
| 678 |
} |
| 679 |
else |
| 680 |
{ |
| 681 |
for (nr=0; nr<13; nr++) |
| 682 |
{ |
| 683 |
if (strcmp(descr,stand[nr]) == 0) goto read_next_entry; |
| 684 |
} |
| 685 |
} |
| 686 |
|
| 687 |
dsc_exist = 0; /* check, if same dest.descr. exists */ |
| 688 |
dpt = dscbptr; /* start of dest. descr list */ |
| 689 |
|
| 690 |
for (nr=0; nr<dsc_count; nr++) |
| 691 |
{ |
| 692 |
if (strcmp(descr,dpt) == 0) |
| 693 |
{ |
| 694 |
dsc_exist = 1; |
| 695 |
break; |
| 696 |
} |
| 697 |
dpt += 50; |
| 698 |
} |
| 699 |
} |
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
find_descr: |
| 704 |
nfr = 1; |
| 705 |
ncleanem = cleanem; |
| 706 |
|
| 707 |
|
| 708 |
data_loop: |
| 709 |
nval = no_elem - nfr + 1; |
| 710 |
nullo = -1; |
| 711 |
|
| 712 |
if (ncleanem == 2) /* check, if descr. already exists */ |
| 713 |
{ |
| 714 |
(void) DSCNAM_COPY(realdescr,descr); /* build uppercase name */ |
| 715 |
status = MID_YDSCDIR(to,'F',realdescr,dtype,&bby,&nno,&ddu, |
| 716 |
&ddb,&ddi,help); |
| 717 |
|
| 718 |
if (status == ERR_NORMAL) /* descr exists, skip it */ |
| 719 |
goto read_next_entry; |
| 720 |
|
| 721 |
ncleanem = 0; /* new descr., no cleaning needed */ |
| 722 |
} |
| 723 |
|
| 724 |
if (dtype[0] == 'I') /* integer descriptor */ |
| 725 |
{ |
| 726 |
if (nval > maxdim[0]) nval = maxdim[0]; |
| 727 |
|
| 728 |
(void) MID_RDSCRI(chanl,dblock,dindx,nfr,nval,ibuf,&nullo); |
| 729 |
if (dsc_exist == 1) |
| 730 |
{ |
| 731 |
if (ncleanem == 1) /* see, if dest. descr. bigger */ |
| 732 |
{ |
| 733 |
(void) DSCNAM_COPY(realdescr,descr); /* build uppercase name */ |
| 734 |
status = MID_YDSCDIR(to,'F',realdescr,dtype,&bby,&nno,&ddu, |
| 735 |
&ddb,&ddi,help); |
| 736 |
ddu = 0; |
| 737 |
if ((status == ERR_NORMAL) && (nno > nval)) |
| 738 |
{ |
| 739 |
mm = nno - nval; |
| 740 |
ii = 0; |
| 741 |
(void) MID_WDSCRI(fctto->IOCHAN,ddb,ddi,&ii,1,nval+1,mm); |
| 742 |
} |
| 743 |
} |
| 744 |
status = SCDHWI(to,descr,ibuf,nfr,nval,&dunit,htxt); |
| 745 |
} |
| 746 |
else |
| 747 |
status = xSCDHWI(to,descr,ibuf,nfr,nval,&dunit,htxt); |
| 748 |
} |
| 749 |
|
| 750 |
else if (dtype[0] == 'R') /* real descriptor */ |
| 751 |
{ |
| 752 |
if (nval > maxdim[1]) nval = maxdim[1]; |
| 753 |
|
| 754 |
(void) MID_RDSCRR(chanl,dblock,dindx,nfr,nval,rbuf,&nullo); |
| 755 |
if (dsc_exist == 1) |
| 756 |
{ |
| 757 |
if (ncleanem == 1) /* see, if dest. descr. bigger */ |
| 758 |
{ |
| 759 |
(void) DSCNAM_COPY(realdescr,descr); /* build uppercase name */ |
| 760 |
status = MID_YDSCDIR(to,'F',realdescr,dtype,&bby,&nno,&ddu, |
| 761 |
&ddb,&ddi,help); |
| 762 |
ddu = 0; |
| 763 |
if ((status == ERR_NORMAL) && (nno > nval)) |
| 764 |
{ |
| 765 |
mm = nno - nval; |
| 766 |
rr = 0.; |
| 767 |
(void) MID_WDSCRR(fctto->IOCHAN,ddb,ddi,&rr,1,nval+1,mm); |
| 768 |
} |
| 769 |
} |
| 770 |
status = SCDHWR(to,descr,rbuf,nfr,nval,&dunit,htxt); |
| 771 |
} |
| 772 |
else |
| 773 |
status = xSCDHWR(to,descr,rbuf,nfr,nval,&dunit,htxt); |
| 774 |
} |
| 775 |
|
| 776 |
else if (dtype[0] == 'C') /* character descriptor */ |
| 777 |
{ |
| 778 |
if (byt_elem > 1) |
| 779 |
{ |
| 780 |
mm = maxdim[2] / byt_elem; |
| 781 |
if (mm < 0) |
| 782 |
{ |
| 783 |
(void) sprintf |
| 784 |
(cbuf,"bytes_per_element = %d > %d, descr %s not copied!", |
| 785 |
byt_elem,maxdim[2],descr); |
| 786 |
SCTPUT(cbuf); |
| 787 |
if (total > 0) |
| 788 |
goto read_next_entry; |
| 789 |
else |
| 790 |
goto end_of_it; |
| 791 |
} |
| 792 |
if (nval > mm) nval = mm; |
| 793 |
mm = nval*byt_elem; |
| 794 |
iav = (nfr-1)*byt_elem + 1; |
| 795 |
} |
| 796 |
else |
| 797 |
{ |
| 798 |
if (nval > maxdim[2]) nval = maxdim[2]; |
| 799 |
mm = nval; |
| 800 |
iav = nfr; |
| 801 |
} |
| 802 |
|
| 803 |
|
| 804 |
(void) MID_RDSCRC(chanl,dblock,dindx,iav,mm,cbuf,&nullo); |
| 805 |
cbuf[mm] = '\0'; |
| 806 |
|
| 807 |
if (dsc_exist == 1) |
| 808 |
{ |
| 809 |
if (ncleanem == 1) /* see, if dest. descr. bigger */ |
| 810 |
{ |
| 811 |
(void) DSCNAM_COPY(realdescr,descr); /* build uppercase name */ |
| 812 |
status = MID_YDSCDIR(to,'F',realdescr,dtype,&bby,&nno,&ddu, |
| 813 |
&ddb,&ddi,help); |
| 814 |
ddu = 0; |
| 815 |
mm = bby * nno; |
| 816 |
if ((status == ERR_NORMAL) && (mm > (byt_elem*nval))) |
| 817 |
{ |
| 818 |
bby = byt_elem * nval; |
| 819 |
mm -= bby; |
| 820 |
cc = ' '; |
| 821 |
(void) MID_WDSCRC(fctto->IOCHAN,ddb,ddi,&cc,1,bby+1,mm); |
| 822 |
} |
| 823 |
} |
| 824 |
status = SCDHWC(to,descr,byt_elem,cbuf,nfr,nval,&dunit,htxt); |
| 825 |
} |
| 826 |
else |
| 827 |
status = xSCDHWC(to,descr,byt_elem,cbuf,nfr,nval,&dunit,htxt); |
| 828 |
} |
| 829 |
|
| 830 |
else if (dtype[0] == 'D') /* double precision descriptor */ |
| 831 |
{ |
| 832 |
if (nval > maxdim[3]) nval = maxdim[3]; |
| 833 |
|
| 834 |
nr = DD_SIZE / II_SIZE; /* we use integers for double descr */ |
| 835 |
iav = (nfr-1)*nr + 1; /* first element in double buf */ |
| 836 |
mm = nval * nr; |
| 837 |
(void) MID_RDSCRI(chanl,dblock,dindx,iav,mm,ibuf,&nullo); |
| 838 |
|
| 839 |
if (dsc_exist == 1) |
| 840 |
{ |
| 841 |
if (ncleanem == 1) /* see, if dest. descr. bigger */ |
| 842 |
{ |
| 843 |
(void) DSCNAM_COPY(realdescr,descr); /* build uppercase name */ |
| 844 |
status = MID_YDSCDIR(to,'F',realdescr,dtype,&bby,&nno,&ddu, |
| 845 |
&ddb,&ddi,help); |
| 846 |
ddu = 0; |
| 847 |
if ((status == ERR_NORMAL) && (nno > nval)) |
| 848 |
{ |
| 849 |
mm = (nno - nval) * nr; |
| 850 |
bby = ((nval+1)*nr) - 1; |
| 851 |
ii = 0; |
| 852 |
(void) MID_WDSCRI(fctto->IOCHAN,ddb,ddi,&ii,1,bby,mm); |
| 853 |
} |
| 854 |
} |
| 855 |
status = SCDHWD(to,descr,dbuf,nfr,nval,&dunit,htxt); |
| 856 |
} |
| 857 |
else |
| 858 |
status = xSCDHWD(to,descr,dbuf,nfr,nval,&dunit,htxt); |
| 859 |
} |
| 860 |
|
| 861 |
else if (dtype[0] == 'S') /* size_t descriptor */ |
| 862 |
{ |
| 863 |
if (nval > maxdim[4]) nval = maxdim[4]; |
| 864 |
|
| 865 |
nr = SS_SIZE / II_SIZE; /* we use integers for double descr */ |
| 866 |
iav = (nfr-1)*nr + 1; /* first element in double buf */ |
| 867 |
mm = nval * nr; |
| 868 |
(void) MID_RDSCRI(chanl,dblock,dindx,iav,mm,ibuf,&nullo); |
| 869 |
|
| 870 |
if (dsc_exist == 1) |
| 871 |
{ |
| 872 |
if (ncleanem == 1) /* see, if dest. descr. bigger */ |
| 873 |
{ |
| 874 |
(void) DSCNAM_COPY(realdescr,descr); /* build uppercase name */ |
| 875 |
status = MID_YDSCDIR(to,'F',realdescr,dtype,&bby,&nno,&ddu, |
| 876 |
&ddb,&ddi,help); |
| 877 |
ddu = 0; |
| 878 |
if ((status == ERR_NORMAL) && (nno > nval)) |
| 879 |
{ |
| 880 |
mm = (nno - nval) * nr; |
| 881 |
bby = ((nval+1)*nr) - 1; |
| 882 |
ii = 0; |
| 883 |
(void) MID_WDSCRI(fctto->IOCHAN,ddb,ddi,&ii,1,bby,mm); |
| 884 |
} |
| 885 |
} |
| 886 |
status = SCDHWS(to,descr,sbuf,nfr,nval,&dunit,htxt); |
| 887 |
} |
| 888 |
else |
| 889 |
status = xSCDHWS(to,descr,sbuf,nfr,nval,&dunit,htxt); |
| 890 |
} |
| 891 |
|
| 892 |
else /* remains logical descriptor */ |
| 893 |
{ |
| 894 |
if (nval > maxdim[0]) nval = maxdim[0]; |
| 895 |
|
| 896 |
(void) MID_RDSCRI(chanl,dblock,dindx,nfr,nval,ibuf,&nullo); |
| 897 |
if (dsc_exist == 1) |
| 898 |
{ |
| 899 |
if (ncleanem == 1) /* see, if dest. descr. bigger */ |
| 900 |
{ |
| 901 |
(void) DSCNAM_COPY(realdescr,descr); /* build uppercase name */ |
| 902 |
status = MID_YDSCDIR(to,'F',realdescr,dtype,&bby,&nno,&ddu, |
| 903 |
&ddb,&ddi,help); |
| 904 |
ddu = 0; |
| 905 |
if ((status == ERR_NORMAL) && (nno > nval)) |
| 906 |
{ |
| 907 |
mm = nno - nval; |
| 908 |
ii = 0; |
| 909 |
(void) MID_WDSCRI(fctto->IOCHAN,ddb,ddi,&ii,1,nval+1,mm); |
| 910 |
} |
| 911 |
} |
| 912 |
status = SCDHWL(to,descr,ibuf,nfr,nval,&dunit,htxt); |
| 913 |
} |
| 914 |
else |
| 915 |
status = xSCDHWL(to,descr,ibuf,nfr,nval,&dunit,htxt); |
| 916 |
} |
| 917 |
|
| 918 |
if (status != ERR_NORMAL) goto end_of_it; |
| 919 |
|
| 920 |
|
| 921 |
if ((nval+nfr) <= no_elem) /* test, if descriptor was copied completely */ |
| 922 |
{ |
| 923 |
nfr += nval; |
| 924 |
dsc_exist = 1; |
| 925 |
ncleanem = 0; |
| 926 |
goto data_loop; |
| 927 |
} |
| 928 |
|
| 929 |
|
| 930 |
copied_once = 1; |
| 931 |
if (total > 0) goto read_next_entry; |
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
end_of_it: |
| 936 |
if (mask == 5) free(dscbptr); |
| 937 |
free(dscdir); |
| 938 |
mapdscdir = -1; |
| 939 |
|
| 940 |
|
| 941 |
end0: |
| 942 |
if ((patflag != 0) && (copied_once == 0)) |
| 943 |
status = ERR_DSCNPR; /* catch non-matched pattern */ |
| 944 |
|
| 945 |
ERRO_CONT = e_c; ERRO_LOG = e_l; /* reset error flags */ |
| 946 |
|
| 947 |
if (tcount != 0) /* free the `dscptr' allocations */ |
| 948 |
{ |
| 949 |
free(dscptr[0]); |
| 950 |
tcount --; |
| 951 |
nr = 1; |
| 952 |
while (tcount > 0) |
| 953 |
{ |
| 954 |
free(dscptr[nr++]); |
| 955 |
tcount --; |
| 956 |
} |
| 957 |
} |
| 958 |
|
| 959 |
|
| 960 |
if (status != ERR_NORMAL) MID_E2(8,from,dsc,status,1); |
| 961 |
return status; |
| 962 |
} |
| 963 |
|