saveg.c File Reference

#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "machine.h"
#include "MALLOC.h"

Include dependency graph for saveg.c:

Go to the source code of this file.

Defines

#define MAXNAM   80

Typedefs

typedef int(*) PF (const void *, const void *)

Functions

char * my_basename ()
void cerro ()
char * dirname ()
int CheckGraphName ()
char * StripGraph ()
static int CompString (char **s1, char **s2)
void C2F() saveg (char *path, int *lpath, char *name, int *lname, int *directed, int *node_number, int *tail, int *head, char ***node_name, int *node_type, int *node_x, int *node_y, int *node_color, int *node_diam, int *node_border, int *node_font_size, double *node_demand, char ***edge_name, int *edge_color, int *edge_width, int *edge_hi_width, int *edge_font_size, double *edge_length, double *edge_cost, double *edge_min_cap, double *edge_max_cap, double *edge_q_weight, double *edge_q_orig, double *edge_weight, int *default_node_diam, int *default_node_border, int *default_edge_width, int *default_edge_hi_width, int *default_font_size, int *ma)


Define Documentation

#define MAXNAM   80

Definition at line 30 of file saveg.c.


Typedef Documentation

typedef int(*) PF(const void *, const void *)

Definition at line 38 of file saveg.c.


Function Documentation

void cerro (  ) 

int CheckGraphName (  ) 

static int CompString ( char **  s1,
char **  s2 
) [static]

Definition at line 40 of file saveg.c.

00041 {
00042   return strcmp((char*)*s1,(char*)*s2);
00043 }

char* dirname (  ) 

char* my_basename (  ) 

void C2F() saveg ( char *  path,
int lpath,
char *  name,
int lname,
int directed,
int node_number,
int tail,
int head,
char ***  node_name,
int node_type,
int node_x,
int node_y,
int node_color,
int node_diam,
int node_border,
int node_font_size,
double *  node_demand,
char ***  edge_name,
int edge_color,
int edge_width,
int edge_hi_width,
int edge_font_size,
double *  edge_length,
double*  edge_cost,
double*  edge_min_cap,
double*  edge_max_cap,
double *  edge_q_weight,
double*  edge_q_orig,
double*  edge_weight,
int default_node_diam,
int default_node_border,
int default_edge_width,
int default_edge_hi_width,
int default_font_size,
int ma 
)

Definition at line 45 of file saveg.c.

References cerro(), CompString(), description, dir, DIR, dirname, f(), fname, FREE, i, it, lar, ma, MALLOC, MAXNAM, my_basename(), name, NULL, path, and StripGraph().

00066 {
00067   FILE *f;
00068 #if !(defined _MSC_VER)
00069   DIR *dirp;
00070 #else
00071   int it;
00072 #endif
00073   char fname[2*MAXNAM];
00074   char description[2*MAXNAM];
00075   char dir[1024], nname[2*MAXNAM];
00076   int i;
00077   char **lar;
00078 
00079   /* check uniqueness of node names */
00080   if (*node_number != 1) {
00081     if ((lar = (char **)MALLOC(sizeof(char *) * *node_number)) == NULL) {
00082       cerro("Running out of memory");
00083       return;
00084     }
00085     for (i = 0; i < *node_number; i++) lar[i] = (*node_name)[i];
00086     qsort((char*)lar,*node_number,sizeof(char*),(PF)CompString);
00087     for (i = 0; i < *node_number - 1; i++) {
00088       if (!strcmp(lar[i],lar[i+1])) {
00089         sprintf(description,
00090                 "Bad graph file. Node \"%s\" is duplicated",lar[i]);
00091         cerro(description);
00092         FREE(lar);
00093         return;
00094       }
00095     }
00096     if (!strcmp(lar[*node_number - 2],lar[*node_number - 1])) {
00097       sprintf(description,
00098               "Bad graph file. Node \"%s\" is duplicated",lar[*node_number - 2]);
00099       cerro(description);
00100       FREE(lar);
00101       return;
00102     }
00103     FREE(lar);
00104   }
00105  
00106   path[*lpath] = '\0';
00107   name[*lname] = '\0';
00108   
00109   if (!strcmp(path," ")) {
00110     getwd(dir);
00111     strcpy(nname,name);
00112   }
00113   else {
00114 #if (defined _MSC_VER)
00115     getwd(dir);
00116 #if (defined _MSC_VER)
00117     it= chdir(path);
00118     chdir(dir);
00119 #else
00120     it= chdir_(path,strlen(path));
00121     chdir_(dir,strlen(dir));
00122 #endif
00123     if (it == 0) {
00124       strcpy(dir,path);
00125     }
00126 #else
00127     if ((dirp=opendir(path)) != NULL) {
00128       strcpy(dir,path);
00129       closedir(dirp);
00130     }
00131 #endif 
00132     else {
00133       strcpy(nname,StripGraph(my_basename(path)));
00134       if (dirname(path) == NULL) getwd(dir);
00135       else strcpy(dir,dirname(path));     
00136     }
00137   }
00138 #if !(defined _MSC_VER)
00139   if ((dirp=opendir(dir)) == NULL) {
00140     sprintf(description,"Directory \"%s\" does not exist",dir);
00141     cerro(description);
00142     return;
00143   }
00144   closedir(dirp);
00145 
00146   /*  if(CheckGraphName(nname,dir)) {
00147     sprintf(description,"Graph \"%s\" already exists in directory \"%s\"",
00148             nname,dir);
00149     cerro(description);
00150     return;
00151     }*/
00152 #endif
00153 
00154   strcpy(fname,dir);
00155   strcat(fname,"/");
00156   strcat(fname,nname);
00157   strcat(fname,".graph");
00158   f = fopen(fname,"w");
00159   if (f == NULL) {
00160     sprintf(description,
00161             "Unable to write file in directory %s, check access",dir);
00162     cerro(description);
00163     return;
00164   }
00165   /* Write graph to file */
00166   
00167   fprintf(f,"GRAPH TYPE (0 = UNDIRECTED, 1 = DIRECTED), DEFAULTS (NODE DIAMETER, NODE BORDER, ARC WIDTH, HILITED ARC WIDTH, FONTSIZE):\n");
00168   fprintf(f,"%d %d %d %d %d %d\n",*directed,*default_node_diam,
00169           *default_node_border,*default_edge_width,*default_edge_hi_width,
00170           *default_font_size);
00171   if (*directed) {
00172     fprintf(f,"NUMBER OF ARCS:\n");
00173   }
00174   else {
00175     fprintf(f,"NUMBER OF EDGES:\n");
00176   }
00177   fprintf(f,"%d\n",*ma);
00178   fprintf(f,"NUMBER OF NODES:\n");
00179   fprintf(f,"%d\n",*node_number);
00180   fprintf(f,"****************************************\n");
00181 
00182   /* Write arcs to files */
00183 
00184   if (*directed) {
00185     fprintf(f,"DESCRIPTION OF ARCS:\n");
00186     fprintf(f,"ARC NAME, TAIL NODE NAME, HEAD NODE NAME, COLOR, WIDTH, HIWIDTH, FONTSIZE\n");
00187   }
00188   else {
00189     fprintf(f,"DESCRIPTION OF EDGES:\n");
00190     fprintf(f,"EDGE NAME, NODE NAME, NODE NAME, COLOR, WIDTH, HIWIDTH, FONTSIZE\n");
00191   }
00192   fprintf
00193     (f,"COST, MIN CAP, MAX CAP, LENGTH, Q WEIGHT, Q ORIGIN, WEIGHT\n");
00194   fprintf(f,"\n");
00195 
00196   for (i = 0; i < *ma; i++) {
00197     fprintf(f,"%s %s %s %d %d %d %d\n",(*edge_name)[i],(*node_name)[tail[i]-1],
00198             (*node_name)[head[i]-1],edge_color[i],edge_width[i],
00199             edge_hi_width[i],edge_font_size[i]);
00200     fprintf(f,"%e %e %e %e %e %e %e\n",
00201             edge_cost[i],edge_min_cap[i],edge_max_cap[i],edge_length[i],
00202             edge_q_weight[i],edge_q_orig[i],edge_weight[i]);
00203   }
00204   
00205   /* Write nodes to files */
00206 
00207   fprintf(f,"****************************************\n");
00208   fprintf(f,"DESCRIPTION OF NODES:\n");
00209   fprintf(f,"NODE NAME, POSSIBLE TYPE (1 = SINK, 2 = SOURCE)\n");
00210   fprintf(f,"X, Y, COLOR, DIAMETER, BORDER, FONTSIZE\n");
00211   fprintf(f,"DEMAND\n");
00212   fprintf(f,"\n");
00213 
00214   for (i = 0; i < *node_number; i++) {
00215     if (node_type[i] == 0)
00216       fprintf(f,"%s\n",(*node_name)[i]);
00217     else fprintf(f,"%s %d\n",(*node_name)[i],node_type[i]);
00218     fprintf(f,"%d %d %d %d %d %d \n",
00219             node_x[i],node_y[i],node_color[i],node_diam[i],
00220             node_border[i],node_font_size[i]);
00221     fprintf(f,"%e\n",node_demand[i]);
00222   }
00223 
00224   fclose(f);
00225 }

Here is the call graph for this function:

char* StripGraph (  ) 


Generated on Sun Mar 4 16:10:26 2007 for Scilab [trunk] by  doxygen 1.5.1