Advanced search
Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Corsair
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

Discussion Forums: general

Start New Thread Start New Thread
Message: 322
BY: Jossitt vargas (jossitt)
DATE: 2017-01-09 13:28
No attachment found
SUBJECT: generador automatico de inputs con variacion de la energia

 

# include <cstdlib>
# include <iostream>
# include <iomanip>
# include <ctime>
# include <cstring>
# include <fstream>

using namespace std;



/// g++ -o exe inputgenerator.cpp
/// ./exe
int main ( );
void test01 ( );
void test02 ( );
void filename_inc ( string *filename );

void timestamp ( );

//****************************************************************************//

int main ( )

//****************************************************************************//
//
// Purpose:
//
// FILES_MULTIPLE demonstrates how to work with multiple CORSIKA files.
//
//
// 6 January 2017
//
// Author:
//
// Jossitt Vargas, CORSAIR
//
{
timestamp ( );
cout << "\n";
cout << "FILES_MULTIPLE:\n";
cout << " C++ version.\n";
cout << " Demonstrate how to work with multiple files.\n";

test01 ( );
// test02 ( );
//
// Terminate.
//
cout << "\n";
cout << "FILES_MULTIPLE:\n";
cout << " Normal end of execution.\n";
cout << "\n";
timestamp ( );

return 0;
}



void test01 ( )

//****************************************************************************//
//
// Purpose:
//
// TEST01 writes data to four files which are open simultaneously.
//
// Discussion:
{
# define FILENUM 18
//
// FILENUM can be increased, and the program will still work the same way.
//
int divisor[18];
string filename[18];
ofstream fileunit[18];
int i;
int j;
// string temp = "input";
string temp = "input0";
string temp2 = "input10";

cout << "\n";
cout << "File generator\n";
cout << " Create "<< FILENUM<<"\t files\n";

int energy[18]={
1.00E+01,
1.33E+01,
1.78E+01,
2.37E+01,
3.16E+01,
4.22E+01,
5.62E+01,
7.50E+01,
1.00E+02,
1.78E+02,
3.16E+02,
5.62E+02,
1.00E+03,
3.16E+03,
1.00E+04,
3.16E+04,
1.00E+05,
3.16E+05};
//
// Set the divisors.
// PRIME is a function which can return the I-th prime number.
//
for ( i = 0; i < FILENUM; i++ )
{
divisor[i] = energy[i];
// cout<<"altitud"<<endl;


}
//
// Define the file names for an arbitrary number of files
// by incrementing the numeric information in a "template".
//
for ( i = 0; i < FILENUM; i++ )
{
filename_inc ( &temp );
filename[i] = temp;
if(i>9)
{
filename_inc ( &temp2 );
filename[i] = temp2;

}

}
//
// Associate a unit number with each file.
//
for ( i = 0; i < FILENUM; i++ )
{

cout<<"i="<<i<<endl;

fileunit[i].open ( filename[i].c_str ( ) );
// fileunit[i] << "Multiples of " << divisor[i] << "\n";
// fileunit[i] << "ENERGIA= " << divisor[i] << "\n";

//************************************
fileunit[i] << "RUNNR" << "\t"<<2 << "\t"<< "\t \t""run number"<< "\n";
fileunit[i] << "EVTNR" << "\t"<<1 << "\t \tnumber of first shower event"<< "\n";
fileunit[i] << "NSHOW" << "\t"<<100 << "\t \tnumber of showers to generate"<< "\n";
fileunit[i] << "PRMPAR" << "\t"<<14 << "\t \tparticle type of prim. particle (p:14, N:A*100+Z)"<< "\n";
fileunit[i] << "ESLOPE" << "\t"<<-2.7 << "\t \tslope of primary energy spectrum"<< "\n";
fileunit[i] << "ERANGE" << "\t"< fileunit[i] << "THETAP" <<"\t"<< 0 << " "<<12.8 << "\t \trange of zenith angle (degree)"<< "\n";
fileunit[i] << "PHIP" <<"\t"<< 180<<" "<<-180 << "\t \trange of azimuth angle (degree)"<< "\n";
fileunit[i] << "SEED" << "\t"<<1<<" "<<0<<" "<<0 << "\t \tseed for 1. random number sequence"<< "\n";
fileunit[i] << "SEED" << "\t"<<2<<" "<<0<<" "<<0 << "\t \tseed for 2. random number sequence"<< "\n";


fileunit[i] << "OBSLEV" <<"\t"<< 230.E2 << "\t"<<"\t \tobservation level (in cm)"<< "\n";
fileunit[i] << "FIXCHI" << "\t"<<0<<"\t"<< "\t \tstarting altitude (g/cm**2)"<< "\n";
fileunit[i] << "MAGNET" << "\t"<<24.2 << "\t"<<38.5<<"\t" << "\t \t magnetic field at Santiago de Compostela"<< "\n";
fileunit[i] << "HADFLG" <<"\t"<< 0 <<" "<< 0 <<" "<< 0 <<" "<< 0 <<" "<< 0 <<" "<< 2 <<" "<< "\t \tflags hadr.interact.&fragmentation"<< "\n";
fileunit[i] << "ECUTS" <<"\t"<< 0.3 <<" "<< 0.3 <<" "<< 0.06 <<" "<< 0.10 << "\t \tenergy cuts for particles"<< "\n";
fileunit[i] << "MUADDI" <<"\t"<< "T"<<"\t"<< "\t traditional info for muons"<< "\n";
fileunit[i] << "MUMULT" << "\t"<<"T" << " \t \t muon multiple scattering angle"<< "\n";
fileunit[i] << "ELMFLG" << "\t"<<"T" <<" "<< "T" << "\t \t em. interaction flags (NKG,EGS)"<< "\n";
fileunit[i] << "STEPFC" << "\t"<<1.0 << "\t \tmult. scattering step length fact."<< "\n";


fileunit[i] << "RADNKG" << "\t"<<200.E2 << "\t \touter radius for NKG lat.dens.distr."<< "\n";
fileunit[i] << "LONGI" << "\t"<< "T" <<" "<<100<<" "<<"T" <<" "<<"T" << "\t \tlongit.distr. & step size & fit & out"<< "\n";
fileunit[i] << "ECTMAP" << " "<<1.E4 << "\t \tcut on gamma factor for printout"<< "\n";
fileunit[i] << "MAXPRT" << "\t"<<0 << "\t \tmax. number of printed events"<< "\n";
fileunit[i] << "DIRECT" << "\t"<<"./" << "\t \toutput directory"<< "\n";
fileunit[i] << "USER" << "\t"<<"you" << "\t \tuser"<< "\n";
fileunit[i] << "DEBUG" << "\t"<<"F" <<" "<< 6<<" "<<"F" <<" "<<1000000<<"\t \tdebug flag and log.unit for out"<< "\n";
fileunit[i] << "EXIT" << "\t \tterminates input" << "\n";





///+++++++++++++++++++++++++++++++++++

}

//
// Close the files.
//
for ( i = 0; i < FILENUM; i++ )
{
fileunit[i].close ( );
}

return;
# undef FILENUM
}
//****************************************************************************//




void filename_inc ( string *filename )

//****************************************************************************80
//
// Purpose:
//
// FILENAME_INC increments a partially numeric file name.
//
// Discussion:
//
// It is assumed that the digits in the name, whether scattered or
// connected, represent a number that is to be increased by 1 on
// each call. If this number is all 9's on input, the output number
// is all 0's. Non-numeric letters of the name are unaffected.
//
// If the name is empty, then the routine stops.
//
// If the name contains no digits, the empty string is returned.
//
// Example:
//
// Input Output
// ----- ------
// "a7to11.txt" "a7to12.txt" (typical case. Last digit incremented)
// "a7to99.txt" "a8to00.txt" (last digit incremented, with carry.)
// "a9to99.txt" "a0to00.txt" (wrap around)
// "cat.txt" " " (no digits to increment)
// " " STOP! (error)
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 22 November 2011
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input/output, string *FILENAME, the filename to be incremented.
//
{
char c;
int change;
int i;
int lens;

lens = (*filename).length ( );

if ( lens <= 0 )
{
cerr << "\n";
cerr << "FILENAME_INC - Fatal error!\n";
cerr << " The input string is empty.\n";
exit ( 1 );
}

change = 0;

for ( i = lens - 1; 0 <= i; i-- )
{
c = (*filename)[i];

if ( '0' <= c && c <= '9' )
{
change = change + 1;

if ( c == '9' )
{
c = '0';
(*filename)[i] = c;
}
else
{
c = c + 1;
(*filename)[i] = c;
return;
}
}
}
//
// No digits were found. Return blank.
//
if ( change == 0 )
{
for ( i = lens - 1; 0 <= i; i-- )
{
(*filename)[i] = ' ';
}
}

return;
}
//****************************************************************************80






void timestamp ( )

//****************************************************************************80
//
// Purpose:
//
// TIMESTAMP prints the current YMDHMS date as a time stamp.
//
// Example:
//
// 31 May 2001 09:45:54 AM
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 08 July 2009
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// None
//
{
# define TIME_SIZE 40

static char time_buffer[TIME_SIZE];
const struct std::tm *tm_ptr;
size_t len;
std::time_t now;

now = std::time ( NULL );
tm_ptr = std::localtime ( &now );

len = std::strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr );

std::cout << time_buffer << "\n";

return;
# undef TIME_SIZE
}


Thread View

Thread Author Date
scripts for corsika inpuntsJossitt vargas2017-01-05 16:24
      exein.shJossitt vargas2017-01-09 13:23
      RE: scripts for corsika inpuntsJossitt vargas2017-01-05 16:30
            clearcorsika.shJossitt vargas2017-01-09 13:25
      generador automatico de inputs con variacion de la energiaJossitt vargas2017-01-09 13:28
SimulacionesJuan A. Garzon2016-11-16 18:03
Welcome to Open-Discussion 2016-09-20 08:36

Post a followup to this message

Please log in


Powered By FusionForge