data.cpp

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 // "data.cpp"
00004 
00005 // (c) OPAC Team, LIFL, January 2006
00006 
00007 /* This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011    
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Lesser General Public License for more details.
00016    
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with this library; if not, write to the Free Software
00019    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020    
00021    Contact: cahon@lifl.fr
00022 */
00023 
00024 #include <stdio.h>
00025 #include <assert.h>
00026 #include <string.h>
00027 #include <stdlib.h>
00028 
00029 #include <utils/eoParser.h>
00030 
00031 #include "data.h"
00032 #include "node.h"
00033 
00034 #define MAX_TRASH_LENGTH 1000
00035 #define MAX_FIELD_LENGTH 1000
00036 #define MAX_LINE_LENGTH 1000
00037 
00038 static void getNextField (FILE * __f, char * __buff) {
00039   
00040   char trash [MAX_TRASH_LENGTH];  
00041 
00042   fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */ 
00043   fscanf (__f, "%[^:\n]", __buff); /* Reading the field */
00044   fgetc (__f);
00045 }
00046 
00047 static void getLine (FILE * __f, char * __buff) {
00048 
00049   char trash [MAX_TRASH_LENGTH];  
00050 
00051   fscanf (__f, "%[ \t:\n]", trash); /* Discarding sep. */ 
00052   fscanf (__f, "%[^\n]", __buff); /* Reading the line */
00053 }
00054 
00055 void loadData (const char * __filename) {
00056 
00057   FILE * f = fopen (__filename, "r");
00058 
00059    if (f) {
00060 
00061      printf ("Loading '%s'.\n", __filename);
00062      
00063      char field [MAX_FIELD_LENGTH];
00064      
00065      getNextField (f, field); /* Name */
00066      assert (strstr (field, "NAME"));
00067      getNextField (f, field); 
00068      printf ("NAME: %s.\n", field);
00069      
00070      getNextField (f, field); /* Comment */
00071      assert (strstr (field, "COMMENT"));
00072      getLine (f, field);
00073      printf ("COMMENT: %s.\n", field);
00074      
00075      getNextField (f, field); /* Type */
00076      assert (strstr (field, "TYPE"));
00077      getNextField (f, field); 
00078      printf ("TYPE: %s.\n", field);
00079 
00080      getNextField (f, field); /* Dimension */
00081      assert (strstr (field, "DIMENSION"));
00082      getNextField (f, field); 
00083      printf ("DIMENSION: %s.\n", field);
00084      numNodes = atoi (field);
00085 
00086      getNextField (f, field); /* Edge weight type */
00087      assert (strstr (field, "EDGE_WEIGHT_TYPE"));
00088      getNextField (f, field); 
00089      printf ("EDGE_WEIGHT_TYPE: %s.\n", field);
00090      
00091      getNextField (f, field); /* Node coord section */
00092      assert (strstr (field, "NODE_COORD_SECTION"));
00093      loadNodes (f);
00094      
00095      getNextField (f, field); /* End of file */
00096      assert (strstr (field, "EOF"));
00097      printf ("EOF.\n");
00098    }
00099    else {
00100      
00101      fprintf (stderr, "Can't open '%s'.\n", __filename); 
00102      exit (1);
00103    }
00104 }
00105 
00106 void loadData (eoParser & __parser) {
00107   
00108   /* Getting the path of the instance */
00109   
00110   eoValueParam <std :: string> param ("", "inst", "Path of the instance") ;
00111   __parser.processParam (param) ;
00112   loadData (param.value ().c_str ());
00113 }

Generated on Fri Dec 22 16:54:58 2006 for ParadisEO by  doxygen 1.4.7