GRASS Programmer's Manual  6.4.2(2012)
smain.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <grass/bitmap.h>
00004 
00005 
00006 static int dump_map(struct BM *map);
00007 
00008 
00009 int main(int argc, char *argv[])
00010 {
00011     int SIZE;
00012     struct BM *map, *map2;
00013     int i, x, y;
00014     int dump;
00015     FILE *fp;
00016 
00017     if (argc < 2)
00018         SIZE = 11;
00019     else
00020         SIZE = atoi(argv[1]);
00021 
00022     if (NULL == getenv("NODUMP"))
00023         dump = 1;
00024     else
00025         dump = 0;
00026 
00027     map = BM_create_sparse(SIZE, SIZE);
00028 
00029     /* turn on bits in X pattern */
00030     for (i = 0; i < SIZE; i++) {
00031         BM_set(map, i, i, 1);
00032         BM_set(map, (SIZE - 1) - i, i, 1);
00033     }
00034 
00035     if (dump)
00036         dump_map(map);
00037 
00038     fprintf(stdout, "Size = %d\n", BM_get_map_size(map));
00039 
00040     /*
00041        BM_dump_map_sparse (map);
00042      */
00043 
00044     fprintf(stdout, "\n\n");
00045     /* now invert it */
00046     for (y = 0; y < SIZE; y++)
00047         for (x = 0; x < SIZE; x++) {
00048             BM_set(map, x, y, !BM_get(map, x, y));
00049 #ifdef FOO
00050              /*DEBUG*/ if (y == 0)
00051                 /*DEBUG*/ BM_dump_map_row_sparse(map, y);
00052 #endif
00053         }
00054 
00055     if (dump)
00056         dump_map(map);
00057 
00058     fprintf(stdout, "Size = %d\n", BM_get_map_size(map));
00059     /*
00060        fprintf (stdout, "\n\n");
00061        BM_dump_map_sparse (map);
00062      */
00063     {
00064         fp = fopen("dumpfile", "w");
00065         if (0 > BM_file_write(fp, map)) {
00066             fprintf(stderr, "File_write failed\n");
00067             goto nowrite;
00068         }
00069         fclose(fp);
00070 
00071         fp = fopen("dumpfile", "r");
00072         map2 = BM_file_read(fp);
00073         fclose(fp);
00074         dump_map(map2);
00075     }
00076 
00077     BM_destroy(map2);
00078   nowrite:
00079 
00080     BM_destroy(map);
00081 
00082     return 0;
00083 }
00084 
00085 
00086 static int dump_map(struct BM *map)
00087 {
00088     int x, y;
00089 
00090     for (y = 0; y < map->rows; y++) {
00091         for (x = 0; x < map->cols; x++) {
00092             fprintf(stdout, "%c", BM_get(map, x, y) ? '#' : '.');
00093 
00094         }
00095         fprintf(stdout, "\n");
00096     }
00097 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines