108 {
109 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
110 if(tac==NULL) {
113 }
118 }
119 if(verbose>0) {printf("%s()\n", __func__); fflush(stdout);}
120
121
122 if(verbose>1) {printf(" verifying CSV regularity\n"); fflush(stdout);}
124 if(verbose>2) {
125 printf("\n <-- CSV contents (irregular) ---\n");
127 printf("\n ------------------------------->\n");
128 printf(
"col_nr := %d\n", csv->
col_nr);
129 printf(
"row_nr := %d\n", csv->
row_nr);
130 if(verbose>3) {
131 for(
int i=0; i<csv->
row_nr; i++)
132 printf(
"columns_on_row[%d] := %d\n", 1+i,
csvRowLength(csv, i));
133 fflush(stdout);
134 }
135 }
136
137 if(verbose>1) {printf(" trying to make it regular\n"); fflush(stdout);}
139 if(verbose>1) {
140 printf("\n <-- CSV contents (still irregular) ---\n");
142 printf("\n ------------------------------->\n");
143 printf(
"col_nr := %d\n", csv->
col_nr);
144 printf(
"row_nr := %d\n", csv->
row_nr);
145 if(verbose>5) {
146 for(
int i=0; i<csv->
row_nr; i++)
147 printf(
"columns_on_row[%d] := %d\n", 1+i,
csvRowLength(csv, i));
148 fflush(stdout);
149 }
150 }
153 }
154 }
155
156
157 int withTitle=0;
158 for(
int i=0; i<csv->
col_nr; i++) {
160 if(c!=NULL && isalpha(c[0])) withTitle++;
161 }
162 if(verbose>1 && withTitle>0) {printf("CSV seems to have title line.\n"); fflush(stdout);}
163 if(withTitle>0) withTitle=1;
164
165 int ret, n, m;
166
167
168 if(verbose>2) {printf(" allocating memory for TAC data\n"); fflush(stdout);}
169 n=csv->
col_nr;
if(n>1) n--;
175 if(verbose>2) {
176 printf(
" tacNr := %d\n", tac->
tacNr);
177 printf(
" sampleNr := %d\n", tac->
sampleNr);
178 fflush(stdout);
179 }
180
181
182
183 if(withTitle) {
184 if(verbose>2) {printf(" copying TAC names from the title columns\n"); fflush(stdout);}
185 char *c;
186 for(
int ri=0; ri<tac->
tacNr; ri++) {
189 }
190 }
191
192
193 if(verbose>2) {printf(" copying data from CSV to TAC\n"); fflush(stdout);}
194 int fi, ri, oknr=0;
195 char *c;
197
198 c=
csvCell(csv, fi+withTitle, 0);
200
201 for(ri=0; ri<tac->
tacNr; ri++) {
202 c=
csvCell(csv, fi+withTitle, 1+ri);
204 }
205 }
206 if(oknr<1) {
209 }
210
211
213
214
217
220
223}
int csvIsRegular(CSV *csv)
char * csvCell(CSV *csv, int row, int col)
int csvTrimRight(CSV *csv)
int csvRowLength(CSV *csv, int row)
int csvWrite(CSV *csv, int regular, FILE *fp, TPCSTATUS *status)
double atofVerified(const char *s)
int iftDuplicate(IFT *ift1, IFT *ift2)
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
size_t strlcpy(char *dst, const char *src, size_t dstsize)
char name[MAX_TACNAME_LEN+1]
IFT h
Optional (but often useful) header information.
int verbose
Verbose level, used by statusPrint() etc.
int tacAllocate(TAC *tac, int sampleNr, int tacNr)
int tacGetHeaderUnit(TAC *tac, TPCSTATUS *status)
int tacGetHeaderTimeunit(TAC *tac, TPCSTATUS *status)
@ WEIGHTING_OFF
Not weighted or weights not available (weights for all included samples are 1.0).
@ WEIGHTING_UNKNOWN
Not known; usually assumed that not weighted.
#define MAX_TACNAME_LEN
Max length of TAC ID name (not including trailing zero).
@ TPCERROR_FAIL
General error.
@ TPCERROR_INVALID_FORMAT
Invalid file format.
@ TPCERROR_NO_DATA
File contains no data.
@ TAC_FORMAT_SIMPLE
x and y's with space delimiters