[Insight-developers] command-line arguments to tests
Tessa Sundaram
tessa@rad.upenn.edu
Fri, 03 May 2002 10:53:40 -0400
This is a multi-part message in MIME format.
--------------040307020501020206090009
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Hi everyone,
What's the correct syntax for providing "command-line" arguments to a
test in the CMakeLists.txt file? The CMake docs list it as
ADD_TEST(testName exeName arg1 arg2 ....)
while the BasicFiltersTests CMakeLists.txt file uses
ADD_TEST(testName exeName testName arg1 arg2 ....).
I've tried both of these for the FEM tests and haven't gotten either one
to work. Code and CMakeLists.txt file attached. Thanks for your help!
-ts
--------------040307020501020206090009
Content-Type: text/plain;
name="CMakeLists.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="CMakeLists.txt"
IF (TCL_TCLSH)
ADD_TEST(PrintSelf-Statistics ${TCL_TCLSH}
${ITK_SOURCE_DIR}/Utilities/Dart/PrintSelfCheck.tcl
${ITK_SOURCE_DIR}/Code/Numerics/Statistics)
ENDIF (TCL_TCLSH)
INCLUDE_DIRECTORIES(
${ITK_SOURCE_DIR}/Code/Common
${ITK_SOURCE_DIR}/Code/Numerics
${ITK_SOURCE_DIR}/Code/Numerics/FEM
${ITK_SOURCE_DIR}/Code/Numerics/vxl
${ITK_SOURCE_DIR}/Code/Numerics/vxl/vnl
)
LINK_DIRECTORIES(
${ITK_BINARY_DIR}/Code/Common
${ITK_BINARY_DIR}/Code/Numerics
${ITK_BINARY_DIR}/Code/Numerics/FEM
${ITK_BINARY_DIR}/Code/Numerics/vxl
${ITK_BINARY_DIR}/Code/Numerics/vxl/vnl
)
SOURCE_FILES(FEM_SRCS
itkFEMElementTestMenu
itkFEMElementTest
itkFEMBar2DTest
)
LINK_LIBRARIES (
VXLNumerics
ITKCommon
ITKNumerics
FEM
)
IF(UNIX)
LINK_LIBRARIES (
-lm
)
ENDIF(UNIX)
ADD_TEST(itkFEMElementTestMenu itkFEMTests itkFEMElementTestMenu)
ADD_TEST(itkFEMElementTest itkFEMTests itkFEMElementTest ${ITK_DATA_ROOT}/Input/FEM/hexa2.fem)
#ADD_TEST(itkFEMElementTest itkFEMTests itkFEMElementTest)
ADD_TEST(itkFEMBar2DTest itkFEMTests itkFEMBar2DTest)
# NOTE: the two commands below are mutually exclusive! Do not
# uncomment both at the same time!
# To run the FEM input menu-based test locally, uncomment the line below
# ADD_EXECUTABLE(itkFEMElementTestMenu itkFEMElementTestMenu)
# To create the standard ITK test program, uncomment the line below
ADD_EXECUTABLE(itkFEMTests itkFEMTests.cxx FEM_SRCS)
--------------040307020501020206090009
Content-Type: text/plain;
name="itkFEMElementTest.cxx"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="itkFEMElementTest.cxx"
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkFEMElementTest.cxx,v $
Language: C++
Date: $Date: 2002/05/02 02:21:25 $
Version: $Revision: 1.2 $
Copyright (c) 2002 Insight Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "itkFEM.h"
#include "itkFEMSolver.h"
#include <iostream>
#include <fstream>
//#include <strings>
using namespace std;
using namespace itk;
using namespace fem;
int itkFEMElementTest(int ac, char** av)
{
// File input stream
ifstream f;
std::cout << " ac = " << ac << std::endl; // why does ac = 0?!
for (int j=0; j < ac; j++)
std::cout << j << ": " << av[j] << std::endl;
// Path to input file
// char fname[] = "../../Insight/Testing/Data/Input/FEM/hexa2.fem";
std::cout << std::endl << "FEM Input: " << av[1] << std::endl;
// Declare the FEM solver & associated input stream and read the input file
f.open(av[1]);
if (!f)
{
std::cout << "ERROR: null file handle...terminating.\n";
return EXIT_FAILURE;
}
std::cout << "Solver()" << std::endl;
Solver S;
std::cout << "Read()" << std::endl;
S.Read(f);
std::cout << "Close file handle" << std::endl;
f.close();
// Call the appropriate sequence of Solver methods to solve the
// problem
std::cout << "GenerateGFN()" << std::endl;
S.GenerateGFN(); // Generate global freedom numbers for system DOFs
std::cout << "AssembleK()" << std::endl;
S.AssembleK(); // Assemble the global stiffness matrix K
std::cout << "DecomposeK()" << std::endl;
S.DecomposeK(); // Invert K
std::cout << "AssembleF()" << std::endl;
S.AssembleF(); // Assemble the global load vector F
std::cout << "Solve()"<< std::endl;
S.Solve(); // Solve the system Ku=F for u
std::cout << "UpdateDisplacements()" << std::endl;
S.UpdateDisplacements(); // Copy the solution u's back to the nodes
std::cout << "Done" << std::endl;
// Print the solutions (displacements)
std::cout << "Print displacements: " << std::endl;
for( ::itk::fem::Solver::NodeArray::iterator n = S.node.begin(); n!=S.node.end(); n++)
{
std::cout<<"Node "<<(*n)->GN<<": ";
/** For each DOF in the node... */
for( unsigned int d=0, dof; (dof=(*n)->GetDegreeOfFreedom(d))!=::itk::fem::Element::InvalidDegreeOfFreedomID; d++ )
{
std::cout<<S.GetSolution(dof);
std::cout<<", ";
}
std::cout<<"\b\b\b \b\n";
}
return EXIT_SUCCESS;
}
--------------040307020501020206090009--