@@ -138,68 +138,81 @@ int main( int argc, char **argv )
138
138
{
139
139
double x , y ;
140
140
int row , col ;
141
- x = atof ( coor_opt -> answers [0 ] );
142
- y = atof ( coor_opt -> answers [1 ] );
141
+ // x = atof( coor_opt->answers[0] );
142
+ // y = atof( coor_opt->answers[1] );
143
143
if ( rast_opt -> answer )
144
144
{
145
145
int fd ;
146
146
RASTER_MAP_TYPE rast_type ;
147
147
DCELL * dcell ;
148
148
CELL * cell ;
149
+ char buff [101 ];
149
150
G_get_cellhd ( rast_opt -> answer , "" , & window );
150
151
G_set_window ( & window );
151
152
fd = G_open_cell_old ( rast_opt -> answer , "" );
152
- col = ( int ) G_easting_to_col ( x , & window );
153
- row = ( int ) G_northing_to_row ( y , & window );
154
- if ( col == window .cols ) col -- ;
155
- if ( row == window .rows ) row -- ;
156
-
157
- if ( col < 0 || col > window .cols || row < 0 || row > window .rows )
158
- {
159
- fprintf ( stdout , "value:null\n" );
160
- }
161
- else
153
+ // wait for coors from stdin
154
+ while ( G_getl2 ( buff , 100 , stdin ) != 0 )
162
155
{
163
- void * ptr ;
164
- double val ;
165
-
166
- #if defined(GRASS_VERSION_MAJOR ) && defined(GRASS_VERSION_MINOR ) && \
167
- ( ( GRASS_VERSION_MAJOR == 6 && GRASS_VERSION_MINOR > 2 ) || GRASS_VERSION_MAJOR > 6 )
168
- rast_type = G_get_raster_map_type ( fd );
169
- #else
170
- rast_type = G_raster_map_type ( rast_opt -> answer , "" );
171
- #endif
172
- cell = G_allocate_c_raster_buf ();
173
- dcell = G_allocate_d_raster_buf ();
174
-
175
- if ( rast_type == CELL_TYPE )
156
+ if ( sscanf ( buff , "%lf%lf" , & x , & y ) != 2 )
176
157
{
177
- if ( G_get_c_raster_row ( fd , cell , row ) < 0 )
178
- {
179
- G_fatal_error (( "Unable to read raster map <%s> row %d" ),
180
- rast_opt -> answer , row );
181
- }
182
- val = cell [col ];
183
- ptr = & ( cell [col ] );
158
+ fprintf ( stdout , "value:error\n" );
184
159
}
185
160
else
186
161
{
187
- if ( G_get_d_raster_row ( fd , dcell , row ) < 0 )
162
+ col = ( int ) G_easting_to_col ( x , & window );
163
+ row = ( int ) G_northing_to_row ( y , & window );
164
+ if ( col == window .cols ) col -- ;
165
+ if ( row == window .rows ) row -- ;
166
+
167
+ if ( col < 0 || col > window .cols || row < 0 || row > window .rows )
188
168
{
189
- G_fatal_error (( "Unable to read raster map <%s> row %d" ),
190
- rast_opt -> answer , row );
169
+ fprintf ( stdout , "value:out\n" );
170
+ }
171
+ else
172
+ {
173
+ void * ptr ;
174
+ double val ;
175
+
176
+ #if defined(GRASS_VERSION_MAJOR ) && defined(GRASS_VERSION_MINOR ) && \
177
+ ( ( GRASS_VERSION_MAJOR == 6 && GRASS_VERSION_MINOR > 2 ) || GRASS_VERSION_MAJOR > 6 )
178
+ rast_type = G_get_raster_map_type ( fd );
179
+ #else
180
+ rast_type = G_raster_map_type ( rast_opt -> answer , "" );
181
+ #endif
182
+ cell = G_allocate_c_raster_buf ();
183
+ dcell = G_allocate_d_raster_buf ();
184
+
185
+ if ( rast_type == CELL_TYPE )
186
+ {
187
+ if ( G_get_c_raster_row ( fd , cell , row ) < 0 )
188
+ {
189
+ G_fatal_error (( "Unable to read raster map <%s> row %d" ),
190
+ rast_opt -> answer , row );
191
+ }
192
+ val = cell [col ];
193
+ ptr = & ( cell [col ] );
194
+ }
195
+ else
196
+ {
197
+ if ( G_get_d_raster_row ( fd , dcell , row ) < 0 )
198
+ {
199
+ G_fatal_error (( "Unable to read raster map <%s> row %d" ),
200
+ rast_opt -> answer , row );
201
+ }
202
+ val = dcell [col ];
203
+ ptr = & ( dcell [col ] );
204
+ }
205
+ if ( G_is_null_value ( ptr , rast_type ) )
206
+ {
207
+ fprintf ( stdout , "value:null\n" );
208
+ }
209
+ else
210
+ {
211
+ fprintf ( stdout , "value:%f\n" , val );
212
+ }
191
213
}
192
- val = dcell [col ];
193
- ptr = & ( dcell [col ] );
194
- }
195
- if ( G_is_null_value ( ptr , rast_type ) )
196
- {
197
- fprintf ( stdout , "value:null\n" );
198
- }
199
- else
200
- {
201
- fprintf ( stdout , "value:%f\n" , val );
202
214
}
215
+ fflush ( stdout );
203
216
}
204
217
G_close_cell ( fd );
205
218
}
0 commit comments