gnuastro-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[task #15317] Concatenate two or more tables by row


From: Mohammad Akhlaghi
Subject: [task #15317] Concatenate two or more tables by row
Date: Sun, 4 Apr 2021 12:43:19 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0

Follow-up Comment #41, task #15317 (project gnuastro):

Its great that you have gone through the code and have a basic understanding.


In the part you have quoted, we just add a '-N' (where 'N' is a counter) to
the new column names, we don't touch the column data/contents in this part.

The option to concatenate rows will be different and arguably much more
easier, for example:

* You don't need to touch the column metadata like the names in the part you
quoted). You can keep the metadata of the first input file (because no new
columns will be added when concatenating rows).

* When we are concatenating rows, we need to work on *all* the columns of each
file (just like how we work on all the rows when concatenating columns). So
there is no need to select some of the columns.

You can define a new 'table_catrow" function for concatenation by rows. Here
is a rough outline of what it can do inside:

0 Add a new '--catrowfile' option.
0 Go through all the files given to the newly added '--catrowfile' option and
count how many rows each one has. The 'gal_table_info' function of 'table.h'
in Gnuastro's library
<https://www.gnu.org/software/gnuastro/manual/html_node/Table-input-output.html>
can do this without reading the actual table contents.
0 Add up all the rows to find how many rows the final table should have. Also
make sure that all the tables have the same number of columns in the process
and that each column has the same type as the respective column in the first
file.
0 You now know the final number of columns (Nc) and final number of rows (Nr)
in your final output table and the type of each column. Allocate Nc
'gal_data_t's as a list (each with 'Nr' elements, and the respective type).
0 Go through the list of files again, but this time read all the column data,
and use 'memcpy' to copy the contents into the respective rows of our output
allocated arrays, then free the read data. You can use the
'gal_pointer_increment' function in combination with 'memcpy' to not have to
worry about the type of the table. There are many examples of using 'memcpy'
and 'gal_pointer_increment' in Gnuastro's code which you can use as an example
(you can find them with a simple 'grep -r memcpy ./' in the top Gnuastro
source directory). For example there is one in 'bin/table/table.c' (in the
'table_bring_to_top' function).

I hope this helps. Later, when you get a good understanding of this, it would
also be good if you can help improve the documentation to clarify the points
that weren't immediately clear to you: others will have a similar problem.

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/task/?15317>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]