~javier-lopez/ubuntu/quantal/cdo/sru-1023329

« back to all changes in this revision

Viewing changes to src/Gather.c

  • Committer: Bazaar Package Importer
  • Author(s): Alastair McKinstry
  • Date: 2010-09-22 15:58:09 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100922155809-u1d3vlmlqj02uxjt
Tags: 1.4.6.dfsg.1-1
New upstream release. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#  include <omp.h>
20
20
#endif
21
21
 
22
 
#include "cdi.h"
 
22
#include <cdi.h>
23
23
#include "cdo.h"
24
24
#include "cdo_int.h"
25
25
#include "pstream.h"
56
56
}
57
57
 
58
58
static
59
 
int cmpxy(const void *s1, const void *s2)
 
59
int cmpxy_lt(const void *s1, const void *s2)
60
60
{
61
61
  int cmp = 0;
62
62
  xyinfo_t *xy1 = (xyinfo_t *) s1;
69
69
}
70
70
 
71
71
static
 
72
int cmpxy_gt(const void *s1, const void *s2)
 
73
{
 
74
  int cmp = 0;
 
75
  xyinfo_t *xy1 = (xyinfo_t *) s1;
 
76
  xyinfo_t *xy2 = (xyinfo_t *) s2;
 
77
 
 
78
  if      ( xy1->y > xy2->y || (!(fabs(xy1->y - xy2->y) > 0) && xy1->x < xy2->x) ) cmp = -1;
 
79
  else if ( xy1->y < xy2->y || (!(fabs(xy1->y - xy2->y) > 0) && xy1->x > xy2->x) ) cmp =  1;
 
80
 
 
81
  return (cmp);
 
82
}
 
83
 
 
84
static
72
85
int genGrid(int nfiles, ens_file_t *ef, int **gridindex, int igrid)
73
86
{
74
87
  static char *func = "genGrid";
 
88
  int lsouthnorth = TRUE;
75
89
  int fileID;
76
90
  int gridID;
77
91
  int gridID2 = -1;
89
103
 
90
104
  for ( fileID = 0; fileID < nfiles; fileID++ )
91
105
    {
92
 
      gridID = vlistGrid(ef[fileID].vlistID, igrid);
 
106
      gridID   = vlistGrid(ef[fileID].vlistID, igrid);
93
107
      gridtype = gridInqType(gridID);
94
108
      if ( !(gridtype == GRID_LONLAT || gridtype == GRID_GAUSSIAN ||
95
 
             (gridtype == GRID_GENERIC && gridInqXsize(gridID) > 0 && gridInqYsize(gridID) > 0)) )
 
109
            (gridtype == GRID_GENERIC && gridInqXsize(gridID) > 0 && gridInqYsize(gridID) > 0)) )
96
110
        cdoAbort("Unsupported grid type: %s!", gridNamePtr(gridtype));
97
111
 
98
112
      if ( xsize == 0 ) xsize = gridInqXsize(gridID);
110
124
      xyinfo[fileID].x  = xvals[fileID][0];
111
125
      xyinfo[fileID].y  = yvals[fileID][0];
112
126
      xyinfo[fileID].id = fileID;
 
127
 
 
128
      if ( fileID == 0 && ysize > 1 )
 
129
        {
 
130
          if ( yvals[fileID][0] > yvals[fileID][ysize-1] ) lsouthnorth = FALSE;
 
131
        }
113
132
    }
114
 
  /*
115
 
  for ( fileID = 0; fileID < nfiles; fileID++ )
116
 
    printf("1 %d %g %g \n",  xyinfo[fileID].id, xyinfo[fileID].x, xyinfo[fileID].y);
117
 
  */
 
133
  
 
134
  if ( cdoVerbose )
 
135
    for ( fileID = 0; fileID < nfiles; fileID++ )
 
136
      printf("1 %d %g %g \n",  xyinfo[fileID].id, xyinfo[fileID].x, xyinfo[fileID].y);
 
137
  
118
138
  qsort(xyinfo, nfiles, sizeof(xyinfo_t), cmpx);              
119
 
  /*
120
 
  for ( fileID = 0; fileID < nfiles; fileID++ )
121
 
    printf("2 %d %g %g \n",  xyinfo[fileID].id, xyinfo[fileID].x, xyinfo[fileID].y);
122
 
  */
123
 
  qsort(xyinfo, nfiles, sizeof(xyinfo_t), cmpxy);             
124
 
  /*
125
 
  for ( fileID = 0; fileID < nfiles; fileID++ )
126
 
    printf("3 %d %g %g \n",  xyinfo[fileID].id, xyinfo[fileID].x, xyinfo[fileID].y);
127
 
  */
 
139
  
 
140
  if ( cdoVerbose )
 
141
    for ( fileID = 0; fileID < nfiles; fileID++ )
 
142
      printf("2 %d %g %g \n",  xyinfo[fileID].id, xyinfo[fileID].x, xyinfo[fileID].y);
 
143
  
 
144
  if ( lsouthnorth )
 
145
    qsort(xyinfo, nfiles, sizeof(xyinfo_t), cmpxy_lt);  
 
146
  else
 
147
    qsort(xyinfo, nfiles, sizeof(xyinfo_t), cmpxy_gt);                
 
148
 
 
149
  if ( cdoVerbose )
 
150
    for ( fileID = 0; fileID < nfiles; fileID++ )
 
151
      printf("3 %d %g %g \n",  xyinfo[fileID].id, xyinfo[fileID].x, xyinfo[fileID].y);
 
152
 
128
153
  nx = 1;
129
154
  for ( fileID = 1; fileID < nfiles; fileID++ )
130
155
    {
208
233
 
209
234
void *Gather(void *argument)
210
235
{
211
 
  static char func[] = "Gather";
 
236
  static const char *func = "Gather";
212
237
  int i;
213
238
  int nvars;
214
239
  int cmpfunc;
259
284
  /* check that the contents is always the same */
260
285
  nvars = vlistNvars(ef[0].vlistID);
261
286
  if ( nvars == 1 ) 
262
 
    cmpfunc = func_sftn;
 
287
    cmpfunc = CMP_NAME | CMP_GRIDSIZE | CMP_NLEVEL;
263
288
  else
264
 
    cmpfunc = func_sftn;
 
289
    cmpfunc = CMP_NAME | CMP_GRIDSIZE | CMP_NLEVEL;
265
290
 
266
291
  for ( fileID = 1; fileID < nfiles; fileID++ )
267
292
    vlistCompare(ef[0].vlistID, ef[fileID].vlistID, cmpfunc);