| 1 |
/*=========================================================================== |
| 2 |
Copyright (C) 1995,2004 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 SCI +++++++++++++++++++++++ |
| 29 |
.LANGUAGE C |
| 30 |
.IDENTIFICATION Module SCI |
| 31 |
.AUTHOR K. Banse ESO - Garching |
| 32 |
.KEYWORDS standard interfaces, data frames, descriptors |
| 33 |
.ENVIRONMENT VMS and UNIX |
| 34 |
.COMMENTS |
| 35 |
holds SCIGET, SCIPUT |
| 36 |
.VERSION [1.20] 861220: creation |
| 37 |
040604 last modif |
| 38 |
|
| 39 |
-----------------------------------------------------------------------------*/ |
| 40 |
|
| 41 |
#include <string.h> |
| 42 |
|
| 43 |
#include <fileexts.h> |
| 44 |
|
| 45 |
|
| 46 |
/* |
| 47 |
|
| 48 |
*/ |
| 49 |
|
| 50 |
int SCIGET(name,dattype,iomode,filtype,maxdim,naxis,npix,start,step,ident, |
| 51 |
cunit,pntr,imno) |
| 52 |
|
| 53 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 54 |
.PURPOSE |
| 55 |
map complete data frame for reading or updating and read |
| 56 |
the standard descriptors. |
| 57 |
.ALGORITHM |
| 58 |
call SCDGET and SCFMAP to map and to read the standard descriptors. |
| 59 |
.RETURNS |
| 60 |
return status ( 0 = o.k. ) |
| 61 |
.REMARKS |
| 62 |
for a description of the parameters , see text for SCF... and SCD... routines |
| 63 |
--------------------------------------------------------------------------*/ |
| 64 |
|
| 65 |
char *name /* IN : data frame name */; |
| 66 |
int dattype /* IN : data type */; |
| 67 |
int iomode /* IN : mode for opening of frame */; |
| 68 |
int filtype /* IN : type no: 1 = image, 2 = mask, 3 = table */; |
| 69 |
int maxdim /* IN : maximum number of dimensions */; |
| 70 |
int *naxis /* OUT: no of dimensions of the image */; |
| 71 |
int *npix /* OUT: size of each dimension */; |
| 72 |
double *start /* OUT: start coordinates: start is the address of an \ |
| 73 |
array of naxis elements */; |
| 74 |
double *step /* OUT: stepsizes : step is the address of an array of \ |
| 75 |
naxis elements */; |
| 76 |
char *ident /* IN/OUT: ascii identifier of image */; |
| 77 |
char *cunit /* IN/OUT: unit of each axis (16 char per unit) */; |
| 78 |
char **pntr /* OUT: pointer to mapped data */; |
| 79 |
int *imno /* OUT: file no. of data frame */; |
| 80 |
|
| 81 |
|
| 82 |
{ |
| 83 |
char *mypntr; |
| 84 |
|
| 85 |
int unit, status, n, kk; |
| 86 |
int maxval, npi[6], mnaxis, size, first_elem; |
| 87 |
int nullo , act_size; |
| 88 |
|
| 89 |
|
| 90 |
*imno = -1; /* so it is set to something... */ |
| 91 |
|
| 92 |
|
| 93 |
/* check maxdim and iomode */ |
| 94 |
|
| 95 |
if ((maxdim < 1) || (maxdim > 6)) |
| 96 |
{ |
| 97 |
status = ERR_INPINV; |
| 98 |
error_ret(name," + MAXDIM",10,status); |
| 99 |
} |
| 100 |
|
| 101 |
else if ((iomode != F_I_MODE) && (iomode != F_IO_MODE)) |
| 102 |
{ |
| 103 |
status = ERR_INPINV; |
| 104 |
error_ret(name," + IOMODE",10,status); |
| 105 |
} |
| 106 |
|
| 107 |
MID_E3("SCIGET"); /* store interface name in case of need... */ |
| 108 |
|
| 109 |
|
| 110 |
/* make sure all npix are set to 1 */ |
| 111 |
|
| 112 |
for (n=0; n<maxdim; n++) |
| 113 |
npix[n] = 1; |
| 114 |
|
| 115 |
|
| 116 |
/* open frame + get descriptors */ |
| 117 |
|
| 118 |
status = SCFOPN(name,dattype,0,filtype,imno); |
| 119 |
if (status != ERR_NORMAL) |
| 120 |
{ |
| 121 |
error_ret(name," + SCFOPN",10,status); |
| 122 |
return status; |
| 123 |
} |
| 124 |
|
| 125 |
status = SCDRDI(*imno,"NAXIS",1,1,&maxval,&mnaxis,&unit,&nullo); |
| 126 |
if (status != ERR_NORMAL) |
| 127 |
error_ret(name," + NAXIS",10,status); |
| 128 |
else if (mnaxis < 1) |
| 129 |
{ |
| 130 |
status = ERR_NODATA; |
| 131 |
error_ret(name," + NAXIS < 1",10,status); |
| 132 |
} |
| 133 |
|
| 134 |
if (mnaxis > 6) mnaxis = 6; /* currently our maximum... */ |
| 135 |
if (maxdim < mnaxis) mnaxis = maxdim; |
| 136 |
|
| 137 |
status = SCDRDI(*imno,"NPIX",1,mnaxis,&maxval,npi,&unit,&nullo); |
| 138 |
if (status != ERR_NORMAL) |
| 139 |
error_ret(name," + NPIX",10,status); |
| 140 |
|
| 141 |
|
| 142 |
kk = mnaxis - 1; /* trailing NPIX = 1 is ignored... */ |
| 143 |
for (n=kk; n>0; n--) |
| 144 |
{ |
| 145 |
if (npi[n] == 1) |
| 146 |
mnaxis --; |
| 147 |
else |
| 148 |
break; |
| 149 |
} |
| 150 |
*naxis = mnaxis; /* that's the NAXIS we return */ |
| 151 |
|
| 152 |
for (n=0; n<mnaxis; n++) |
| 153 |
npix[n] = npi[n]; |
| 154 |
|
| 155 |
status = SCDRDD(*imno,"START",1,mnaxis,&maxval,start,&unit,&nullo); |
| 156 |
if (status != ERR_NORMAL) |
| 157 |
error_ret(name," + START",10,status); |
| 158 |
status = SCDRDD(*imno,"STEP",1,mnaxis,&maxval,step,&unit,&nullo); |
| 159 |
if (status != ERR_NORMAL) |
| 160 |
error_ret(name," + STEP",10,status); |
| 161 |
|
| 162 |
kk = (int)strlen(ident); |
| 163 |
if (kk > 0) |
| 164 |
{ |
| 165 |
status = SCDRDC(*imno,"IDENT",1,1,kk,&maxval,ident,&unit,&nullo); |
| 166 |
if (status != ERR_NORMAL) |
| 167 |
error_ret(name," + IDENT",10,status); |
| 168 |
} |
| 169 |
|
| 170 |
kk = (int)strlen(cunit); |
| 171 |
if (kk > 0) |
| 172 |
{ |
| 173 |
status = SCDRDC(*imno,"CUNIT",1,1,kk,&maxval,cunit,&unit,&nullo); |
| 174 |
if (status != ERR_NORMAL) |
| 175 |
error_ret(name," + CUNIT",10,status); |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
first_elem = 1; |
| 180 |
size = npi[0]; |
| 181 |
for (n=1; n<mnaxis; n++) |
| 182 |
size *= npi[n]; |
| 183 |
|
| 184 |
|
| 185 |
/* finally map bulk data frame for reading/writing */ |
| 186 |
|
| 187 |
status = SCFMAP(*imno,iomode,first_elem,size,&act_size,&mypntr); |
| 188 |
*pntr = mypntr; |
| 189 |
|
| 190 |
return status; |
| 191 |
|
| 192 |
} |
| 193 |
|
| 194 |
/* |
| 195 |
|
| 196 |
*/ |
| 197 |
|
| 198 |
int SCIPUT(name,dattype,iomode,filtype,naxis,npix,start,step,ident,cunit,pntr,imno) |
| 199 |
|
| 200 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 201 |
.PURPOSE |
| 202 |
create and map complete bulk data frame |
| 203 |
and write the standard descriptors |
| 204 |
.ALGORITHM |
| 205 |
call SCFCRE, SCFMAP and SCDWRx routines |
| 206 |
.RETURNS |
| 207 |
return status ( 0 = o.k. ) |
| 208 |
.REMARKS |
| 209 |
for a description of the parameters , see text for SCF... and SCD... routines |
| 210 |
--------------------------------------------------------------------------*/ |
| 211 |
|
| 212 |
char *name /* IN : data frame name */; |
| 213 |
int dattype /* IN : data type */; |
| 214 |
int iomode /* IN : mode for opening of frame */; |
| 215 |
int filtype /* IN : type no: 1 = image, 2 = mask, 3 = table */; |
| 216 |
int naxis /* IN : no of dimensions of the image */; |
| 217 |
int *npix /* IN : size of each dimension */; |
| 218 |
double *start /* IN : start coordinates: start is the address of an \ |
| 219 |
array of naxis elements */; |
| 220 |
double *step /* IN : stepsizes : step is the address of an array of \ |
| 221 |
naxis elements */; |
| 222 |
char *ident /* IN : ascii identifier of image */; |
| 223 |
char *cunit /* IN : unit of each axis (16 char per unit) */; |
| 224 |
char **pntr /* OUT: pointer to mapped data */; |
| 225 |
int *imno /* OUT: file no. of data frame */; |
| 226 |
|
| 227 |
|
| 228 |
{ |
| 229 |
|
| 230 |
char temp[84], *mypntr; |
| 231 |
|
| 232 |
int unit, status, kk, n; |
| 233 |
int tsize, size; |
| 234 |
|
| 235 |
float lhcuts[4]; |
| 236 |
|
| 237 |
|
| 238 |
*imno = -1; /* so it is set to something... */ |
| 239 |
|
| 240 |
|
| 241 |
/* check naxis and npix */ |
| 242 |
|
| 243 |
if (naxis < 1) |
| 244 |
{ |
| 245 |
status = ERR_INPINV; |
| 246 |
error_ret(name," + NAXIS < 1",9,status); |
| 247 |
} |
| 248 |
|
| 249 |
for (n=0; n<naxis; n++) |
| 250 |
{ |
| 251 |
if (npix[n] <= 0) |
| 252 |
{ |
| 253 |
status = ERR_INPINV; |
| 254 |
error_ret(name," + NPIX",9,status); |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
/* Input ok -- compute total size of frame */ |
| 260 |
|
| 261 |
size = npix[0]; |
| 262 |
for (n=1; n<naxis; n++) size *= npix[n]; |
| 263 |
|
| 264 |
|
| 265 |
/* create frame */ |
| 266 |
|
| 267 |
status = SCFCRE(name,dattype,iomode,filtype,size,imno); |
| 268 |
if (status == ERR_NORMAL) |
| 269 |
status = SCFMAP(*imno,iomode,1,size,&tsize,&mypntr); |
| 270 |
if (status != ERR_NORMAL) return status; |
| 271 |
|
| 272 |
*pntr = mypntr; |
| 273 |
|
| 274 |
if (iomode == F_X_MODE) |
| 275 |
return status; /* for scratch files we're already done */ |
| 276 |
|
| 277 |
|
| 278 |
/* write standard descriptors */ |
| 279 |
|
| 280 |
status = SCDWRI(*imno,"NAXIS",&naxis,1,1,&unit); |
| 281 |
if (status == ERR_NORMAL) |
| 282 |
{ |
| 283 |
status = SCDWRI(*imno,"NPIX",npix,1,naxis,&unit); |
| 284 |
if (status == ERR_NORMAL) |
| 285 |
{ |
| 286 |
status = SCDWRD(*imno,"START",start,1,naxis,&unit); |
| 287 |
if (status == ERR_NORMAL) |
| 288 |
status = SCDWRD(*imno,"STEP",step,1,naxis,&unit); |
| 289 |
} |
| 290 |
} |
| 291 |
if (status != ERR_NORMAL) return status; |
| 292 |
|
| 293 |
|
| 294 |
/* first, create IDENT + CUNIT with correct length and fill with blanks */ |
| 295 |
|
| 296 |
memset((void *)temp,32,(size_t)80); |
| 297 |
temp[80] = '\0'; |
| 298 |
|
| 299 |
status = SCDWRC(*imno,"IDENT",1,temp,1,72,&unit); |
| 300 |
kk = (int)strlen(ident); |
| 301 |
if (kk > 0) status = SCDWRC(*imno,"IDENT",1,ident,1,kk,&unit); |
| 302 |
if (status != ERR_NORMAL) return status; |
| 303 |
|
| 304 |
kk = (naxis+1) * 16; |
| 305 |
if (kk > 80) kk = 80; |
| 306 |
status = SCDWRC(*imno,"CUNIT",1,temp,1,kk,&unit); |
| 307 |
kk = (int)strlen(cunit); |
| 308 |
if (kk > 0) status = SCDWRC(*imno,"CUNIT",1,cunit,1,kk,&unit); |
| 309 |
if (status != ERR_NORMAL) return status; |
| 310 |
|
| 311 |
for (n=0; n<4; n++) lhcuts[n] = 0.0; |
| 312 |
status = SCDWRR(*imno,"LHCUTS",lhcuts,1,4,&unit); |
| 313 |
|
| 314 |
return status; |
| 315 |
} |