~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to prim/general/libsrc/ccopyf.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* @(#)ccopyf.c 19.2 (ESO-DMD) 05/20/03 09:42:23 */
 
2
/*===========================================================================
 
3
  Copyright (C) 1995 European Southern Observatory (ESO)
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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, 
 
18
  MA 02139, USA.
 
19
 
 
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 
 
26
                        GERMANY
 
27
===========================================================================*/
 
28
 
 
29
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
30
.COPYRIGHT:  Copyright (c) 1994 European Southern Observatory,
 
31
                                         all rights reserved
 
32
.IDENTIFIER  module CCOPYF
 
33
.LANGUAGE    C
 
34
.AUTHOR      K. Banse                   IPG-ESO Garching
 
35
.KEYWORDS    
 
36
.COMMENTS    holds: Copywnd, Copyf, Copyf1, Copyf2, Copyi, Copyfx, Fillima
 
37
.ENVIRONment MIDAS
 
38
 #include <midas_def.h>   Prototypes for MIDAS interfaces
 
39
 
 
40
.VERSIONS    
 
41
 030520         last modif
 
42
 
 
43
------------------------------------------------------------*/
 
44
 
 
45
/* Define _POSIX_SOURCE to indicate that this is a POSIX program */
 
46
 
 
47
#define  _POSIX_SOURCE 1
 
48
 
 
49
 
 
50
 
 
51
#include <stdlib.h>
 
52
#include <midas_def.h>
 
53
 
 
54
/*
 
55
 
 
56
*/
 
57
 
 
58
/*++++++++++++++++++++++++++++++
 
59
.PURPOSE     Copy parts of frame A to artifical 1dim frame B
 
60
.INPUT/OUTPUT
 
61
  call as    Fillima(flag,imno,npix,auxstr,insize,retimno)
 
62
 
 
63
  input:
 
64
          int   flag            0 = create art. image
 
65
                                1 = fill image
 
66
                                2 = expand 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
 
71
  in/output:
 
72
          int   *insize         IN: no. of pixels for art. image (flag = 0)
 
73
                                OUT: current nopix of art. image (flag = 3)
 
74
  output:
 
75
          int   *retimno        file id of artificial 1dim image
 
76
 
 
77
.RETURNS     = 0, if o.k.
 
78
               < 0, if problems
 
79
 
 
80
------------------------------*/
 
81
 
 
82
int Fillima(flag,imno,npix,auxstr,insize,retimno)
 
83
int  flag, imno, *npix, *insize, *retimno;
 
84
char *auxstr;
 
85
 
 
86
{
 
87
int  first, stat, kk, iav, size, endx, endy, sublo[3], subhi[3];
 
88
register int nr, ny;
 
89
static int felem, totsize;
 
90
 
 
91
register float  *apntr, *bpntr, *xpntr;
 
92
 
 
93
char  *impntr;
 
94
static char  *mypntr, namend;
 
95
 
 
96
 
 
97
 
 
98
/*
 
99
printf("Fillima: flag = %d, totsize = %d, felem = %d\n",
 
100
       flag,totsize,felem);
 
101
*/
 
102
 
 
103
 
 
104
if (flag == 0)                  /* create artificial image (allocate memory) */
 
105
   {
 
106
   if (*insize < 1) return (-2);
 
107
   totsize = *insize;                   /* save nopix of 1-dim result image */
 
108
   namend = 'y';
 
109
   felem = 0;
 
110
   for (nr=0; nr<3; nr++)
 
111
      {
 
112
      sublo[nr] = subhi[nr] = 0;
 
113
      }
 
114
 
 
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);
 
118
 
 
119
   if (stat != ERR_NORMAL) return (-1);
 
120
   }
 
121
 
 
122
else if (flag == 1)                     /* fill artificial image */
 
123
   {
 
124
   stat = Convcoo(1,imno,auxstr,3,&iav,sublo,subhi);
 
125
   if (stat != ERR_NORMAL) return (-3);
 
126
   
 
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 */
 
132
 
 
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);
 
136
 
 
137
   apntr = (float *) impntr;
 
138
   apntr += sublo[0];
 
139
   bpntr = (float *) mypntr;
 
140
   bpntr += felem;
 
141
 
 
142
   for (ny=0; ny<endy; ny++)
 
143
      {
 
144
      xpntr = apntr;
 
145
      for (nr=0; nr<endx; nr++) *bpntr++ = *xpntr++;
 
146
      apntr += npix[0];
 
147
      }
 
148
 
 
149
   felem += kk;                 /* update offset */
 
150
   (void) SCFUNM(imno);
 
151
   }
 
152
 
 
153
else if (flag == 2)                     /* expand artificial image */
 
154
   {
 
155
   int  myimno;
 
156
 
 
157
   if (*insize < 1) return (-2);
 
158
   totsize = *insize;                   /* save new size */
 
159
 
 
160
   if (namend == 'y')                   /* switch between ...#z and ...#y */
 
161
      {
 
162
      stat = SCFCRE("middumm#z",D_R4_FORMAT,F_X_MODE,F_IMA_TYPE,
 
163
                    totsize,&myimno);
 
164
      namend = 'z';
 
165
      }
 
166
   else
 
167
      {
 
168
      stat = SCFCRE("middumm#y",D_R4_FORMAT,F_X_MODE,F_IMA_TYPE,
 
169
                    totsize,&myimno);
 
170
      namend = 'y';
 
171
      }
 
172
   if (stat == ERR_NORMAL)
 
173
      stat = SCFMAP(myimno,F_X_MODE,1,totsize,&iav,&impntr);
 
174
 
 
175
   if (stat != ERR_NORMAL) return (-1);
 
176
 
 
177
   apntr = (float *) mypntr;
 
178
   bpntr = (float *) impntr;
 
179
   for (nr=0; nr<felem; nr++) *bpntr++ = *apntr++;
 
180
   stat = SCFCLO(*retimno);
 
181
 
 
182
   mypntr = impntr;                     /* save new pointer + imno */
 
183
   *retimno = myimno;                   /* felem remains as it is */
 
184
   }
 
185
 
 
186
else
 
187
   {
 
188
   *insize = felem;                     /* just get current size */
 
189
   }
 
190
 
 
191
return (0);
 
192
}
 
193
 
 
194
/*
 
195
 
 
196
*/
 
197
 
 
198
/*++++++++++++++++++++++++++++++
 
199
.PURPOSE     Copy (part of) frame A to frame B, start pixels don't have to be
 
200
             the same
 
201
.ALGORITHM   Note, that all arrays are foreseen for 3-D frames
 
202
.INPUT/OUTPUT
 
203
  call as    Ccopwnd( pntrA, npixA, pntrB, npixB, bgnA, bgnB, endA )
 
204
 
 
205
  input:
 
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
 
213
 
 
214
.RETURNS     nothing
 
215
------------------------------*/
 
216
 
 
217
void Ccopwnd( pntrA, npixA, pntrB, npixB, bgnA, bgnB, endA )
 
218
int   *npixA, *npixB, *bgnA, *bgnB, *endA;
 
219
float *pntrA, *pntrB;
 
220
 
 
221
{
 
222
register int ix, iy, iz, xyz;
 
223
 
 
224
int offsA, offsB, dimwA[3], dimwB[3];
 
225
 
 
226
 
 
227
/*  Make sure, son frame fits into father frame */
 
228
 
 
229
for (xyz=0; xyz<3; xyz++)
 
230
   {
 
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];
 
234
   } 
 
235
 
 
236
offsA = npixA[0] - dimwA[0];
 
237
offsB = npixB[0] - dimwA[0];
 
238
 
 
239
 
 
240
/* Move the pointers to start positions */
 
241
 
 
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));
 
244
 
 
245
/* Copy frame A to frame B */
 
246
 
 
247
for (iz=0; iz<dimwA[2]; iz++)
 
248
   {
 
249
   for (iy=0; iy<dimwA[1]; iy++)
 
250
      {
 
251
      for (ix=0; ix<dimwA[0]; ix++) *pntrB++ = *pntrA++;
 
252
      pntrA += offsA;
 
253
      pntrB += offsB;
 
254
      }
 
255
   }
 
256
}
 
257
 
 
258
/*
 
259
 
 
260
*/
 
261
 
 
262
/*++++++++++++++++++++++++++++++
 
263
.PURPOSE     Copy (part of) frame A to frame B, start pixels don't have to be
 
264
             the same
 
265
.ALGORITHM   straight forward
 
266
.INPUT/OUTPUT
 
267
  call as    Ccopyf1( pntrA, npixA, bgnA, dimwA, pntrB, npixB, bgnB )
 
268
 
 
269
  input:
 
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
 
277
 
 
278
.RETURNS     nothing
 
279
------------------------------*/
 
280
 
 
281
void Ccopyf1( pntrA, npixA, bgnA, dimwA, pntrB, npixB, bgnB )
 
282
int   *npixA, *npixB, *bgnA, *bgnB, *dimwA;
 
283
float *pntrA, *pntrB;
 
284
{
 
285
register int ix, iy;
 
286
 
 
287
int offsA = npixA[0] - dimwA[0],
 
288
    offsB = npixB[0] - dimwA[0];
 
289
      
 
290
/*
 
291
 * Move the pointers to start positions
 
292
 */
 
293
pntrA += bgnA[0] - 1 + npixA[0] * (bgnA[1] - 1);
 
294
pntrB += bgnB[0] - 1 + npixB[0] * (bgnB[1] - 1);
 
295
 
 
296
/*
 
297
 * Copy frame A to frame B
 
298
 */
 
299
for ( iy = 0; iy < dimwA[1]; iy++ )
 
300
    { for ( ix = 0; ix < dimwA[0]; ix++ ) *pntrB++ = *pntrA++;
 
301
      pntrA += offsA;
 
302
      pntrB += offsB;
 
303
    }
 
304
}
 
305
 
 
306
/*
 
307
 
 
308
*/
 
309
 
 
310
/*++++++++++++++++++++++++++++++
 
311
.PURPOSE     Copy a constant value to (part of) frame B
 
312
.ALGORITHM   straight forward
 
313
.INPUT/OUTPUT
 
314
  call as    Ccopyf2( value, pntrB, npixB, bgnB, dimwB )
 
315
 
 
316
  input:
 
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
 
322
 
 
323
.RETURNS     nothing
 
324
------------------------------*/
 
325
 
 
326
#ifdef __STDC__
 
327
void Ccopyf2( float value, float *pntrB, int *npixB, int *bgnB, int *dimwB )
 
328
#else
 
329
void Ccopyf2( value, pntrB, npixB, bgnB, dimwB )
 
330
int   *npixB, *bgnB, *dimwB;
 
331
float value, *pntrB;
 
332
#endif
 
333
{
 
334
register int ix, iy; 
 
335
 
 
336
int offsB = npixB[0] - dimwB[0];
 
337
      
 
338
/*
 
339
 * Move the pointers to start positions
 
340
 */
 
341
pntrB += bgnB[0] - 1 + npixB[0] * (bgnB[1] - 1);
 
342
 
 
343
/*
 
344
 * Copy value to frame B
 
345
 */
 
346
for ( iy = 0; iy < dimwB[1]; iy++ )
 
347
    { for ( ix = 0; ix < dimwB[0]; ix++ ) *pntrB++ = value;
 
348
      pntrB += offsB;
 
349
    }
 
350
}
 
351
 
 
352
/*
 
353
 
 
354
*/
 
355
 
 
356
/*++++++++++++++++++++++++++++++
 
357
.PURPOSE     Copy (part of) floating point frame A to frame B
 
358
.ALGORITHM   straight forward
 
359
.INPUT/OUTPUT
 
360
  call as    Ccopyf( pntrA, pntrB, dim )
 
361
 
 
362
  input:
 
363
          float *pntrA          input frame A
 
364
          float *pntrB          output frame B
 
365
          int   dim             number of items to be copied
 
366
 
 
367
.RETURNS     nothing
 
368
------------------------------*/
 
369
 
 
370
void Ccopyf( pntrA, pntrB, dim )
 
371
int   dim;
 
372
float *pntrA, *pntrB;
 
373
{
 
374
register int ii;      
 
375
 
 
376
for ( ii = 0; ii < dim; ii++ ) *pntrB++ = *pntrA++;
 
377
}
 
378
 
 
379
/*++++++++++++++++++++++++++++++
 
380
.PURPOSE     Copy (part of) integer frame A to frame B
 
381
.ALGORITHM   straight forward
 
382
.INPUT/OUTPUT
 
383
  call as    Ccopyi( pntrA, pntrB, dim )
 
384
 
 
385
  input:
 
386
          int *pntrA            input frame A
 
387
          int *pntrB            output frame B
 
388
          int dim               number of items to be copied
 
389
 
 
390
.RETURNS     nothing
 
391
------------------------------*/
 
392
 
 
393
void Ccopyi( pntrA, pntrB, dim )
 
394
int *pntrA, *pntrB, dim;
 
395
{
 
396
register int ii;      
 
397
 
 
398
for ( ii = 0; ii < dim; ii++ ) *pntrB++ = *pntrA++;
 
399
}
 
400
/*
 
401
 
 
402
*/
 
403
 
 
404
/*++++++++++++++++++++++++++++++
 
405
.PURPOSE     Copy a "big" file in pieces
 
406
.ALGORITHM   straight forward
 
407
.INPUT/OUTPUT
 
408
  call as    Ccopyfx(pntrA,imni,imno,npix,istrip)
 
409
 
 
410
  input:
 
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
 
414
          int   npix            NPIX
 
415
          int   strip           no. of lines to be copied
 
416
 
 
417
.RETURNS     nothing
 
418
------------------------------*/
 
419
 
 
420
#ifdef __STDC__
 
421
 void Ccopyfx(float *pntrA,int imni,int imno,int *npix,int strip)
 
422
#else
 
423
 void Ccopyfx(pntrA,imni,imno,npix,strip)
 
424
 int   imni, imno, strip, *npix;
 
425
 float *pntrA;
 
426
#endif
 
427
 
 
428
{
 
429
int   actvals, felem, ksize, looplm;
 
430
register int   nr;
 
431
 
 
432
char *cpntrA;
 
433
 
 
434
 
 
435
cpntrA = (char *) pntrA;
 
436
looplm = npix[1] / strip;
 
437
if ((npix[1] - (looplm*strip)) > 0) looplm ++;
 
438
 
 
439
felem = 1;
 
440
ksize = npix[0] * strip;
 
441
 
 
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 */
 
447
   }
 
448
 
 
449
}