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,FOR_OPEN_FILE,for_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,FOR_CLOSE_FILE,for_close_file) (
00043   const f_int& iunit, const f_int& keep );
00044 
00045 } // end extern "C"
00046 
00047 void FortranTypes::f_open_file( const f_int iunit, const char file[]
00048   , EOpenStatus status, EOpenForm form, EOpenBlank blank
00049   , EOpenAccess access, f_int recl )
00050 {
00051   int result;
00052   // Convert the file name to an integer to pass to Fortran.
00053   FortranTypes::f_int int_file[100], int_file_len;
00054   result = convert_to_f_int_string( file, int_file, &int_file_len );
00055   TEST_FOR_EXCEPTION(
00056     result, InvalidFileNameException
00057     ,"f_open_file(...) : Error, the "
00058     << -result << " Character of the file name \""
00059     << file << "\" is not a valid ASCII character." );
00060 
00061   if(
00062     //result = FORTRAN_FUNC_CALL_UL_(F_OPEN_FILE,f_open_file)(
00063     result = FORTRAN_FUNC_CALL_UL_(FOR_OPEN_FILE,for_open_file)(
00064       iunit, int_file, int_file_len, status, form, blank, access, recl
00065       )
00066     )
00067   {
00068     TEST_FOR_EXCEPTION(
00069       result < 0, InvalidFileNameException
00070       ,"f_open_file(...) : Error, the "
00071       << -result << " Character of the file name \""
00072       << file << "\" is not a valid ASCII character." );
00073     TEST_FOR_EXCEPTION(
00074       result > 0, OpenException
00075       ,"f_open_file(...) : Error, the file named \""
00076       << file << "\" could not be opened and OPEN(...) "
00077       << "returned and IOSTAT = " << result );
00078   }
00079 }
00080 
00081 void FortranTypes::f_close_file( const f_int iunit, bool keep )
00082 {
00083   FORTRAN_FUNC_CALL_UL_(FOR_CLOSE_FILE,for_close_file)( iunit, keep ? 1 : 0 ); 
00084 }

Generated on Tue Oct 20 12:50:39 2009 for MoochoPack: Miscellaneous Utilities for MOOCHO by doxygen 1.4.7