Skip to content

Commit

Permalink
Reduce the main() function to an absolute minimum.
Browse files Browse the repository at this point in the history
  • Loading branch information
yakutovicha committed Jul 24, 2024
1 parent cbc1553 commit b35f9bf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 210 deletions.
56 changes: 39 additions & 17 deletions cleedpy/cleed/src/leed.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#include "leed.h"

real ** leed(
struct cryst_str * bulk,
struct cryst_str *over,
struct phs_str *phs_shifts,
int energy_list_size,
real *energy_list,
struct var_str *v_par,
FILE *res_stream
char * bul_file,
char * par_file,
char *res_file
){
struct cryst_str *bulk=NULL;
struct cryst_str *over=NULL;
struct phs_str *phs_shifts=NULL;
struct var_str *v_par=NULL;


struct beams_str * beams_now=NULL;
struct beams_str * beams_set=NULL;
Expand All @@ -21,38 +22,57 @@ real ** leed(
int i_layer;
int energy_index;
int n_set;

int energy_list_size;
real *energy_list;
real energy;
real vec[4];

float **iv_curves=NULL;
real **iv_curves=NULL;

mat R_bulk=NULL, R_tot=NULL;
mat Amp=NULL;

mat Tpp=NULL, Tmm=NULL, Rpm=NULL, Rmp=NULL;
mat Tpp_s=NULL, Tmm_s=NULL, Rpm_s=NULL, Rmp_s=NULL;

struct eng_str eng;
struct eng_str *eng=NULL;

FILE *res_stream;

// Read input parameters
printf("HERE %s\n", bul_file);
inp_rdbul_nd(&bulk, &phs_shifts, bul_file);
inp_rdpar(&v_par, &eng, bulk, bul_file);
inp_rdovl_nd(&over, &phs_shifts, bulk, par_file);
inp_showbop(bulk, over, phs_shifts);


// Construct energy list
energy_list_size = (eng->fin - eng->ini)/eng->stp + 1;
energy_list = (real *) malloc(energy_list_size * sizeof(real));
for (energy_index=0; energy_index<energy_list_size; energy_index++)
{
energy_list[energy_index] = eng->ini + energy_index * eng->stp;
}

// Printing stuff
printf("TEST SASHA\n");
inp_showbop(bulk, over, phs_shifts);
printf("END TEST SASHA\n");


res_stream = fopen(res_file,"w");

out_head(bulk, res_stream);


mk_cg_coef (2*v_par->l_max); // Setting up Clebsh Gordan coefficients as global variables.
mk_ylm_coef(2*v_par->l_max); // Setting up spherical harmonics coefficients as global variables.

eng.ini = energy_list[0];
eng.stp = energy_list[1] - energy_list[0];
eng.fin = energy_list[energy_list_size-1];



/* Generate beams out */
n_set = bm_gen(&beams_all, bulk, v_par, eng.fin);
out_bmlist(&beams_out, beams_all, &eng, res_stream);
n_set = bm_gen(&beams_all, bulk, v_par, eng->fin);
out_bmlist(&beams_out, beams_all, eng, res_stream);


/* Main Energy Loop */
Expand Down Expand Up @@ -243,6 +263,8 @@ real ** leed(

} /* end of energy loop */

fclose(res_stream);

return iv_curves;
}

Expand Down
200 changes: 8 additions & 192 deletions cleedpy/cleed/test_cleed.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,198 +4,14 @@
#include "gh_stddef.h"
#include "leed.h"

#define CTR_NORMAL 998
#define CTR_EARLY_RETURN 999
main(){
// File names
char *bul_file="Ni111_Cu.inp"; // bulk and non-geometrical parameters.
char *par_file="Ni111_Cu.inp"; // overlayer parameters of all parameters (if bul_file does not exist)
char *res_file="leed.res"; // output file containing the LEED intensities

main(int argc, char *argv[])/*Perform a LEED calculation for anisotropic vibrations a general case */
{
struct cryst_str *bulk;
struct cryst_str *over;
struct phs_str *phs_shifts;
struct beam_str *beams_all;
struct beam_str *beams_out;
struct beam_str *beams_now;
struct beam_str *beams_set;
struct var_str *v_par;
struct eng_str *eng;

mat Tpp, Tmm, Rpm, Rmp;
mat Tpp_s, Tmm_s, Rpm_s, Rmp_s;
mat R_bulk, R_tot;
mat Amp;

int ctr_flag;
int i_c, i_arg;
int n_beams_now, n_beams_set;
int i_set, n_set, offset;
int i_layer;

int energy_list_size, energy_index;
real *energy_list;

real energy;
real vec[4];

char linebuffer[STRSZ];

char bul_file[STRSZ]; /* input/output files */
char par_file[STRSZ];
char pro_name[STRSZ];
char res_file[STRSZ];

FILE *pro_stream;
FILE *res_stream;

Tpp = Tmm = Rpm = Rmp = NULL;
Tpp_s = Tmm_s = Rpm_s = Rmp_s = NULL;
R_bulk = R_tot = NULL;
Amp = NULL;

bulk = over = NULL;
phs_shifts = NULL;
beams_all = NULL;
beams_now = NULL;
beams_set = NULL;
beams_out = NULL;
v_par = NULL;
eng = NULL;


/*********************************************************************
Preset parameters (file names) set by arguments
*********************************************************************/

ctr_flag = CTR_NORMAL;

strncpy(bul_file,"---", STRSZ);

strncpy(par_file,"---", STRSZ);
strncpy(res_file,"leed.res", STRSZ);
strncpy(pro_name,"leed.pro", STRSZ);

/*********************************************************************
Decode arguments:
-b <bul_file> - (optional input file) bulk and non-geometrical
parameters.
-i <par_file> - (mandatory input file) overlayer parameters of all
parameters (if bul_file does not exist).
-o <res_file> - (output file) IV output.
*********************************************************************/

for (i_arg = 1; i_arg < argc; i_arg++)
{
if(*argv[i_arg] != '-')
{
fprintf(STDERR,"*** error (LEED_TEMP):\tsyntax error: %s\n", argv[i_arg]);
fprintf(STDERR,"\tusage: \tleed -i <par_file> -o <res_file>");
fprintf(STDERR," [-b <bul_file> -e]\n");
exit(1);
}
else
{
/* Read parameter input file */
if(strncmp(argv[i_arg], "-b", 2) == 0)
{
i_arg++;
strncpy(bul_file, argv[i_arg], STRSZ);
} /* -b */

/* Read parameter input file */
if(strncmp(argv[i_arg], "-i", 2) == 0)
{
i_arg++;
strncpy(par_file, argv[i_arg], STRSZ);
} /* -i */

/* Read and open results file */
if(strncmp(argv[i_arg], "-o", 2) == 0)
{
i_arg++;
strncpy(res_file, argv[i_arg], STRSZ);
if ((res_stream = fopen(res_file, "w")) == NULL)
{
fprintf(STDERR,
"*** error (LEED_TEMP): could not open output file \"%s\"\n",
res_file);
exit(1);
}
} /* -o */

/* Read parameter input file */
if(strncmp(argv[i_arg], "-e", 2) == 0)
{
ctr_flag = CTR_EARLY_RETURN;
} /* -e */


} /* else */
} /* for i_arg */

/*********************************************************************
Check arguments:
- check existence of par_file.
- if bul_file is not specified, use par_file instead.
- check existence of res_file.
*********************************************************************/

if(strncmp(par_file, "---", 3) == 0)
{
fprintf(STDERR,"*** error (LEED_TEMP): no parameter input file (option -i) specified\n");
exit(1);
}

if(strncmp(bul_file, "---", 3) == 0)
{
strncpy(bul_file, par_file, STRSZ);
}

if(strncmp(res_file, "leed.res", 8) == 0)
{
fprintf(STDWAR, "* warning (LEED_TEMP): no output file (option -o) specified\n\toutput will be written to file \"%s\"\n", res_file);
if ((res_stream = fopen(res_file,"w")) == NULL)
{
fprintf(STDERR, "*** error (LEED_TEMP): could not open output file \"%s\"\n",res_file);
exit(1);
}
}

/*********************************************************************
Read input parameters
*********************************************************************/

inp_rdbul_nd(&bulk, &phs_shifts, bul_file);
inp_rdpar(&v_par, &eng, bulk, bul_file);
inp_rdovl_nd(&over, &phs_shifts, bulk, par_file);

inp_showbop(bulk, over, phs_shifts);

if( ctr_flag == CTR_EARLY_RETURN )
{
fprintf(STDCTR, "(LEED_TEMP): EARLY RETURN \n");
exit(0);
}

out_head (bulk, res_stream);

/*********************************************************************
Prepare some often used parameters.
*********************************************************************/

// Construct energy list
energy_list_size = (eng->fin - eng->ini)/eng->stp + 1;
energy_list = (real *) malloc(energy_list_size * sizeof(real));
for (energy_index=0; energy_index<energy_list_size; energy_index++)
{
energy_list[energy_index] = eng->ini + energy_index * eng->stp;
}

leed(bulk, over, phs_shifts, energy_list_size, energy_list, v_par, res_stream);
printf("Finished leed\n");
fprintf(STDCTR, "(LEED): end of energy loop: close files\n");

fclose(res_stream);
// Calculate LEED intensities
leed(bul_file, par_file, res_file);

exit(0);

} /* end of main */
}
2 changes: 1 addition & 1 deletion examples/cleed_example_old/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export CLEED_PHASE=./PHASE
EXECUTABLE=../../cleedpy/cleed/bin/test_cleed

${EXECUTABLE} -i Ni111_Cu.inp
${EXECUTABLE}

0 comments on commit b35f9bf

Please sign in to comment.