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

Generated on Wed May 12 21:50:25 2010 for MoochoPack: Miscellaneous Utilities for MOOCHO by  doxygen 1.4.7