File: select.c

package info (click to toggle)
vis5d 4.3-5
  • links: PTS
  • area: main
  • in suites: slink
  • size: 16,856 kB
  • ctags: 6,127
  • sloc: ansic: 66,158; fortran: 4,470; makefile: 1,683; tcl: 414; sh: 69
file content (258 lines) | stat: -rw-r--r-- 5,605 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/* select.c */


#include "grid.h"


/*
 * Set or clear the selection bits for all grids in a particular table
 * position.
 * Input:  table - the grid table
 *         time - which timestep
 *         var - which variable
 *         bitmask - which bits to change
 *         state - 1 means set the bits, 0 means clear the bits
 */
static void set_cell_selection( struct grid_db *db, int time, int var,
                                int bitmask, int state )
{
   struct grid_info *g;

   g = db->Matrix[time][var];
   while (g) {
      if (state) {
         g->SelectBits |= bitmask;
      }
      else {
         g->SelectBits &= ~bitmask;
      }
      g->NewSelState = 1;
      g = g->Sibling;
   }
}


#ifdef LEAVEOUT
/*
 * Test if any grid in the chain attached to the named cell has the
 * specified selection bits set.
 */
static int is_cell_selected( struct grid_db *db, int time, int var,
                             int bitmask )
{
   struct grid_info *g;

   g = db->Matrix[time][var];
   while (g) {
      if ((g->SelectBits & bitmask) == bitmask) {
         return 1;
      }
      g = g->Sibling;
   }
   return 0;
}
#endif


/*
 * Mark a time step and all associated grids as selected or unselected
 * according to the state.
 * Input:  db - the grid database
 *         time - which timestep (starting at 0)
 *         state - selection status.
 * Return:  1=there was a side-effect, 0=no side-effect
 *          A side-effect occurs when changing the selection status of a
 *          timestep changes the selection status of some variable.
 */
void select_time( struct grid_db *db, int time, int state )
{
   int var;

   db->TimeSelected[time] = state;

   for (var=0;var<db->NumVars;var++) {
      if (db->Matrix[time][var]) {
         set_cell_selection( db, time, var, TIME_BIT, state );
      }
   }
}



/*
 * Mark a variable and all associated grids as selected or unselected
 * according to the state.
 */
void select_variable( struct grid_db *db, int var, int state )
{
   int time;

   db->VarSelected[var] = state;

   for (time=0;time<db->NumTimes;time++) {
      if (db->Matrix[time][var]) {
         set_cell_selection( db, time, var, VAR_BIT, state );
      }
   }
}




/*
 * Mark a map projection and all associated grids as selected or unselected
 * according to the state.
 */
void select_projection( struct grid_db *db, int projnum, int state )
{
   int time, var;
   struct projection *p;

   db->ProjSelected[projnum] = state;

   p = db->ProjList[projnum];

   for (time=0;time<db->NumTimes;time++) {
      for (var=0;var<db->NumVars;var++) {
         struct grid_info *g;

         g = db->Matrix[time][var];
         while (g) {
            if (g->Proj == p) {
               if (state) {
                  g->SelectBits |= PROJ_BIT;
               }
               else {
                  g->SelectBits &= ~PROJ_BIT;
               }
               g->NewSelState = 1;
            }
            g = g->Sibling;
         }
      }
   }
}



/*
 * Mark a vertical coordinate system and all associated grids as selected
 * or unselected according to the state.
 */
void select_vcs( struct grid_db *db, int vcsnum, int state )
{
   int time, var;
   struct vcs *v;

   db->VcsSelected[vcsnum] = state;

   v = db->VcsList[vcsnum];

   for (time=0;time<db->NumTimes;time++) {
      for (var=0;var<db->NumVars;var++) {
         struct grid_info *g;

         g = db->Matrix[time][var];
         while (g) {
            if (g->Vcs == v) {
               if (state) {
                  g->SelectBits |= VCS_BIT;
               }
               else {
                  g->SelectBits &= ~VCS_BIT;
               }
               g->NewSelState = 1;
            }
            g = g->Sibling;
         }
      }
   }
}



/*
 * Mark all grids in the table as selected or unselected according to 
 * bitmask and state.
 */
void select_all( struct grid_db *db, int bitmask, int state )
{
   int time, var, proj, vcs;

   for (time=0;time<db->NumTimes;time++) {
      for (var=0;var<db->NumVars;var++) {
         set_cell_selection( db, time, var, bitmask, state );
      }
   }

   if (bitmask & TIME_BIT) {
      for (time=0;time<db->NumTimes;time++) {
         db->TimeSelected[time] = state;
      }
   }

   if (bitmask & VAR_BIT) {
      for (var=0;var<db->NumVars;var++) {
         db->VarSelected[var] = state;
      }
   }

   if (bitmask & PROJ_BIT) {
      for (proj=0;proj<db->NumProj;proj++) {
         db->ProjSelected[proj] = state;
      }
   }

   if (bitmask & VCS_BIT) {
      for (vcs=0;vcs<db->NumVcs;vcs++) {
         db->VcsSelected[vcs] = state;
      }
   }
}


#ifdef LEAVEOUT
/*
 * Find the greatest number of levels of any grids for the specified variable.
 * Input:  table - which table
 *         var - which variable in [0,NumVars-1]
 * Return:  max number of levels for the named variable
 */
int table_max_nl( db, var )
struct grid_db *db;
int var;
{
   struct grid_info *g;
   int it, maxnl;
   int count, all_2d;

   maxnl = 0;
   count = 0;
   all_2d = 1;

   for (it=0;it<db->NumTimes;it++) {
      g = db->Matrix[it][var];
      while (g) {
         if (g->SelectBits==ALL_BITS) {
            if (g->Nl > maxnl) {
               maxnl = g->Nl;
            }
            if (g->Nl!=1) {
               all_2d = 0;
            }
            count++;
         }
         g = g->Sibling;
      }
   }

   /* If all grids in the chain are really 2-D grids (ala McIDAS) then */
   /* we'll probably stack those 2-D grids to make a 3-D grid. */
   if (all_2d && maxnl==1 && count>1) {
      maxnl = count;
   }

   return maxnl;
}
#endif