File: hvref.c

package info (click to toggle)
lrslib 0.73-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,888 kB
  • sloc: ansic: 20,893; sh: 279; makefile: 252; perl: 97; csh: 51
file content (142 lines) | stat: -rwxr-xr-x 3,409 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/******************************************************************
December 30,2019
Program to make a cross reference list between H and V reps
Usage (same for ext file):
Add  printcobasis and incidence options to cube.ine

% lrs cube.ine cube.ext
% xref cube.ext

Edit the output file  cube.ext.x so that the second line contains two integers

rows maxindex
 
where rows >= # output lines in cube.ext.x 
      maxindex >= # input lines in cube.ine 

or just use 0 0 and the program will tell you which values to use

% hvref cube.ext.x

gives V to H and H to V cross reference tables
**********************************************************************/
int main(int argc, char *argv[]) {
  int i=0, j=0;
  int first=1;
  int Hrep=1;
  int rows=0, maxindex=0;
  int inrows=0, outrows=0;
  int rowindex;
  char s[10000];
  int x;

  int *nrow;
  int **table;

  FILE *lrs_ifp;

  if(argc > 1)
    {
     if((lrs_ifp = fopen (argv[1], "r")) == NULL)
      {
         printf ("\nBad input file name\n");
         return 1;
      }
    }
    else
      lrs_ifp=stdin;

  x=fscanf(lrs_ifp,"%s", s);
  while(first && x != EOF )
    {
      if(strcmp(s,"H-representation") == 0 || strcmp(s,"V-representation") == 0)
       {
         if(strcmp(s,"H-representation") == 0)
            printf("\nH-representation");
         else
          {
            printf("\nV-representation");
            Hrep=0;
          }
         first=0;
         if(fscanf(lrs_ifp,"%d %d",&rows,&maxindex)==EOF)
             {
               printf("\n*input file missing data");
               return 0;
             }            
         printf("\n%d %d",rows,maxindex);

         nrow=(int *)malloc((maxindex+2)*sizeof(int));
         table = (int **)malloc((rows+2) * (maxindex+2) * sizeof(int));
         for (i=0;i<=maxindex+1;i++)
             table[i] = (int*)malloc((rows+2) * sizeof(int));
         for(i=0;i<=maxindex;i++)
          {
           nrow[i]=0;
           for(j=0;j<=rows;j++)
             table[i][j]=0;
          }
       }
      if(first)
        x=fscanf(lrs_ifp,"%s", s);
     }
  while(x != EOF)
    {
      first=1;
      x=fscanf(lrs_ifp,"%s", s);
      while(x != EOF && strcmp(s,"#") !=0)
          {
           i=atoi(s);
           if(first==1)
             {
              printf("\n%d:",i);
              rowindex=i;
              inrows++;
             }
           else 
             {
              if(i>outrows)
               outrows=i;
              if(i <= maxindex && nrow[i] < rows)
                {
                  nrow[i]++;
                  table[i][ nrow[i]]=rowindex;
                }
              printf(" %d",i);
             }
           x=fscanf(lrs_ifp,"%s", s);
           first=0;
          }
    }

  if(inrows <= rows && outrows <= maxindex)
    {
      if(Hrep)
         printf("\n\nV-representation");
      else
         printf("\n\nH-representation");
      printf("\n%d %d",outrows,inrows);

      for(i=1;i<=outrows;i++)
          {
            printf("\n%d:",i);
            for(j=1;j<=nrow[i];j++)
                printf(" %d",table[i][j]);
          }
    }
  else
       printf("\n\nInput parameters too small, rerun with:");

  printf("\ninput rows=%d maxindex=%d",inrows,outrows);
  printf("\n");
  free(nrow);
  for (i=0;i<=maxindex+1;i++)
       free(table[i]); 
  free(table);
  return 0;
}