-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Writing an Array Attribute of String #220
Comments
Update: I just checked what
while else it results in
That means: choose #include <cstring>
// ...
const uint N = 14;
typedef char MyCharN[N+1]; // +1 for trailing \0
ColTypeString ctAxisLabels(N);
MyCharN *axisLabels = new MyCharN[simDim];
// pre-pad all targets with NULLs (including NULL terminator for max length string!)
for( uint32_t d = 0; d < simDim; ++d )
{
memset( axisLabels[d], '\0', N+1 );
}
strcpy( axisLabels[0], "spatial idx" ); // only 12 chars
for( uint i = 11; i <= N; ++N )
axisLabels[0][i] = '\0';
strcpy( axisLabels[1], "frequency idx" ); // 14 chars (let us wrap away the null-padding in some helper ;) ) |
Nevertheless, libSplash strings are currently using
nevertheless, NULL terminated should not care if the bytes behind it are undefined during access. else space padding and final NULL will still work as a work-around. |
Adds ArrayOfString helpers for libSplash write calls. See ComputationalRadiationPhysics/libSplash#220 for the description of the problem. If a user wants to write an array of strings they need to be padded to the longest one. This helper does that. Use it like this: ```C++ // [...] helper::GetSplashArrayOfString getSplashArrayOfString; helper::GetSplashArrayOfString::Result myArrOfStr; std::list<std::string> myListOfStr; myListOfStr.push_back("short"); myListOfStr.push_back("middle"); myListOfStr.push_back("loooong"); myArrOfStr = getSplashArrayOfString( myListOfStr ); ``` Also adds a `helper::` namespace to avoid polluting the `PIConGPU` namespace.
Adds ArrayOfString helpers for libSplash write calls. See ComputationalRadiationPhysics/libSplash#220 for the description of the problem. If a user wants to write an array of strings they need to be padded to the longest one. This helper does that. Use it like this: ```C++ // [...] helper::GetSplashArrayOfString getSplashArrayOfString; helper::GetSplashArrayOfString::Result myArrOfStr; std::list<std::string> myListOfStr; myListOfStr.push_back("short"); myListOfStr.push_back("middle"); myListOfStr.push_back("loooong"); myArrOfStr = getSplashArrayOfString( myListOfStr ); ``` Also adds a `helper::` namespace to avoid polluting the `PIConGPU` namespace.
Adds ArrayOfString helpers for libSplash write calls. See ComputationalRadiationPhysics/libSplash#220 for the description of the problem. If a user wants to write an array of strings they need to be padded to the longest one. This helper does that. Use it like this: ```C++ // [...] helper::GetSplashArrayOfString getSplashArrayOfString; helper::GetSplashArrayOfString::Result myArrOfStr; std::list<std::string> myListOfStr; myListOfStr.push_back("short"); myListOfStr.push_back("middle"); myListOfStr.push_back("loooong"); myArrOfStr = getSplashArrayOfString( myListOfStr ); ``` Also adds a `helper::` namespace to avoid polluting the `PIConGPU` namespace.
Adds ArrayOfString helpers for libSplash write calls. See ComputationalRadiationPhysics/libSplash#220 for the description of the problem. If a user wants to write an array of strings they need to be padded to the longest one. This helper does that. Use it like this: ```C++ // [...] helper::GetSplashArrayOfString getSplashArrayOfString; helper::GetSplashArrayOfString::Result myArrOfStr; std::list<std::string> myListOfStr; myListOfStr.push_back("short"); myListOfStr.push_back("middle"); myListOfStr.push_back("loooong"); myArrOfStr = getSplashArrayOfString( myListOfStr ); ``` Also adds a `helper::` namespace to avoid polluting the `PIConGPU` namespace.
Adds ArrayOfString helpers for libSplash write calls. See ComputationalRadiationPhysics/libSplash#220 for the description of the problem. If a user wants to write an array of strings they need to be padded to the longest one. This helper does that. Use it like this: ```C++ // [...] helper::GetSplashArrayOfString getSplashArrayOfString; helper::GetSplashArrayOfString::Result myArrOfStr; std::list<std::string> myListOfStr; myListOfStr.push_back("short"); myListOfStr.push_back("middle"); myListOfStr.push_back("loooong"); myArrOfStr = getSplashArrayOfString( myListOfStr ); ``` Also adds a `helper::` namespace to avoid polluting the `PIConGPU` namespace.
@ax3l |
Adds ArrayOfString helpers for libSplash write calls. See ComputationalRadiationPhysics/libSplash#220 for the description of the problem. If a user wants to write an array of strings they need to be padded to the longest one. This helper does that. Use it like this: ```C++ #include "plugins/common/stringHelpers.hpp" // [...] helper::GetSplashArrayOfString getSplashArrayOfString; helper::GetSplashArrayOfString::Result myArrOfStr; std::list<std::string> myListOfStr; myListOfStr.push_back("short"); myListOfStr.push_back("middle"); myListOfStr.push_back("loooong"); myArrOfStr = getSplashArrayOfString( myListOfStr ); ``` Also adds a `helper::` namespace to avoid polluting the `PIConGPU` namespace.
Adds ArrayOfString helpers for libSplash write calls. See ComputationalRadiationPhysics/libSplash#220 for the description of the problem. If a user wants to write an array of strings they need to be padded to the longest one. This helper does that. Use it like this: ```C++ #include "plugins/common/stringHelpers.hpp" // [...] // create some strings std::list<std::string> myListOfStr; myListOfStr.push_back("short"); myListOfStr.push_back("middle"); myListOfStr.push_back("loooong"); // convert to splash format helper::GetSplashArrayOfString getSplashArrayOfString; helper::GetSplashArrayOfString::Result myArrOfStr; myArrOfStr = getSplashArrayOfString( myListOfStr ); // splash calls dc->writeGlobalAttribute( threadParams->currentStep, myArrOfStr.colType, "someListOfStr", 1u, /* ndims: 1D array */ Dimensions(myListOfStr.size(),0,0), /* size of 1D array */ &(myArrOfStr.buffers.at(0)) ); ``` Also adds a `helper::` namespace to avoid polluting the `PIConGPU` namespace.
Adds ArrayOfString helpers for libSplash write calls. See ComputationalRadiationPhysics/libSplash#220 for the description of the problem. If a user wants to write an array of strings they need to be padded to the longest one. This helper does that. Use it like this: ```C++ #include "plugins/common/stringHelpers.hpp" // [...] // create some strings std::list<std::string> myListOfStr; myListOfStr.push_back("short"); myListOfStr.push_back("middle"); myListOfStr.push_back("loooong"); // convert to splash format helper::GetSplashArrayOfString getSplashArrayOfString; helper::GetSplashArrayOfString::Result myArrOfStr; myArrOfStr = getSplashArrayOfString( myListOfStr ); // splash calls dc->writeGlobalAttribute( threadParams->currentStep, myArrOfStr.colType, "someListOfStr", 1u, /* ndims: 1D array */ Dimensions(myListOfStr.size(),0,0), /* size of 1D array */ &(myArrOfStr.buffers.at(0)) ); ``` Also adds a `helper::` namespace to avoid polluting the `PIConGPU` namespace.
@ax3l for( uint i = 11; i <= N; ++N )
axisLabels[0][i] = '\0'; You already pre-paded all targets with NULLs for( uint32_t d = 0; d < simDim; ++d )
{
memset( axisLabels[d], '\0', N+1 );
} |
What you are referring to is just a quick hack that I needed and documented for testing. The usage that is of interest for you is in |
Adds ArrayOfString helpers for libSplash write calls. See ComputationalRadiationPhysics/libSplash#220 for the description of the problem. If a user wants to write an array of strings they need to be padded to the longest one. This helper does that. Use it like this: ```C++ #include "plugins/common/stringHelpers.hpp" // [...] // create some strings std::list<std::string> myListOfStr; myListOfStr.push_back("short"); myListOfStr.push_back("middle"); myListOfStr.push_back("loooong"); // convert to splash format helper::GetSplashArrayOfString getSplashArrayOfString; helper::GetSplashArrayOfString::Result myArrOfStr; myArrOfStr = getSplashArrayOfString( myListOfStr ); // splash calls dc->writeGlobalAttribute( threadParams->currentStep, myArrOfStr.colType, "someListOfStr", 1u, /* ndims: 1D array */ Dimensions(myListOfStr.size(),0,0), /* size of 1D array */ &(myArrOfStr.buffers.at(0)) ); ``` Also adds a `helper::` namespace to avoid polluting the `PIConGPU` namespace.
Adds ArrayOfString helpers for libSplash write calls. See ComputationalRadiationPhysics/libSplash#220 for the description of the problem. If a user wants to write an array of strings they need to be padded to the longest one. This helper does that. Use it like this: ```C++ // include "plugins/common/stringHelpers.hpp" // include <splash/splash.h> // include <list> // include <string> // create some strings std::list<std::string> myListOfStr; myListOfStr.push_back("short"); myListOfStr.push_back("middle"); myListOfStr.push_back("loooong"); // convert to splash format helper::GetSplashArrayOfString getSplashArrayOfString; helper::GetSplashArrayOfString::Result myArrOfStr; myArrOfStr = getSplashArrayOfString( myListOfStr ); ColTypeString ctSomeListOfStr( myArrOfStr.maxLen ); // splash call dc->writeGlobalAttribute( threadParams->currentStep, ctSomeListOfStr, "someListOfStr", 1u, /* ndims: 1D array */ Dimensions( myListOfStr.size(), 0, 0 ), /* size of 1D array */ &( myArrOfStr.buffers.at(0) ) ); ``` - Also adds a `helper::` namespace to avoid polluting the PIConGPU namespace. - Declutters the helpers in a `.hpp` + `.cpp` file.
migrated to future: the above linked helper in PIConGPU should be ported to libSplash. |
Two write an array of constant size string one can currently do as equivalent to:
Write an array of three strings, example here of size 1, one can do in C-style notation:
which works.
I am not 100% sure currently if one can write something like the following python equivalent where the three const-size static lengths strings can vary between each other in size:
It might be possible to do something like
char**
for thewriteAttribute()
argumentaxisLabels
and then putting in each entry a different size c-string (null-terminated as usual). But I am not sure that will work since we only have oneColTypeString ctAxisLabels(N)
and this would meanN
can vary.So if you can, make your labels of the same lengths. (In your case "spatial idx" and "frequen idx" / " omega idx ", add trailing spaces before the
'\0'
etc. ... nasty)Official (but VLEN) example
CCing @PrometheusPi
The text was updated successfully, but these errors were encountered: