GRASS Programmer's Manual
6.4.2(2012)
|
00001 00015 #include <stdlib.h> 00016 #include <stdio.h> 00017 #include <grass/gis.h> 00018 #include <grass/segment.h> 00019 00020 00035 int segment_setup(SEGMENT * SEG) 00036 { 00037 int i; 00038 00039 SEG->open = 0; 00040 00041 if (SEG->nrows <= 0 || SEG->ncols <= 0 00042 || SEG->srows <= 0 || SEG->scols <= 0 00043 || SEG->len <= 0 || SEG->nseg <= 0) { 00044 G_warning("segment_setup: illegal segment file parameters\n"); 00045 return -1; 00046 } 00047 00048 /* This is close to the beginning of the file, so doesn't need to be an off_t */ 00049 SEG->offset = (int)lseek(SEG->fd, 0L, SEEK_CUR); 00050 00051 SEG->spr = SEG->ncols / SEG->scols; 00052 SEG->spill = SEG->ncols % SEG->scols; 00053 if (SEG->spill) 00054 SEG->spr++; 00055 00056 if ((SEG->scb = 00057 (struct SEGMENT_SCB *)G_malloc(SEG->nseg * 00058 sizeof(struct SEGMENT_SCB))) == NULL) 00059 return -2; 00060 00061 SEG->size = SEG->srows * SEG->scols * SEG->len; 00062 00063 for (i = 0; i < SEG->nseg; i++) { 00064 if ((SEG->scb[i].buf = G_malloc(SEG->size)) == NULL) 00065 return -2; 00066 00067 SEG->scb[i].n = -1; /* mark free */ 00068 SEG->scb[i].dirty = 0; 00069 SEG->scb[i].age = 0; 00070 } 00071 SEG->cur = 0; 00072 SEG->open = 1; 00073 00074 return 1; 00075 }