- Main Page
- Classes
- Files

- Search for |

# data.cpp

    00001 // "data.cpp"
    00002
    00003 // (c) OPAC Team, LIFL, January 2006
    00004
    00005 /*
    00006    Contact: paradiseo-help@lists.gforge.inria.fr
    00007 */
    00008
    00009 #include <stdio.h>
    00010 #include <assert.h>
    00011 #include <string.h>
    00012 #include <stdlib.h>
    00013
    00014 #include <utils/eoParser.h>
    00015
    00016 #include "data.h"
    00017 #include "node.h"
    00018
    00019 #define MAX_TRASH_LENGTH 1000
    00020 #define MAX_FIELD_LENGTH 1000
    00021 #define MAX_LINE_LENGTH 1000
    00022
    00023 static void getNextField (FILE * __f, char * __buff) {
    00024
    00025   char trash [MAX_TRASH_LENGTH];
    00026
    00027   fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */
    00028   fscanf (__f, "%[^:\n]", __buff); /* Reading the field */
    00029   fgetc (__f);
    00030 }
    00031
    00032 static void getLine (FILE * __f, char * __buff) {
    00033
    00034   char trash [MAX_TRASH_LENGTH];
    00035
    00036   fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */
    00037   fscanf (__f, "%[^\n]", __buff); /* Reading the line */
    00038 }
    00039
    00040 void loadData (const char * __filename) {
    00041
    00042   FILE * f = fopen (__filename, "r");
    00043
    00044    if (f) {
    00045
    00046      printf ("Loading '%s'.\n", __filename);
    00047
    00048      char field [MAX_FIELD_LENGTH];
    00049
    00050      getNextField (f, field); /* Name */
    00051      assert (strstr (field, "NAME"));
    00052      getNextField (f, field);
    00053      printf ("NAME: %s.\n", field);
    00054
    00055      getNextField (f, field); /* Comment */
    00056      assert (strstr (field, "COMMENT"));
    00057      getLine (f, field);
    00058      printf ("COMMENT: %s.\n", field);
    00059
    00060      getNextField (f, field); /* Type */
    00061      assert (strstr (field, "TYPE"));
    00062      getNextField (f, field);
    00063      printf ("TYPE: %s.\n", field);
    00064
    00065      getNextField (f, field); /* Dimension */
    00066      assert (strstr (field, "DIMENSION"));
    00067      getNextField (f, field);
    00068      printf ("DIMENSION: %s.\n", field);
    00069      numNodes = atoi (field);
    00070
    00071      getNextField (f, field); /* Edge weight type */
    00072      assert (strstr (field, "EDGE_WEIGHT_TYPE"));
    00073      getNextField (f, field);
    00074      printf ("EDGE_WEIGHT_TYPE: %s.\n", field);
    00075
    00076      getNextField (f, field); /* Node coord section */
    00077      assert (strstr (field, "NODE_COORD_SECTION"));
    00078      loadNodes (f);
    00079
    00080      getNextField (f, field); /* End of file */
    00081      assert (strstr (field, "EOF"));
    00082      printf ("EOF.\n");
    00083    }
    00084    else {
    00085
    00086      fprintf (stderr, "Can't open '%s'.\n", __filename);
    00087      exit (1);
    00088    }
    00089 }
    00090
    00091 void loadData (eoParser & __parser) {
    00092
    00093   /* Getting the path of the instance */
    00094
    00095   eoValueParam <std :: string> param ("", "inst", "Path of the instance") ;
    00096   __parser.processParam (param) ;
    00097   loadData (param.value ().c_str ());
    00098 }