00001 #include <stdlib.h>
00002 #include "string.h"
00003 #include "anamod.h"
00004
00005 #define NALLOC 70
00006
00007 struct IntArray_ {
00008 char *name; int alloc,fill; PetscTruth *has; int *data;
00009 };
00010
00011 #undef __FUNCT__
00012 #define __FUNCT__ "CreateIntArray"
00013 PetscErrorCode CreateIntArray(const char *name,int size,IntArray *array)
00014 {
00015 IntArray inew; PetscErrorCode ierr;
00016 PetscFunctionBegin;
00017 ierr = PetscMalloc(sizeof(struct IntArray_),&inew); CHKERRQ(ierr);
00018 ierr = PetscMemzero(inew,sizeof(struct IntArray_)); CHKERRQ(ierr);
00019 if (name) inew->name = strdup(name);
00020 inew->fill = 0; inew->alloc = NALLOC;
00021 ierr = PetscMalloc(inew->alloc*sizeof(PetscTruth),&(inew->has)); CHKERRQ(ierr);
00022 ierr = PetscMemzero(inew->has,inew->alloc*sizeof(PetscTruth)); CHKERRQ(ierr);
00023 ierr = PetscMalloc(inew->alloc*sizeof(int),&(inew->data)); CHKERRQ(ierr);
00024 ierr = PetscMemzero(inew->data,inew->alloc*sizeof(int)); CHKERRQ(ierr);
00025 *array = inew;
00026 PetscFunctionReturn(0);
00027 }
00028
00029 #undef __FUNCT__
00030 #define __FUNCT__ "DeleteIntArray"
00031 PetscErrorCode DeleteIntArray(IntArray array)
00032 {
00033 PetscErrorCode ierr;
00034 PetscFunctionBegin;
00035 ierr = PetscFree(array->data); CHKERRQ(ierr);
00036 ierr = PetscFree(array->has); CHKERRQ(ierr);
00037 if (array->name) free(array->name);
00038 ierr = PetscFree(array); CHKERRQ(ierr);
00039 PetscFunctionReturn(0);
00040 }
00041
00042 #undef __FUNCT__
00043 #define __FUNCT__ "IntArrayAdd"
00044
00045
00046
00047 PetscErrorCode IntArrayAdd(IntArray array,int val,int *idx)
00048 {
00049 int ins;
00050 PetscFunctionBegin;
00051 if (array->fill>=array->alloc-1) SETERRQ(1,"No more space");
00052 ins = array->fill++;
00053 array->data[ins] = val;
00054 array->has[ins] = PETSC_TRUE;
00055 PetscFunctionReturn(0);
00056 }
00057
00058 #undef __FUNCT__
00059 #define __FUNCT__ "IntArraySetAt"
00060
00061
00062
00063 PetscErrorCode IntArraySetAt(IntArray array,int idx,int val)
00064 {
00065 PetscFunctionBegin;
00066 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
00067 array->data[idx] = val; array->has[idx] = PETSC_TRUE;
00068 if (idx>array->fill) array->fill = idx;
00069 PetscFunctionReturn(0);
00070 }
00071
00072 #undef __FUNCT__
00073 #define __FUNCT__ "IntArrayTryGetAt"
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 PetscErrorCode IntArrayTryGetAt(IntArray array,int idx,int *val,PetscTruth *has)
00086 {
00087 PetscFunctionBegin;
00088 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
00089 if (has) *has = array->has[idx];
00090 if (array->has[idx] && val) *val = array->data[idx];
00091 PetscFunctionReturn(0);
00092 }
00093
00094 #undef __FUNCT__
00095 #define __FUNCT__ "IntArrayGetAt"
00096
00097
00098
00099 PetscErrorCode IntArrayGetAt(IntArray array,int idx,int *val)
00100 {
00101 PetscFunctionBegin;
00102 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
00103 if (!array->has[idx]) SETERRQ1(1,"Asking for non-set element: %d",idx);
00104 *val = array->data[idx];
00105 PetscFunctionReturn(0);
00106 }
00107
00108
00109
00110
00111 struct StringArray_ {
00112 char *name; int alloc,fill; PetscTruth *has; char **data;
00113 };
00114
00115 #undef __FUNCT__
00116 #define __FUNCT__ "CreateStringArray"
00117 PetscErrorCode CreateStringArray(const char *name,int size,StringArray *array)
00118 {
00119 StringArray snew; PetscErrorCode ierr;
00120 PetscFunctionBegin;
00121 ierr = PetscMalloc(sizeof(struct StringArray_),&snew); CHKERRQ(ierr);
00122 ierr = PetscMemzero(snew,sizeof(struct StringArray_)); CHKERRQ(ierr);
00123 if (name) snew->name = strdup(name);
00124 snew->fill = 0; snew->alloc = NALLOC;
00125 ierr = PetscMalloc(snew->alloc*sizeof(PetscTruth),&(snew->has)); CHKERRQ(ierr);
00126 ierr = PetscMemzero(snew->has,snew->alloc*sizeof(PetscTruth)); CHKERRQ(ierr);
00127 ierr = PetscMalloc(snew->alloc*sizeof(char*),&(snew->data)); CHKERRQ(ierr);
00128 ierr = PetscMemzero(snew->data,snew->alloc*sizeof(char*)); CHKERRQ(ierr);
00129 *array = snew;
00130 PetscFunctionReturn(0);
00131 }
00132
00133 #undef __FUNCT__
00134 #define __FUNCT__ "DeleteStringArray"
00135 PetscErrorCode DeleteStringArray(StringArray array)
00136 {
00137 int i; PetscErrorCode ierr;
00138 PetscFunctionBegin;
00139 for (i=0; i<array->fill; i++)
00140 if (array->has[i]) free(array->data[i]);
00141 ierr = PetscFree(array->data); CHKERRQ(ierr);
00142 ierr = PetscFree(array->has); CHKERRQ(ierr);
00143 if (array->name) free(array->name);
00144 ierr = PetscFree(array); CHKERRQ(ierr);
00145 PetscFunctionReturn(0);
00146 }
00147
00148 #undef __FUNCT__
00149 #define __FUNCT__ "StringArrayAdd"
00150
00151
00152
00153 PetscErrorCode StringArrayAdd(StringArray array,char *val,int *idx)
00154 {
00155 int ins;
00156 PetscFunctionBegin;
00157 if (array->fill>=array->alloc-1) SETERRQ(1,"No more space");
00158 ins = array->fill++;
00159 array->data[ins] = strdup(val);
00160 array->has[ins] = PETSC_TRUE;
00161 PetscFunctionReturn(0);
00162 }
00163
00164 #undef __FUNCT__
00165 #define __FUNCT__ "StringArrayGetFill"
00166 PetscErrorCode StringArrayGetFill(StringArray array,int *idx)
00167 {
00168 PetscFunctionBegin;
00169 *idx = array->fill;
00170 PetscFunctionReturn(0);
00171 }
00172
00173 #undef __FUNCT__
00174 #define __FUNCT__ "StringArraySetAt"
00175
00176
00177
00178 PetscErrorCode StringArraySetAt(StringArray array,int idx,char *val)
00179 {
00180 PetscFunctionBegin;
00181 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
00182 array->data[idx] = strdup(val); array->has[idx] = PETSC_TRUE;
00183 if (idx>array->fill) array->fill = idx;
00184 PetscFunctionReturn(0);
00185 }
00186
00187 #undef __FUNCT__
00188 #define __FUNCT__ "StringArrayTryGetAt"
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 PetscErrorCode StringArrayTryGetAt(StringArray array,int idx,char **val,PetscTruth *has)
00201 {
00202 PetscFunctionBegin;
00203 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
00204 if (has) *has = array->has[idx];
00205 if (array->has[idx] && val) *val = array->data[idx];
00206 PetscFunctionReturn(0);
00207 }
00208
00209 #undef __FUNCT__
00210 #define __FUNCT__ "StringArrayGetAt"
00211
00212
00213
00214 PetscErrorCode StringArrayGetAt(StringArray array,int idx,char **val)
00215 {
00216 PetscFunctionBegin;
00217 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
00218 if (!array->has[idx]) SETERRQ1(1,"Asking for non-set element: %d",idx);
00219 *val = array->data[idx];
00220 PetscFunctionReturn(0);
00221 }
00222
00223
00224
00225
00226 struct AnalysisItemArray_ {
00227 char *name; int alloc,fill,*has; AnalysisItem *data;
00228 };
00229
00230 #undef __FUNCT__
00231 #define __FUNCT__ "CreateAnalysisItemArray"
00232 PetscErrorCode CreateAnalysisItemArray(char *name,int size,AnalysisItemArray *array)
00233 {
00234 AnalysisItemArray anew; PetscErrorCode ierr;
00235 PetscFunctionBegin;
00236 ierr = PetscMalloc(sizeof(struct AnalysisItemArray_),&anew); CHKERRQ(ierr);
00237 ierr = PetscMemzero(anew,sizeof(struct AnalysisItemArray_)); CHKERRQ(ierr);
00238 if (name) anew->name = strdup(name);
00239 anew->fill = 0; anew->alloc = NALLOC;
00240 ierr = PetscMalloc(anew->alloc*sizeof(PetscTruth),&(anew->has)); CHKERRQ(ierr);
00241 ierr = PetscMemzero(anew->has,anew->alloc*sizeof(PetscTruth)); CHKERRQ(ierr);
00242 ierr = PetscMalloc(anew->alloc*sizeof(AnalysisItem),&(anew->data)); CHKERRQ(ierr);
00243 ierr = PetscMemzero(anew->data,anew->alloc*sizeof(AnalysisItem)); CHKERRQ(ierr);
00244 *array = anew;
00245 PetscFunctionReturn(0);
00246 }
00247
00248 #undef __FUNCT__
00249 #define __FUNCT__ "DeleteAnalysisItemArray"
00250 PetscErrorCode DeleteAnalysisItemArray(AnalysisItemArray array)
00251 {
00252 PetscErrorCode ierr;
00253 PetscFunctionBegin;
00254 ierr = PetscFree(array->data); CHKERRQ(ierr);
00255 ierr = PetscFree(array->has); CHKERRQ(ierr);
00256 if (array->name) free(array->name);
00257 ierr = PetscFree(array); CHKERRQ(ierr);
00258 PetscFunctionReturn(0);
00259 }
00260
00261 #undef __FUNCT__
00262 #define __FUNCT__ "AnalysisItemArrayAdd"
00263
00264
00265
00266 PetscErrorCode AnalysisItemArrayAdd(AnalysisItemArray array,AnalysisItem val,int *idx)
00267 {
00268 int ins;
00269 PetscFunctionBegin;
00270 if (array->fill>=array->alloc-1) SETERRQ(1,"No more space");
00271 ins = array->fill++;
00272 array->data[ins] = val;
00273 array->has[ins] = PETSC_TRUE;
00274 PetscFunctionReturn(0);
00275 }
00276
00277 #undef __FUNCT__
00278 #define __FUNCT__ "AnalysisItemArraySetAt"
00279
00280
00281
00282 PetscErrorCode AnalysisItemArraySetAt(AnalysisItemArray array,int idx,AnalysisItem val)
00283 {
00284 PetscFunctionBegin;
00285 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
00286 array->data[idx] = val; array->has[idx] = PETSC_TRUE;
00287 if (idx>array->fill) array->fill = idx;
00288 PetscFunctionReturn(0);
00289 }
00290
00291 #undef __FUNCT__
00292 #define __FUNCT__ "AnalysisItemArrayTryGetAt"
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 PetscErrorCode AnalysisItemArrayTryGetAt(AnalysisItemArray array,int idx,AnalysisItem *val,PetscTruth *has)
00305 {
00306 PetscFunctionBegin;
00307 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
00308 if (has) *has = (PetscTruth)array->has[idx];
00309 if (array->has[idx] && val) *val = array->data[idx];
00310 PetscFunctionReturn(0);
00311 }
00312
00313 #undef __FUNCT__
00314 #define __FUNCT__ "AnalysisItemArrayGetAt"
00315
00316
00317
00318 PetscErrorCode AnalysisItemArrayGetAt(AnalysisItemArray array,int idx,AnalysisItem *val)
00319 {
00320 PetscFunctionBegin;
00321 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
00322 if (!array->has[idx]) SETERRQ1(1,"Asking for non-set element: %d",idx);
00323 *val = array->data[idx];
00324 PetscFunctionReturn(0);
00325 }
00326
00327
00328
00329
00330 struct AnalysisDataTypeArray_ {
00331 char *name; int alloc,fill,*has; AnalysisDataType *data;
00332 };
00333
00334 #undef __FUNCT__
00335 #define __FUNCT__ "CreateAnalysisDataTypeArray"
00336 PetscErrorCode CreateAnalysisDataTypeArray(char *name,int size,AnalysisDataTypeArray *array)
00337 {
00338 AnalysisDataTypeArray anew; PetscErrorCode ierr;
00339 PetscFunctionBegin;
00340 ierr = PetscMalloc(sizeof(struct AnalysisDataTypeArray_),&anew); CHKERRQ(ierr);
00341 ierr = PetscMemzero(anew,sizeof(struct AnalysisDataTypeArray_)); CHKERRQ(ierr);
00342 if (name) anew->name = strdup(name);
00343 anew->fill = 0; anew->alloc = NALLOC;
00344 ierr = PetscMalloc(anew->alloc*sizeof(PetscTruth),&(anew->has)); CHKERRQ(ierr);
00345 ierr = PetscMemzero(anew->has,anew->alloc*sizeof(PetscTruth)); CHKERRQ(ierr);
00346 ierr = PetscMalloc(anew->alloc*sizeof(AnalysisDataType),&(anew->data)); CHKERRQ(ierr);
00347 ierr = PetscMemzero(anew->data,anew->alloc*sizeof(AnalysisDataType)); CHKERRQ(ierr);
00348 *array = anew;
00349 PetscFunctionReturn(0);
00350 }
00351
00352 #undef __FUNCT__
00353 #define __FUNCT__ "DeleteAnalysisDataTypeArray"
00354 PetscErrorCode DeleteAnalysisDataTypeArray(AnalysisDataTypeArray array)
00355 {
00356 PetscErrorCode ierr;
00357 PetscFunctionBegin;
00358 ierr = PetscFree(array->data); CHKERRQ(ierr);
00359 ierr = PetscFree(array->has); CHKERRQ(ierr);
00360 if (array->name) free(array->name);
00361 ierr = PetscFree(array); CHKERRQ(ierr);
00362 PetscFunctionReturn(0);
00363 }
00364
00365 #undef __FUNCT__
00366 #define __FUNCT__ "AnalysisDataTypeArrayAdd"
00367
00368
00369
00370 PetscErrorCode AnalysisDataTypeArrayAdd(AnalysisDataTypeArray array,AnalysisDataType val,int *idx)
00371 {
00372 int ins;
00373 PetscFunctionBegin;
00374 if (array->fill>=array->alloc-1) SETERRQ(1,"No more space");
00375 ins = array->fill++;
00376 array->data[ins] = val;
00377 array->has[ins] = PETSC_TRUE;
00378 PetscFunctionReturn(0);
00379 }
00380
00381 #undef __FUNCT__
00382 #define __FUNCT__ "AnalysisDataTypeArraySetAt"
00383
00384
00385
00386 PetscErrorCode AnalysisDataTypeArraySetAt(AnalysisDataTypeArray array,int idx,AnalysisDataType val)
00387 {
00388 PetscFunctionBegin;
00389 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
00390 array->data[idx] = val; array->has[idx] = PETSC_TRUE;
00391 if (idx>array->fill) array->fill = idx;
00392 PetscFunctionReturn(0);
00393 }
00394
00395 #undef __FUNCT__
00396 #define __FUNCT__ "AnalysisDataTypeArrayTryGetAt"
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408 PetscErrorCode AnalysisDataTypeArrayTryGetAt(AnalysisDataTypeArray array,int idx,AnalysisDataType *val,PetscTruth *has)
00409 {
00410 PetscFunctionBegin;
00411 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
00412 if (has) *has = (PetscTruth)array->has[idx];
00413 if (array->has[idx] && val) *val = array->data[idx];
00414 PetscFunctionReturn(0);
00415 }
00416
00417 #undef __FUNCT__
00418 #define __FUNCT__ "AnalysisDataTypeArrayGetAt"
00419
00420
00421
00422 PetscErrorCode AnalysisDataTypeArrayGetAt(AnalysisDataTypeArray array,int idx,AnalysisDataType *val)
00423 {
00424 PetscFunctionBegin;
00425 if (idx>=array->alloc) SETERRQ1(1,"Index out of bounds: %d",idx);
00426 if (!array->has[idx]) SETERRQ1(1,"Asking for non-set element: %d",idx);
00427 *val = array->data[idx];
00428 PetscFunctionReturn(0);
00429 }
00430