// File: /workspace/github_c_makefile_star2_O2/usgs[P]nshmp-haz-catalogs/src/agrid/adaptive/calc_agrid_seis_rates.c
// Function: main
int main (int argc, char *argv[])
/*--------------------------------------------------------------------------*/
{
  int stop_run=0, fnew=0;
//  float magv;
  float atotal[NV];
  char paramf[200], paramf_format[200], summf[200], outf[200];
  struct compl_levels cat_compl;
  struct boundaries region;
  struct catalog cat;
  struct smoothp smoothing_params;
  struct rates seis_rates;
  struct eqcat eq_catalog;


// check input arguments and assign command line arguments for parameter file, file formatting, summary file
  if ( check_args(argc,argv,paramf,summf,paramf_format,&stop_run,&fnew) ) exit(1);
  
// initialize parameters, then open and read parameters file
  initialize_params(&cat_compl, &region, &cat, &smoothing_params);
  if( ! read_params_new_old(paramf, &cat_compl, &region, &cat, &smoothing_params, outf,fnew) ) exit(1);
fprintf(stderr,"outfnm: %s\n", outf);
  write_params(&cat_compl, &region, &cat, &smoothing_params, outf);
  write_params_to_file(summf, &cat_compl, &region, &cat, &smoothing_params, outf);
  if ( stop_run == 1 ) exit(1);

// get source region parameters
  fprintf(stderr,"Number of source points: %d (%d x %d)\n",region.nsrc, region.nsx, region.nsy);
  if (region.nsrc > NV ) {
    fprintf(stderr,"nsrc (%d) > NV (%d)\n", region.nsrc, NV); exit(1);
  }

// initialize distances to neighbors and seismicity rate variables
  init_dist_rates(&eq_catalog,atotal,&seis_rates);

// read earthquakes from catalog and assign to grid cells
  if ( ! get_eqs_fm_catalog(cat.catnm, &eq_catalog, &cat_compl, &region, &seis_rates) ) {
    fprintf(stderr,"Error getting earthquakes from catalog. Exiting ...\n"); exit(1);
  }
  seis_rates.nv=region.nsrc;

// get distances from all earthquakes to 10-nearest neighbors
  get_eq_neighbor_dists(&eq_catalog);

// smooth seismicity rates, if smoothing is specified
  smooth_seis_rates(&seis_rates, &smoothing_params, &eq_catalog, &region, &cat_compl, &cat);
  write_eq_neighbor_dists(&eq_catalog, &smoothing_params);
// convert from earthquake numbers in each bin to earthquake rates, adjust completeness, if required
  convert_eq_nos_rates(&seis_rates, &cat_compl, &smoothing_params, &cat, &region);

// write results to file
//fprintf(stdout,"call to write_results_to_file - %s\n", outf);
  write_results_to_file(&smoothing_params, &seis_rates, &cat, &region, outf);

// code completion steps
  fprintf(stdout,"\nSummary of processing written to file, %s\n", summf);
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x728558, %rsp         # imm = 0x728558
leaq 0x10(%rsp), %r9
andl $0x0, (%r9)
leaq 0xc(%rsp), %rax
andl $0x0, (%rax)
movq %rax, (%rsp)
leaq 0x2e0(%rsp), %rdx
leaq 0x210(%rsp), %rcx
leaq 0x3b0(%rsp), %r8
callq 0x4e50
testl %eax, %eax
jne 0x535f
leaq 0xa64c8(%rsp), %rbx
leaq 0x14(%rsp), %r14
leaq 0x68(%rsp), %r15
leaq 0x38(%rsp), %r12
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x5368
movl 0xc(%rsp), %eax
movl %eax, (%rsp)
leaq 0x2e0(%rsp), %rdi
leaq 0x140(%rsp), %r9
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, %rcx
movq %r12, %r8
callq 0x169f
testl %eax, %eax
je 0x535f
movq 0x4e6a(%rip), %rbp      # 0x9ff8
movq (%rbp), %rdi
leaq 0x2715(%rip), %rsi      # 0x78ae
leaq 0x140(%rsp), %rbx
movq %rbx, %rdx
xorl %eax, %eax
callq 0x10f0
leaq 0xa64c8(%rsp), %r14
leaq 0x14(%rsp), %r15
leaq 0x68(%rsp), %r12
leaq 0x38(%rsp), %r13
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %rbx, %r8
callq 0x212f
leaq 0x210(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
movq %r13, %r8
movq %rbx, %r9
callq 0x23c3
cmpl $0x1, 0x10(%rsp)
je 0x535f
movq (%rbp), %rdi
movl 0x1c(%rsp), %edx
movl 0x14(%rsp), %ecx
movl 0x18(%rsp), %r8d
leaq 0x26a5(%rip), %rsi      # 0x78ba
xorl %eax, %eax
callq 0x10f0
movl 0x1c(%rsp), %edx
cmpl $0x29811, %edx          # imm = 0x29811
jge 0x5330
leaq 0x33f5b0(%rsp), %rbx
leaq 0x480(%rsp), %rsi
leaq 0x490454(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x2680
leaq 0x78(%rsp), %rdi
leaq 0xa64c8(%rsp), %rdx
leaq 0x14(%rsp), %rcx
movq %rbx, %rsi
movq %r14, %r8
callq 0x2947
testl %eax, %eax
je 0x5349
leaq 0x14(%rsp), %rbx
movl 0x8(%rbx), %eax
leaq 0x490454(%rsp), %r14
movl %eax, 0x298100(%r14)
leaq 0x33f5b0(%rsp), %r15
movq %r15, %rdi
callq 0x2c79
leaq 0x38(%rsp), %r12
leaq 0xa64c8(%rsp), %r13
leaq 0x68(%rsp), %rbp
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq %r13, %r8
movq %rbp, %r9
callq 0x3cac
movq %r15, %rdi
movq %r12, %rsi
callq 0x34d8
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %rbp, %rcx
movq %rbx, %r8
callq 0x3680
leaq 0x140(%rsp), %r8
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x5004
movq 0x4cd5(%rip), %rax      # 0x9fd8
movq (%rax), %rdi
leaq 0x261e(%rip), %rsi      # 0x792b
leaq 0x210(%rsp), %rdx
xorl %eax, %eax
callq 0x10f0
xorl %eax, %eax
addq $0x728558, %rsp         # imm = 0x728558
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbp), %rdi
leaq 0x25a6(%rip), %rsi      # 0x78e1
movl $0x29810, %ecx          # imm = 0x29810
xorl %eax, %eax
callq 0x10f0
jmp 0x535f
movq (%rbp), %rcx
leaq 0x25a2(%rip), %rdi      # 0x78f6
pushq $0x34
popq %rsi
pushq $0x1
popq %rdx
callq 0x1190
pushq $0x1
popq %rdi
callq 0x1180
nop