9 * Functions to deal with raster objects, which are not directly interfaces
13 /* Some global variables are defined here */
14 /* Default reclass - property of reclass command
15 Something wrong with it. It should be allocated once, not upon each
16 intiialization of package
19 /* Points to list of all open rasters. This is good, becouse it would
20 correctly handle access to open rasters from multiple interptreters
22 XEPP *first_raster=NULL;
23 RASTER_OBJECT firstobject=NULL;
25 * Returns maximal value of raster, using current reclass
28 int Fgis_RasterMax(RASTER_OBJECT handle)
32 if(handle->reclass==def_reclass)
36 for(i=e->min;i<=e->max;i++)
37 if (i!=e->offsite&&handle->reclass[i]>max)
38 max=handle->reclass[i];
44 * Returns minimal value of raster, taking into account current reclass
47 int Fgis_RasterMin(RASTER_OBJECT handle)
51 if(handle->reclass==def_reclass)
55 for(i=e->min;i<=e->min;i++)
56 if (i!=e->offsite&&handle->reclass[i]<min)
57 min=handle->reclass[i];
62 * Reopens file in new mode. Returns 0 on success, non-zero on failure.
63 * If fails, file remains open in old mode.
68 * Creates new XEPP object from open EPP* object.
72 XEPP* Fgis_NewXEPP(EPP *file,char *filename)
75 xptr=malloc(sizeof(XEPP));
78 xptr->filename=stralloc(filename);
79 xptr->next=first_raster;
85 * Opens existing epp file. If file already opened, returns pointer
89 XEPP* Fgis_OpenXEPP(char *filename,EPP *(*openfunc)(char *))
92 XEPP * xptr=first_raster;
96 if (!strcmp(xptr->filename,filename)) break;
101 /* îÅÔ ÔÁËÏÇÏ × ÔÁÂÌÉÃÅ, ÏÔËÒÙ×ÁÅÍ ÎÏ×ÙÊ*/
102 epp_ptr=openfunc(filename);
106 xptr=Fgis_NewXEPP(epp_ptr,filename);
107 xptr->editable=(openfunc==load_epp);
111 /* if it was open in read-only mode and now we want it to
113 if (!xptr->editable&&openfunc==load_epp) {
116 /* reopen for read-write */
117 xptr->e=load_epp(filename);
118 /* if failed, restore it back in readonly mode and return NULL*/
120 xptr->e=open_epp(filename);
124 /* fix reclass tables for all objects, which refers to this file*/
125 reclass_size=1<<(xptr->e->kind);
126 for (obj=firstobject;obj!=NULL;obj=obj->next) {
127 if (obj->file==xptr) {
128 obj->reclass=realloc(obj->reclass,reclass_size*sizeof(short));
139 * Gets rid of XEPP object (if only reference - deletes, otherwise
140 * decrements link count)
143 void Fgis_CloseXEPP(XEPP* file)
146 if(!file->linkcount) {
147 /* Remove it from list */
148 if (first_raster==file) {
149 first_raster=file->next;
151 XEPP* tmp=first_raster;
152 while (tmp->next!=file)
154 tmp->next=file->next;
158 free(file->filename);