|
| 1 | +/* |
| 2 | + * a-float.c - functions to allocate arrays of float |
| 3 | + * |
| 4 | + * copyright (c) 1991, George K. Thiruvathukal |
| 5 | + * This file is distributed with the Apt Compiler Toolkit |
| 6 | + */ |
| 7 | + |
| 8 | +#include "a-float.h" |
| 9 | + |
| 10 | +#include <stdio.h> |
| 11 | +#include <stdlib.h> |
| 12 | + |
| 13 | +#ifdef __STDC__ |
| 14 | +float *New1DOffloat (int l1, int h1) |
| 15 | +#else |
| 16 | +float *New1DOffloat (l1, h1) |
| 17 | +int l1, h1; |
| 18 | +#endif |
| 19 | +{ |
| 20 | + float *x = (float *)calloc( (h1 - l1 + 1), sizeof(float)); |
| 21 | + if (x == NULL) { |
| 22 | + fprintf(stderr,"New1DOffloat: allocation failure.\n"); |
| 23 | + return NULL; |
| 24 | + } |
| 25 | + return x - l1; |
| 26 | +} |
| 27 | + |
| 28 | +#ifdef __STDC__ |
| 29 | +float **New2DOffloat (int l1, int h1, int l2, int h2) |
| 30 | +#else |
| 31 | +float **New2DOffloat (l1, h1, l2, h2) |
| 32 | +int l1, h1, l2, h2; |
| 33 | +#endif |
| 34 | +{ |
| 35 | + float **x = (float **)calloc( (h1 - l1 + 1), sizeof(float *)); |
| 36 | + int i; |
| 37 | + |
| 38 | + |
| 39 | + if (x == NULL) { |
| 40 | + fprintf(stderr,"New2DOffloat: allocation failure; dimension 1\n"); |
| 41 | + return NULL; |
| 42 | + } |
| 43 | + x -= l1; |
| 44 | + for (i=l1; i <= h1; i++) { |
| 45 | + x[i] = New1DOffloat (l2, h2); |
| 46 | + if (x[i] == NULL) { |
| 47 | + fprintf(stderr,"New2DOffloat: allocation failure; dimension 2\n"); |
| 48 | + return NULL; |
| 49 | + } |
| 50 | + } |
| 51 | + return x; |
| 52 | +} |
| 53 | + |
| 54 | +#ifdef __STDC__ |
| 55 | +float ***New3DOffloat (int l1, int h1, int l2, int h2, int l3, int h3) |
| 56 | +#else |
| 57 | +float ***New3DOffloat (l1, h1, l2, h2, l3, h3) |
| 58 | +int l1, h1, l2, h2, l3, h3; |
| 59 | +#endif |
| 60 | +{ |
| 61 | + float ***x = (float ***)calloc( (h1 - l1 + 1), sizeof(float **)); |
| 62 | + int i; |
| 63 | + |
| 64 | + if (x == NULL) { |
| 65 | + fprintf(stderr,"New3DOffloat: allocation failure; dimension 1\n"); |
| 66 | + return NULL; |
| 67 | + } |
| 68 | + x -= l1; |
| 69 | + for (i=l1; i <= h1; i++) { |
| 70 | + x[i] = New2DOffloat (l2, h2, l3, h3); |
| 71 | + if (x[i] == NULL) { |
| 72 | + fprintf(stderr,"New3DOffloat: allocation failure; dimension 2\n"); |
| 73 | + return NULL; |
| 74 | + } |
| 75 | + } |
| 76 | + return x; |
| 77 | +} |
| 78 | + |
| 79 | +#ifdef __STDC__ |
| 80 | +void Dispose1DOffloat (float *a) |
| 81 | +#else |
| 82 | +void Dispose1DOffloat (a) |
| 83 | +float *a; |
| 84 | +#endif |
| 85 | +{ |
| 86 | + free(a); |
| 87 | +} |
| 88 | + |
| 89 | +#ifdef __STDC__ |
| 90 | +void Dispose2DOffloat (float **a, int l1, int h1) |
| 91 | +#else |
| 92 | +void Dispose2DOffloat (a, l1, h1) |
| 93 | +float **a; |
| 94 | +int l1, h1; |
| 95 | +#endif |
| 96 | +{ |
| 97 | + int i; |
| 98 | + |
| 99 | + for (i=l1; i <= h1; i++) |
| 100 | + Dispose1DOffloat (a[i]); |
| 101 | +} |
| 102 | + |
| 103 | +#ifdef __STDC__ |
| 104 | +void Dispose3DOffloat (float ***a, int l1, int h1, int l2, int h2) |
| 105 | +#else |
| 106 | +void Dispose3DOffloat (a, l1, h1, l2, h2) |
| 107 | +float ***a; |
| 108 | +int l1, h1, l2, h2; |
| 109 | +#endif |
| 110 | +{ |
| 111 | + int i; |
| 112 | + |
| 113 | + for (i=l1; i <= h1; i++) |
| 114 | + Dispose2DOffloat (a[i],l2,h2); |
| 115 | +} |
0 commit comments