- Timestamp:
- Dec 15, 2009, 6:42:33 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
proiecte/Parallel-DT/R8/Src/getdata.c
r26 r32 6 6 /*************************************************************************/ 7 7 8 9 8 #include "defns.i" 10 9 #include "types.i" … … 12 11 13 12 #define Inc 2048 14 15 16 13 17 14 /*************************************************************************/ … … 25 22 /*************************************************************************/ 26 23 27 GetData(Extension) 28 /* -------- */ 29 String Extension; 30 { 31 FILE *Df, *fopen(); 32 char Fn[100]; 33 ItemNo i=0, j, ItemSpace=0; 34 Description GetDescription(); 24 GetData(Extension) 25 /* -------- */ 26 String Extension; { 27 FILE *Df, *fopen(); 28 char Fn[100]; 29 ItemNo i = 0, j, ItemSpace = 0; 30 Description GetDescription(); 35 31 36 32 /* Open data file */ 37 33 38 strcpy(Fn, FileName); 39 strcat(Fn, Extension); 40 if ( ! ( Df = fopen(Fn, "r") ) ) Error(0, Fn, ""); 34 strcpy(Fn, FileName); 35 strcat(Fn, Extension); 36 if (!(Df = fopen(Fn, "r"))) 37 Error(0, Fn, ""); 41 38 42 do 43 { 44 MaxItem = i; 39 do { 40 MaxItem = i; 45 41 46 /* Make sure there is room for another item */42 /* Make sure there is room for another item */ 47 43 48 if ( i >= ItemSpace ) 49 { 50 if ( ItemSpace ) 51 { 52 ItemSpace += Inc; 53 Item = (Description *) 54 realloc(Item, ItemSpace*sizeof(Description)); 55 } 56 else 57 { 58 Item = (Description *) 59 malloc((ItemSpace=Inc)*sizeof(Description)); 60 } 61 } 44 if (i >= ItemSpace) { 45 if (ItemSpace) { 46 ItemSpace += Inc; 47 Item = (Description *) realloc(Item, ItemSpace 48 * sizeof(Description)); 49 } else { 50 Item = (Description *) malloc((ItemSpace = Inc) 51 * sizeof(Description)); 52 } 53 } 62 54 63 Item[i] = GetDescription(Df);55 Item[i] = GetDescription(Df); 64 56 65 } while ( Item[i] != Nil && ++i);57 } while (Item[i] != Nil && ++i); 66 58 67 68 59 fclose(Df); 60 MaxItem = i - 1; 69 61 } 70 71 72 62 73 63 /*************************************************************************/ … … 84 74 /*************************************************************************/ 85 75 76 Description GetDescription(Df) 77 /* --------------- */ 78 FILE *Df; { 79 Attribute Att; 80 char name[500], *endname, *CopyString(); 81 Boolean ReadName(); 82 int Dv; 83 float Cv; 84 Description Dvec; 85 double strtod(); 86 86 87 Description GetDescription(Df) 88 /* --------------- */ 89 FILE *Df; 90 { 91 Attribute Att; 92 char name[500], *endname, *CopyString(); 93 Boolean ReadName(); 94 int Dv; 95 float Cv; 96 Description Dvec; 97 double strtod(); 87 if (ReadName(Df, name)) { 88 Dvec = (Description) calloc(MaxAtt + 2, sizeof(AttValue)); 98 89 99 if ( ReadName(Df, name) ) 100 101 Dvec = (Description) calloc(MaxAtt+2, sizeof(AttValue));90 ForEach(Att, 0, MaxAtt) { 91 if (SpecialStatus[Att] == IGNORE) { 92 /* Skip this value */ 102 93 103 ForEach(Att, 0, MaxAtt) 104 { 105 if ( SpecialStatus[Att] == IGNORE ) 106 { 107 /* Skip this value */ 94 DVal(Dvec, Att) = 0; 95 } else if (MaxAttVal[Att] || SpecialStatus[Att] == DISCRETE) { 96 /* Discrete value */ 108 97 109 DVal(Dvec, Att) = 0; 110 } 111 else 112 if ( MaxAttVal[Att] || SpecialStatus[Att] == DISCRETE ) 113 { 114 /* Discrete value */ 98 if (!(strcmp(name, "?"))) { 99 Dv = 0; 100 } else { 101 Dv = Which(name, AttValName[Att], 1, MaxAttVal[Att]); 102 if (!Dv) { 103 if (SpecialStatus[Att] == DISCRETE) { 104 /* Add value to list */ 115 105 116 if ( ! ( strcmp(name, "?") ) ) 117 { 118 Dv = 0; 106 Dv = ++MaxAttVal[Att]; 107 if (Dv > (int) AttValName[Att][0]) { 108 printf("\nToo many values for %s (max %d)\n", 109 AttName[Att], (int) AttValName[Att][0]); 110 exit(1); 111 } 112 113 AttValName[Att][Dv] = CopyString(name); 114 } else { 115 Error(4, AttName[Att], name); 116 } 117 } 118 } 119 DVal(Dvec, Att) = Dv; 120 } else { 121 /* Continuous value */ 122 123 if (!(strcmp(name, "?"))) { 124 Cv = Unknown; 125 } else { 126 Cv = strtod(name, &endname); 127 if (endname == name || *endname != '\0') 128 Error(4, AttName[Att], name); 129 } 130 CVal(Dvec, Att) = Cv; 131 } 132 133 ReadName(Df, name); 119 134 } 120 else121 {122 Dv = Which(name, AttValName[Att], 1, MaxAttVal[Att]);123 if ( ! Dv )124 {125 if ( SpecialStatus[Att] == DISCRETE )126 {127 /* Add value to list */128 135 129 Dv = ++MaxAttVal[Att]; 130 if ( Dv > (int) AttValName[Att][0] ) 131 { 132 printf("\nToo many values for %s (max %d)\n", 133 AttName[Att], (int) AttValName[Att][0]); 134 exit(1); 135 } 136 if ((Dv = Which(name, ClassName, 0, MaxClass)) < 0) { 137 Error(5, "", name); 138 Dv = 0; 139 } 140 Class(Dvec) = Dv; 136 141 137 AttValName[Att][Dv] = CopyString(name); 138 } 139 else 140 { 141 Error(4, AttName[Att], name); 142 } 143 } 144 } 145 DVal(Dvec, Att) = Dv; 146 } 147 else 148 { 149 /* Continuous value */ 150 151 if ( ! ( strcmp(name, "?") ) ) 152 { 153 Cv = Unknown; 154 } 155 else 156 { 157 Cv = strtod(name, &endname); 158 if ( endname == name || *endname != '\0' ) 159 Error(4, AttName[Att], name); 160 } 161 CVal(Dvec, Att) = Cv; 162 } 163 164 ReadName(Df, name); 165 } 166 167 if ( (Dv = Which(name, ClassName, 0, MaxClass)) < 0 ) 168 { 169 Error(5, "", name); 170 Dv = 0; 171 } 172 Class(Dvec) = Dv; 173 174 return Dvec; 175 } 176 else 177 { 178 return Nil; 179 } 142 return Dvec; 143 } else { 144 return Nil; 145 } 180 146 }
Note: See TracChangeset
for help on using the changeset viewer.