This is invalid for the "csv" standard and reading in such output causes trouble, e.g.,
x <- read.csv("Ouptut/g_bmass_cell_avg.csv)
x[1:3, 1:4]
Year PPT StdDev Temp
1 372.75 106.53130 8.548158 0.152039
2 283.75 36.84540 8.570971 0.112957
3 302.00 47.71443 8.545592 0.145258
x[1:3, 99:102]
chvi chvi_Indivs oppo oppo_Indivs
1 0.00 0.000000 0.00 NA
2 0.25 0.000000 0.00 NA
3 0.00 0.823861 0.25 NA
Note: Values for columns are shifted, i.e., values of "Year" are dropped (or used as row names) and take on values that belonged to "PPT" instead, values of "PPT" are those of "StdDev", etc. and the last column "oppo_Indivs" has NAs.
All other output functions, e.g., output_Bmass_Yearly, make_header_with_std, and _Output_AllCellAvgMort do not add a superfluous separator at the end of each line.
--> Possible approaches
A complication is that every column is optional BmassFlags.
Suggestion 1) Remove last sep from final buf just before writing to disk (currently line 1487 in ST_grid.c)
Suggestion 2) Use approach implemented by functions output_Bmass_Yearly and make_header_with_std, i.e., first copy output values into an array and count elements; then loop over the array and copy into output text buffer until the last element (which isn't followed by a separator), e.g.,
void output_Bmass_Yearly( Int year ) {
...
/* Write data line to already opened file */
for (i=0; i< fc-1; i++) {
fprintf(Globals->bmass.fp_year,"%s%c", fields[i], BmassFlags.sep);
}
if (i) fprintf(Globals->bmass.fp_year,"%s\n", fields[i]);
...
}
Function
_Output_AllCellAvgBmass
adds asep
(currently ",") at the end of each data line (where there should be none),:This leads to output that looks like this, e.g.,
This is invalid for the "csv" standard and reading in such output causes trouble, e.g.,
Note: Values for columns are shifted, i.e., values of "Year" are dropped (or used as row names) and take on values that belonged to "PPT" instead, values of "PPT" are those of "StdDev", etc. and the last column "oppo_Indivs" has NAs.
All other output functions, e.g.,
output_Bmass_Yearly
,make_header_with_std
, and_Output_AllCellAvgMort
do not add a superfluous separator at the end of each line.--> Possible approaches A complication is that every column is optional
BmassFlags
.Suggestion 1) Remove last
sep
from finalbuf
just before writing to disk (currently line 1487 inST_grid.c
)Suggestion 2) Use approach implemented by functions
output_Bmass_Yearly
andmake_header_with_std
, i.e., first copy output values into an array and count elements; then loop over the array and copy into output text buffer until the last element (which isn't followed by a separator), e.g.,