/* * This file is part of qpOASES. * * qpOASES -- An Implementation of the Online Active Set Strategy. * Copyright (C) 2007-2008 by Hans Joachim Ferreau et al. All rights reserved. * * qpOASES is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * qpOASES is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with qpOASES; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ /** * \file SRC/Utils.cpp * \author Hans Joachim Ferreau, Eckhard Arnold * \version 1.3embedded * \date 2007-2008 * * Implementation of some inlined utilities for working with the different QProblem * classes. */ #include #if defined(__WIN32__) || defined(WIN32) #include #elif defined(LINUX) #include #include #endif #ifdef __MATLAB__ #include #endif #include #ifdef PC_DEBUG /* Define print functions only for debugging! */ /* * p r i n t */ returnValue print( const real_t* const v, int n ) { int i; char myPrintfString[160]; /* Print a vector. */ myPrintf( "[\t" ); for( i=0; ithrowError( RET_UNABLE_TO_OPEN_FILE,errstr,__FUNCTION__,__FILE__,__LINE__,VS_VISIBLE ); } /* 2) Read data from file. */ for( i=0; ithrowError( RET_UNABLE_TO_READ_FILE,errstr,__FUNCTION__,__FILE__,__LINE__,VS_VISIBLE ); } data[i*ncol + j] = ( (real_t) float_data ); } } /* 3) Close file. */ fclose( datafile ); return SUCCESSFUL_RETURN; } /* * r e a d F r o m F i l e */ returnValue readFromFile( real_t* data, int n, const char* datafilename ) { return readFromFile( data, n, 1, datafilename ); } /* * r e a d F r o m F i l e */ returnValue readFromFile( int* data, int n, const char* datafilename ) { int i; myFILE* datafile; /* 1) Open file. */ if ( ( datafile = fopen( datafilename, "r" ) ) == 0 ) { char errstr[80]; sprintf( errstr,"(%s)",datafilename ); return getGlobalMessageHandler( )->throwError( RET_UNABLE_TO_OPEN_FILE,errstr,__FUNCTION__,__FILE__,__LINE__,VS_VISIBLE ); } /* 2) Read data from file. */ for( i=0; ithrowError( RET_UNABLE_TO_READ_FILE,errstr,__FUNCTION__,__FILE__,__LINE__,VS_VISIBLE ); } } /* 3) Close file. */ fclose( datafile ); return SUCCESSFUL_RETURN; } /* * w r i t e I n t o F i l e */ returnValue writeIntoFile( const real_t* const data, int nrow, int ncol, const char* datafilename, BooleanType append ) { int i, j; myFILE* datafile; /* 1) Open file. */ if ( append == BT_TRUE ) { /* append data */ if ( ( datafile = fopen( datafilename, "a" ) ) == 0 ) { char errstr[80]; sprintf( errstr,"(%s)",datafilename ); return getGlobalMessageHandler( )->throwError( RET_UNABLE_TO_OPEN_FILE,errstr,__FUNCTION__,__FILE__,__LINE__,VS_VISIBLE ); } } else { /* do not append data */ if ( ( datafile = fopen( datafilename, "w" ) ) == 0 ) { char errstr[80]; sprintf( errstr,"(%s)",datafilename ); return getGlobalMessageHandler( )->throwError( RET_UNABLE_TO_OPEN_FILE,errstr,__FUNCTION__,__FILE__,__LINE__,VS_VISIBLE ); } } /* 2) Write data into file. */ for( i=0; ithrowError( RET_UNABLE_TO_OPEN_FILE,errstr,__FUNCTION__,__FILE__,__LINE__,VS_VISIBLE ); } } else { /* do not append data */ if ( ( datafile = fopen( datafilename, "w" ) ) == 0 ) { char errstr[80]; sprintf( errstr,"(%s)",datafilename ); return getGlobalMessageHandler( )->throwError( RET_UNABLE_TO_OPEN_FILE,errstr,__FUNCTION__,__FILE__,__LINE__,VS_VISIBLE ); } } /* 2) Write data into file. */ for( i=0; i