tmp
This commit is contained in:
parent
4e7a7f3791
commit
e44f34958e
2
lib/io.h
2
lib/io.h
@ -28,6 +28,7 @@
|
||||
#ifndef _GCTL_IO_H
|
||||
#define _GCTL_IO_H
|
||||
|
||||
#include "io/netcdf_io.h"
|
||||
#include "io/mesh_io.h"
|
||||
#include "io/native_io.h"
|
||||
#include "io/text_io.h"
|
||||
@ -37,6 +38,5 @@
|
||||
#include "io/tetgen_io.h"
|
||||
#include "io/triangle_io.h"
|
||||
#include "io/off_io.h"
|
||||
#include "io/netcdf_io.h"
|
||||
|
||||
#endif // _GCTL_IO_H
|
@ -228,6 +228,13 @@ namespace gctl
|
||||
*/
|
||||
void set_delimeter(char deli_sym){deli_sym_ = deli_sym;}
|
||||
|
||||
/**
|
||||
* @brief 获取列分隔符
|
||||
*
|
||||
* @return 分隔符
|
||||
*/
|
||||
char get_delimeter(){return deli_sym_;}
|
||||
|
||||
/**
|
||||
* @brief 设置头信息行数
|
||||
*
|
||||
@ -235,6 +242,13 @@ namespace gctl
|
||||
*/
|
||||
void set_head_number(char num){head_num_ = num;}
|
||||
|
||||
/**
|
||||
* @brief 获取头信息行数
|
||||
*
|
||||
* @return 行数
|
||||
*/
|
||||
int get_head_number(){return head_num_;}
|
||||
|
||||
/**
|
||||
* @brief 设置注释行符号
|
||||
*
|
||||
@ -242,6 +256,13 @@ namespace gctl
|
||||
*/
|
||||
void set_annotation_symbol(char att_sym){att_sym_ = att_sym;}
|
||||
|
||||
/**
|
||||
* @brief 获取注释行符号
|
||||
*
|
||||
* @return 注释符号
|
||||
*/
|
||||
char get_annotation_symbol(){return att_sym_;}
|
||||
|
||||
/**
|
||||
* @brief 设置标记行符号
|
||||
*
|
||||
|
@ -125,6 +125,16 @@ void display_cmds()
|
||||
}
|
||||
|
||||
std::clog << "\nEnter \"<command>?\" to see detailed instructions.\n";
|
||||
|
||||
std::clog << "\nFile:\n";
|
||||
std::clog << "Each line of the input file(s) will be parsed as a command.\nAny line starts with '#' will be skipped.\n";
|
||||
|
||||
std::clog << "\nHereDoc:\n";
|
||||
std::clog << "You can use HereDoc to input commands. A simple example is:\n";
|
||||
std::clog << "dsviewer << EOF\n";
|
||||
std::clog << "open file1.csv\n";
|
||||
std::clog << "info\n";
|
||||
std::clog << "EOF\n";
|
||||
return;
|
||||
}
|
||||
|
||||
@ -217,6 +227,38 @@ void info(const std::vector<std::string> &cmd_units)
|
||||
return;
|
||||
}
|
||||
|
||||
void head(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// head [number]
|
||||
int h = 10;
|
||||
if (cmd_units.size() > 1) h = atoi(cmd_units[1].c_str());
|
||||
if (h <= 0) throw std::runtime_error("head: invalid number.");
|
||||
|
||||
_1s_array line;
|
||||
for (size_t i = 1; i <= h; i++)
|
||||
{
|
||||
tc.get_row(line, i);
|
||||
line.show(std::cout, tc.get_delimeter());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void tail(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// tail [number]
|
||||
int h = 10;
|
||||
if (cmd_units.size() > 1) h = atoi(cmd_units[1].c_str());
|
||||
if (h <= 0) throw std::runtime_error("tail: invalid number.");
|
||||
|
||||
_1s_array line;
|
||||
for (size_t i = tc.row_number() - h + 1; i <= tc.row_number(); i++)
|
||||
{
|
||||
tc.get_row(line, i);
|
||||
line.show(std::cout, tc.get_delimeter());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void set_enable(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// enable column|row <column> <column>...
|
||||
@ -269,7 +311,7 @@ void set_disable(const std::vector<std::string> &cmd_units)
|
||||
|
||||
void load_file(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// load <file> [nohead|hashead] [<delimeter>] [tag_sym] [att_sym] [head_num]
|
||||
// load <file> [nohead|column|row|both] [head_num] [<delimeter>] [att_sym] [tag_sym]
|
||||
if (cmd_units.size() < 2) throw std::runtime_error("open: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(5, "null");
|
||||
@ -284,14 +326,14 @@ void load_file(const std::vector<std::string> &cmd_units)
|
||||
else if (copy_str[0] == "row") ht = RowHead;
|
||||
else if (copy_str[0] == "both") ht = BothHead;
|
||||
|
||||
if (copy_str[1] != "null") tc.set_delimeter(copy_str[1][0]);
|
||||
if (copy_str[2] != "null") tc.set_tag_symbol(copy_str[2][0]);
|
||||
if (copy_str[3] != "null") tc.set_annotation_symbol(copy_str[3][0]);
|
||||
|
||||
int hnum = 0;
|
||||
if (copy_str[4] != "null") hnum = atoi(copy_str[4].c_str());
|
||||
if (copy_str[1] != "null") hnum = atoi(copy_str[1].c_str());
|
||||
if (hnum != 0) tc.set_head_number(hnum);
|
||||
|
||||
if (copy_str[2] != "null") tc.set_delimeter(copy_str[2][0]);
|
||||
if (copy_str[3] != "null") tc.set_annotation_symbol(copy_str[3][0]);
|
||||
if (copy_str[4] != "null") tc.set_tag_symbol(copy_str[4][0]);
|
||||
|
||||
std::string naked_name, exten_name;
|
||||
parse_filename(cmd_units[1], naked_name, exten_name);
|
||||
|
||||
@ -302,7 +344,7 @@ void load_file(const std::vector<std::string> &cmd_units)
|
||||
|
||||
void save_file(const std::vector<std::string> &cmd_units)
|
||||
{
|
||||
// save <file> [<delimeter>] [tag_sym] [att_sym]
|
||||
// save <file> [<delimeter>] [att_sym] [tag_sym]
|
||||
if (cmd_units.size() < 2) throw std::runtime_error("save: insufficient parameters.");
|
||||
|
||||
gctl::array<std::string> copy_str(3, "null");
|
||||
@ -312,8 +354,8 @@ void save_file(const std::vector<std::string> &cmd_units)
|
||||
}
|
||||
|
||||
if (copy_str[0] != "null") tc.set_delimeter(copy_str[0][0]);
|
||||
if (copy_str[1] != "null") tc.set_tag_symbol(copy_str[1][0]);
|
||||
if (copy_str[2] != "null") tc.set_annotation_symbol(copy_str[2][0]);
|
||||
if (copy_str[1] != "null") tc.set_annotation_symbol(copy_str[1][0]);
|
||||
if (copy_str[2] != "null") tc.set_tag_symbol(copy_str[2][0]);
|
||||
|
||||
std::string naked_name, exten_name;
|
||||
parse_filename(cmd_units[1], naked_name, exten_name);
|
||||
@ -369,6 +411,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
display_logo();
|
||||
std::clog << "dsviewer - read, manipulate and write dsv/csv files.\n";
|
||||
std::clog << "Usage: dsviewer [<file1> <file2>...]\n";
|
||||
std::clog << "Enter '?' to see all available commands.\n";
|
||||
|
||||
std::string cmd_str;
|
||||
|
@ -45,16 +45,20 @@ struct cmd_pair
|
||||
|
||||
void quit(const std::vector<std::string> &cmd_units);
|
||||
void info(const std::vector<std::string> &cmd_units);
|
||||
void head(const std::vector<std::string> &cmd_units);
|
||||
void tail(const std::vector<std::string> &cmd_units);
|
||||
void load_file(const std::vector<std::string> &cmd_units);
|
||||
void save_file(const std::vector<std::string> &cmd_units);
|
||||
void statistic(const std::vector<std::string> &cmd_units);
|
||||
void set_enable(const std::vector<std::string> &cmd_units);
|
||||
void set_disable(const std::vector<std::string> &cmd_units);
|
||||
|
||||
#define CMD_NUM 8
|
||||
#define CMD_NUM 10
|
||||
const cmd_pair commands[CMD_NUM] = {
|
||||
{"quit", quit, "Quit the program."},
|
||||
{"info", info, "Show the table information."},
|
||||
{"head", head, "Show head line(s) of the table."},
|
||||
{"tail", tail, "Show tail line(s) of the table."},
|
||||
{"open", load_file, "Open a dsv/csv file."},
|
||||
{"save", save_file, "Save the table to a file."},
|
||||
{"stats", statistic, "Calculate statistics of the selected columns."},
|
||||
|
@ -1,14 +1,23 @@
|
||||
#### quit
|
||||
Does what it says.
|
||||
|
||||
#### info
|
||||
#### info [column|row|both]
|
||||
Show the table information.
|
||||
|
||||
#### open \<file\> [hashead|nohead] [\<delimeter\>] [\<tag-sym\>] [\<att-sym\>]
|
||||
Open a dsv/csv file. The default setups are 'nohead', space for delimeter, '#' for annotations, and '!' for tags.
|
||||
#### head
|
||||
Show the first `n` (the default is 10) rows of the table.
|
||||
|
||||
#### save \<file\>
|
||||
Save table to a dsv/csv file
|
||||
#### tail
|
||||
Show the last `n` (the default is 10) rows of the table.
|
||||
|
||||
#### stats \<column\> \<column\>...
|
||||
Show statistics of a data column or columns.
|
||||
#### open \<file\> [nohead|column|row|both] [\<head_num\>] [\<deli-sym\>] [\<att-sym\>] [\<tag-sym\>]
|
||||
Open a dsv/csv file. The default setups are 'nohead', space for delimeter, '#' for annotations, and '!' for tags. If the file name ends with '.csv', the default delimeter is ','.
|
||||
|
||||
#### save \<file\> [\<delimeter\>] [\<att-sym\>] [\<tag-sym\>]
|
||||
Save table to a dsv/csv file. The default setups are space for delimeter, '#' for annotations, and '!' for tags. If the file name ends with '.csv', the default delimeter is ','.
|
||||
|
||||
#### stats \<colname1\> \<colname2\> ...
|
||||
Show statistics of a data column or columns. If the input file has no column names, use inbuild names `C<id>` to select the columns.
|
||||
|
||||
#### enable column|row \<name1\> \<name2\> ...
|
||||
Enable table outputs. If the input file has no row or column names, use inbuild names `R<id>` and `C<id>` to select the rows and columns.
|
Loading…
Reference in New Issue
Block a user