Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

b6stream.cpp

Go to the documentation of this file.
00001 /*
00002  * ******** fete: From ENDF To ENDL *********
00003  * 
00004  * Copyright (c) 2006, The Regents of the University of California. 
00005  * All rights reserved.
00006  * 
00007  * Produced at the Lawrence Livermore National Laboratory. 
00008  * Written by David A. Brown, Gerry Hedstrom, Tony Hill
00009  * 
00010  * This file is part of fete v1.0  (UCRL-CODE-218718)
00011  * 
00012  * Please read the COPYING file for "Our Notice and GNU General 
00013  * Public License" in the root of this software distribution.  
00014  * 
00015  * This program is free software; you can redistribute it and/or modify 
00016  * it under the terms of the GNU General Public License (as published by 
00017  * the Free Software Foundation) version 2, dated June 1991. 
00018  * 
00019  * This program is distributed in the hope that it will be useful, 
00020  * but WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF 
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms 
00022  * and conditions of the GNU General Public License for more details. 
00023  * 
00024  * You should have received a copy of the GNU General Public License along 
00025  * with this program; if not, write to the Free Software Foundation, Inc., 
00026  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
00027  * 
00028  * $Revision: 1841 $
00029  * $Date: 2006-04-14 16:27:07 -0700 (Fri, 14 Apr 2006) $
00030  * $Author: hedstrom $
00031  * $Id: b6stream.cpp 1841 2006-04-14 23:27:07Z hedstrom $
00032  * 
00033  * ******** fete: From ENDF To ENDL *********
00034  */
00035 
00036 #include "b6stream.hpp"
00037 #include "record_types.hpp"
00038 #include "endl_formats.hpp"
00039 #include "convert.hpp"
00040 #include "global_params.hpp"
00041 #include "messaging.hpp"
00042 
00043 extern GlobalParameterClass Global;
00044 
00045 // *********** class iMF_array_link ******************
00046 // ----------- iMF_array_link::print_MF ---------------
00047 void iMF_array_link::print_MF( )
00048 {
00049   cout << "    MT: " << MT( );
00050   for( iMF_array_link::iterator this_mf = begin( ); 
00051        this_mf != end( ); ++this_mf )
00052   {
00053     cout << "  " << *this_mf;
00054   }
00055   cout << endl;
00056 }
00057 // ----------- iMF_array_link::angle_cm ---------------
00058 bool iMF_array_link::angle_cm( )
00059 // function to determine whether angular data should be CM or lab frame
00060 {
00061   bool CM = true;
00062 
00063   for( iMF_array_link::iterator this_mf = begin( ); 
00064        this_mf != end( ); ++this_mf )
00065   {
00066     // are there energy distributions?
00067     if( *this_mf == 5 )
00068     {
00069       CM = false;
00070       break;
00071     }
00072   }
00073   return CM;
00074 }
00075 
00076 // *********** class iMF_array_list ******************
00077 // ----------- iMF_array_list::at ---------------
00078 // Function to get the link at "x"
00079 // Returns "false" if the entry is not found.
00080 bool iMF_array_list::at(int x, iMF_array_list::iterator& link)
00081 {
00082   for( link = begin( ); 
00083        link != end( );
00084        ++link )
00085   {
00086     if ( link->MT( ) == x ) 
00087     {
00088       return true;
00089     }
00090   }
00091   return false;
00092 }
00093 // -------------------- iMF_array_list::found ----------------
00094 bool iMF_array_list::found( int mt )
00095 {
00096   bool found_it = false;
00097 
00098   for( iMF_array_list::iterator this_mt = begin();
00099        this_mt != end(); ++this_mt)
00100   {
00101     if( mt == this_mt->MT( ) )
00102     {
00103       found_it = true;
00104       break;
00105     }
00106   }
00107   return found_it;
00108 }
00109 
00110 // *********** class b6stream ******************
00111 // -------------------- b6stream constructor ----------------
00112 b6stream::b6stream(string inputFile)
00113 {
00114   //zero out all the identifiers
00115   NTAPE=0;MAT=0;MF=0;MT=0;NS=-1;LRP=0;LFI=0;NLIB=0;
00116   NMOD=0;LIS=0;LISO=0;NFOR=0;NSUB=0;NVER=0;LDRV=0;NWD=0;
00117   NXC=0;ZA=0;AWR=0;ELIS=0;STA=0;AWI=0;TEMP=0;
00118   prev_mt = 0;
00119   prev_mf = 0;
00120   //zero out logical flags
00121   SEND=false;FEND=false;MEND=false;TEND=false;DONE=false;lofile=false;
00122   // we start at the top of the file
00123   file_top = true;
00124 
00125   // set the input file
00126   if (inputFile == "") input_file = "endf.prepro";
00127   else input_file = inputFile;
00128 
00129   //Here we go...
00130   Efile.open(input_file.c_str(),ios::in); // Open the preprocessed ENDF file stream
00131   
00132   if ( !Efile.is_open() )             // opened failed 
00133     { FatalError("b6stream::b6stream","Cannot find "+input_file+" file",false); }
00134   else
00135     { Info("",input_file+" opened successfully!"); }
00136 
00137   //Loop through the entire file, reading one line at a time
00138   for ( int i=0; !DONE; i++ ) { readENDF(); }  
00139   
00140   Efile.close();  //close the ENDF file stream
00141   
00142 }
00143 // -------------------- b6stream destructor ----------------
00144 //default destructor
00145 b6stream::~b6stream() 
00146 { 
00147   
00148 }
00149 // -------------------- b6stream::readENDF ----------------
00150 void b6stream::readENDF()
00151 {
00152   //First, read in the line
00153   if (!getline( Efile, sBuff )) {DONE=true;return;}
00154 
00155   // initialize everything before processing any lines
00156   if ( ( file_top ) && ( NS == -1 ) )
00157   {
00158     SEND=false;FEND=false;MEND=false;TEND=false;
00159     NTAPE=0; MAT=0; 
00160     
00161     //Need to open the "comments" output file
00162     //This is always the first thing in the ENDF file
00163     oFile.open(endf_file_name(1,451).c_str(),ios::out);
00164     if ( !oFile.is_open() )  //open failed
00165     {
00166         FatalError("b6stream::readENDF",
00167             "File "+endf_file_name(1,451)+" not opened");
00168     }
00169     else          //open successful -> start writing
00170     {
00171       Info("","File "+endf_file_name(1,451)+" opened for write..."); 
00172       oFile << sBuff << endl;
00173       lofile=true;  //lofile true when there is an open output file
00174       prev_mf = 1;
00175       prev_mt = 451;
00176     }
00177   }//end of if ( NS = -1 )
00178 
00179   get_MAT_MF_MT_NS();  //convert the last four columns and strip them  
00180 
00181   // Set some flags if this is a "special" record
00182   if ( MT == 0 && MF != 0 && MAT != 0 ) SEND=true;
00183   if ( MT == 0 && MF == 0 && MAT != 0 ) FEND=true;
00184   if ( MT == 0 && MF == 0 && MAT == 0 ) MEND=true;
00185   if ( MT == 0 && MF == 0 && MAT ==-1 ) TEND=true;
00186   
00187   // Several lines of the comments section are important...
00188   if( file_top )
00189   {
00190     if ( NS == 0 ) //TPID is the first line of the file
00191     { 
00192       if ( MF != 0 || MT != 0 ) //Both are zero ONLY on first line
00193     {                       //This is just a double check
00194       Warning("b6stream::readENDF","MF or MT not zero in first line of input!");
00195     }
00196       
00197       NTAPE=MAT; MAT=0; //Tape number, not MAT, is reported on line 0
00198     }//end of if ( NS = 0 )
00199 
00200     else if ( NS == 1 ) 
00201     {
00202       check_mf_mt( );
00203       read_idiiii(&sBuff,&ZA,&AWR,&LRP,&LFI,&NLIB,&NMOD);
00204       oFile << sBuff << endl;
00205     }//end of if ( NS = 1 )
00206 
00207     else if ( NS == 2 )
00208     {
00209       check_mf_mt( );
00210       read_ddiiii(&sBuff,&ELIS,&STA,&LIS,&LISO,&iDummy,&NFOR);
00211       oFile << sBuff << endl;
00212     }//end of if ( NS = 2 )
00213 
00214     else if ( NS == 3 )
00215     {
00216       check_mf_mt( );
00217       read_ddiiii(&sBuff,&AWI,&dDummy,&iDummy,&iDummy,&NSUB,&NVER);
00218       yi=NSUB_to_yi(NSUB);
00219       oFile << sBuff << endl;
00220     }//end of if ( NS = 3 )
00221 
00222     else if ( NS == 4 )
00223     {
00224       check_mf_mt( );
00225       read_ddiiii(&sBuff,&TEMP,&dDummy,&LDRV,&iDummy,&NWD,&NXC);
00226       oFile << sBuff << endl;
00227     }//end of if ( NS = 4 )
00228 
00229     else if ( NS == 5 )  //get the date, maybe
00230     {
00231       check_mf_mt( );
00232       date = 0;
00233       if (Global.Value("skip_date") == 0.) read_date(&sBuff,&date);
00234       else Info("b6stream::readENDF","skipping ENDFB6 evaluation date read.");
00235       oFile << sBuff << endl;
00236       // Test to make sure everything seems okay with this evaluation
00237       // based on the comments file information and print a summary.
00238       print_summary( );
00239       // We are done with the first 6 lines
00240       file_top = false;      
00241     }//end of if ( NS = 5 )
00242     else //rest of top data
00243     {
00244       check_mf_mt( );
00245       oFile << sBuff << endl;
00246     }
00247   }
00248 
00249   else if ( TEND )
00250   {
00251     DONE=true;  // last line of endf.prepro file
00252   }
00253   else if ( MEND )
00254   {
00255     DONE=true;  // no more data for this mf number
00256   }
00257   else if ( FEND )
00258   {
00259     // no more data for this mf-mt combination; file should be closed
00260     if ( lofile )
00261     {
00262       Warning("b6stream::readENDF","Closing file with FEND");
00263       oFile.close();
00264       lofile=false;
00265     }
00266   }
00267   else if ( SEND )
00268   {
00269     // end of this mf-mt data; close the current file
00270     if ( lofile )
00271     {
00272       oFile.close();
00273       lofile=false;
00274       Info("b6stream::readENDF","File closed.");
00275     }
00276   }
00277   else if ( !lofile )
00278   {
00279     // this is new mf-mt data
00280     // store the mf and mt numbers
00281     iMF_array_list::iterator this_mt;
00282     if( MT_MF_list.at( MT, this_mt ) )
00283     {
00284       // this mt number is already in the list, so append this mf
00285       this_mt->push_back( MF );
00286     }
00287     else
00288     {
00289       iMF_array_link new_link; // to make a new link
00290       new_link.MT( ) = MT;
00291       MT_MF_list.insert( MT_MF_list.end( ), new_link );
00292       this_mt = MT_MF_list.end( );
00293       --this_mt;
00294       // save this mf
00295       this_mt->push_back( MF );
00296     }
00297 
00298     // We need to open a new file, test and then send
00299     oFile.open(endf_file_name(MF,MT).c_str(),ios::out); 
00300     if ( !oFile.is_open() )  //open failed
00301     { 
00302       SevereError("b6stream::readENDF",
00303              "File "+endf_file_name(MF,MT)+" not opened.");
00304     }
00305     else            //open successful
00306     { 
00307       Info("b6stream::readENDF","File "+endf_file_name(MF,MT)+
00308            " opened for write..."); 
00309       oFile << sBuff << endl;
00310       lofile=true;
00311       prev_mf = MF;
00312       prev_mt = MT;
00313     }
00314   }
00315   else //rest of data
00316   {
00317     check_mf_mt( );
00318     oFile << sBuff << endl;
00319   }
00320   
00321   //Reset these after line has been handled
00322   SEND=false;FEND=false;MEND=false;TEND=false;
00323   
00324 }
00325 // -------------------- b6stream::check_mf_mt ----------------
00326 void b6stream::check_mf_mt( )
00327 {
00328   if( ( MF != prev_mf ) || ( MT != prev_mt ) )
00329   {
00330     cout << "MF: " << MF << " prev_mf: " << prev_mf <<
00331       "  MT: " << MT << " prev_mt: " << prev_mt << endl;
00332     SevereError( " b6stream::check_mf_mt", " inconsistent mf-mt numbers" );
00333   }
00334 }
00335 // -------------------- b6stream::get_MAT_MF_MT_NS ----------------
00336 void b6stream::get_MAT_MF_MT_NS()
00337 {
00338   // Read the MAT, MF, MT and NS into memory, strip them from string buffer
00339   MAT=stoi(sBuff.substr(66,4));
00340   MF=stoi(sBuff.substr(70,2));
00341   MT=stoi(sBuff.substr(72,3));
00342   if (sBuff.size()>75) NS=stoi(sBuff.substr(75,5));
00343   else {
00344     if (NS>=0) NS++;
00345     else NS=0;
00346   }
00347   sBuff = sBuff.substr(0,66) ;
00348 }
00349 // -------------------- b6stream::NSUB_to_yi ----------------
00350 int b6stream::NSUB_to_yi(int NSUB){
00351     if ( ( NSUB>3     )&&( NSUB<10    ) ) return 0; // activation data
00352     if ( ( NSUB>9     )&&( NSUB<13    ) ) return 1; // neutrons
00353     if ( ( NSUB>10009 )&&( NSUB<10020 ) ) return 2; // protons
00354     if ( ( NSUB>10019 )&&( NSUB<10030 ) ) return 3; // deuterons
00355     if ( ( NSUB>10029 )&&( NSUB<10040 ) ) return 4; // tritons
00356     if ( ( NSUB>20029 )&&( NSUB<20040 ) ) return 5; // 3He's
00357     if ( ( NSUB>20039 )&&( NSUB<20050 ) ) return 6; // alphas
00358     if ( ( NSUB>=0    )&&( NSUB<4     ) ) return 7; // gammas
00359     SevereError("b6stream::NSUB_to_yi",
00360         pastenum("Illegal Sublibrary designator NSUB=",NSUB)
00361         +", Cannot compute yi");  
00362     return -1; // should never get here 
00363 }
00364 // -------------------- b6stream::print_summary ----------------
00365 void b6stream::print_summary()
00366 { //Print a short summary from the comments section header
00367   if (MESSAGELEVEL_INFO) cout<<"Info :  b6stream summary :"<<endl
00368     <<"   ENDF Tape number " << NTAPE << endl
00369     <<"   Library version "<<NVER<<"; identifier "<<NLIB<<endl
00370     <<"   Library format = "<<NFOR<<endl
00371     <<"   ZA = "<<ZA<<"  AWR = "<<AWR<<endl;
00372   if ( LRP==-1 )
00373     {if (MESSAGELEVEL_INFO) cout<<"   No File 2 given and LRP = -1 (we can't use it anyway...)"<<endl;}
00374   else if (LRP==0)
00375     {if (MESSAGELEVEL_INFO) cout<<"   File 2 contains effective scattering radius..."<<endl;}
00376   else if (LRP==1)
00377     {/*This is okay */}
00378   else if (LRP==2)
00379     {if (MESSAGELEVEL_INFO) cout<<"   LRP = 2 :for use with derived files only"<<endl;}
00380   else
00381     {SevereError("b6stream::print_summary","LRP out of range!");}
00382   if (ZA/1000 > 88) {
00383     if (LFI==1) if (MESSAGELEVEL_INFO) cout<<"   Material fizzes."<<endl;
00384     else Warning("b6stream::print_summary",
00385             pastenum("LFI = ",LFI)+", but material should fiz.");
00386   } else {
00387     if (LFI==0) if (MESSAGELEVEL_INFO) cout<<"   Material does not fizz."<<endl;
00388     else SevereError("b6stream::print_summary",
00389             pastenum("LFI = ",LFI)+", but material cannot fiz!");
00390   }
00391   if (STA==0)
00392     {if (MESSAGELEVEL_INFO) cout<<"   Target is stable."<<endl;}
00393   else
00394     {if (MESSAGELEVEL_INFO) cout<<"   Target is unstable."<<endl;}
00395   if (MESSAGELEVEL_INFO) cout
00396     <<"   Incident particle (yi) = "<<yi<<endl
00397     <<"   Excitation energy =      "<<ELIS<<endl
00398     <<"   Nucleus state number =   "<<LIS<<endl
00399     <<"   Isomeric state number =  "<<LISO<<endl
00400     <<"   Temperature =            "<<TEMP<<endl;
00401 }
00402 // -------------------- b6stream::print_MT_MF ----------------
00403 void b6stream::print_MT_MF( )
00404 {
00405   cout << "Info: Data for each reaction:"<<endl;
00406   for( iMF_array_list::iterator this_mt = MT_MF_list.begin();
00407        this_mt != MT_MF_list.end(); ++this_mt)
00408   {
00409     this_mt->print_MF( );
00410   }
00411 }

Generated on Thu Sep 7 10:30:01 2006 for fete -- From ENDFB6 To ENDL by doxygen 1.3.4