|
MoochoPack: Miscellaneous Utilities for MOOCHO Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization 00005 // Copyright (2003) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 00030 #include "Moocho_Config.h" 00031 00032 00033 #ifdef HAVE_MOOCHO_FORTRAN 00034 00035 00036 #include "FortranTypes_f_open_file.hpp" 00037 #include "FortranTypes_CppFortranStrings.hpp" 00038 #include "Teuchos_TestForException.hpp" 00039 00040 00041 typedef FortranTypes::f_int f_int; 00042 00043 00044 extern "C" { 00045 00046 00047 FORTRAN_FUNC_DECL_UL_(f_int,FOR_OPEN_FILE,for_open_file) ( const f_int& iunit 00048 , const f_int i_file[], const f_int& i_file_len, const f_int& istatus 00049 , const f_int& iform, const f_int& iblank, const f_int& iaccess 00050 , const f_int& irecl ); 00051 00052 00053 FORTRAN_FUNC_DECL_UL_(void,FOR_CLOSE_FILE,for_close_file) ( 00054 const f_int& iunit, const f_int& keep ); 00055 00056 00057 } // end extern "C" 00058 00059 00060 void FortranTypes::f_open_file( const f_int iunit, const char file[] 00061 , EOpenStatus status, EOpenForm form, EOpenBlank blank 00062 , EOpenAccess access, f_int recl ) 00063 { 00064 int result; 00065 // Convert the file name to an integer to pass to Fortran. 00066 FortranTypes::f_int int_file[100], int_file_len; 00067 result = convert_to_f_int_string( file, int_file, &int_file_len ); 00068 TEST_FOR_EXCEPTION( 00069 result, InvalidFileNameException 00070 ,"f_open_file(...) : Error, the " 00071 << -result << " Character of the file name \"" 00072 << file << "\" is not a valid ASCII character." ); 00073 00074 if( 00075 //result = FORTRAN_FUNC_CALL_UL_(F_OPEN_FILE,f_open_file)( 00076 result = FORTRAN_FUNC_CALL_UL_(FOR_OPEN_FILE,for_open_file)( 00077 iunit, int_file, int_file_len, status, form, blank, access, recl 00078 ) 00079 ) 00080 { 00081 TEST_FOR_EXCEPTION( 00082 result < 0, InvalidFileNameException 00083 ,"f_open_file(...) : Error, the " 00084 << -result << " Character of the file name \"" 00085 << file << "\" is not a valid ASCII character." ); 00086 TEST_FOR_EXCEPTION( 00087 result > 0, OpenException 00088 ,"f_open_file(...) : Error, the file named \"" 00089 << file << "\" could not be opened and OPEN(...) " 00090 << "returned and IOSTAT = " << result ); 00091 } 00092 } 00093 00094 00095 void FortranTypes::f_close_file( const f_int iunit, bool keep ) 00096 { 00097 FORTRAN_FUNC_CALL_UL_(FOR_CLOSE_FILE,for_close_file)( iunit, keep ? 1 : 0 ); 00098 } 00099 00100 00101 #endif // HAVE_MOOCHO_FORTRAN
1.7.4