How to use H5ocopy to copy a group with hard links

Hello,
I am trying to copy the group “post” which is the symbolic link to csmexpl…so my expectation is when ever i copy the group path like post/constant i want it to copy the symbolic link too like csmexpl/constant…so can you please help me on this.(i am using C methods)
Below is the image to illustrate
image%20(1)

Hi @sandhya.v250,

If you are ok in using HDFql, you can make a (deep) copy of (link) post like the following in C:

#include "HDFql.h"
void main(int argc, char *argv[])
{
      hdfql_execute("COPY allinone_RESULT.erfh5 post TO allinone_RESULT.erfh5 post_copy");
}

Additional information can be found on section 6.4.13 of HDFql reference manual.

Thanks for your answer, i want to copy all the groups except multistate so each time i need to give a path to copy…It’s better if i get to use h5ocopy()

Ok - that’s a different requirement from the one stated in the beginning…

If you wish to copy all groups (stored in group CSMEXPL) except multistate into a group called post, then one way of doing this is as follows:

#include "HDFql.h"

void main(int argc, char *argv[])
{
    // declare variable
    char script[1024];

    // use (i.e. open) HDF5 file 'allinone_RESULT.erfh5'
    hdfql_execute("USE FILE allinone_RESULT.erfh5");

    // create new group 'post'
    hdfql_execute("CREATE GROUP post");

    // get all (sub)groups stored in group 'CSMEXPL'
    hdfql_execute("SHOW GROUP CSMEXPL/");

    // copy each (sub)group found in 'group 'CSMEXPL' (except (sub)group 'multistate') into group 'post'
    while(hdfql_cursor_next(NULL) == HDFQL_SUCCESS)
    {
        if (strcmp(hdfql_cursor_get_char(NULL), "multistate") != 0)
        {
            sprintf(script, "COPY CSMEXPL/%s TO post/%s", hdfql_cursor_get_char(NULL), hdfql_cursor_get_char(NULL));
            hdfql_execute(script);
        }
    }

    // close HDF5 file 'allinone_RESULT.erfh5'
    hdfql_execute("CLOSE FILE");
}

In addition, if you just wish to create symbolic (soft) links to groups (instead of copying these), just replace this line:

sprintf(script, "COPY CSMEXPL/%s TO post/%s", hdfql_cursor_get_char(NULL), hdfql_cursor_get_char(NULL));

with this:

sprintf(script, "CREATE SOFT LINK post/%s TO CSMEXPL/%s", hdfql_cursor_get_char(NULL), hdfql_cursor_get_char(NULL));

Hope this helps!

To be honest, I don’t understand the question. Are you trying to copy groups or links?

You are telling us that you want to copy the group post, but then you are telling us that that’s actually not a group but a symbolic link. A group is a collection of links. Copying a group means creating a new group that contains copies of the original group’s links (and attributes). Copying a link means something else. Which one would you like? G.

Post is a hardlink to CSMEXPL group in the image.
So when i copy the whole post group, the CSMEXPL should also need to be copied because it’s a hard link this is my requirement.
Is there any copy or link property list flags to copy hard links as well. I tried all the flags but did not work.
The following code copies only group

lcpl_id = H5Pcreate(H5P_LINK_CREATE);
status = H5Pset_create_intermediate_group(lcpl_id, 1);
status = H5Ocopy(file_id, “post”, file_id_two, “post”, H5P_DEFAULT, lcpl_id);
I saw in specification that lcpl_id has flags to copy hard links but i could not make it work

Can you send us the output of h5dump -pH <your-file.h5>? G.