FortranTypes_f_open_file.cpp

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 #include "FortranTypes_f_open_file.hpp"
00030 #include "FortranTypes_CppFortranStrings.hpp"
00031 #include "Teuchos_TestForException.hpp"
00032 
00033 typedef FortranTypes::f_int f_int;
00034 
00035 extern "C" {
00036 
00037 FORTRAN_FUNC_DECL_UL_(f_int,F_OPEN_FILE,f_open_file) ( const f_int& IUNIT
00038   , const f_int I_FILE[], const f_int& I_FILE_LEN, const f_int& ISTATUS
00039   , const f_int& IFORM, const f_int& IBLANK, const f_int& IACCESS
00040   , const f_int& IRECL );
00041 
00042 FORTRAN_FUNC_DECL_UL_(void,F_CLOSE_FILE,f_close_file) ( const f_int& IUNIT, const f_int& KEEP );
00043 
00044 } // end extern "C"
00045 
00046 void FortranTypes::f_open_file( const f_int iunit, const char file[]
00047   , EOpenStatus status, EOpenForm form, EOpenBlank blank
00048   , EOpenAccess access, f_int recl )
00049 {
00050   int result;
00051   // Convert the file name to an integer to pass to Fortran.
00052   f_int I_FILE[100], I_FILE_LEN;
00053   result = convert_to_f_int_string( file, I_FILE, &I_FILE_LEN );
00054   TEST_FOR_EXCEPTION(
00055     result, InvalidFileNameException
00056     ,"f_open_file(...) : Error, the "
00057     << -result << " Character of the file name \""
00058     << file << "\" is not a valid ASCII character." );
00059 
00060   if( result = FORTRAN_FUNC_CALL_UL_(F_OPEN_FILE,f_open_file)(iunit, I_FILE, I_FILE_LEN
00061     , status, form, blank, access, recl ) )
00062   {
00063     TEST_FOR_EXCEPTION(
00064       result < 0, InvalidFileNameException
00065       ,"f_open_file(...) : Error, the "
00066       << -result << " Character of the file name \""
00067       << file << "\" is not a valid ASCII character." );
00068     TEST_FOR_EXCEPTION(
00069       result > 0, OpenException
00070       ,"f_open_file(...) : Error, the file named \""
00071       << file << "\" could not be opened and OPEN(...) "
00072       << "returned and IOSTAT = " << result );
00073   }
00074 }
00075 
00076 void FortranTypes::f_close_file( const f_int iunit, bool keep )
00077 {
00078   FORTRAN_FUNC_CALL_UL_(F_CLOSE_FILE,f_close_file)( iunit, keep ? 1 : 0 ); 
00079 }

Generated on Thu Sep 18 12:33:34 2008 for MoochoPack: Miscellaneous Utilities for MOOCHO by doxygen 1.3.9.1