36 #define X_BOTTOMLEFTCORNER 4
37 #define Y_BOTTOMLEFTCORNER 3
40 #define INTEGER_NULL -99
41 #define INIT_VALUE2 -990
43 #define REFERENCE_INDEX 1
44 SQUARE_GRID *
get_square_grid(
DOUBLEMATRIX *DTM,
T_INIT *UV,
char *file_resume_lines,
char *file_resume_polygons,
char *file_resume_connections,
long (*
index_pixel_from_a_bin)(
long r,
long c,
LONGVECTOR *s_index),
int (*check_novalues)(
double x,
DOUBLEVECTOR *V),
long displacement,
short print) {
68 if (!sq)
t_error(
"Square Grid sq was not allocated");
83 if (!sq->
grid)
t_error(
"Grid of a Square Grid was not allocated");
89 if (print==1) printf(
"number of lines: %ld \n",sq->
grid->
lines->
nh);
91 if (print==1) printf(
"number of polygons: %ld \n",sq->
grid->
polygons->
nh);
122 printf(
"write_grid function: write_linevector %s (exit statues %d)\n",grid->
file_resume_lines,l);
123 printf(
"write_grid function: write_polygonvector %s (exit statues %d)\n",grid->
file_resume_polygons,s);
124 printf(
"write_grid function: write_polygonconnectionattributearray %s (exit statues %d)\n",grid->
file_resume_connections,r);
144 if (!raster)
t_error(
"Raster map was not allocated");
152 if (!raster->
UV)
t_error(
"Raster map UV was not allocated");
155 if (!raster->
layer)
t_error(
"Raster layer was not allocated");
179 if(print==1) printf(
"\n raster [%ld] reference_map %ld: \n",index,raster->
reference_index_map);
186 if (print==1) printf (
"Add_map_to_raster map: map %s was successfully read (index %ld of %ld) (reference index: %ld) (map %ld,%ld)\n",filename,index,raster->
nh,raster->
reference_index_map,raster->
layer[index]->
nrh,raster->
layer[index]->
nch);
189 printf (
"Error in add_map_to_raster map index of %s corresponds to the reference map index %ld \n",filename,index);
192 if (print==1) printf (
"Add_map_to_raster map: map %s was successfully read (index %ld of %ld) (reference index: %ld) \n",filename,index,raster->
nh,raster->
reference_index_map);
195 printf (
"Error in add_map_to_raster map: map (%s) was not read (index %ld) \n",filename,index);
215 if (!vector)
t_error(
"Longmatrix_vector map was not allocated");
222 if (!vector->
element)
t_error(
"Longmatrix vector was not allocated");
223 printf(
"new_longmatrix_vector\n\n ");
247 long l,r,c,rs,cs,rp,cp;
248 long nrsh,ncsh,enrsh,encsh;
249 long i_novalue=novalue-5;
250 long ncells=i_lastcell-i_firstcell+1;
253 nrsh=fine->
nrh/coarse->
nrh;
254 ncsh=fine->
nch/coarse->
nch;
255 enrsh=fine->
nrh%coarse->
nrh;
256 encsh=fine->
nch%coarse->
nch;
258 if (enrsh!=0)
t_error(
"Error in get_fine_indices: number of rows (coarse and grid) are not multiples");
259 if (encsh!=0)
t_error(
"Error in get_fine_indices: number of rows (coarse and grid) are not multiples");
262 for(l=lco->
nl;l<=lco->nh;l++) {
265 for (r=lco->
element[l]->
nrl;r<=lco->element[l]->nrh;r++){
266 for (c=lco->
element[l]->
ncl;c<=lco->element[l]->nch;c++){
267 lco->
element[l]->element[r][c]=i_novalue;
273 for(r=fine->
nrl;r<=fine->nrh;r++){
274 for(c=fine->
ncl;c<=fine->nch;c++){
280 l=coarse->element[rs][cs];
281 if (l!=novalue) l=l-i_firstcell+1;
282 if ((l!=novalue) && ((l<=lco->
nh) && (l>=lco->
nl))) lco->
element[l]->element[rp][cp]=fine->element[r][c];
283 if ((l!=novalue) && ((l>lco->
nh) || (l<lco->nl))) printf(
"Error in get_fine_indices: incorrect value %ld of %ld for coearse->element[%ld][%ld] r=%ld c=%ld \n",l,lco->
nh,rs,cs,rp,cp);
289 for(l=lco->
nl;l<=lco->nh;l++) {
290 for (r=lco->
element[l]->
nrl;r<=lco->element[l]->nrh;r++){
291 for (c=lco->
element[l]->
ncl;c<=lco->element[l]->nch;c++){
292 if (lco->
element[l]->element[r][c]==i_novalue) {
293 printf(
"Error in get_fine_elements element %ld (row=%ld col=%ld) was not assigned (number of elements: %ld)",l,r,c,lco->
nh);
300 if (print==1) printf(
"Function get_fine_elements was successfully assigned (number of elements: %ld)",lco->
nh);
323 if (print==1) printf(
"get_fine_line_indices n_horizonal=%ld \n",n_horizontal);
326 if (print==1) printf(
"get_fine_line_indices (vertical) n_horizonal=%ld \n",n_horizontal);
327 vertical=
get_fine_indices(v_fine,v_coarse,n_horizontal+1,n_lines,novalue,print);
331 for (l=index->
nl;l<=n_horizontal;l++){
332 index->element[l]=horizontal->
element[l]->
nch;
334 for (l=n_horizontal+1;l<=index->
nh;l++){
335 index->element[l]=vertical->
element[l-n_horizontal]->
nrh;
340 for(l=lb->
index->
nl;l<=n_horizontal;l++){
341 for (i=1;i<=lb->
index->element[l];i++){
342 lb->element[l][i]=horizontal->
element[l]->element[horizontal->
element[l]->
nrl][i];
343 if (print==1) printf(
"get_fine_line_indices: horizontal line element [%ld][%ld] = %ld was assigned!\n",l,i,lb->element[l][i]);
348 for(l=n_horizontal+1;l<=lb->
index->
nh;l++) {
349 for (i=1;i<=lb->
index->element[l];i++){
350 lb->element[l][i]=vertical->
element[l-n_horizontal]->element[i][vertical->
element[l-n_horizontal]->
ncl];
351 if (print==1) printf(
"get_fine_line_indices: vertical line element [%ld][%ld] = %ld was assigned!\n",l,i,lb->element[l][i]);
362 if (print==1) printf(
"Function get_fine_elements was successfully assigned (number of elements: %ld)",lb->
index->
nh);
392 if (!draster)
t_error(
"DOUBLERASTER_MAP was not allocated");
413 if (print==1) printf(
"\n Doubleraster_map %s (coarse_map) and %s (fine_map) was successfully read \n",draster->
mapname_coarse,draster->
mapname_fine);
421 DOUBLESQUARE_GRID *
get_doublesquare_grid(
DOUBLERASTER_MAP *
draster,
char *resume_filenames,
long (*index_pixel_from_a_bin_coarse)(
long r,
long c,
LONGVECTOR *s_index),
long (*index_pixel_from_a_bin_fine)(
long r,
long c,
LONGVECTOR *s_index),
long d_coarse,
long d_fine,
short print){
438 if (print==1) printf(
"Function get_doublesquare_grid file_resume: %s \n",resume_filenames);
439 char *file_resume_lines_coarse=
join_strings(resume_filenames,
"__coarse_lines.txt");
440 char *file_resume_polygons_coarse=
join_strings(resume_filenames,
"__coarse_polygons.txt");
441 char *file_resume_connections_coarse=
join_strings(resume_filenames,
"__coarse_connections.txt");
443 char *file_resume_lines_fine=
join_strings(resume_filenames,
"__fine_lines.txt");
444 char *file_resume_polygons_fine=
join_strings(resume_filenames,
"__fine_polygons.txt");
445 char *file_resume_connections_fine=
join_strings(resume_filenames,
"__fine_connections.txt");
446 char *file_resume_c_polygon=
join_strings(resume_filenames,
"_c_polygon.txt");
447 char *file_resume_c_line=
join_strings(resume_filenames,
"_c_line.txt");
450 if (!dsq)
t_error(
"DOUBLESQUARE_GRID was not allocated");
465 if (print==1) printf(
"Function get_doublesquare_grid was executed successfully! \n");
467 free(file_resume_lines_coarse);
468 free(file_resume_polygons_coarse);
469 free(file_resume_connections_coarse);
470 free(file_resume_lines_fine);
471 free(file_resume_polygons_fine);
472 free(file_resume_connections_fine);
473 free(file_resume_c_polygon);
474 free(file_resume_c_line);
496 fprintf(f,
"index{%ld} \n\n",lmv->
nh);
497 fprintf(f,
" /*!* MATRICES OF ''SMALL'' cells */ \n ");
498 for (i=lmv->
nl;i<=lmv->nh;i++) {
500 fprintf(f,
"%ld: long matrix small_cell {%ld,%ld} \n",i,lmv->
element[i]->
nrh,lmv->
element[i]->
nch);
526 fprintf(f,
"index{%ld}\n",small_lines->
index->
nh);
527 fprintf(f,
"/*!* FILE CONTAINIG NECESSARY INFORMATION FOR LINE CONTENTS \n");
528 fprintf(f,
" each (small line) array for (big) line is expressed as a double array */ \n");
529 for(j=small_lines->
index->
nl;j<=small_lines->index->nh;j++) {
530 fprintf(f,
"%ld:long array big line %ld {",j,j);
531 for(c=
NL;c<small_lines->
index->element[j];c++){
532 fprintf(f,
"%ld,",small_lines->element[j][c]);
534 fprintf(f,
"%ld}\n",small_lines->element[j][small_lines->
index->element[j]]);
569 if (!lmv) printf(
"Error in free_longmatrix_vector: longmatrix_vector was not allocated! /n");
570 if (!lmv->
element) printf(
"Error in free_longmatrix_vector: longmatrix_vector elements were not allocated! /n");
571 for (i=lmv->
nl;i<=lmv->nh;i++){
573 if (!lmv->
element[i]) printf(
"Error in free_longmatrix_vector: longmatrix at %ld (of %ld) was not allocated! /n",i,lmv->
nh);
591 if (!grid) printf(
"Error in free_grid: grid was never allocated! \n");
592 if (!grid->
links) printf(
"Error in free_grid: links (connection) was never allocated! \n");
594 if (!grid->
polygons) printf(
"Error in free_grid: polygons was never allocated! \n");
596 if (!grid->
lines) printf(
"Error in free_grid: lines was never allocated! \n");
612 if (!sq->
grid) printf(
"Error in free_square_grid: a grid was never allocated!\n");
615 if (!sq->
indices_horizontal_lines->element) printf(
"Error in free_square_grid: indices_horizontal_lines was never allocated \n");
617 if (!sq->
indices_vertical_lines->element) printf(
"Error in free_square_grid: indices_vertical_lines was never allocated \n");
619 if (!sq->
indices_vertex->element) printf(
"Error in free_square_grid: indices_vertex was never allocated \n");
621 if (!sq->
indices_pixel->element) printf(
"Error in free_square_grid: indices_pixel was never allocated \n");
640 for(i=raster->
nl;i<=raster->nh;i++){
673 if (!dsq) printf(
"Error in free_doublesquare_grid: doublesquare_grid was never allocated! /n");
674 if (!dsq->
big) printf(
"Error in free_doublesquare_grid: coarse (big) grid was never allocated! /n");
676 if (!dsq->
fine) printf(
"Error in free_doublesquare_grid: fine grid was never allocated! /n");
678 if (!dsq->
small_content_line) printf(
"Error in free_doublesquare_grid: small_content_line was never allocated! /n");
680 if (!dsq->
small_content_polygon) printf(
"Error in free_doublesquare_grid: small_content_polygon was never allocated! /n");
697 for(p = src, q = dest; *p !=
'\0'; p++, q++)
715 dest=(
char *)malloc((
size_t)(strlen(origin)+4)*
sizeof(
char));