source: trunk/src/STGrid.cpp @ 2386

Last change on this file since 2386 was 2386, checked in by Takeshi Nakazato, 12 years ago

New Development: No

JIRA Issue: Yes CAS-2816

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No?

Module(s): Module Names change impacts.

Description: Describe your changes here...

Do data selection by TableExprNode? only when it is really needed.


File size: 35.0 KB
Line 
1#include <iostream>
2#include <fstream>
3
4#include <casa/BasicSL/String.h>
5#include <casa/Arrays/Vector.h>
6#include <casa/Arrays/Matrix.h>
7#include <casa/Arrays/Cube.h>
8#include <casa/Arrays/ArrayMath.h>
9#include <casa/Arrays/ArrayIter.h>
10#include <casa/Quanta/Quantum.h>
11#include <casa/Quanta/QuantumHolder.h>
12#include <casa/Utilities/CountedPtr.h>
13#include <casa/Logging/LogIO.h>
14
15#include <tables/Tables/Table.h>
16#include <tables/Tables/TableRecord.h>
17#include <tables/Tables/ExprNode.h>
18#include <tables/Tables/ScalarColumn.h>
19#include <tables/Tables/ArrayColumn.h>
20#include <tables/Tables/TableIter.h>
21
22#include <measures/Measures/MDirection.h>
23
24#include <MathUtils.h>
25
26#include "STGrid.h"
27
28using namespace std ;
29using namespace casa ;
30using namespace asap ;
31
32namespace asap {
33
34// for performance check
35double eToInt = 0.0 ;
36double eGetWeight = 0.0 ;
37
38// constructor
39STGrid::STGrid()
40{
41  init() ;
42}
43
44STGrid::STGrid( const string infile )
45{
46  init() ;
47
48  setFileIn( infile ) ;
49}
50
51void  STGrid::init()
52{
53  ifno_ = -1 ;
54  nx_ = -1 ;
55  ny_ = -1 ;
56  npol_ = 0 ;
57  nchan_ = 0 ;
58  nrow_ = 0 ;
59  cellx_ = 0.0 ;
60  celly_ = 0.0 ;
61  center_ = Vector<Double> ( 2, 0.0 ) ;
62  convType_ = "BOX" ;
63  wtype_ = "UNIFORM" ;
64  convSupport_ = -1 ;
65  userSupport_ = -1 ;
66  convSampling_ = 100 ;
67  nprocessed_ = 0 ;
68  nchunk_ = 0 ;
69}
70
71void STGrid::setFileIn( const string infile )
72{
73  String name( infile ) ;
74  if ( infile_.compare( name ) != 0 ) {
75    infile_ = String( infile ) ;
76    tab_ = Table( infile_ ) ;
77  }
78}
79
80void STGrid::setPolList( vector<unsigned int> pols )
81{
82  pollist_.assign( Vector<uInt>( pols ) ) ;
83}
84
85void STGrid::setScanList( vector<unsigned int> scans )
86{
87  scanlist_.assign( Vector<uInt>( scans ) ) ;
88}
89
90void STGrid::setWeight( const string wType )
91{
92  wtype_ = String( wType ) ;
93  wtype_.upcase() ;
94}
95
96void STGrid::defineImage( int nx,
97                          int ny,
98                          string scellx,
99                          string scelly,
100                          string scenter )
101{
102  ROArrayColumn<Double> dirCol( tab_, "DIRECTION" ) ;
103  Matrix<Double> direction = dirCol.getColumn() ;
104  Double rmax, rmin, dmax, dmin ;
105  minMax( rmin, rmax, direction.row( 0 ) ) ;
106  minMax( dmin, dmax, direction.row( 1 ) ) ;
107
108  Int npx = (Int)nx ;
109  Int npy = (Int)ny ;
110  String cellx( scellx ) ;
111  String celly( scelly ) ;
112  String center( scenter ) ;
113  setupGrid( npx, npy,
114             cellx, celly,
115             rmin, rmax,
116             dmin, dmax,
117             center ) ;
118}
119 
120void STGrid::setFunc( string convType,
121                      int convSupport )
122{
123  convType_ = String( convType ) ;
124  convType_.upcase() ;
125  userSupport_ = (Int)convSupport ;
126}
127
128#define NEED_UNDERSCORES
129#if defined(NEED_UNDERSCORES)
130#define ggridsd ggridsd_
131#endif
132extern "C" {
133   void ggridsd(Double*,
134                const Complex*,
135                Int*,
136                Int*,
137                Int*,
138                const Int*,
139                const Int*,
140                const Float*,
141                Int*,
142                Int*,
143                Complex*,
144                Float*,
145                Int*,
146                Int*,
147                Int *,
148                Int *,
149                Int*,
150                Int*,
151                Float*,
152                Int*,
153                Int*,
154                Double*);
155}
156void STGrid::call_ggridsd( Array<Double> &xypos,
157                           Array<Complex> &spectra,
158                           Int &nvispol,
159                           Int &nvischan,
160                           Array<Int> &flagtra,
161                           Array<Int> &flagrow,
162                           Array<Float> &weight,
163                           Int &nrow,
164                           Int &irow,
165                           Array<Complex> &gdata,
166                           Array<Float> &gwgt,
167                           Int &nx,
168                           Int &ny,
169                           Int &npol,
170                           Int &nchan,
171                           Int &support,
172                           Int &sampling,
173                           Vector<Float> &convFunc,
174                           Int *chanMap,
175                           Int *polMap )
176{
177  // parameters for gridding
178  Int idopsf = 0 ;
179  Int len = npol*nchan ;
180  Double *sumw_p = new Double[len] ;
181  {
182    Double *work_p = sumw_p ;
183    for ( Int i = 0 ; i < len ; i++ ) {
184      *work_p = 0.0 ;
185      work_p++ ;
186    }
187  }
188
189  // prepare pointer
190  Bool deletePos, deleteData, deleteWgt, deleteFlag, deleteFlagR, deleteConv, deleteDataG, deleteWgtG ;
191  Double *xy_p = xypos.getStorage( deletePos ) ;
192  const Complex *values_p = spectra.getStorage( deleteData ) ;
193  const Int *flag_p = flagtra.getStorage( deleteFlag ) ;
194  const Int *rflag_p = flagrow.getStorage( deleteFlagR ) ;
195  const Float *wgt_p = weight.getStorage( deleteWgt ) ;
196  Complex *grid_p = gdata.getStorage( deleteDataG ) ;
197  Float *wgrid_p = gwgt.getStorage( deleteWgtG ) ;
198  Float *conv_p = convFunc.getStorage( deleteConv ) ;
199
200  // pass copy of irow to ggridsd since it will be modified in theroutine
201  Int irowCopy = irow ;
202     
203  // call ggridsd
204  ggridsd( xy_p,
205           values_p,
206           &nvispol,
207           &nvischan,
208           &idopsf,
209           flag_p,
210           rflag_p,
211           wgt_p,
212           &nrow,
213           &irowCopy,
214           grid_p,
215           wgrid_p,
216           &nx,
217           &ny,
218           &npol,
219           &nchan,
220           &support,
221           &sampling,
222           conv_p,
223           chanMap,
224           polMap,
225           sumw_p ) ;
226
227  // finalization
228  xypos.putStorage( xy_p, deletePos ) ;
229  spectra.freeStorage( values_p, deleteData ) ;
230  flagtra.freeStorage( flag_p, deleteFlag ) ;
231  flagrow.freeStorage( rflag_p, deleteFlagR ) ;
232  weight.freeStorage( wgt_p, deleteWgt ) ;
233  gdata.putStorage( grid_p, deleteDataG ) ;
234  gwgt.putStorage( wgrid_p, deleteWgtG ) ;
235  convFunc.putStorage( conv_p, deleteConv ) ;
236  delete sumw_p ;
237}
238
239Bool STGrid::pastEnd()
240{
241  LogIO os( LogOrigin("STGrid","pastEnd",WHERE) ) ;
242  Bool b = nprocessed_ >= nrow_ ;
243  return b ;
244}
245
246void STGrid::grid()
247{
248  LogIO os( LogOrigin("STGrid", "grid", WHERE) ) ;
249  double t0,t1 ;
250
251  // data selection
252  t0 = mathutil::gettimeofday_sec() ;
253  selectData() ;
254  t1 = mathutil::gettimeofday_sec() ;
255  os << "selectData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
256
257  setupArray() ;
258
259  if ( wtype_.compare("UNIFORM") != 0 &&
260       wtype_.compare("TINT") != 0 &&
261       wtype_.compare("TSYS") != 0 &&
262       wtype_.compare("TINTSYS") != 0 ) {
263    LogIO os( LogOrigin("STGrid", "grid", WHERE) ) ;
264    os << LogIO::WARN << "Unsupported weight type '" << wtype_ << "', apply UNIFORM weight" << LogIO::POST ;
265    wtype_ = "UNIFORM" ;
266  }
267
268  // grid parameter
269  os << LogIO::DEBUGGING ;
270  os << "----------" << endl ;
271  os << "Data selection summary" << endl ;
272  os << "   ifno = " << ifno_ << endl ;
273  os << "   pollist = " << pollist_ << endl ;
274  os << "   scanlist = " << scanlist_ << endl ;
275  os << "----------" << endl ;
276  os << "Grid parameter summary" << endl ;
277  os << "   (nx,ny) = (" << nx_ << "," << ny_ << ")" << endl ;
278  os << "   (cellx,celly) = (" << cellx_ << "," << celly_ << ")" << endl ;
279  os << "   center = " << center_ << endl ;
280  os << "   weighting = " << wtype_ << endl ;
281  os << "   convfunc = " << convType_ << " with support " << convSupport_ << endl ;
282  os << "----------" << LogIO::POST ;
283  os << LogIO::NORMAL ;
284
285  Bool doAll = examine() ;
286
287  if ( doAll )
288    gridPerPol() ;
289  else
290    gridPerRow() ;
291}
292
293Bool STGrid::examine()
294{
295  // TODO: nchunk_ must be determined from nchan_, npol_, and (nx_,ny_)
296  //       by considering data size to be allocated for ggridsd input/output
297  nchunk_ = 400 ;
298  Bool b = nchunk_ >= nrow_ ;
299  nchunk_ = min( nchunk_, nrow_ ) ;
300  return b ;
301}
302
303void STGrid::gridPerRow()
304{
305  LogIO os( LogOrigin("STGrid", "gridPerRow", WHERE) ) ;
306  double t0, t1 ;
307
308  // convolution kernel
309  Vector<Float> convFunc ;
310  t0 = mathutil::gettimeofday_sec() ;
311  setConvFunc( convFunc ) ;
312  t1 = mathutil::gettimeofday_sec() ;
313  os << "setConvFunc: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
314
315  // grid data
316  Int gnx = nx_ ;
317  Int gny = ny_ ;
318  // Extend grid plane with convSupport_
319//   Int gnx = nx_+convSupport_*2 ;
320//   Int gny = ny_+convSupport_*2 ;
321  IPosition gshape( 4, gnx, gny, npol_, nchan_ ) ;
322  Array<Complex> gdataArrC( gshape, 0.0 ) ;
323  // 2011/12/20 TN
324  // data_ and gwgtArr share storage
325  data_.resize( gshape ) ;
326  data_ = 0.0 ;
327  Array<Float> gwgtArr( data_ ) ;
328
329  // parameters for gridding
330  Int *chanMap = new Int[nchan_] ;
331  {
332    Int *work_p = chanMap ;
333    for ( Int i = 0 ; i < nchan_ ; i++ ) {
334      *work_p = i ;
335      work_p++ ;
336    }
337  }
338  Int *polMap = new Int[1] ;
339  Int nvispol = 1 ;
340  Int irow = -1 ;
341
342  // for performance check
343  double eGetData = 0.0 ;
344  double eToPixel = 0.0 ;
345  double eGGridSD = 0.0 ;
346  double eInitPol = 0.0 ;
347
348  for ( Int ipol = 0 ; ipol < npol_ ; ipol++ ) {
349    t0 = mathutil::gettimeofday_sec() ;
350    initPol( ipol ) ;
351    t1 = mathutil::gettimeofday_sec() ;
352    eInitPol += t1-t0 ;
353   
354    polMap[0] = ipol ;
355
356    os << "start pol " << ipol << LogIO::POST ;
357
358    while( !pastEnd() ) {
359      // data storage
360      IPosition cshape( 3, npol_, nchan_, nchunk_ ) ;
361      IPosition mshape( 2, npol_, nchunk_ ) ;
362      IPosition vshape( 1, nchunk_ ) ;
363      IPosition dshape( 2, 2, nchunk_ ) ;
364      IPosition wshape( 2, nchan_, nchunk_ ) ;
365      Array<Complex> spectra( wshape ) ;
366      Array<Int> flagtra( wshape ) ;
367      Array<Int> rflag( vshape ) ;
368      Array<Float> weight( wshape ) ;
369      Array<Double> direction( dshape ) ;
370      Array<Double> xypos( dshape ) ;
371     
372      spectraF_.resize( wshape ) ;
373      flagtraUC_.resize( wshape ) ;
374      rflagUI_.resize( vshape ) ;
375
376      // retrieve data
377      t0 = mathutil::gettimeofday_sec() ;
378      Int nrow = getDataChunk( spectra, direction, flagtra, rflag, weight ) ;
379      t1 = mathutil::gettimeofday_sec() ;
380      eGetData += t1-t0 ;
381     
382      // world -> pixel
383      t0 = mathutil::gettimeofday_sec() ;
384      toPixel( direction, xypos ) ;
385      t1 = mathutil::gettimeofday_sec() ;
386      eToPixel += t1-t0 ;
387   
388      // call ggridsd
389      t0 = mathutil::gettimeofday_sec() ;
390      call_ggridsd( xypos,
391                    spectra,
392                    nvispol,
393                    nchan_,
394                    flagtra,
395                    rflag,
396                    weight,
397                    nrow,
398                    irow,
399                    gdataArrC,
400                    gwgtArr,
401                    gnx,
402                    gny,
403                    npol_,
404                    nchan_,
405                    convSupport_,
406                    convSampling_,
407                    convFunc,
408                    chanMap,
409                    polMap ) ;
410      t1 = mathutil::gettimeofday_sec() ;
411      eGGridSD += t1-t0 ;
412
413    }
414
415    os << "end pol " << ipol << LogIO::POST ;
416
417    nprocessed_ = 0 ;
418  }
419  os << "initPol: elapsed time is " << eInitPol << " sec." << LogIO::POST ;
420  os << "getData: elapsed time is " << eGetData-eToInt-eGetWeight << " sec." << LogIO::POST ;
421  os << "toPixel: elapsed time is " << eToPixel << " sec." << LogIO::POST ;
422  os << "ggridsd: elapsed time is " << eGGridSD << " sec." << LogIO::POST ;
423  os << "toInt: elapsed time is " << eToInt << " sec." << LogIO::POST ;
424  os << "getWeight: elapsed time is " << eGetWeight << " sec." << LogIO::POST ;
425 
426  delete polMap ;
427  delete chanMap ;
428
429  // set data
430  setData( gdataArrC, gwgtArr ) ;
431
432}
433
434void STGrid::gridPerPol()
435{
436  LogIO os( LogOrigin("STGrid", "gridPerPol", WHERE) ) ;
437  double t0, t1 ;
438
439  // convolution kernel
440  Vector<Float> convFunc ;
441  t0 = mathutil::gettimeofday_sec() ;
442  setConvFunc( convFunc ) ;
443  t1 = mathutil::gettimeofday_sec() ;
444  os << "setConvFunc: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
445
446  // prepare grid data storage
447  Int gnx = nx_ ;
448  Int gny = ny_ ;
449//   // Extend grid plane with convSupport_
450//   Int gnx = nx_+convSupport_*2 ;
451//   Int gny = ny_+convSupport_*2 ;
452  IPosition gshape( 4, gnx, gny, npol_, nchan_ ) ;
453  Array<Complex> gdataArrC( gshape, 0.0 ) ;
454  //Array<Float> gwgtArr( gshape, 0.0 ) ;
455  // 2011/12/20 TN
456  // data_ and weight array shares storage
457  data_.resize( gshape ) ;
458  data_ = 0.0 ;
459  Array<Float> gwgtArr( data_ ) ;
460
461  // to read data from the table
462  IPosition mshape( 2, nchan_, nrow_ ) ;
463  IPosition dshape( 2, 2, nrow_ ) ;
464  Array<Complex> spectra( mshape ) ;
465  Array<Double> direction( dshape ) ;
466  Array<Int> flagtra( mshape ) ;
467  Array<Int> rflag( IPosition(1,nrow_) ) ;
468  Array<Float> weight( mshape ) ;
469  Array<Double> xypos( dshape ) ;
470
471  // maps
472  Int *chanMap = new Int[nchan_] ;
473  {
474    Int *work_p = chanMap ;
475    for ( Int i = 0 ; i < nchan_ ; i++ ) {
476      *work_p = i ;
477      work_p++ ;
478    }
479  }
480  Int *polMap = new Int[1] ;
481
482  // some parameters for ggridsd
483  Int nvispol = 1 ;
484  Int irow = -1 ;
485 
486  // for performance check
487  double eInitPol = 0.0 ;
488  double eGetData = 0.0 ;
489  double eToPixel = 0.0 ;
490  double eGGridSD = 0.0 ;
491  double eToInt = 0.0 ;
492
493  for ( Int ipol = 0 ; ipol < npol_ ; ipol++ ) {
494    t0 = mathutil::gettimeofday_sec() ;
495    initPol( ipol ) ;
496    t1 = mathutil::gettimeofday_sec() ;
497    eInitPol += t1-t0 ;
498
499    // retrieve data
500    t0 = mathutil::gettimeofday_sec() ;
501    getDataPerPol( spectra, direction, flagtra, rflag, weight ) ;
502    t1 = mathutil::gettimeofday_sec() ;
503    eGetData += t1-t0 ;
504   
505    // world -> pixel
506    t0 = mathutil::gettimeofday_sec() ;
507    toPixel( direction, xypos ) ; 
508    t1 = mathutil::gettimeofday_sec() ;
509    eToPixel += t1-t0 ;
510   
511    // call ggridsd
512    polMap[0] = ipol ;
513    t0 = mathutil::gettimeofday_sec() ;
514    call_ggridsd( xypos,
515                  spectra,
516                  nvispol,
517                  nchan_,
518                  flagtra,
519                  rflag,
520                  weight,
521                  nrow_,
522                  irow,
523                  gdataArrC,
524                  gwgtArr,
525                  gnx,
526                  gny,
527                  npol_,
528                  nchan_,
529                  convSupport_,
530                  convSampling_,
531                  convFunc,
532                  chanMap,
533                  polMap ) ;
534    t1 = mathutil::gettimeofday_sec() ;
535    eGGridSD += t1-t0 ;
536  }
537  os << "initPol: elapsed time is " << eInitPol << " sec." << LogIO::POST ;
538  os << "getData: elapsed time is " << eGetData-eToInt-eGetWeight << " sec." << LogIO::POST ;
539  os << "toPixel: elapsed time is " << eToPixel << " sec." << LogIO::POST ;
540  os << "ggridsd: elapsed time is " << eGGridSD << " sec." << LogIO::POST ;
541  os << "toInt: elapsed time is " << eToInt << " sec." << LogIO::POST ;
542  os << "getWeight: elapsed time is " << eGetWeight << " sec." << LogIO::POST ;
543
544  // delete maps
545  delete polMap ;
546  delete chanMap ;
547
548  setData( gdataArrC, gwgtArr ) ;
549//   os << "gdataArr = " << gdataArr << LogIO::POST ;
550//   os << "gwgtArr = " << gwgtArr << LogIO::POST ;
551//   os << "data_ " << data_ << LogIO::POST ;
552}
553
554void STGrid::initPol( Int ipol )
555{
556  LogIO os( LogOrigin("STGrid","initPol",WHERE) ) ;
557  if ( npolOrg_ == 1 ) {
558    os << "single polarization data." << LogIO::POST ;
559    ptab_ = tab_ ;
560  }
561  else
562    ptab_ = tab_( tab_.col("POLNO") == (uInt)ipol ) ;
563
564  attach( ptab_ ) ;
565}
566
567void STGrid::setData( Array<Complex> &gdata,
568                      Array<Float> &gwgt )
569{
570  // 2011/12/20 TN
571  // gwgt and data_ share storage
572  LogIO os( LogOrigin("STGrid","setData",WHERE) ) ;
573  double t0, t1 ;
574  t0 = mathutil::gettimeofday_sec() ;
575  uInt len = data_.nelements() ;
576  const Complex *w1_p ;
577  Float *w2_p ;
578  Bool b1, b2 ;
579  const Complex *gdata_p = gdata.getStorage( b1 ) ;
580  Float *gwgt_p = data_.getStorage( b2 ) ;
581  w1_p = gdata_p ;
582  w2_p = gwgt_p ;
583  for ( uInt i = 0 ; i < len ; i++ ) {
584    if ( *w2_p > 0.0 ) *w2_p = (*w1_p).real() / *w2_p ;
585    w1_p++ ;
586    w2_p++ ;
587  }
588  gdata.freeStorage( gdata_p, b1 ) ;
589  data_.putStorage( gwgt_p, b2 ) ;
590  t1 = mathutil::gettimeofday_sec() ;
591  os << "setData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
592}
593
594void STGrid::setupGrid( Int &nx,
595                        Int &ny,
596                        String &cellx,
597                        String &celly,
598                        Double &xmin,
599                        Double &xmax,
600                        Double &ymin,
601                        Double &ymax,
602                        String &center )
603{
604  LogIO os( LogOrigin("STGrid","setupGrid",WHERE) ) ;
605  //cout << "nx=" << nx << ", ny=" << ny << endl ;
606
607  // center position
608  if ( center.size() == 0 ) {
609    center_(0) = 0.5 * ( xmin + xmax ) ;
610    center_(1) = 0.5 * ( ymin + ymax ) ;
611  }
612  else {
613    String::size_type pos0 = center.find( " " ) ;
614    if ( pos0 == String::npos ) {
615      throw AipsError( "bad string format in parameter center" ) ;
616    }
617    String::size_type pos1 = center.find( " ", pos0+1 ) ;
618    String typestr, xstr, ystr ;
619    if ( pos1 != String::npos ) {
620      typestr = center.substr( 0, pos0 ) ;
621      xstr = center.substr( pos0+1, pos1-pos0 ) ;
622      ystr = center.substr( pos1+1 ) ;
623      // todo: convert to J2000 (or direction ref for DIRECTION column)
624    }
625    else {
626      typestr = "J2000" ;
627      xstr = center.substr( 0, pos0 ) ;
628      ystr = center.substr( pos0+1 ) ;
629    }
630    QuantumHolder qh ;
631    String err ;
632    qh.fromString( err, xstr ) ;
633    Quantum<Double> xcen = qh.asQuantumDouble() ;
634    qh.fromString( err, ystr ) ;
635    Quantum<Double> ycen = qh.asQuantumDouble() ;
636    center_(0) = xcen.getValue( "rad" ) ;
637    center_(1) = ycen.getValue( "rad" ) ;
638  }
639
640
641  nx_ = nx ;
642  ny_ = ny ;
643  if ( nx < 0 && ny > 0 ) {
644    nx_ = ny ;
645    ny_ = ny ;
646  }
647  if ( ny < 0 && nx > 0 ) {
648    nx_ = nx ;
649    ny_ = nx ;
650  }
651
652  //Double wx = xmax - xmin ;
653  //Double wy = ymax - ymin ;
654  Double wx = max( abs(xmax-center_(0)), abs(xmin-center_(0)) ) * 2 ;
655  Double wy = max( abs(ymax-center_(1)), abs(ymin-center_(1)) ) * 2 ;
656  // take 10% margin
657  wx *= 1.10 ;
658  wy *= 1.10 ;
659
660  Quantum<Double> qcellx ;
661  Quantum<Double> qcelly ;
662  //cout << "nx_ = " << nx_ << ",  ny_ = " << ny_ << endl ;
663  if ( cellx.size() != 0 && celly.size() != 0 ) {
664    readQuantity( qcellx, cellx ) ;
665    readQuantity( qcelly, celly ) ;
666  }
667  else if ( celly.size() != 0 ) {
668    os << "Using celly to x-axis..." << LogIO::POST ;
669    readQuantity( qcelly, celly ) ;
670    qcellx = qcelly ;
671  }
672  else if ( cellx.size() != 0 ) {
673    os << "Using cellx to y-axis..." << LogIO::POST ;
674    readQuantity( qcellx, cellx ) ;
675    qcelly = qcellx ;
676  }
677  else {
678    if ( nx_ < 0 ) {
679      os << "No user preference in grid setting. Using default..." << LogIO::POST ;
680      readQuantity( qcellx, "1.0arcmin" ) ;
681      qcelly = qcellx ;
682    }
683    else {
684      if ( wx == 0.0 ) {
685        os << "Using default spatial extent (10arcmin) in x" << LogIO::POST ;
686        wx = 0.00290888 ;
687      }
688      if ( wy == 0.0 ) {
689        os << "Using default spatial extent (10arcmin) in y" << LogIO::POST ;
690        wy = 0.00290888 ;
691      }
692      qcellx = Quantum<Double>( wx/nx_, "rad" ) ;
693      qcelly = Quantum<Double>( wy/ny_, "rad" ) ;
694    }
695  }
696  cellx_ = qcellx.getValue( "rad" ) ;
697  celly_ = qcelly.getValue( "rad" ) ;
698  if ( nx_ < 0 ) {
699    if ( wx == 0.0 ) {
700      os << "Using default spatial extent (10arcmin) in x" << LogIO::POST ;
701      wx = 0.00290888 ;
702    }
703    if ( wy == 0.0 ) {
704      os << "Using default spatial extent (10arcmin) in y" << LogIO::POST ;
705      wy = 0.00290888 ;
706    }
707    nx_ = Int( ceil( wx/cellx_ ) ) ;
708    ny_ = Int( ceil( wy/celly_ ) ) ;
709  }
710}
711
712void STGrid::selectData()
713{
714  LogIO os( LogOrigin("STGrid","selectData",WHERE) ) ;   
715  Int ifno = ifno_ ;
716  Table taborg( infile_ ) ;
717  if ( ifno == -1 ) {
718    ROScalarColumn<uInt> ifnoCol( taborg, "IFNO" ) ;
719    ifno = ifnoCol( 0 ) ;
720    os << LogIO::WARN
721       << "IFNO is not given. Using default IFNO: " << ifno << LogIO::POST ;
722  }
723  TableExprNode node ;
724  if ( isMultiIF( taborg ) ) {
725    os << "apply selection on IFNO" << LogIO::POST ;
726    node = taborg.col("IFNO") == ifno ;
727  }
728  if ( scanlist_.size() > 0 ) {
729    os << "apply selection on SCANNO" << LogIO::POST ;
730    node = node && taborg.col("SCANNO").in( scanlist_ ) ;
731  }
732  if ( node.isNull() ) {
733    tab_ = taborg ;
734  }
735  else {
736    tab_ = taborg( node ) ;
737  }
738  if ( tab_.nrow() == 0 ) {
739    os << LogIO::SEVERE
740       << "No corresponding rows for given selection: IFNO " << ifno ;
741    if ( scanlist_.size() > 0 )
742      os << " SCANNO " << scanlist_ ;
743    os << LogIO::EXCEPTION ;
744  }
745}
746
747Bool STGrid::isMultiIF( Table &tab )
748{
749  ROScalarColumn<uInt> ifnoCol( tab, "IFNO" ) ;
750  Vector<uInt> ifnos = ifnoCol.getColumn() ;
751  return anyNE( ifnos, ifnos[0] ) ;
752}
753
754void STGrid::attach( Table &tab )
755{
756  // attach to table
757  spectraCol_.attach( tab, "SPECTRA" ) ;
758  flagtraCol_.attach( tab, "FLAGTRA" ) ;
759  directionCol_.attach( tab, "DIRECTION" ) ;
760  flagRowCol_.attach( tab, "FLAGROW" ) ;
761  tsysCol_.attach( tab, "TSYS" ) ;
762  intervalCol_.attach( tab, "INTERVAL" ) ;
763//   Vector<String> colnames( 6 ) ;
764//   colnames[0] = "SPECTRA" ;
765//   colnames[1] = "FLAGTRA" ;
766//   colnames[2] = "DIRECTION" ;
767//   colnames[3] = "FLAGROW" ;
768//   colnames[4] = "TSYS" ;
769//   colnames[5] = "INTERVAL" ;
770//   row_ = ROTableRow( tab_, colnames ) ;
771//   const TableRecord &rec = row_.record() ;
772//   spectraRF_.attachToRecord( rec, colnames[0] ) ;
773//   flagtraRF_.attachToRecord( rec, colnames[1] ) ;
774//   directionRF_.attachToRecord( rec, colnames[2] ) ;
775//   flagRowRF_.attachToRecord( rec, colnames[3] ) ;
776//   tsysRF_.attachToRecord( rec, colnames[4] ) ;
777//   intervalRF_.attachToRecord( rec, colnames[5] ) ;
778}
779
780void STGrid::getDataPerPol( Array<Float> &spectra,
781                            Array<Double> &direction,
782                            Array<uChar> &flagtra,
783                            Array<uInt> &rflag,
784                            Array<Float> &weight )
785{
786  LogIO os( LogOrigin("STGrid","getDataPerPol",WHERE) ) ;
787
788  // 2011/12/22 TN
789  // weight and tsys shares its storage
790  Array<Float> tsys( weight ) ;
791  Array<Double> tint( rflag.shape() ) ;
792
793  Vector<uInt> rflagVec( rflag ) ;
794  Vector<Double> tintVec( tint ) ;
795
796  spectraCol_.getColumn( spectra ) ;
797  flagtraCol_.getColumn( flagtra ) ;
798  flagRowCol_.getColumn( rflagVec ) ;
799  directionCol_.getColumn( direction ) ;
800  intervalCol_.getColumn( tintVec ) ;
801  Vector<Float> tsysTemp = tsysCol_( 0 ) ;
802  if ( tsysTemp.nelements() == (uInt)nchan_ ) {
803    tsysCol_.getColumn( tsys ) ;
804  }
805  else {
806    tsys = tsysTemp[0] ;
807  }
808 
809  double t0,t1 ;
810  t0 = mathutil::gettimeofday_sec() ;
811  getWeight( weight, tsys, tint ) ;
812  t1 = mathutil::gettimeofday_sec() ;
813  eGetWeight += t1-t0 ;
814}
815
816void STGrid::getDataPerPol( Array<Complex> &spectra,
817                            Array<Double> &direction,
818                            Array<Int> &flagtra,
819                            Array<Int> &rflag,
820                            Array<Float> &weight )
821{
822  LogIO os( LogOrigin("STGrid","getDataPerPol",WHERE) ) ;
823  double t0, t1 ;
824
825  Array<uChar> flagUC( flagtra.shape() ) ;
826  Array<uInt> rflagUI( rflag.shape() ) ;
827  Array<Float> spectraF( spectra.shape() ) ;
828  getDataPerPol( spectraF, direction, flagUC, rflagUI, weight ) ;
829
830  convertArray( spectra, spectraF ) ;
831  t0 = mathutil::gettimeofday_sec() ;
832  toInt( flagUC, flagtra ) ;
833  toInt( rflagUI, rflag ) ;
834  t1 = mathutil::gettimeofday_sec() ;
835  eToInt += t1-t0 ;
836  //os << "toInt: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
837}
838
839Int STGrid::getDataChunk( Array<Complex> &spectra,
840                          Array<Double> &direction,
841                          Array<Int> &flagtra,
842                          Array<Int> &rflag,
843                          Array<Float> &weight )
844{
845  LogIO os( LogOrigin("STGrid","getDataChunk",WHERE) ) ;
846  Int nrow = getDataChunk( spectraF_, direction, flagtraUC_, rflagUI_, weight ) ;
847  if ( nrow < nchunk_ ) {
848    spectra.resize( spectraF_.shape() ) ;
849    flagtra.resize( flagtraUC_.shape() ) ;
850    rflag.resize( rflagUI_.shape() ) ;
851  }
852  double t0, t1 ;
853  t0 = mathutil::gettimeofday_sec() ;
854  convertArray( spectra, spectraF_ ) ;
855  toInt( flagtraUC_, flagtra ) ;
856  toInt( rflagUI_, rflag ) ;
857  t1 = mathutil::gettimeofday_sec() ;
858  eToInt = t1 - t0 ;
859 
860  return nrow ;
861}
862
863Int STGrid::getDataChunk( Array<Float> &spectra,
864                          Array<Double> &direction,
865                          Array<uChar> &flagtra,
866                          Array<uInt> &rflag,
867                          Array<Float> &weight )
868{
869  LogIO os( LogOrigin("STGrid","getDataChunk",WHERE) ) ;
870  Int nrow = spectra.shape()[1] ;
871  Int remainingRow = nrow_ - nprocessed_ ;
872  if ( remainingRow < nrow ) {
873    nrow = remainingRow ;
874    IPosition mshape( 2, nchan_, nrow ) ;
875    IPosition vshape( 1, nrow ) ;
876    spectra.resize( mshape ) ;
877    flagtra.resize( mshape ) ;
878    direction.resize( IPosition(2,2,nrow) ) ;
879    rflag.resize( vshape ) ;
880    weight.resize( mshape ) ;
881  }
882  // 2011/12/22 TN
883  // tsys shares its storage with weight
884  Array<Float> tsys( weight ) ;
885  Array<Double> tint( rflag.shape() ) ;
886
887  Vector<uInt> rflagVec( rflag ) ;
888  Vector<Double> tintVec( tint ) ;
889
890  RefRows rows( nprocessed_, nprocessed_+nrow-1, 1 ) ;
891  //os<<LogIO::DEBUGGING<<"nprocessed_="<<nprocessed_<<": rows.nrows()="<<rows.nrows()<<LogIO::POST ;
892  spectraCol_.getColumnCells( rows, spectra ) ;
893  flagtraCol_.getColumnCells( rows, flagtra ) ;
894  directionCol_.getColumnCells( rows, direction ) ;
895  flagRowCol_.getColumnCells( rows, rflagVec ) ;
896  intervalCol_.getColumnCells( rows, tintVec ) ;
897  Vector<Float> tsysTemp = tsysCol_( nprocessed_ ) ;
898  if ( tsysTemp.nelements() == (uInt)nchan_ )
899    tsysCol_.getColumnCells( rows, tsys ) ;
900  else
901    tsys = tsysTemp[0] ;
902
903  double t0,t1 ;
904  t0 = mathutil::gettimeofday_sec() ;
905  getWeight( weight, tsys, tint ) ;
906  t1 = mathutil::gettimeofday_sec() ;
907  eGetWeight += t1-t0 ;
908
909  nprocessed_ += nrow ;
910 
911  return nrow ;
912}
913
914void STGrid::setupArray()
915{
916  LogIO os( LogOrigin("STGrid","setupArray",WHERE) ) ;
917  ROScalarColumn<uInt> polnoCol( tab_, "POLNO" ) ;
918  Vector<uInt> pols = polnoCol.getColumn() ;
919  //os << pols << LogIO::POST ;
920  Vector<uInt> pollistOrg ;
921  npolOrg_ = 0 ;
922  uInt polno ;
923  for ( uInt i = 0 ; i < polnoCol.nrow() ; i++ ) {
924    //polno = polnoCol( i ) ;
925    polno = pols( i ) ;
926    if ( allNE( pollistOrg, polno ) ) {
927      pollistOrg.resize( npolOrg_+1, True ) ;
928      pollistOrg[npolOrg_] = polno ;
929      npolOrg_++ ;
930    }
931  }
932  if ( pollist_.size() == 0 )
933    pollist_ = pollistOrg ;
934  else {
935    Vector<uInt> newlist ;
936    uInt newsize = 0 ;
937    for ( uInt i = 0 ; i < pollist_.size() ; i++ ) {
938      if ( anyEQ( pollistOrg, pollist_[i] ) ) {
939        newlist.resize( newsize+1, True ) ;
940        newlist[newsize] = pollist_[i] ;
941        newsize++ ;
942      }
943    }
944    pollist_.assign( newlist ) ;
945  }
946  npol_ = pollist_.size() ;
947  if ( npol_ == 0 ) {
948    os << LogIO::SEVERE << "Empty pollist" << LogIO::EXCEPTION ;
949  }
950  nrow_ = tab_.nrow() / npolOrg_ ;
951  ROArrayColumn<uChar> tmpCol( tab_, "FLAGTRA" ) ;
952  nchan_ = tmpCol( 0 ).nelements() ;
953//   os << "npol_ = " << npol_ << "(" << pollist_ << ")" << endl
954//      << "nchan_ = " << nchan_ << endl
955//      << "nrow_ = " << nrow_ << LogIO::POST ;
956}
957
958void STGrid::getWeight( Array<Float> &w,
959                              Array<Float> &tsys,
960                              Array<Double> &tint )
961{
962  LogIO os( LogOrigin("STGrid","getWeight",WHERE) ) ;
963
964  // 2011/12/22 TN
965  // w (weight) and tsys share storage
966  IPosition refShape = tsys.shape() ;
967  Int nchan = refShape[0] ;
968  Int nrow = refShape[1] ;
969//   os << "nchan=" << nchan << ", nrow=" << nrow << LogIO::POST ;
970//   os << "w.shape()=" << w.shape() << endl
971//      << "tsys.shape()=" << tsys.shape() << endl
972//      << "tint.shape()=" << tint.shape() << LogIO::POST ;
973
974  // set weight
975  if ( wtype_.compare( "UNIFORM" ) == 0 ) {
976    w = 1.0 ;
977  }
978  else if ( wtype_.compare( "TINT" ) == 0 ) {
979    Bool b0, b1 ;
980    Float *w_p = w.getStorage( b0 ) ;
981    Float *w0_p = w_p ;
982    const Double *ti_p = tint.getStorage( b1 ) ;
983    const Double *w1_p = ti_p ;
984    for ( Int irow = 0 ; irow < nrow ; irow++ ) {
985      for ( Int ichan = 0 ; ichan < nchan ; ichan++ ) {
986        *w0_p = *w1_p ;
987        w0_p++ ;
988      }
989      w1_p++ ;
990    }
991    w.putStorage( w_p, b0 ) ;
992    tint.freeStorage( ti_p, b1 ) ;
993  }
994  else if ( wtype_.compare( "TSYS" ) == 0 ) {
995    Bool b0 ;
996    Float *w_p = w.getStorage( b0 ) ;
997    Float *w0_p = w_p ;
998    for ( Int irow = 0 ; irow < nrow ; irow++ ) {
999      for ( Int ichan = 0 ; ichan < nchan ; ichan++ ) {
1000        Float temp = *w0_p ;
1001        *w0_p = 1.0 / ( temp * temp ) ;
1002        w0_p++ ;
1003      }
1004    }
1005    w.putStorage( w_p, b0 ) ;
1006  }
1007  else if ( wtype_.compare( "TINTSYS" ) == 0 ) {
1008    Bool b0, b1 ;
1009    Float *w_p = w.getStorage( b0 ) ;
1010    Float *w0_p = w_p ;
1011    const Double *ti_p = tint.getStorage( b1 ) ;
1012    const Double *w1_p = ti_p ;
1013    for ( Int irow = 0 ; irow < nrow ; irow++ ) {
1014      Float interval = *w1_p ;
1015      for ( Int ichan = 0 ; ichan < nchan ; ichan++ ) {
1016        Float temp = *w0_p ;
1017        *w0_p = interval / ( temp * temp ) ;
1018        w0_p++ ;
1019      }
1020      w1_p++ ;
1021    }
1022    w.putStorage( w_p, b0 ) ;
1023    tint.freeStorage( ti_p, b1 ) ;
1024  }
1025  else {
1026    //LogIO os( LogOrigin("STGrid", "getWeight", WHERE) ) ;
1027    //os << LogIO::WARN << "Unsupported weight type '" << wtype_ << "', apply UNIFORM weight" << LogIO::POST ;
1028    w = 1.0 ;
1029  }
1030}
1031
1032void STGrid::toInt( Array<uChar> &u, Array<Int> &v )
1033{
1034  uInt len = u.nelements() ;
1035  Int *int_p = new Int[len] ;
1036  Bool deleteIt ;
1037  const uChar *data_p = u.getStorage( deleteIt ) ;
1038  Int *i_p = int_p ;
1039  const uChar *u_p = data_p ;
1040  for ( uInt i = 0 ; i < len ; i++ ) {
1041    *i_p = ( *u_p == 0 ) ? 0 : 1 ;
1042    i_p++ ;
1043    u_p++ ;
1044  }
1045  u.freeStorage( data_p, deleteIt ) ;
1046  v.takeStorage( u.shape(), int_p, TAKE_OVER ) ;
1047}
1048
1049void STGrid::toInt( Array<uInt> &u, Array<Int> &v )
1050{
1051  uInt len = u.nelements() ;
1052  Int *int_p = new Int[len] ;
1053  Bool deleteIt ;
1054  const uInt *data_p = u.getStorage( deleteIt ) ;
1055  Int *i_p = int_p ;
1056  const uInt *u_p = data_p ;
1057  for ( uInt i = 0 ; i < len ; i++ ) {
1058    *i_p = ( *u_p == 0 ) ? 0 : 1 ;
1059    i_p++ ;
1060    u_p++ ;
1061  }
1062  u.freeStorage( data_p, deleteIt ) ;
1063  v.takeStorage( u.shape(), int_p, TAKE_OVER ) ;
1064}
1065
1066void STGrid::toPixel( Array<Double> &world, Array<Double> &pixel )
1067{
1068  // gridding will be done on (nx_+2*convSupport_) x (ny_+2*convSupport_)
1069  // grid plane to avoid unexpected behavior on grid edge
1070  Block<Double> pixc( 2 ) ;
1071  pixc[0] = Double( nx_-1 ) * 0.5 ;
1072  pixc[1] = Double( ny_-1 ) * 0.5 ;
1073//   pixc[0] = Double( nx_+2*convSupport_-1 ) * 0.5 ;
1074//   pixc[1] = Double( ny_+2*convSupport_-1 ) * 0.5 ;
1075  uInt nrow = world.shape()[1] ;
1076  Bool bw, bp ;
1077  const Double *w_p = world.getStorage( bw ) ;
1078  Double *p_p = pixel.getStorage( bp ) ;
1079  const Double *ww_p = w_p ;
1080  Double *wp_p = p_p ;
1081  for ( uInt i = 0 ; i < nrow ; i++ ) {
1082    *wp_p = pixc[0] + ( *ww_p - center_[0] ) / cellx_ ;
1083    wp_p++ ;
1084    ww_p++ ;
1085    *wp_p = pixc[1] + ( *ww_p - center_[1] ) / celly_ ;
1086    wp_p++ ;
1087    ww_p++ ;
1088  }
1089  world.freeStorage( w_p, bw ) ;
1090  pixel.putStorage( p_p, bp ) ; 
1091//   String gridfile = "grid."+convType_+"."+String::toString(convSupport_)+".dat" ;
1092//   ofstream ofs( gridfile.c_str(), ios::out ) ;
1093//   ofs << "center " << center_(0) << " " << pixc(0)
1094//       << " " << center_(1) << " " << pixc(1) << endl ;
1095//   for ( uInt irow = 0 ; irow < nrow ; irow++ ) {
1096//     ofs << irow ;
1097//     for ( uInt i = 0 ; i < 2 ; i++ ) {
1098//       ofs << " " << world(i, irow) << " " << pixel(i, irow) ;
1099//     }
1100//     ofs << endl ;
1101//   }
1102//   ofs.close() ;
1103}
1104
1105void STGrid::boxFunc( Vector<Float> &convFunc, Int &convSize )
1106{
1107  convFunc = 0.0 ;
1108  for ( Int i = 0 ; i < convSize/2 ; i++ )
1109    convFunc(i) = 1.0 ;
1110}
1111
1112#define NEED_UNDERSCORES
1113#if defined(NEED_UNDERSCORES)
1114#define grdsf grdsf_
1115#endif
1116extern "C" {
1117   void grdsf(Double*, Double*);
1118}
1119void STGrid::spheroidalFunc( Vector<Float> &convFunc )
1120{
1121  convFunc = 0.0 ;
1122  for ( Int i = 0 ; i < convSampling_*convSupport_ ; i++ ) {
1123    Double nu = Double(i) / Double(convSupport_*convSampling_) ;
1124    Double val ;
1125    grdsf( &nu, &val ) ;
1126    convFunc(i) = ( 1.0 - nu * nu ) * val ;
1127  }
1128}
1129
1130void STGrid::gaussFunc( Vector<Float> &convFunc )
1131{
1132  convFunc = 0.0 ;
1133  // HWHM of the Gaussian is convSupport_ / 4
1134  // To take into account Gaussian tail, kernel cutoff is set to 4 * HWHM
1135  Int len = convSampling_ * convSupport_ ;
1136  Double hwhm = len * 0.25 ;
1137  for ( Int i = 0 ; i < len ; i++ ) {
1138    Double val = Double(i) / hwhm ;
1139    convFunc(i) = exp( -log(2)*val*val ) ;
1140  }
1141}
1142
1143void STGrid::pbFunc( Vector<Float> &convFunc )
1144{
1145  convFunc = 0.0 ;
1146}
1147
1148void STGrid::setConvFunc( Vector<Float> &convFunc )
1149{
1150  convSupport_ = userSupport_ ;
1151  if ( convType_ == "BOX" ) {
1152    if ( convSupport_ < 0 )
1153      convSupport_ = 0 ;
1154    Int convSize = convSampling_ * ( 2 * convSupport_ + 2 )  ;
1155    convFunc.resize( convSize ) ;
1156    boxFunc( convFunc, convSize ) ;
1157  }
1158  else if ( convType_ == "SF" ) {
1159    if ( convSupport_ < 0 )
1160      convSupport_ = 3 ;
1161    Int convSize = convSampling_ * ( 2 * convSupport_ + 2 )  ;
1162    convFunc.resize( convSize ) ;
1163    spheroidalFunc( convFunc ) ;
1164  }
1165  else if ( convType_ == "GAUSS" ) {
1166    // to take into account Gaussian tail
1167    if ( convSupport_ < 0 )
1168      convSupport_ = 12 ; // 3 * 4
1169    else {
1170      convSupport_ = userSupport_ * 4 ;
1171    }
1172    Int convSize = convSampling_ * ( 2 * convSupport_ + 2 ) ;
1173    convFunc.resize( convSize ) ;
1174    gaussFunc( convFunc ) ;
1175  }
1176  else if ( convType_ == "PB" ) {
1177    if ( convSupport_ < 0 )
1178      convSupport_ = 0 ;
1179    pbFunc( convFunc ) ;
1180  }
1181  else {
1182    throw AipsError( "Unsupported convolution function" ) ;
1183  }
1184}
1185
1186string STGrid::saveData( string outfile )
1187{
1188  LogIO os( LogOrigin("STGrid", "saveData", WHERE) ) ;
1189  double t0, t1 ;
1190  t0 = mathutil::gettimeofday_sec() ;
1191
1192  //Int polno = 0 ;
1193  String outfile_ ;
1194  if ( outfile.size() == 0 ) {
1195    if ( infile_.lastchar() == '/' ) {
1196      outfile_ = infile_.substr( 0, infile_.size()-1 ) ;
1197    }
1198    else {
1199      outfile_ = infile_ ;
1200    }
1201    outfile_ += ".grid" ;
1202  }
1203  else {
1204    outfile_ = outfile ;
1205  }
1206  Table tab ;
1207  prepareTable( tab, outfile_ ) ;
1208  IPosition dshape = data_.shape() ;
1209  Int nrow = nx_ * ny_ * npol_ ;
1210  tab.rwKeywordSet().define( "nPol", npol_ ) ;
1211  tab.addRow( nrow ) ;
1212  Vector<Double> cpix( 2 ) ;
1213  cpix(0) = Double( nx_ - 1 ) * 0.5 ;
1214  cpix(1) = Double( ny_ - 1 ) * 0.5 ;
1215  Vector<Double> dir( 2 ) ;
1216  ArrayColumn<Double> directionCol( tab, "DIRECTION" ) ;
1217  ArrayColumn<Float> spectraCol( tab, "SPECTRA" ) ;
1218  ScalarColumn<uInt> polnoCol( tab, "POLNO" ) ;
1219  Int irow = 0 ;
1220  Vector<Float> sp( nchan_ ) ;
1221  Bool bsp, bdata ;
1222  const Float *data_p = data_.getStorage( bdata ) ;
1223  Float *wsp_p, *sp_p ;
1224  const Float *wdata_p = data_p ;
1225  long step = nx_ * ny_ * npol_ ;
1226  long offset ;
1227  for ( Int iy = 0 ; iy < ny_ ; iy++ ) {
1228    dir(1) = center_(1) - ( cpix(1) - (Double)iy ) * celly_ ;
1229    for ( Int ix = 0 ; ix < nx_ ; ix++ ) {
1230      dir(0) = center_(0) - ( cpix(0) - (Double)ix ) * cellx_ ;
1231      for ( Int ipol = 0 ; ipol < npol_ ; ipol++ ) {
1232        offset = ix + iy * nx_ + ipol * nx_ * ny_ ;
1233        //os << "offset = " << offset << LogIO::POST ;
1234        sp_p = sp.getStorage( bsp ) ;
1235        wsp_p = sp_p ;
1236        wdata_p = data_p + offset ;
1237        for ( Int ichan = 0 ; ichan < nchan_ ; ichan++ ) {
1238          *wsp_p = *wdata_p ;
1239          wsp_p++ ;
1240          wdata_p += step ;
1241        }
1242        sp.putStorage( sp_p, bsp ) ;
1243        spectraCol.put( irow, sp ) ;
1244        directionCol.put( irow, dir ) ;
1245        polnoCol.put( irow, pollist_[ipol] ) ;
1246        irow++ ;
1247      }
1248    }
1249  }
1250  data_.freeStorage( data_p, bdata ) ;
1251
1252  t1 = mathutil::gettimeofday_sec() ;
1253  os << "saveData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
1254
1255  return outfile_ ;
1256}
1257
1258void STGrid::prepareTable( Table &tab, String &name )
1259{
1260  Table t( infile_, Table::Old ) ;
1261  t.deepCopy( name, Table::New, False, t.endianFormat(), True ) ;
1262  tab = Table( name, Table::Update ) ;
1263}
1264
1265}
Note: See TracBrowser for help on using the repository browser.