Changeset 32


Ignore:
Timestamp:
Dec 15, 2009, 6:42:33 PM (14 years ago)
Author:
(none)
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • proiecte/Parallel-DT/R8/Src/getdata.c

    r26 r32  
    66/*************************************************************************/
    77
    8 
    98#include "defns.i"
    109#include "types.i"
     
    1211
    1312#define Inc 2048
    14 
    15 
    1613
    1714/*************************************************************************/
     
    2522/*************************************************************************/
    2623
    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();
     24GetData(Extension)
     25        /*  --------  */
     26        String Extension; {
     27        FILE *Df, *fopen();
     28        char Fn[100];
     29        ItemNo i = 0, j, ItemSpace = 0;
     30        Description GetDescription();
    3531
    36     /*  Open data file  */
     32        /*  Open data file  */
    3733
    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, "");
    4138
    42     do
    43     {
    44         MaxItem = i;
     39        do {
     40                MaxItem = i;
    4541
    46         /*  Make sure there is room for another item  */
     42                /*  Make sure there is room for another item  */
    4743
    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                }
    6254
    63         Item[i] = GetDescription(Df);
     55                Item[i] = GetDescription(Df);
    6456
    65     } while ( Item[i] != Nil && ++i );
     57        } while (Item[i] != Nil && ++i);
    6658
    67     fclose(Df);
    68     MaxItem = i - 1;
     59        fclose(Df);
     60        MaxItem = i - 1;
    6961}
    70 
    71 
    7262
    7363/*************************************************************************/
     
    8474/*************************************************************************/
    8575
     76Description 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();
    8686
    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));
    9889
    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  */
    10293
    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  */
    10897
    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  */
    115105
    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);
    119134                }
    120                 else
    121                 {
    122                     Dv = Which(name, AttValName[Att], 1, MaxAttVal[Att]);
    123                     if ( ! Dv )
    124                     {
    125                         if ( SpecialStatus[Att] == DISCRETE )
    126                         {
    127                             /*  Add value to list  */
    128135
    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;
    136141
    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        }
    180146}
Note: See TracChangeset for help on using the changeset viewer.