MCPcopy Create free account
hub / github.com/brainflow-dev/brainflow / write_file

Function write_file

src/data_handler/data_handler.cpp:979–1009  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

977}
978
979int write_file (
980 const double *data, int num_rows, int num_cols, const char *file_name, const char *file_mode)
981{
982 if ((strcmp (file_mode, "w") != 0) && (strcmp (file_mode, "w+") != 0) &&
983 (strcmp (file_mode, "a") != 0) && (strcmp (file_mode, "a+") != 0))
984 {
985 data_logger->error ("Incorrect file_mode. File_mode:{}", file_mode);
986 return (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR;
987 }
988 FILE *fp;
989 fp = fopen (file_name, file_mode);
990 if (fp == NULL)
991 {
992 data_logger->error (
993 "Couldn't open file with file_name and file_mode argument. File_Mode:{}, File_name:{}",
994 file_mode, file_name);
995 return (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR;
996 }
997
998 // in read/write file data is transposed!
999 for (int i = 0; i < num_cols; i++)
1000 {
1001 for (int j = 0; j < num_rows - 1; j++)
1002 {
1003 fprintf (fp, "%lf\t", data[j * num_cols + i]);
1004 }
1005 fprintf (fp, "%lf\n", data[(num_rows - 1) * num_cols + i]);
1006 }
1007 fclose (fp);
1008 return (int)BrainFlowExitCodes::STATUS_OK;
1009}
1010
1011int read_file (double *data, int *num_rows, int *num_cols, const char *file_name, int num_elements)
1012{

Callers 2

write_fileMethod · 0.50
mainFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected