nysol-take 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +7 -0
  2. data/bin/mbiclique.rb +317 -0
  3. data/bin/mbipolish.rb +362 -0
  4. data/bin/mccomp.rb +235 -0
  5. data/bin/mclique.rb +295 -0
  6. data/bin/mclique2g.rb +105 -0
  7. data/bin/mcliqueInfo.rb +203 -0
  8. data/bin/mfriends.rb +202 -0
  9. data/bin/mgdiff.rb +252 -0
  10. data/bin/mhifriend.rb +456 -0
  11. data/bin/mhipolish.rb +465 -0
  12. data/bin/mitemset.rb +168 -0
  13. data/bin/mpal.rb +410 -0
  14. data/bin/mpolishing.rb +399 -0
  15. data/bin/msequence.rb +165 -0
  16. data/bin/mtra2g.rb +476 -0
  17. data/bin/mtra2gc.rb +360 -0
  18. data/ext/grhfilrun/extconf.rb +12 -0
  19. data/ext/grhfilrun/grhfilrun.c +85 -0
  20. data/ext/grhfilrun/src/_sspc.c +358 -0
  21. data/ext/grhfilrun/src/aheap.c +545 -0
  22. data/ext/grhfilrun/src/aheap.h +251 -0
  23. data/ext/grhfilrun/src/base.c +92 -0
  24. data/ext/grhfilrun/src/base.h +59 -0
  25. data/ext/grhfilrun/src/fstar.c +497 -0
  26. data/ext/grhfilrun/src/fstar.h +80 -0
  27. data/ext/grhfilrun/src/grhfil.c +214 -0
  28. data/ext/grhfilrun/src/itemset.c +713 -0
  29. data/ext/grhfilrun/src/itemset.h +170 -0
  30. data/ext/grhfilrun/src/problem.c +415 -0
  31. data/ext/grhfilrun/src/problem.h +179 -0
  32. data/ext/grhfilrun/src/queue.c +533 -0
  33. data/ext/grhfilrun/src/queue.h +182 -0
  34. data/ext/grhfilrun/src/sample.c +19 -0
  35. data/ext/grhfilrun/src/sspc.c +597 -0
  36. data/ext/grhfilrun/src/sspc2.c +491 -0
  37. data/ext/grhfilrun/src/stdlib2.c +1482 -0
  38. data/ext/grhfilrun/src/stdlib2.h +892 -0
  39. data/ext/grhfilrun/src/trsact.c +817 -0
  40. data/ext/grhfilrun/src/trsact.h +160 -0
  41. data/ext/grhfilrun/src/vec.c +745 -0
  42. data/ext/grhfilrun/src/vec.h +172 -0
  43. data/ext/lcmrun/extconf.rb +20 -0
  44. data/ext/lcmrun/lcmrun.cpp +99 -0
  45. data/ext/lcmrun/src/aheap.c +216 -0
  46. data/ext/lcmrun/src/aheap.h +111 -0
  47. data/ext/lcmrun/src/base.c +92 -0
  48. data/ext/lcmrun/src/base.h +59 -0
  49. data/ext/lcmrun/src/itemset.c +496 -0
  50. data/ext/lcmrun/src/itemset.h +157 -0
  51. data/ext/lcmrun/src/lcm.c +427 -0
  52. data/ext/lcmrun/src/problem.c +349 -0
  53. data/ext/lcmrun/src/problem.h +177 -0
  54. data/ext/lcmrun/src/queue.c +528 -0
  55. data/ext/lcmrun/src/queue.h +176 -0
  56. data/ext/lcmrun/src/sgraph.c +359 -0
  57. data/ext/lcmrun/src/sgraph.h +173 -0
  58. data/ext/lcmrun/src/stdlib2.c +1282 -0
  59. data/ext/lcmrun/src/stdlib2.h +823 -0
  60. data/ext/lcmrun/src/trsact.c +747 -0
  61. data/ext/lcmrun/src/trsact.h +159 -0
  62. data/ext/lcmrun/src/vec.c +731 -0
  63. data/ext/lcmrun/src/vec.h +171 -0
  64. data/ext/lcmseq0run/extconf.rb +20 -0
  65. data/ext/lcmseq0run/lcmseq0run.cpp +59 -0
  66. data/ext/lcmseq0run/src/aheap.c +216 -0
  67. data/ext/lcmseq0run/src/aheap.h +111 -0
  68. data/ext/lcmseq0run/src/base.c +92 -0
  69. data/ext/lcmseq0run/src/base.h +59 -0
  70. data/ext/lcmseq0run/src/itemset.c +518 -0
  71. data/ext/lcmseq0run/src/itemset.h +157 -0
  72. data/ext/lcmseq0run/src/itemset_zero.c +522 -0
  73. data/ext/lcmseq0run/src/lcm_seq.c +446 -0
  74. data/ext/lcmseq0run/src/lcm_seq_zero.c +446 -0
  75. data/ext/lcmseq0run/src/problem.c +439 -0
  76. data/ext/lcmseq0run/src/problem.h +179 -0
  77. data/ext/lcmseq0run/src/problem_zero.c +439 -0
  78. data/ext/lcmseq0run/src/queue.c +533 -0
  79. data/ext/lcmseq0run/src/queue.h +182 -0
  80. data/ext/lcmseq0run/src/stdlib2.c +1350 -0
  81. data/ext/lcmseq0run/src/stdlib2.h +864 -0
  82. data/ext/lcmseq0run/src/trsact.c +747 -0
  83. data/ext/lcmseq0run/src/trsact.h +159 -0
  84. data/ext/lcmseq0run/src/vec.c +779 -0
  85. data/ext/lcmseq0run/src/vec.h +172 -0
  86. data/ext/lcmseqrun/extconf.rb +20 -0
  87. data/ext/lcmseqrun/lcmseqrun.cpp +101 -0
  88. data/ext/lcmseqrun/src/aheap.c +216 -0
  89. data/ext/lcmseqrun/src/aheap.h +111 -0
  90. data/ext/lcmseqrun/src/base.c +92 -0
  91. data/ext/lcmseqrun/src/base.h +59 -0
  92. data/ext/lcmseqrun/src/itemset.c +518 -0
  93. data/ext/lcmseqrun/src/itemset.h +157 -0
  94. data/ext/lcmseqrun/src/itemset_zero.c +522 -0
  95. data/ext/lcmseqrun/src/lcm_seq.c +447 -0
  96. data/ext/lcmseqrun/src/lcm_seq_zero.c +446 -0
  97. data/ext/lcmseqrun/src/problem.c +439 -0
  98. data/ext/lcmseqrun/src/problem.h +179 -0
  99. data/ext/lcmseqrun/src/problem_zero.c +439 -0
  100. data/ext/lcmseqrun/src/queue.c +533 -0
  101. data/ext/lcmseqrun/src/queue.h +182 -0
  102. data/ext/lcmseqrun/src/stdlib2.c +1350 -0
  103. data/ext/lcmseqrun/src/stdlib2.h +864 -0
  104. data/ext/lcmseqrun/src/trsact.c +747 -0
  105. data/ext/lcmseqrun/src/trsact.h +159 -0
  106. data/ext/lcmseqrun/src/vec.c +779 -0
  107. data/ext/lcmseqrun/src/vec.h +172 -0
  108. data/ext/lcmtransrun/extconf.rb +18 -0
  109. data/ext/lcmtransrun/lcmtransrun.cpp +264 -0
  110. data/ext/macerun/extconf.rb +20 -0
  111. data/ext/macerun/macerun.cpp +57 -0
  112. data/ext/macerun/src/aheap.c +217 -0
  113. data/ext/macerun/src/aheap.h +112 -0
  114. data/ext/macerun/src/itemset.c +491 -0
  115. data/ext/macerun/src/itemset.h +158 -0
  116. data/ext/macerun/src/mace.c +503 -0
  117. data/ext/macerun/src/problem.c +346 -0
  118. data/ext/macerun/src/problem.h +174 -0
  119. data/ext/macerun/src/queue.c +529 -0
  120. data/ext/macerun/src/queue.h +177 -0
  121. data/ext/macerun/src/sgraph.c +360 -0
  122. data/ext/macerun/src/sgraph.h +174 -0
  123. data/ext/macerun/src/stdlib2.c +993 -0
  124. data/ext/macerun/src/stdlib2.h +811 -0
  125. data/ext/macerun/src/vec.c +634 -0
  126. data/ext/macerun/src/vec.h +170 -0
  127. data/ext/sspcrun/extconf.rb +20 -0
  128. data/ext/sspcrun/src/_sspc.c +358 -0
  129. data/ext/sspcrun/src/aheap.c +545 -0
  130. data/ext/sspcrun/src/aheap.h +251 -0
  131. data/ext/sspcrun/src/base.c +92 -0
  132. data/ext/sspcrun/src/base.h +59 -0
  133. data/ext/sspcrun/src/fstar.c +496 -0
  134. data/ext/sspcrun/src/fstar.h +80 -0
  135. data/ext/sspcrun/src/grhfil.c +213 -0
  136. data/ext/sspcrun/src/itemset.c +713 -0
  137. data/ext/sspcrun/src/itemset.h +170 -0
  138. data/ext/sspcrun/src/problem.c +415 -0
  139. data/ext/sspcrun/src/problem.h +179 -0
  140. data/ext/sspcrun/src/queue.c +533 -0
  141. data/ext/sspcrun/src/queue.h +182 -0
  142. data/ext/sspcrun/src/sample.c +19 -0
  143. data/ext/sspcrun/src/sspc.c +598 -0
  144. data/ext/sspcrun/src/sspc2.c +491 -0
  145. data/ext/sspcrun/src/stdlib2.c +1482 -0
  146. data/ext/sspcrun/src/stdlib2.h +892 -0
  147. data/ext/sspcrun/src/trsact.c +817 -0
  148. data/ext/sspcrun/src/trsact.h +160 -0
  149. data/ext/sspcrun/src/vec.c +745 -0
  150. data/ext/sspcrun/src/vec.h +172 -0
  151. data/ext/sspcrun/sspcrun.cpp +54 -0
  152. data/lib/nysol/enumLcmEp.rb +338 -0
  153. data/lib/nysol/enumLcmEsp.rb +284 -0
  154. data/lib/nysol/enumLcmIs.rb +275 -0
  155. data/lib/nysol/enumLcmSeq.rb +143 -0
  156. data/lib/nysol/items.rb +201 -0
  157. data/lib/nysol/seqDB.rb +256 -0
  158. data/lib/nysol/take.rb +39 -0
  159. data/lib/nysol/taxonomy.rb +113 -0
  160. data/lib/nysol/traDB.rb +257 -0
  161. metadata +239 -0
@@ -0,0 +1,172 @@
1
+ /* library for sparse vector */
2
+ /* Takeaki Uno 27/Dec/2008 */
3
+
4
+ #ifndef _vec_h_
5
+ #define _vec_h_
6
+
7
+ //#define USE_MATH
8
+
9
+ #include"math.h"
10
+ #include"queue.h"
11
+
12
+ #ifndef SVEC_VAL
13
+ #ifdef SVEC_VAL_INT
14
+ #define SVEC_VAL int
15
+ #define SVEC_VAL2 LONG
16
+ #define SVEC_VAL_END INTHUGE
17
+ #define SVEC_VAL2_END LONGHUGE
18
+ #define SVEC_VALF "%d"
19
+ #else
20
+ #define SVEC_VAL double
21
+ #define SVEC_VAL2 double
22
+ #define SVEC_VAL_END DOUBLEHUGE
23
+ #define SVEC_VAL2_END DOUBLEHUGE
24
+ #define SVEC_VALF "%f"
25
+ #endif
26
+ #endif
27
+
28
+ #define VEC_LOAD_BIN 16777216 // read binary file
29
+ #define VEC_LOAD_BIN2 33554432 // read binary file with 2byte for each number
30
+ #define VEC_LOAD_BIN4 67108864 // read binary file with 4byte for each number
31
+ #define VEC_LOAD_CENTERIZE 134217728 // read binary file, and minus the half(128) from each number
32
+ #define VEC_NORMALIZE 268435456 // read binary file, and minus the half(128) from each number
33
+
34
+ /* matrix */
35
+ typedef struct {
36
+ unsigned char type; // mark to identify type of the structure
37
+ char *fname; // input file name
38
+ int flag; // flag
39
+
40
+ VEC *v;
41
+ VEC_ID end;
42
+ VEC_ID t;
43
+ VEC_VAL *buf, *buf2;
44
+ VEC_ID clms;
45
+ size_t eles;
46
+ VEC_VAL *buf_org, *buf2_org;
47
+ } MAT;
48
+
49
+ /* sparse vector, element */
50
+ typedef struct {
51
+ QUEUE_ID i;
52
+ SVEC_VAL a;
53
+ } SVEC_ELE;
54
+
55
+ /* sparse vector, vector */
56
+ typedef struct {
57
+ unsigned char type; // mark to identify type of the structure
58
+ SVEC_ELE *v;
59
+ VEC_ID end;
60
+ VEC_ID t;
61
+ } SVEC;
62
+
63
+ /* sparse vector, matrix */
64
+ typedef struct {
65
+ unsigned char type; // mark to identify type of the structure
66
+ char *fname; // input file name
67
+ int flag; // flag
68
+
69
+ SVEC *v;
70
+ VEC_ID end;
71
+ VEC_ID t;
72
+ SVEC_ELE *buf, *buf2;
73
+ VEC_ID clms;
74
+ size_t eles, ele_end;
75
+ } SMAT;
76
+
77
+ /* set family */
78
+ typedef struct {
79
+ unsigned char type; // mark to identify type of the structure
80
+ char *fname; // input file name
81
+ int flag; // flag
82
+
83
+ QUEUE *v;
84
+ VEC_ID end;
85
+ VEC_ID t;
86
+ QUEUE_INT *buf, *buf2;
87
+ VEC_ID clms;
88
+ size_t eles, ele_end;
89
+ WEIGHT *cw, *rw, **w, *wbuf;
90
+ int unit;
91
+ char *wfname, *cwfname, *rwfname; // weight file name
92
+ PERM *rperm, *cperm; // row permutation
93
+ } SETFAMILY;
94
+
95
+ #define INIT_SETFAMILY_ {TYPE_SETFAMILY,NULL,0,NULL,0,0,NULL,NULL,0,0,0,NULL,NULL,NULL,NULL,sizeof(QUEUE_INT),NULL,NULL,NULL,NULL,NULL}
96
+
97
+ extern MAT INIT_MAT;
98
+ extern SVEC INIT_SVEC;
99
+ extern SMAT INIT_SMAT;
100
+ extern SETFAMILY INIT_SETFAMILY;
101
+
102
+ QSORT_TYPE_HEADER (SVEC_VAL, SVEC_VAL)
103
+ QSORT_TYPE_HEADER (SVEC_VAL2, SVEC_VAL2)
104
+
105
+ #define ARY_QUEUE_INPRO(f,U,V) do{(f)=0;FLOOP(common_QUEUE_ID, 0, (QUEUE_ID)(U).t)(f)+=(V)[(U).v[common_QUEUE_ID]];}while(0)
106
+ #define ARY_SVEC_INPRO(f,U,V) do{(f)=0;FLOOP(common_VEC_ID, 0, (VEC_ID)(U).t)(f)+=((double)(U).v[common_VEC_ID].a)*(V)[(U).v[common_VEC_ID].i];}while(0)
107
+
108
+ /* terminate routine for VEC */
109
+ void VEC_end (VEC *V);
110
+ void MAT_end (MAT *M);
111
+ void SVEC_end (SVEC *V);
112
+ void SMAT_end (SMAT *M);
113
+ void SETFAMILY_end (SETFAMILY *M);
114
+
115
+ /* allocate memory according to rows and rowt */
116
+ void VEC_alloc (VEC *V, VEC_ID clms);
117
+ void MAT_alloc (MAT *M, VEC_ID rows, VEC_ID clms);
118
+ void SVEC_alloc (SVEC *V, VEC_ID end);
119
+ void SMAT_alloc (SMAT *M, VEC_ID rows, VEC_ID *rowt, VEC_ID clms, size_t eles);
120
+ void SETFAMILY_alloc (SETFAMILY *M, VEC_ID rows, VEC_ID *rowt, VEC_ID clms, size_t eles);
121
+ void SETFAMILY_alloc_weight (SETFAMILY *M, QUEUE_ID *t);
122
+
123
+ /* count/read the number in file for MAT */
124
+ /* if *rows>0, only read count the numbers in a row, for the first scan. */
125
+ void MAT_load_bin (MAT *M, FILE2 *fp, int unit);
126
+ void MAT_file_load (MAT *M, FILE2 *fp);
127
+ void MAT_load (MAT *M);
128
+ void SMAT_load (SMAT *M);
129
+ void SETFAMILY_load (SETFAMILY *M);
130
+ void SETFAMILY_load_weight (SETFAMILY *M);
131
+ void SETFAMILY_load_row_weight (SETFAMILY *M);
132
+ void SETFAMILY_load_column_weight (SETFAMILY *M);
133
+
134
+ void MAT_print (FILE *fp, MAT *M);
135
+ void SVEC_print (FILE *fp, SVEC *M);
136
+ void SMAT_print (FILE *fp, SMAT *M);
137
+ void SETFAMILY_print (FILE *fp, SETFAMILY *M);
138
+ void SETFAMILY_print_weight (FILE *fp, SETFAMILY *M);
139
+
140
+
141
+ /* norm, normalization **************************/
142
+ double SVEC_norm (SVEC *V);
143
+ void SVEC_normalize (SVEC *V);
144
+
145
+ /* inner product **************************/
146
+ SVEC_VAL2 SVEC_inpro (SVEC *V1, SVEC *V2);
147
+
148
+ /** Euclidean distance routines *********************************/
149
+ double VEC_eucdist (VEC *V1, VEC *V2);
150
+ double SVEC_eucdist (SVEC *V1, SVEC *V2);
151
+ double VEC_SVEC_eucdist (VEC *V1, SVEC *V2);
152
+ double QUEUE_eucdist (QUEUE *Q1, QUEUE *Q2);
153
+ double VEC_QUEUE_eucdist (VEC *V, QUEUE *Q);
154
+
155
+ void VEC_rand_gaussian (VEC *V);
156
+
157
+ double VEC_linfdist (VEC *V1, VEC *V2);
158
+
159
+ /* compute the inner product, Euclidean distance for multi vector */
160
+ double MVEC_norm (void *V);
161
+ double MVEC_inpro (void *V, void *U);
162
+ double MVEC_double_inpro (void *V, double *p);
163
+ double MVEC_eucdist (void *V, void *U);
164
+
165
+ /* compute the inner product, euclidean distance for i,jth vector */
166
+ double MMAT_inpro_ij (void *M, int i, int j);
167
+ double MMAT_double_inpro_i (void *M, int i, double *p);
168
+ double MMAT_eucdist_ij (void *M, int i, int j);
169
+ double MMAT_norm_i (void *M, int i);
170
+
171
+
172
+ #endif
@@ -0,0 +1,18 @@
1
+ require "rubygems"
2
+ require "mkmf"
3
+
4
+
5
+ $CPPFLAGS += " -Wall"
6
+ $LOCAL_LIBS += " -lstdc++ "
7
+
8
+ cp = "$(srcdir)"
9
+
10
+ $CFLAGS = " -O3 -Wall -I. -I#{cp}/src -DB_STATIC -D_NO_MAIN_ -DLINE -fPIC -Wno-error=format-security"
11
+ $CPPFLAGS = " -O3 -Wall -I. -I#{cp}/src -DB_STATIC -D_NO_MAIN_ -DLINE -fPIC -Wno-error=format-security"
12
+ $CXXFLAGS = " -O3 -Wall -I. -I#{cp}/src -DB_STATIC -D_NO_MAIN_ -DLINE -fPIC -Wno-error=format-security"
13
+
14
+ $LOCAL_LIBS += " -lstdc++ -lkgmod3"
15
+
16
+
17
+ create_makefile("nysol/lcmtransrun")
18
+
@@ -0,0 +1,264 @@
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <string.h>
4
+ #include <ruby.h>
5
+ #include <kgMethod.h>
6
+
7
+ #define MAXC 1024000
8
+
9
+ extern "C" {
10
+ void Init_lcmtransrun(void);
11
+ }
12
+
13
+ int lcmtrans(int argc, char **argv){
14
+ char mode;
15
+ char *hd;
16
+ if(argc==2 && 0==strcmp(*(argv+1),"-v" )){
17
+ fprintf(stderr,"lcm_trans 1.0\n");
18
+ return 1;
19
+ }
20
+
21
+ if(argc!=4){
22
+ hd="\
23
+ usage) lcm_trans filename p|t\n\
24
+ filename: output file by lcm(lcm_seq)\n\
25
+ p: output patterns and their frequency\n\
26
+ t: output transaction number with pattern ID\n\
27
+ \n\
28
+ ex. of input file(output file by lcm)\n\
29
+ -----------\n\
30
+ 3\n\
31
+ 0 1 2\n\
32
+ 4 2\n\
33
+ 0 2\n\
34
+ 4 8 1\n\
35
+ 0\n\
36
+ 4 8 6 1\n\
37
+ 0\n\
38
+ -----------\n\
39
+ odd line: pattern with frequency\n\
40
+ even line: transaction number \n\
41
+ \n\
42
+ standard output (2nd parameter is 'p')\n\
43
+ pattern,count,size,pid\n\
44
+ ,3,0,0\n\
45
+ 4,2,1,1\n\
46
+ 4 8,1,2,2\n\
47
+ 4 8 6,1,3,3\n\
48
+ \n\
49
+ standard output (2nd parameter is 't')\n\
50
+ __tid,pid\n\
51
+ 0,0\n\
52
+ 1,0\n\
53
+ 2,0\n\
54
+ 0,1\n\
55
+ 2,1\n\
56
+ 0,2\n\
57
+ 0,3\n\
58
+ ";
59
+ fprintf(stderr,"%s",hd);
60
+ return EXIT_FAILURE;
61
+ }
62
+
63
+ if(**(argv+2)=='p'){
64
+ mode='p';
65
+ }else if(**(argv+2)=='e'){
66
+ mode='e';
67
+ }else if(**(argv+2)=='t'){
68
+ mode='t';
69
+ }else{
70
+ fprintf(stderr,"argument error2: %s\n",argv+2);
71
+ }
72
+
73
+ FILE *fp;
74
+ if((fp=fopen(*(argv+1),"rb"))==NULL){
75
+ fprintf(stderr,"file open error\n");
76
+ return EXIT_FAILURE;
77
+ }
78
+ FILE *ofp;
79
+ if((ofp=fopen(*(argv+3),"w"))==NULL){
80
+ fprintf(stderr,"file open error\n");
81
+ return EXIT_FAILURE;
82
+ }
83
+
84
+
85
+
86
+ int odd=1; // 奇数行フラグ
87
+
88
+ // enumLcmSeq.rb,enumLcmIs.rbでのパターン
89
+ // 4 5 (2)
90
+ if(mode=='p'){
91
+ fprintf(ofp,"pattern,count,size,pid\n");
92
+ size_t recNo=0;
93
+ char buf[MAXC]; // 出力バッファ
94
+ char buf2[MAXC]; // 出力バッファ
95
+ int spcCount=0; // スペースのカウント
96
+ int opos=-1;
97
+
98
+ while(1){
99
+ int rsize = fread(buf, sizeof(char), MAXC, fp);
100
+ if( rsize < 0 ){
101
+ fprintf(stderr,"file read error\n");
102
+ return EXIT_FAILURE;
103
+ }
104
+ if( rsize == 0 ) { break;}
105
+ int i;
106
+ for(i=0 ; i<rsize ;i++){
107
+ if(buf[i]=='\n'){
108
+ if(odd==1){
109
+ fprintf(ofp,"%s,%d,%ld\n",buf2,spcCount,recNo);
110
+ recNo++;
111
+ }
112
+ spcCount=0;
113
+ opos=-1;
114
+ odd*=(-1);
115
+ continue;
116
+ }
117
+ if(odd!=1) { continue;}
118
+ if(buf[i]==' '){
119
+ buf2[++opos]=buf[i];
120
+ if(opos!=0){ spcCount++; }
121
+ }
122
+ else if(buf[i]=='('){
123
+ buf2[opos]=',';
124
+ }
125
+ else if(buf[i]==')'){
126
+ buf2[++opos]='\0';
127
+ }
128
+ else { buf2[++opos]=buf[i];}
129
+ }
130
+ }
131
+ }else if(mode=='e'){
132
+ fprintf(ofp,"pattern,countP,countN,size,pid\n");
133
+ size_t recNo=0;
134
+ char buf[MAXC]; // 出力バッファ
135
+ char buf2[MAXC]; // 出力バッファ
136
+ int spcCount=0; // スペースのカウント
137
+ int comCount=0; // スペースのカウント
138
+ int opos=-1;
139
+
140
+ while(1){
141
+ int rsize = fread(buf, sizeof(char), MAXC, fp);
142
+ if( rsize < 0 ){
143
+ fprintf(stderr,"file read error\n");
144
+ return EXIT_FAILURE;
145
+ }
146
+ if( rsize == 0 ) { break;}
147
+ int i;
148
+ for(i=0 ; i<rsize ;i++){
149
+ if(buf[i]=='\n'){
150
+ if(odd==1){
151
+ fprintf(ofp,"%s,%d,%ld\n",buf2,spcCount,recNo);
152
+ recNo++;
153
+ }
154
+ spcCount=0;
155
+ comCount=0;
156
+ opos=-1;
157
+ odd*=(-1);
158
+ continue;
159
+ }
160
+ if(odd!=1) { continue;}
161
+ if(buf[i]==' '){
162
+ buf2[++opos]=buf[i];
163
+ if(opos!=0){ spcCount++; }
164
+ }
165
+ else if(buf[i]=='('){
166
+ buf2[opos]=',';
167
+ }
168
+ else if(buf[i]==','){
169
+ comCount++;
170
+ if(comCount==2){ buf2[++opos]='\0';}
171
+ else{ buf2[++opos]=buf[i];}
172
+ }
173
+ else { buf2[++opos]=buf[i];}
174
+ }
175
+ }
176
+
177
+ }else{
178
+ fprintf(ofp,"__tid,pid\n");
179
+ size_t recNo=0;
180
+ int opos=-1;
181
+ char buf[MAXC]; // 出力バッファ
182
+ char buf2[MAXC]; // 出力バッファ
183
+
184
+ while(1){
185
+ int rsize = fread(buf, sizeof(char), MAXC, fp);
186
+ if( rsize < 0 ){
187
+ fprintf(stderr,"file read error\n");
188
+ return EXIT_FAILURE;
189
+ }
190
+ if( rsize == 0 ) { break;}
191
+ int i;
192
+ for(i=0 ; i<rsize ;i++){
193
+ if(odd==1){//奇数行は¥nまでなにもしない
194
+ if(buf[i]=='\n'){
195
+ opos=-1;
196
+ odd*=(-1);
197
+ buf2[0]='\0';
198
+ }
199
+ }
200
+ else{
201
+ if(buf[i]==' '||buf[i]=='\n'){
202
+ buf2[++opos]='\0';
203
+ if(buf2[0] != '\0'){
204
+ fprintf(ofp,"%s,%ld\n",buf2,recNo);
205
+ }
206
+ opos=-1;
207
+ if(buf[i]=='\n'){
208
+ odd*=(-1);
209
+ recNo++;
210
+ }
211
+ }
212
+ else{ buf2[++opos]=buf[i]; }
213
+ }
214
+ }
215
+ }
216
+ }
217
+
218
+ if(0!=fclose(fp)){
219
+ fprintf(stderr,"file close error\n");
220
+ return EXIT_FAILURE;
221
+ }
222
+ if(0!=fclose(ofp)){
223
+ fprintf(stderr,"file close error\n");
224
+ return EXIT_FAILURE;
225
+ }
226
+ return 0;
227
+ }
228
+
229
+ VALUE lcm_trans(int argc, VALUE *argvV, VALUE self){
230
+ VALUE inf;
231
+ VALUE para;
232
+ VALUE outf;
233
+ rb_scan_args(argc, argvV, "30",&inf,&para,&outf);
234
+
235
+ // 引数文字列へのポインタの領域はここでauto変数に確保する
236
+ size_t vvSize=4;
237
+
238
+ kglib::kgAutoPtr2<char*> argv;
239
+ char** vv;
240
+ try{
241
+ argv.set(new char*[vvSize]);
242
+ vv = argv.get();
243
+ }catch(...){
244
+ rb_raise(rb_eRuntimeError,"memory allocation error");
245
+ }
246
+ // vv配列0番目はコマンド名
247
+ vv[0]=const_cast<char*>("lcm_trans");
248
+ vv[1]=RSTRING_PTR(inf);
249
+ vv[2]=RSTRING_PTR(para);
250
+ vv[3]=RSTRING_PTR(outf);
251
+ lcmtrans(vvSize,vv);
252
+ return Qtrue;
253
+
254
+ }
255
+
256
+
257
+
258
+ void Init_lcmtransrun(void)
259
+ {
260
+ // モジュール定義:MCMD::xxxxの部分
261
+ VALUE mtake=rb_define_module("TAKE");
262
+ rb_define_module_function(mtake,"run_lcmtrans" , (VALUE (*)(...))lcm_trans,-1);
263
+
264
+ }
@@ -0,0 +1,20 @@
1
+ require "rubygems"
2
+ require "mkmf"
3
+
4
+ unless have_library("kgmod3")
5
+ puts("need libkgmod.")
6
+ puts("refer https://github.com/nysol/mcmd")
7
+ exit 1
8
+ end
9
+
10
+
11
+ cp = "$(srcdir)"
12
+
13
+ $CFLAGS = " -O3 -Wall -I. -I#{cp}/src -DB_STATIC -D_NO_MAIN_ -DLINE -fPIC -Wno-error=format-security"
14
+ $CPPFLAGS = " -O3 -Wall -I. -I#{cp}/src -DB_STATIC -D_NO_MAIN_ -DLINE -fPIC -Wno-error=format-security"
15
+ $CXXFLAGS = " -O3 -Wall -I. -I#{cp}/src -DB_STATIC -D_NO_MAIN_ -DLINE -fPIC -Wno-error=format-security"
16
+
17
+ $LOCAL_LIBS += " -lstdc++ -lm -lkgmod3"
18
+
19
+ create_makefile("nysol/macerun")
20
+
@@ -0,0 +1,57 @@
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <unistd.h>
4
+ #include <fcntl.h>
5
+ #include <sys/stat.h>
6
+ #include <string>
7
+ #include <ruby.h>
8
+
9
+ #include "src/mace.c"
10
+
11
+
12
+ #include <kgMethod.h>
13
+
14
+ extern "C" {
15
+ void Init_macerun(void);
16
+ }
17
+
18
+
19
+ VALUE macerun(VALUE self,VALUE argvV){
20
+
21
+ string argstr=RSTRING_PTR(argvV);
22
+ vector<char *> opts = kglib::splitToken(const_cast<char*>(argstr.c_str()), ' ',true);
23
+
24
+ // 引数文字列へのポインタの領域はここでauto変数に確保する
25
+ kglib::kgAutoPtr2<char*> argv;
26
+ char** vv;
27
+ try{
28
+ argv.set(new char*[opts.size()+1]);
29
+ vv = argv.get();
30
+ }catch(...){
31
+ rb_raise(rb_eRuntimeError,"memory allocation error");
32
+ }
33
+
34
+ // vv配列0番目はコマンド名
35
+ vv[0]=const_cast<char*>("lcm");
36
+
37
+ size_t vvSize;
38
+ for(vvSize=0; vvSize<opts.size(); vvSize++){
39
+ vv[vvSize+1] = opts.at(vvSize);
40
+ }
41
+ vvSize+=1;
42
+
43
+ MACE_main(vvSize,vv);
44
+ return Qtrue;
45
+ }
46
+
47
+ // -----------------------------------------------------------------------------
48
+ // ruby Mcsvin クラス init
49
+ // -----------------------------------------------------------------------------
50
+ void Init_macerun(void)
51
+ {
52
+ // モジュール定義:MCMD::xxxxの部分
53
+ VALUE mtake=rb_define_module("TAKE");
54
+ rb_define_module_function(mtake,"run_mace" , (VALUE (*)(...))macerun,1);
55
+ }
56
+
57
+