| 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 SCFE +++++++++++++++++++++++ |
| 29 |
.LANGUAGE C |
| 30 |
.IDENTIFICATION Module scfe.c |
| 31 |
.AUTHOR K. Banse ESO - Garching |
| 32 |
.KEYWORDS standard interfaces, bulk data files |
| 33 |
.ENVIRONMENT VMS and UNIX |
| 34 |
.COMMENTS |
| 35 |
holds SCFINF, SCFNAME, SCFXMP,SCFYMP |
| 36 |
.REMARKS |
| 37 |
opening modes are: F_I_MODE, F_O_MODE, F_IO_MODE, F_X_MODE. |
| 38 |
data types are: D_R4_FORMAT, D_I2_FORMAT, D_I1_FORMAT, D_OLD_FORMAT. |
| 39 |
filetype no's are: F_IMA_TYPE, F_TBL_TYPE, F_FIT_TYPE. |
| 40 |
|
| 41 |
.VERSION [1.00] 920211: pulled over from scf.c |
| 42 |
|
| 43 |
100816 last modif |
| 44 |
----------------------------------------------------------------------------*/ |
| 45 |
|
| 46 |
#include <fileexts.h> |
| 47 |
|
| 48 |
#include <stdio.h> |
| 49 |
|
| 50 |
|
| 51 |
static int virt_count = -1; |
| 52 |
|
| 53 |
/* |
| 54 |
|
| 55 |
*/ |
| 56 |
|
| 57 |
int SCFINF(name,flag,ibuf) |
| 58 |
|
| 59 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 60 |
.PURPOSE |
| 61 |
open a frame + return the file info in buffer of 5 integers |
| 62 |
.ALGORITHM |
| 63 |
use CGN_CLEANF + MID_ACCFRM to do the job |
| 64 |
for 'flag' = 0, we do not pass via MID_ERROR ! |
| 65 |
.RETURNS |
| 66 |
return status ( 0 = o.k) |
| 67 |
-----------------------------------------------------------------------*/ |
| 68 |
|
| 69 |
char *name; /* IN: name of data frame */ |
| 70 |
int flag; /* IN: specify desired info, |
| 71 |
0 = FCT_number (= `imno' of SCFOPN) (1 val) |
| 72 |
1 = version_no, file_type (Ima/Tab/Fits), FCB.SWPSHORT, |
| 73 |
FCB.SWPINT, FCB.FLOTFMT (5 vals) |
| 74 |
2 = nobytes, data_format, pixpbl, stblok, lastblk |
| 75 |
(5 vals) |
| 76 |
3 = file_type(Ima/Tab/Fits), data_format, file_protect, |
| 77 |
file_compress (4 vals) |
| 78 |
4 = nobytes, data_format, |
| 79 |
file_format (FITS/Midas), FCB.NDVAL, |
| 80 |
file_type (Ima/Tab/Fits) (5 vals) |
| 81 |
5 = part_no, namtyp (info via CGN_CLEANF, no FCT access) |
| 82 |
(2 vals) |
| 83 |
6 = version_no, file_type (Ima/Tab/Fits), FCB.DSCFLAG, |
| 84 |
file_format (FITS/Midas), file_protect, |
| 85 |
file_compress (6 vals) |
| 86 |
7 = nobytes, data_format, |
| 87 |
file_format (FITS/Midas), FCB.NDVAL, |
| 88 |
file_type (Ima/Tab/Fits), FCB.DSCFLAG (6 vals) |
| 89 |
9 = file_format (FITS/Midas), file_type (Ima/Tab/Fits) |
| 90 |
(2 vals) |
| 91 |
|
| 92 |
-1,-2,-3,-4,-6 as 1,2,3,4,6 above but with FCT_number |
| 93 |
also passed in ibuf[0] (will be overwritten) |
| 94 |
|
| 95 |
99 = just check, if frame already in FCT */ |
| 96 |
|
| 97 |
int *ibuf; /* IN/OUT: buffer with desired info; |
| 98 |
if flag < 0 then ibuf[0] already holds the |
| 99 |
FCT_number (so we have faster access) */ |
| 100 |
|
| 101 |
|
| 102 |
{ |
| 103 |
char temp[200]; |
| 104 |
|
| 105 |
int mm, namtyp, part_no; |
| 106 |
int ista, jkno, tmpno; |
| 107 |
|
| 108 |
struct FCT_STRUCT *fctpntr; |
| 109 |
|
| 110 |
struct FCB_STRUCT *fcbp; |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
/* |
| 116 |
printf("entering SCFINF(%s,%d) \n",name,flag); |
| 117 |
*/ |
| 118 |
|
| 119 |
|
| 120 |
if (flag < 0) /* ibuf[0] = tmpno from last call */ |
| 121 |
{ |
| 122 |
flag = -flag; |
| 123 |
tmpno = jkno = *ibuf; |
| 124 |
ista = ERR_NORMAL; |
| 125 |
if (flag != 5) goto do_it; |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
/* check file name */ |
| 130 |
|
| 131 |
CGN_CLEANF(name,F_IMA_TYPE,temp,FCT_NAME_LEN,&namtyp,&part_no); |
| 132 |
if (flag == 5) |
| 133 |
{ |
| 134 |
*ibuf++ = part_no; |
| 135 |
*ibuf = namtyp; |
| 136 |
return ERR_NORMAL; |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
jkno = MID_FINDFR(temp); /* to know if it was already opened */ |
| 141 |
|
| 142 |
if (flag == 0) |
| 143 |
{ |
| 144 |
if (jkno < 0) /* do not use MID_ERROR stuff ... */ |
| 145 |
return ERR_FRMNAC; |
| 146 |
else |
| 147 |
{ |
| 148 |
*ibuf = jkno; |
| 149 |
return ERR_NORMAL; |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
/* for flag = 1,2,3,4,6,7,9 and 99 access data frame + get FCB in */ |
| 155 |
|
| 156 |
if (jkno < 0) |
| 157 |
{ |
| 158 |
tmpno = 0; |
| 159 |
ista = MID_ACCFRM(temp,0,&tmpno,&mm); /* get file into FCT */ |
| 160 |
} |
| 161 |
else |
| 162 |
{ |
| 163 |
tmpno = jkno; |
| 164 |
ista = ERR_NORMAL; |
| 165 |
} |
| 166 |
|
| 167 |
if (ista == ERR_VERNOR) /* if Version problem, try FITS */ |
| 168 |
{ |
| 169 |
char bname[200], dummy[8]; |
| 170 |
int iext; |
| 171 |
float rbuf; |
| 172 |
double dbuf; |
| 173 |
|
| 174 |
if (part_no < 0) /* we have a FITS extension */ |
| 175 |
{ |
| 176 |
int i; |
| 177 |
|
| 178 |
mm = - part_no; |
| 179 |
i = CGN_CNVT(&name[mm+1],1,1,&iext,&rbuf,&dbuf); |
| 180 |
if (i != 1) return ERR_FITEXT; |
| 181 |
} |
| 182 |
else |
| 183 |
iext = -1; |
| 184 |
|
| 185 |
if (flag == 9) /* just test type of FITS file */ |
| 186 |
{ /* do not create internal FITS file */ |
| 187 |
(void) sprintf(dummy,"%3.3d",iext); |
| 188 |
(void) strcpy(bname,"FITZ"); |
| 189 |
(void) strcat(bname,temp); |
| 190 |
(void) strcat(bname,dummy); |
| 191 |
|
| 192 |
ista = MID_fitsin(0,temp,iext,bname,dummy,&jkno,&mm); |
| 193 |
if (ista == 0) |
| 194 |
{ |
| 195 |
*ibuf++ = 1; /* = 1 for FITS file */ |
| 196 |
if (mm != 1) /* file_type (Ima/Tab) */ |
| 197 |
*ibuf = F_TBL_TYPE; |
| 198 |
else |
| 199 |
*ibuf = F_IMA_TYPE; |
| 200 |
|
| 201 |
MID_POPERR(); |
| 202 |
return (ERR_NORMAL); |
| 203 |
} |
| 204 |
else |
| 205 |
return (ERR_INPINV); |
| 206 |
} |
| 207 |
else |
| 208 |
{ |
| 209 |
ista = MID_ACCFITS(temp,0,iext,&tmpno); |
| 210 |
if (ista != ERR_NORMAL) |
| 211 |
return (ista); |
| 212 |
else |
| 213 |
MID_POPERR(); |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
if ((flag == 99) || /* we just want to see, if it's there */ |
| 218 |
(ista != ERR_NORMAL)) /* error... */ |
| 219 |
return (ista); |
| 220 |
|
| 221 |
|
| 222 |
do_it: /* store required info in return buffer */ |
| 223 |
fctpntr = FCT.ENTRIES + tmpno; |
| 224 |
fcbp = fctpntr->FZP; |
| 225 |
|
| 226 |
switch (flag) |
| 227 |
{ |
| 228 |
case 1: /* 5 return values */ |
| 229 |
if (fcbp->VERSION[5] == '1') /* version no. */ |
| 230 |
*ibuf++ = 100; /* 100 (new) as of 010301 */ |
| 231 |
else if (fcbp->VERSION[6] == '1') |
| 232 |
*ibuf++ = 10; /* 010 (old) */ |
| 233 |
else |
| 234 |
*ibuf++ = 8; /* 008 (very old) */ |
| 235 |
|
| 236 |
if (fcbp->BDTYPE[0] == 'T') /* file_type (Ima/Tab/Fits) */ |
| 237 |
*ibuf++ = F_TBL_TYPE; |
| 238 |
else if (fcbp->BDTYPE[0] == 'F') |
| 239 |
*ibuf++ = F_FIT_TYPE; |
| 240 |
else |
| 241 |
*ibuf++ = F_IMA_TYPE; |
| 242 |
|
| 243 |
if (fcbp->SWPSHORT == '=') /* FCB.SWPSHORT */ |
| 244 |
*ibuf++ = 12; |
| 245 |
else |
| 246 |
*ibuf++ = 21; |
| 247 |
|
| 248 |
if (fcbp->SWPINT == '=') /* FCB.SWPINT */ |
| 249 |
*ibuf++ = 1234; |
| 250 |
else if (fcbp->SWPINT == 's') |
| 251 |
*ibuf++ = 4321; |
| 252 |
else if (fcbp->SWPINT == 'h') |
| 253 |
*ibuf++ = 2143; |
| 254 |
else |
| 255 |
*ibuf++ = 3412; |
| 256 |
|
| 257 |
if (fcbp->FLOTFMT == '=') /* FCB.FLOTFMT */ |
| 258 |
*ibuf = 11; |
| 259 |
else if (fcbp->FLOTFMT == 'V') |
| 260 |
*ibuf = 12; |
| 261 |
else if (fcbp->FLOTFMT == 'G') |
| 262 |
*ibuf = 13; |
| 263 |
else |
| 264 |
*ibuf = 14; |
| 265 |
break; |
| 266 |
|
| 267 |
|
| 268 |
case 2: /* return |
| 269 |
nobytes, data_format, pixpbl, stblok, lastblk */ |
| 270 |
*ibuf++ = fcbp->NOBYT; |
| 271 |
*ibuf++ = fcbp->DFORMAT; |
| 272 |
*ibuf++ = fcbp->PIXPBL; |
| 273 |
*ibuf++ = fcbp->D1BLOCK; |
| 274 |
*ibuf = fcbp->DLBLOCK; |
| 275 |
break; |
| 276 |
|
| 277 |
|
| 278 |
case 3: /* 3 return values */ |
| 279 |
if (fcbp->BDTYPE[0] == 'T') /* file_type(Ima/Tab/Fits) */ |
| 280 |
*ibuf++ = F_TBL_TYPE; |
| 281 |
else if (fcbp->BDTYPE[0] == 'F') |
| 282 |
*ibuf++ = F_FIT_TYPE; |
| 283 |
else |
| 284 |
*ibuf++ = F_IMA_TYPE; |
| 285 |
|
| 286 |
*ibuf++ = fcbp->DFORMAT; /* data format */ |
| 287 |
|
| 288 |
*ibuf++ = fctpntr->PROT; /* file protection */ |
| 289 |
*ibuf = fctpntr->COMPRESS; /* compression flag */ |
| 290 |
break; |
| 291 |
|
| 292 |
|
| 293 |
case 4: /* 5 return values */ |
| 294 |
case 7: /* 6 return values */ |
| 295 |
*ibuf++ = fcbp->NOBYT; /* nobytes */ |
| 296 |
*ibuf++ = fcbp->DFORMAT; /* data_format */ |
| 297 |
*ibuf++ = fctpntr->FILTYP; /* = 1 for FITS file */ |
| 298 |
*ibuf++ = fcbp->NDVAL; /* FCB.NDVAL */ |
| 299 |
if (fcbp->BDTYPE[0] == 'T') /* file_type (Ima/Tab/Fits) */ |
| 300 |
*ibuf = F_TBL_TYPE; |
| 301 |
else if (fcbp->BDTYPE[0] == 'F') |
| 302 |
*ibuf = F_FIT_TYPE; |
| 303 |
else |
| 304 |
*ibuf = F_IMA_TYPE; |
| 305 |
if (flag == 4) break; |
| 306 |
|
| 307 |
ibuf ++; |
| 308 |
if (fcbp->DSCFLAG == 'Y') |
| 309 |
*ibuf = 2; /* 2 for descr flag = 'Y' */ |
| 310 |
else if (fcbp->DSCFLAG == 'Z') |
| 311 |
*ibuf = 1; /* 1 for descr flag = 'Z' */ |
| 312 |
else |
| 313 |
*ibuf = 0; |
| 314 |
break; |
| 315 |
|
| 316 |
|
| 317 |
case 6: /* 6 return values */ |
| 318 |
if (fcbp->VERSION[5] == '1') /* version no. */ |
| 319 |
*ibuf++ = 100; /* 100 (new) as of 010301 */ |
| 320 |
else if (fcbp->VERSION[6] == '1') |
| 321 |
*ibuf++ = 10; /* 010 (old) */ |
| 322 |
else |
| 323 |
*ibuf++ = 8; /* 008 (very old) */ |
| 324 |
|
| 325 |
if (fcbp->BDTYPE[0] == 'T') /* file_type (Ima/Tab/Fits) */ |
| 326 |
*ibuf++ = F_TBL_TYPE; |
| 327 |
else if (fcbp->BDTYPE[0] == 'F') |
| 328 |
*ibuf++ = F_FIT_TYPE; |
| 329 |
else |
| 330 |
*ibuf++ = F_IMA_TYPE; |
| 331 |
|
| 332 |
if (fcbp->DSCFLAG == 'Y') |
| 333 |
*ibuf++ = 2; /* 2 for descr flag = 'Y' */ |
| 334 |
else if (fcbp->DSCFLAG == 'Z') |
| 335 |
*ibuf++ = 1; /* 1 for descr flag = 'Z' */ |
| 336 |
else |
| 337 |
*ibuf++ = 0; |
| 338 |
|
| 339 |
*ibuf++ = fctpntr->FILTYP; /* = 1 for FITS file */ |
| 340 |
*ibuf++ = fctpntr->PROT; /* file protection */ |
| 341 |
*ibuf = fctpntr->COMPRESS; /* compression flag */ |
| 342 |
break; |
| 343 |
|
| 344 |
|
| 345 |
case 9: /* 2 return values */ |
| 346 |
*ibuf++ = fctpntr->FILTYP; /* = 1 for FITS file */ |
| 347 |
if (fcbp->BDTYPE[0] == 'T') /* file_type (Ima/Tab/Fits) */ |
| 348 |
*ibuf = F_TBL_TYPE; |
| 349 |
else if (fcbp->BDTYPE[0] == 'F') |
| 350 |
*ibuf = F_FIT_TYPE; |
| 351 |
else |
| 352 |
*ibuf = F_IMA_TYPE; |
| 353 |
|
| 354 |
if (jkno < 0) /* was not open before, so */ |
| 355 |
(void) SCFCLO(tmpno); /* get rid of it again */ |
| 356 |
break; |
| 357 |
|
| 358 |
|
| 359 |
default: |
| 360 |
ista = ERR_INPINV; |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
return (ista); |
| 365 |
} |
| 366 |
|
| 367 |
/* |
| 368 |
|
| 369 |
*/ |
| 370 |
|
| 371 |
int SCFNAME(fno,fname,fnamlen) |
| 372 |
|
| 373 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 374 |
.PURPOSE |
| 375 |
get the FCT name of a file id |
| 376 |
.ALGORITHM |
| 377 |
return the name in given FCT_entry |
| 378 |
.RETURNS |
| 379 |
if wrong fno return -2, if empty slot return -1, else 0 |
| 380 |
-----------------------------------------------------------------------*/ |
| 381 |
|
| 382 |
int fno; /* IN: file no. */ |
| 383 |
char *fname; /* OUT: name of data frame */ |
| 384 |
int fnamlen; /* IN: max. length of `fname' */ |
| 385 |
|
| 386 |
{ |
| 387 |
return (MID_RETNAM(fno,fname,fnamlen)); |
| 388 |
} |
| 389 |
|
| 390 |
/* |
| 391 |
|
| 392 |
*/ |
| 393 |
|
| 394 |
int SCFYMP(nopix,datform,imno,pntr) |
| 395 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 396 |
.PURPOSE |
| 397 |
use SCFCRE + SCFMAP to get virtual memory |
| 398 |
.ALGORITHM |
| 399 |
straight forward |
| 400 |
.RETURNS |
| 401 |
return status ( 0 = o.k ) |
| 402 |
-----------------------------------------------------------------------*/ |
| 403 |
|
| 404 |
int nopix; /* IN: size in pixels */ |
| 405 |
int datform; /* IN: data format of pixels */ |
| 406 |
int *imno; /* OUT: file id (entry in FCT) */ |
| 407 |
char **pntr; /* OUT: pointer to data */ |
| 408 |
|
| 409 |
{ |
| 410 |
int status, iav; |
| 411 |
|
| 412 |
char dumnam[20], *mypntr; |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
/* check, if creation or deletion */ |
| 417 |
|
| 418 |
if (nopix < 1) /* get rid of allocated space */ |
| 419 |
{ |
| 420 |
struct FCT_STRUCT *fctpntr; |
| 421 |
|
| 422 |
|
| 423 |
status = ERR_INPINV; |
| 424 |
|
| 425 |
fctpntr = FCT.ENTRIES; |
| 426 |
for (iav=0; iav<FCT.MAXENT; iav++) |
| 427 |
{ |
| 428 |
if ((iav == *imno) && (fctpntr->ACCESS == 'X')) |
| 429 |
{ |
| 430 |
status = SCFCLO(iav); |
| 431 |
break; |
| 432 |
} |
| 433 |
fctpntr ++; |
| 434 |
} |
| 435 |
return status; |
| 436 |
} |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
/* allocate space - build up unique name */ |
| 441 |
|
| 442 |
virt_count++ ; |
| 443 |
(void) snprintf(dumnam,(size_t)20,"virtual%d",virt_count); |
| 444 |
|
| 445 |
|
| 446 |
/* create + map X-MODE frame */ |
| 447 |
|
| 448 |
status = SCFCRE(dumnam,datform,F_X_MODE,F_IMA_TYPE,nopix,imno); |
| 449 |
if (status == ERR_NORMAL) |
| 450 |
status = SCFMAP(*imno,F_X_MODE,1,nopix,&iav,&mypntr); |
| 451 |
|
| 452 |
if (status != ERR_NORMAL) |
| 453 |
{ |
| 454 |
*pntr = 0; |
| 455 |
(void) snprintf(dumnam,(size_t)20,"nopix = %d",nopix); |
| 456 |
MID_E1(13,dumnam,status,1); |
| 457 |
} |
| 458 |
else |
| 459 |
*pntr = mypntr; |
| 460 |
|
| 461 |
return status; |
| 462 |
} |
| 463 |
|
| 464 |
/* |
| 465 |
|
| 466 |
*/ |
| 467 |
|
| 468 |
int SCFXMP(nopix,datform,pntr) |
| 469 |
|
| 470 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 471 |
.PURPOSE |
| 472 |
use SCFCRE + SCFMAP to get virtual memory |
| 473 |
.ALGORITHM |
| 474 |
straight forward |
| 475 |
.RETURNS |
| 476 |
return status ( 0 = o.k ) |
| 477 |
-----------------------------------------------------------------------*/ |
| 478 |
|
| 479 |
int nopix; /* IN: size in pixels */ |
| 480 |
int datform; /* IN: data format of pixels */ |
| 481 |
char **pntr; /* OUT: pointer to data */ |
| 482 |
|
| 483 |
{ |
| 484 |
int status, imno, iav; |
| 485 |
|
| 486 |
char dumnam[20], *mypntr; |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
/* allocate space - build up unique name */ |
| 491 |
|
| 492 |
virt_count++ ; |
| 493 |
(void) snprintf(dumnam,(size_t)20,"virtual%d",virt_count); |
| 494 |
|
| 495 |
|
| 496 |
/* create + map X-MODE frame */ |
| 497 |
|
| 498 |
status = SCFCRE(dumnam,datform,F_X_MODE,F_IMA_TYPE,nopix,&imno); |
| 499 |
if (status == ERR_NORMAL) |
| 500 |
status = SCFMAP(imno,F_X_MODE,1,nopix,&iav,&mypntr); |
| 501 |
|
| 502 |
if (status != ERR_NORMAL) |
| 503 |
{ |
| 504 |
*pntr = 0; |
| 505 |
(void) snprintf(dumnam,(size_t)20,"nopix = %d",nopix); |
| 506 |
MID_E1(13,dumnam,status,1); |
| 507 |
} |
| 508 |
else |
| 509 |
*pntr = mypntr; |
| 510 |
|
| 511 |
return status; |
| 512 |
} |
| 513 |
|