1
/* @(#)ccopyf.c 19.2 (ESO-DMD) 05/20/03 09:42:23 */
2
/*===========================================================================
3
Copyright (C) 1995 European Southern Observatory (ESO)
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License as
7
published by the Free Software Foundation; either version 2 of
8
the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public
16
License along with this program; if not, write to the Free
17
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
20
Correspondence concerning ESO-MIDAS should be addressed as follows:
21
Internet e-mail: midas@eso.org
22
Postal address: European Southern Observatory
23
Data Management Division
24
Karl-Schwarzschild-Strasse 2
25
D 85748 Garching bei Muenchen
27
===========================================================================*/
29
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
.COPYRIGHT: Copyright (c) 1994 European Southern Observatory,
32
.IDENTIFIER module CCOPYF
34
.AUTHOR K. Banse IPG-ESO Garching
36
.COMMENTS holds: Copywnd, Copyf, Copyf1, Copyf2, Copyi, Copyfx, Fillima
38
#include <midas_def.h> Prototypes for MIDAS interfaces
43
------------------------------------------------------------*/
45
/* Define _POSIX_SOURCE to indicate that this is a POSIX program */
47
#define _POSIX_SOURCE 1
52
#include <midas_def.h>
58
/*++++++++++++++++++++++++++++++
59
.PURPOSE Copy parts of frame A to artifical 1dim frame B
61
call as Fillima(flag,imno,npix,auxstr,insize,retimno)
64
int flag 0 = create art. image
67
3 = get exact size of art. image
68
int imno file id of input frame
69
int *npix NPIX of input frame
70
char *auxstr aux. string with subarea info
72
int *insize IN: no. of pixels for art. image (flag = 0)
73
OUT: current nopix of art. image (flag = 3)
75
int *retimno file id of artificial 1dim image
80
------------------------------*/
82
int Fillima(flag,imno,npix,auxstr,insize,retimno)
83
int flag, imno, *npix, *insize, *retimno;
87
int first, stat, kk, iav, size, endx, endy, sublo[3], subhi[3];
89
static int felem, totsize;
91
register float *apntr, *bpntr, *xpntr;
94
static char *mypntr, namend;
99
printf("Fillima: flag = %d, totsize = %d, felem = %d\n",
104
if (flag == 0) /* create artificial image (allocate memory) */
106
if (*insize < 1) return (-2);
107
totsize = *insize; /* save nopix of 1-dim result image */
110
for (nr=0; nr<3; nr++)
112
sublo[nr] = subhi[nr] = 0;
115
stat = SCFCRE("middumm#y",D_R4_FORMAT,F_X_MODE,F_IMA_TYPE,totsize,retimno);
116
if (stat == ERR_NORMAL)
117
stat = SCFMAP(*retimno,F_X_MODE,1,totsize,&iav,&mypntr);
119
if (stat != ERR_NORMAL) return (-1);
122
else if (flag == 1) /* fill artificial image */
124
stat = Convcoo(1,imno,auxstr,3,&iav,sublo,subhi);
125
if (stat != ERR_NORMAL) return (-3);
127
endx = subhi[0] - sublo[0] + 1;
128
endy = subhi[1] - sublo[1] + 1;
129
size = endy * npix[0]; /* full strip */
130
first = (sublo[1] * npix[0]) + 1; /* 1st elem in input frame */
131
kk = (endx*endy); /* no. of pixels to copy */
133
if ((felem+kk) > totsize) return (-4); /* check for overflow */
134
/* get strip of input frame */
135
stat = SCFMAP(imno,F_I_MODE,first,size,&iav,&impntr);
137
apntr = (float *) impntr;
139
bpntr = (float *) mypntr;
142
for (ny=0; ny<endy; ny++)
145
for (nr=0; nr<endx; nr++) *bpntr++ = *xpntr++;
149
felem += kk; /* update offset */
153
else if (flag == 2) /* expand artificial image */
157
if (*insize < 1) return (-2);
158
totsize = *insize; /* save new size */
160
if (namend == 'y') /* switch between ...#z and ...#y */
162
stat = SCFCRE("middumm#z",D_R4_FORMAT,F_X_MODE,F_IMA_TYPE,
168
stat = SCFCRE("middumm#y",D_R4_FORMAT,F_X_MODE,F_IMA_TYPE,
172
if (stat == ERR_NORMAL)
173
stat = SCFMAP(myimno,F_X_MODE,1,totsize,&iav,&impntr);
175
if (stat != ERR_NORMAL) return (-1);
177
apntr = (float *) mypntr;
178
bpntr = (float *) impntr;
179
for (nr=0; nr<felem; nr++) *bpntr++ = *apntr++;
180
stat = SCFCLO(*retimno);
182
mypntr = impntr; /* save new pointer + imno */
183
*retimno = myimno; /* felem remains as it is */
188
*insize = felem; /* just get current size */
198
/*++++++++++++++++++++++++++++++
199
.PURPOSE Copy (part of) frame A to frame B, start pixels don't have to be
201
.ALGORITHM Note, that all arrays are foreseen for 3-D frames
203
call as Ccopwnd( pntrA, npixA, pntrB, npixB, bgnA, bgnB, endA )
206
float *pntrA input frame A
207
int npixA[3] NPIX of A
208
float *pntrB output frame B
209
int npixB[3] NPIX of B
210
int bgnA[3] start pixel of window in A
211
int bgnB[3] start pixel of window in B
212
int endA[3] end pixel of window in A
215
------------------------------*/
217
void Ccopwnd( pntrA, npixA, pntrB, npixB, bgnA, bgnB, endA )
218
int *npixA, *npixB, *bgnA, *bgnB, *endA;
219
float *pntrA, *pntrB;
222
register int ix, iy, iz, xyz;
224
int offsA, offsB, dimwA[3], dimwB[3];
227
/* Make sure, son frame fits into father frame */
229
for (xyz=0; xyz<3; xyz++)
231
dimwA[xyz] = endA[xyz] - bgnA[xyz] + 1;
232
dimwB[xyz] = npixB[xyz] - bgnB[xyz] + 1;
233
if ( dimwA[xyz] > dimwB[xyz] ) dimwA[xyz] = dimwB[xyz];
236
offsA = npixA[0] - dimwA[0];
237
offsB = npixB[0] - dimwA[0];
240
/* Move the pointers to start positions */
242
pntrA += bgnA[0] - 1 + npixA[0]*((bgnA[1] - 1) + npixA[1] * (bgnA[2] -1));
243
pntrB += bgnB[0] - 1 + npixB[0]*((bgnB[1] - 1) + npixB[1] * (bgnB[2] -1));
245
/* Copy frame A to frame B */
247
for (iz=0; iz<dimwA[2]; iz++)
249
for (iy=0; iy<dimwA[1]; iy++)
251
for (ix=0; ix<dimwA[0]; ix++) *pntrB++ = *pntrA++;
262
/*++++++++++++++++++++++++++++++
263
.PURPOSE Copy (part of) frame A to frame B, start pixels don't have to be
265
.ALGORITHM straight forward
267
call as Ccopyf1( pntrA, npixA, bgnA, dimwA, pntrB, npixB, bgnB )
270
float *pntrA input frame A
271
int npixA[2] NPIX of A
272
int bgnA[2] start pixel of window in A
273
int dimwA[2] dimension of window in A
274
float *pntrB output frame B
275
int npixB[2] NPIX of B
276
int bgnB[2] start pixel of window in B
279
------------------------------*/
281
void Ccopyf1( pntrA, npixA, bgnA, dimwA, pntrB, npixB, bgnB )
282
int *npixA, *npixB, *bgnA, *bgnB, *dimwA;
283
float *pntrA, *pntrB;
287
int offsA = npixA[0] - dimwA[0],
288
offsB = npixB[0] - dimwA[0];
291
* Move the pointers to start positions
293
pntrA += bgnA[0] - 1 + npixA[0] * (bgnA[1] - 1);
294
pntrB += bgnB[0] - 1 + npixB[0] * (bgnB[1] - 1);
297
* Copy frame A to frame B
299
for ( iy = 0; iy < dimwA[1]; iy++ )
300
{ for ( ix = 0; ix < dimwA[0]; ix++ ) *pntrB++ = *pntrA++;
310
/*++++++++++++++++++++++++++++++
311
.PURPOSE Copy a constant value to (part of) frame B
312
.ALGORITHM straight forward
314
call as Ccopyf2( value, pntrB, npixB, bgnB, dimwB )
317
float value constant value
318
float *pntrB output frame B
319
int npixB[2] NPIX of B
320
int bgnB[2] start pixel of window in B
321
int dimwB[2] dimension of window in B
324
------------------------------*/
327
void Ccopyf2( float value, float *pntrB, int *npixB, int *bgnB, int *dimwB )
329
void Ccopyf2( value, pntrB, npixB, bgnB, dimwB )
330
int *npixB, *bgnB, *dimwB;
336
int offsB = npixB[0] - dimwB[0];
339
* Move the pointers to start positions
341
pntrB += bgnB[0] - 1 + npixB[0] * (bgnB[1] - 1);
344
* Copy value to frame B
346
for ( iy = 0; iy < dimwB[1]; iy++ )
347
{ for ( ix = 0; ix < dimwB[0]; ix++ ) *pntrB++ = value;
356
/*++++++++++++++++++++++++++++++
357
.PURPOSE Copy (part of) floating point frame A to frame B
358
.ALGORITHM straight forward
360
call as Ccopyf( pntrA, pntrB, dim )
363
float *pntrA input frame A
364
float *pntrB output frame B
365
int dim number of items to be copied
368
------------------------------*/
370
void Ccopyf( pntrA, pntrB, dim )
372
float *pntrA, *pntrB;
376
for ( ii = 0; ii < dim; ii++ ) *pntrB++ = *pntrA++;
379
/*++++++++++++++++++++++++++++++
380
.PURPOSE Copy (part of) integer frame A to frame B
381
.ALGORITHM straight forward
383
call as Ccopyi( pntrA, pntrB, dim )
386
int *pntrA input frame A
387
int *pntrB output frame B
388
int dim number of items to be copied
391
------------------------------*/
393
void Ccopyi( pntrA, pntrB, dim )
394
int *pntrA, *pntrB, dim;
398
for ( ii = 0; ii < dim; ii++ ) *pntrB++ = *pntrA++;
404
/*++++++++++++++++++++++++++++++
405
.PURPOSE Copy a "big" file in pieces
406
.ALGORITHM straight forward
408
call as Ccopyfx(pntrA,imni,imno,npix,istrip)
411
float *pntrA working buffer, size = *npix * istrip
412
int imni file no. of input data frame
413
int imno file no. of output data frame
415
int strip no. of lines to be copied
418
------------------------------*/
421
void Ccopyfx(float *pntrA,int imni,int imno,int *npix,int strip)
423
void Ccopyfx(pntrA,imni,imno,npix,strip)
424
int imni, imno, strip, *npix;
429
int actvals, felem, ksize, looplm;
435
cpntrA = (char *) pntrA;
436
looplm = npix[1] / strip;
437
if ((npix[1] - (looplm*strip)) > 0) looplm ++;
440
ksize = npix[0] * strip;
442
for (nr=0; nr<looplm; nr++)
443
{ /* actvals <- real size */
444
(void) SCFGET(imni,felem,ksize,&actvals,cpntrA);
445
(void) SCFPUT(imno,felem,actvals,cpntrA);
446
felem += actvals; /* update I/O pointer */