@@ -120,110 +120,116 @@ short **toa_ = NULL;
120
120
if ((bands [b ++ ] = find_domain (TOA , "SWIR1" )) < 0 ) return FAILURE ;
121
121
if ((bands [b ++ ] = find_domain (TOA , "SWIR2" )) < 0 ) return FAILURE ;
122
122
123
+ #pragma omp parallel private() shared() default(none)
124
+ {
123
125
124
- /** initialize and allocate
125
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++**/
126
+ /** initialize and allocate
127
+ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++**/
126
128
127
- // kernel size
128
- w = r * 2 + 1 ; nw = w * w ;
129
+ // kernel size
130
+ w = r * 2 + 1 ; nw = w * w ;
129
131
130
- // nw-by-nv predictor variables; kernel + central pixel
131
- X = gsl_matrix_calloc (nw , nv );
132
- x = gsl_vector_calloc (nv );
133
-
134
- // set first column of X to 1 -> intercept c0
135
- for (k = 0 ; k < nw ; k ++ ) gsl_matrix_set (X , k , 0 , 1.0 );
136
- gsl_vector_set (x , 0 , 1.0 );
132
+ // nw-by-nv predictor variables; kernel + central pixel
133
+ X = gsl_matrix_calloc (nw , nv );
134
+ x = gsl_vector_calloc (nv );
135
+
136
+ // set first column of X to 1 -> intercept c0
137
+ for (k = 0 ; k < nw ; k ++ ) gsl_matrix_set (X , k , 0 , 1.0 );
138
+ gsl_vector_set (x , 0 , 1.0 );
137
139
138
- // vector of nw observations
139
- alloc ((void * * )& y , nb , sizeof (gsl_vector * ));
140
- for (b = 0 ; b < nb ; b ++ ) y [b ] = gsl_vector_calloc (nw );
140
+ // vector of nw observations
141
+ alloc ((void * * )& y , nb , sizeof (gsl_vector * ));
142
+ for (b = 0 ; b < nb ; b ++ ) y [b ] = gsl_vector_calloc (nw );
141
143
142
- // nv regression coefficients
143
- alloc ((void * * )& c , nb , sizeof (gsl_vector * ));
144
- for (b = 0 ; b < nb ; b ++ ) c [b ] = gsl_vector_calloc (nv );
144
+ // nv regression coefficients
145
+ alloc ((void * * )& c , nb , sizeof (gsl_vector * ));
146
+ for (b = 0 ; b < nb ; b ++ ) c [b ] = gsl_vector_calloc (nv );
145
147
146
- // nv-by-nv covariance matrix
147
- alloc ((void * * )& cov , nb , sizeof (gsl_matrix * ));
148
- for (b = 0 ; b < nb ; b ++ ) cov [b ] = gsl_matrix_calloc (nv , nv );
148
+ // nv-by-nv covariance matrix
149
+ alloc ((void * * )& cov , nb , sizeof (gsl_matrix * ));
150
+ for (b = 0 ; b < nb ; b ++ ) cov [b ] = gsl_matrix_calloc (nv , nv );
149
151
150
- // workspace
151
- alloc ((void * * )& work , nb , sizeof (gsl_multifit_linear_workspace * ));
152
- for (b = 0 ; b < nb ; b ++ ) work [b ] = gsl_multifit_linear_alloc (nw , nv );
152
+ // workspace
153
+ alloc ((void * * )& work , nb , sizeof (gsl_multifit_linear_workspace * ));
154
+ for (b = 0 ; b < nb ; b ++ ) work [b ] = gsl_multifit_linear_alloc (nw , nv );
153
155
154
156
155
- /** do regression for every valid pixel, and for each 20m band
156
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++**/
157
- for (i = 0 , p = 0 ; i < ny ; i ++ ){
158
- for (j = 0 ; j < nx ; j ++ , p ++ ){
157
+ /** do regression for every valid pixel, and for each 20m band
158
+ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++**/
159
159
160
- if (get_off (QAI , p ) || get_cloud (QAI , p ) > 0 || get_shadow (QAI , p )) continue ;
160
+ #pragma omp for schedule(guided)
161
+ for (i = 0 , p = 0 ; i < ny ; i ++ ){
162
+ for (j = 0 ; j < nx ; j ++ , p ++ ){
161
163
162
- // add central pixel
163
- gsl_vector_set (x , 1 , toa_ [green ][p ]/10000.0 );
164
- gsl_vector_set (x , 2 , toa_ [red ][p ]/10000.0 );
165
- gsl_vector_set (x , 3 , toa_ [bnir ][p ]/10000.0 );
164
+ if (get_off (QAI , p ) || get_cloud (QAI , p ) > 0 || get_shadow (QAI , p )) continue ;
166
165
167
- k = 0 ;
166
+ // add central pixel
167
+ gsl_vector_set (x , 1 , toa_ [green ][p ]/10000.0 );
168
+ gsl_vector_set (x , 2 , toa_ [red ][p ]/10000.0 );
169
+ gsl_vector_set (x , 3 , toa_ [bnir ][p ]/10000.0 );
168
170
169
- // add neighboring pixels
170
- for (ii = - r ; ii <=r ; ii ++ ){
171
- for (jj = - r ; jj <=r ; jj ++ ){
171
+ k = 0 ;
172
172
173
- ni = i + ii ; nj = j + jj ;
174
- if ( ni < 0 || ni >= ny || nj < 0 || nj >= nx ) continue ;
175
- np = ni * nx + nj ;
173
+ // add neighboring pixels
174
+ for ( ii = - r ; ii <= r ; ii ++ ){
175
+ for ( jj = - r ; jj <= r ; jj ++ ){
176
176
177
- if (get_off (QAI , np )) continue ;
177
+ ni = i + ii ; nj = j + jj ;
178
+ if (ni < 0 || ni >= ny || nj < 0 || nj >= nx ) continue ;
179
+ np = ni * nx + nj ;
178
180
179
- gsl_matrix_set (X , k , 1 , toa_ [green ][np ]/10000.0 );
180
- gsl_matrix_set (X , k , 2 , toa_ [red ][np ]/10000.0 );
181
- gsl_matrix_set (X , k , 3 , toa_ [bnir ][np ]/10000.0 );
182
-
183
- for (b = 0 ; b < nb ; b ++ ) gsl_vector_set (y [b ], k , toa_ [bands [b ]][np ]/10000.0 );
181
+ if (get_off (QAI , np )) continue ;
184
182
185
- k ++ ;
183
+ gsl_matrix_set (X , k , 1 , toa_ [green ][np ]/10000.0 );
184
+ gsl_matrix_set (X , k , 2 , toa_ [red ][np ]/10000.0 );
185
+ gsl_matrix_set (X , k , 3 , toa_ [bnir ][np ]/10000.0 );
186
+
187
+ for (b = 0 ; b < nb ; b ++ ) gsl_vector_set (y [b ], k , toa_ [bands [b ]][np ]/10000.0 );
186
188
187
- }
188
- }
189
+ k ++ ;
189
190
190
- // append zeros, if less than nw neighboring pixels were added
191
- while (k < nw ){
192
- gsl_matrix_set (X , k , 1 , 0.0 );
193
- gsl_matrix_set (X , k , 2 , 0.0 );
194
- gsl_matrix_set (X , k , 3 , 0.0 );
195
- for (b = 0 ; b < nb ; b ++ ) gsl_vector_set (y [b ], k , 0.0 );
196
- k ++ ;
197
- }
191
+ }
192
+ }
198
193
199
- // solve model, and predict central pixel
200
- for (b = 0 ; b < nb ; b ++ ){
194
+ // append zeros, if less than nw neighboring pixels were added
195
+ while (k < nw ){
196
+ gsl_matrix_set (X , k , 1 , 0.0 );
197
+ gsl_matrix_set (X , k , 2 , 0.0 );
198
+ gsl_matrix_set (X , k , 3 , 0.0 );
199
+ for (b = 0 ; b < nb ; b ++ ) gsl_vector_set (y [b ], k , 0.0 );
200
+ k ++ ;
201
+ }
202
+
203
+ // solve model, and predict central pixel
204
+ for (b = 0 ; b < nb ; b ++ ){
201
205
202
- gsl_multifit_linear (X , y [b ], c [b ], cov [b ], & chisq , work [b ]);
203
- gsl_multifit_linear_est (x , c [b ], cov [b ], & est , & err );
204
- toa_ [bands [b ]][p ] = (short )(est * 10000 );
206
+ gsl_multifit_linear (X , y [b ], c [b ], cov [b ], & chisq , work [b ]);
207
+ gsl_multifit_linear_est (x , c [b ], cov [b ], & est , & err );
208
+ toa_ [bands [b ]][p ] = (short )(est * 10000 );
205
209
210
+ }
211
+
212
+ }
206
213
}
207
214
208
- }
209
- }
210
215
216
+ #ifdef FORCE_DEBUG
217
+ set_brick_filename (TOA , "TOA-RESMERGED" );
218
+ print_brick_info (TOA ); set_brick_open (TOA , OPEN_CREATE ); write_brick (TOA );
219
+ #endif
211
220
212
- #ifdef FORCE_DEBUG
213
- set_brick_filename (TOA , "TOA-RESMERGED" );
214
- print_brick_info (TOA ); set_brick_open (TOA , OPEN_CREATE ); write_brick (TOA );
215
- #endif
216
221
222
+ /** clean
223
+ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++**/
224
+ gsl_matrix_free (X ); gsl_vector_free (x );
225
+ for (b = 0 ; b < nb ; b ++ ) gsl_vector_free (y [b ]);
226
+ for (b = 0 ; b < nb ; b ++ ) gsl_vector_free (c [b ]);
227
+ for (b = 0 ; b < nb ; b ++ ) gsl_matrix_free (cov [b ]);
228
+ for (b = 0 ; b < nb ; b ++ ) gsl_multifit_linear_free (work [b ]);
229
+ free ((void * )y ); free ((void * )c );
230
+ free ((void * )cov ); free ((void * )work );
217
231
218
- /** clean
219
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++**/
220
- gsl_matrix_free (X ); gsl_vector_free (x );
221
- for (b = 0 ; b < nb ; b ++ ) gsl_vector_free (y [b ]);
222
- for (b = 0 ; b < nb ; b ++ ) gsl_vector_free (c [b ]);
223
- for (b = 0 ; b < nb ; b ++ ) gsl_matrix_free (cov [b ]);
224
- for (b = 0 ; b < nb ; b ++ ) gsl_multifit_linear_free (work [b ]);
225
- free ((void * )y ); free ((void * )c );
226
- free ((void * )cov ); free ((void * )work );
232
+ }
227
233
228
234
#ifdef FORCE_CLOCK
229
235
proctime_print ("Resolution merge" , TIME );
0 commit comments