Print Table of Contents
This example demonstrates how to open an SDRC Universal file and display its table of contents using the DataSource interface. We’ll walk through the process step by step, showing you how to create a data source, open a file, and print a complete table of contents.
Quick Navigation:
- Overview
- Step 1: Initialize and Setup
- Step 2: Open File with DataSource
- Step 3: Error Checking
- Step 4: Print Table of Contents
- Complete Source Code
Overview
The example performs the following main tasks:
- Parse command line arguments, and validate license
- Open the file using DataSource
- Check for errors and handle them appropriately
- Print the complete table of contents
Let’s examine each step in detail.
Step 1: Initialize and Setup
First, we include necessary headers, declare variables, and handle command line arguments:
#include "samcpp/core/core.h"
#include "samcpp/access/access.h"
#include "sam/hoops_license.h"
#include <iostream>
/*----------------------------------------------------------------------
Print Table of Contents
----------------------------------------------------------------------*/
int
main(int argc, char** argv)
{
char inputFile[cae::core::MAX_NAME_LENGTH] = {};
// Check input arguments
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " inputfile [appendfile]\n";
std::cerr << " inputfile is blank, 'bumper.unv' is assumed\n";
strcpy(inputFile, "bumper.unv");
}
else {
strcpy(inputFile, argv[1]);
}
cae::core::license::validate(HOOPS_LICENSE);
The program provides helpful information about all the data in the “bumper.unv” file which is provided along with
the SDK. The license is validated using the validate() function.
Step 2: Open File with DataSource
Next, we create a DataSource and open the input file:
// Open file
cae::access::DataSource dataSource;
cae::core::Status status = dataSource.openFile(inputFile, nullptr);
The DataSource provides a high-level interface for file operations using openFile(). The file format is
automatically detected. A nullptr is provided instead of options since we are not interested
in any particular options or conventions while reading this file.
Step 3: Error Checking
After opening the file, we check for any errors and handle them appropriately:
// Check for error
if (!status) {
std::cerr << "Error: opening file " << inputFile << '\n';
exit(1);
}
Proper error checking is essential when working with file operations. The DataSource’s openFile() method
returns a Status object that can be checked for success or failure.
Step 4: Print Table of Contents
Now we use the DataSource’s built-in table of contents function:
// Set verbose mode and print table of contents
dataSource.setIntegerParameter(cae::access::DataSource::IntegerParameter::VERBOSE, true);
dataSource.printTableOfContents("*");
The setIntegerParameter() method is used to configure the DataSource’s behavior. In this case, we set the
VERBOSE parameter to 1, which enables detailed output formatting for the table of contents.
This provides the attribute information of each result.
Then, printTableOfContents() provides a complete table of contents for the file. The “*” parameter is a wildcard
that requests information about all results. You can also use specific patterns like “D.N*” to get only
displacement results for each iteration/timestep.
Complete Source Code
The complete source code for this example can be found at: src/sam/vdm/exam/tutorial_table_of_contents.cpp
You can also view the full source here:
1#include "samcpp/core/core.h"
2#include "samcpp/access/access.h"
3#include "sam/hoops_license.h"
4#include <iostream>
5
6/*----------------------------------------------------------------------
7 Print Table of Contents
8----------------------------------------------------------------------*/
9int
10main(int argc, char** argv)
11{
12 char inputFile[cae::core::MAX_NAME_LENGTH] = {};
13 // Check input arguments
14 if (argc < 2) {
15 std::cerr << "Usage: " << argv[0] << " inputfile [appendfile]\n";
16 std::cerr << " inputfile is blank, 'bumper.unv' is assumed\n";
17 strcpy(inputFile, "bumper.unv");
18 }
19 else {
20 strcpy(inputFile, argv[1]);
21 }
22
23 cae::core::license::validate(HOOPS_LICENSE);
24
25 // Open file
26 cae::access::DataSource dataSource;
27 cae::core::Status status = dataSource.openFile(inputFile, nullptr);
28
29 // Check for error
30 if (!status) {
31 std::cerr << "Error: opening file " << inputFile << '\n';
32 exit(1);
33 }
34
35 // Set verbose mode and print table of contents
36 dataSource.setIntegerParameter(cae::access::DataSource::IntegerParameter::VERBOSE, 1);
37 dataSource.printTableOfContents("*");
38
39 return 0;
40}
This example demonstrates how to open an SDRC Universal file and display its table of contents using the LMan (Library Manager) interface. We’ll walk through the process step by step, showing you how to initialize the library manager, open a file, and print a complete table of contents.
Quick Navigation:
- Overview
- Step 1: Initialize and Setup
- Step 2: Open File with Library Manager
- Step 3: Error Checking
- Step 4: Print Table of Contents
- Step 5: Cleanup
- Complete Source Code
Overview
The example performs the following main tasks:
- Parse command line arguments, and validate license
- Open the file using Library Manager
- Check for errors and handle them appropriately
- Print the complete table of contents
- Clean up resources
Let’s examine each step in detail.
Step 1: Initialize and Setup
First, we include necessary headers, declare variables, and handle command line arguments:
#include "sam/base/base.h"
#include "sam/vdm/vdm.h"
#include "sam/base/license.h"
#include "sam/hoops_license.h"
int main(int argc, char** argv)
{
char inputFile[256];
/* check input arguments */
if (argc < 2) {
fprintf(stderr, "Usage: %s inputfile [appendfile]\n", argv[0]);
fprintf(stderr, " inputfile is blank, 'bumper.unv' is assumed\n");
strcpy(inputFile, "bumper.unv");
}
else {
strcpy(inputFile, argv[1]);
}
vsy_LicenseValidate(HOOPS_LICENSE);
The program provides helpful information about all the datasets in the “bumper.unv” file which is provided along with
the SDK. The license is validated using the vsy_LicenseValidate() function.
Step 2: Open File with Library Manager
Next, we create a Library Manager and open the input file:
/* Open file */
vdm_LMan* libraryManager = vdm_LManBegin();
vdm_LManOpenFile(libraryManager, inputFile, nullptr);
The LMan (Library Manager) provides a high-level interface for file operations, automatically detecting the file format and initializing the appropriate library based on the file format. A nullptr is provided instead of options since we are not interested in any particular options or conventions while reading this file.
Step 3: Error Checking
After opening the file, we check for any errors and handle them appropriately:
/* check for error */
Vint ierr = vdm_LManError(libraryManager);
if (ierr) {
fprintf(stderr, "Error: opening file %s\n", inputFile);
vdm_LManCloseFile(libraryManager);
vdm_LManEnd(libraryManager);
exit(1);
}
Proper error checking is essential when working with file operations. The Library Manager provides a simple error
checking mechanism through vdm_LManError().
Step 4: Print Table of Contents
Now we use the Library Manager’s built-in table of contents function:
vdm_LManSetParami(libraryManager, LMAN_VERBOSE, SYS_ON);
vdm_LManTOC(libraryManager, "*");
The vdm_LManSetParami() function is used to configure the Library Manager’s behavior. In this case, we set the
LMAN_VERBOSE parameter to SYS_ON, which enables detailed output formatting for the table of contents. This
provides the dataset attribute information.
Then, vdm_LManTOC() provides a complete table of contents for the file. The “*” parameter is a wildcard
that requests information about all datasets. You can also use specific patterns like “D.N*” to get only
displacement datasets for each iteration/timestep.
Step 5: Cleanup
Finally, we close the file and free all allocated resources:
vdm_LManCloseFile(libraryManager);
vdm_LManEnd(libraryManager);
return 0;
The Library Manager interface requires only two cleanup calls: vdm_LManCloseFile() to close the file and
vdm_LManEnd() to free the Library Manager object.
Complete Source Code
The complete source code for this example can be found at: src/sam/vdm/exam/exam1.cpp
You can also view the full source here:
1#include "sam/base/base.h"
2#include "sam/vdm/vdm.h"
3#include "sam/base/license.h"
4#include "sam/hoops_license.h"
5
6/*----------------------------------------------------------------------
7 Print Table of Contents
8----------------------------------------------------------------------*/
9int
10main(int argc, char** argv)
11{
12 char inputFile[256];
13 /* check input arguments */
14 if (argc < 2) {
15 fprintf(stderr, "Usage: %s inputfile [appendfile]\n", argv[0]);
16 fprintf(stderr, " inputfile is blank, 'bumper.unv' is assumed\n");
17 strcpy(inputFile, "bumper.unv");
18 }
19 else {
20 strcpy(inputFile, argv[1]);
21 }
22
23 vsy_LicenseValidate(HOOPS_LICENSE);
24
25 /* Open file */
26 vdm_LMan* libraryManager = vdm_LManBegin();
27 vdm_LManOpenFile(libraryManager, inputFile, nullptr);
28
29 /* check for error */
30 Vint ierr = vdm_LManError(libraryManager);
31 if (ierr) {
32 fprintf(stderr, "Error: opening file %s\n", inputFile);
33 vdm_LManCloseFile(libraryManager);
34 vdm_LManEnd(libraryManager);
35 exit(1);
36 }
37 /* Set verbose mode */
38 vdm_LManSetParami(libraryManager, LMAN_VERBOSE, SYS_ON);
39 vdm_LManTOC(libraryManager, "*");
40
41 vdm_LManCloseFile(libraryManager);
42 vdm_LManEnd(libraryManager);
43 return 0;
44}
Expected Output
When you run this example with a typical Universal file, you’ll see a comprehensive table of contents output similar to:
Library Table of Contents
Path: bumper.unv
Type: SDRC/IDEAS Universal File
IDst LRec NRow NCol Type NAtt Dataset
0 200 1 200 1 2 PARAMETER.INT.T
Model = Parameters
Description = Model Integer Parameters
1 200 1 200 3 2 PARAMETER.HOL.T
Model = Parameters
Description = Model Hollerith Parameters
2 1956 3 652 2 4 X.N
Model = Mesh
Description = Node Coordinates
Contents = Position
DataType = Vector
3 652 1 652 1 2 NID.N
Model = Mesh
Description = Node User Identifier