// File: /workspace/github_c_makefile_star2_O1/usgs[P]nshmp-haz-catalogs/src/agrid/adaptive/write_asum_to_file.c
// Function: write_asum_to_csvfile
void write_asum_to_csvfile(
    struct rates *seisr,
    char *fbasenm,
    struct catalog *catv,
    struct boundaries *boundR,
    float mag)
/*--------------------------------------------------------------------------*/  
{
  FILE *fpout;
  FILE *foutAscii;
  int nsrc, cnt;
  int iy, ix;
  float diffth=1e-1;
  char fileout[200];
  char fileoutAscii[200];
                                                                                
  // compute lon/lat array
  // get rate array and naming based on magnitude input values
  nsrc=seisr->nv;
  
  // Magnitudes
  if ( fabsf(mag-0.0)<diffth ) {
    sprintf(fileout,"%s_M0.csv", fbasenm);
    sprintf(fileoutAscii,"%s_M0.asc", fbasenm);

    fprintf(stderr,"M%.2f, writing to file - %s\n", mag, fileout);
    fprintf(stderr,"M%.2f, writing to file - %s\n", mag, fileoutAscii);

    fpout=fopen(fileout,"w");
    foutAscii = fopen(fileoutAscii, "w");

    for(cnt=0; cnt<nsrc; cnt++) {
      iy=cnt/boundR->nsx;
      ix=cnt-iy*boundR->nsx;
      fprintf(
        fpout,
        "%9.3f, %8.3f, GR, %12.6e \n",
        boundR->minlon+ix*boundR->dlon,
        boundR->maxlat-iy*boundR->dlat,
        seisr->asum[cnt]);

      fprintf(
        foutAscii,
        "%9.3f %8.3f %12.6e \n",
        boundR->minlon+ix*boundR->dlon,
        boundR->maxlat-iy*boundR->dlat,
        seisr->asum[cnt]);
    }

    fclose(fpout);
    fclose(foutAscii);
  } else {
    fprintf(stderr, "No csvfile write option for M~=0\n");
  }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movaps 0x2308(%rip), %xmm1     # 0x74a0
andps %xmm0, %xmm1
movss 0x230d(%rip), %xmm2     # 0x74b0
ucomiss %xmm1, %xmm2
jbe 0x5336
movq %rcx, %rbx
movq %rsi, %r13
movq %rdi, %r14
movl 0x298100(%rdi), %ebp
cvtss2sd %xmm0, %xmm0
movsd %xmm0, (%rsp)
leaq 0x23c1(%rip), %rsi      # 0x758c
leaq 0x10(%rsp), %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x1180
leaq 0x23b5(%rip), %rsi      # 0x7596
leaq 0xe0(%rsp), %r12
movq %r12, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x1180
movq 0x4dfb(%rip), %r15      # 0x9ff8
movq (%r15), %rdi
leaq 0x22d3(%rip), %r13      # 0x74da
movq %r13, %rsi
movsd (%rsp), %xmm0
leaq 0x10(%rsp), %rdx
movb $0x1, %al
callq 0x1100
movq (%r15), %rdi
movq %r13, %rsi
movsd (%rsp), %xmm0
movq %r12, %rdx
movb $0x1, %al
callq 0x1100
leaq 0x13c4(%rip), %r13      # 0x65fb
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x1160
movq %rax, %r15
movq %r12, %rdi
movq %r13, %rsi
callq 0x1160
movq %rax, %r12
testl %ebp, %ebp
jle 0x5324
xorl %r13d, %r13d
movl (%rbx), %ecx
movl %r13d, %eax
cltd
idivl %ecx
imull %eax, %ecx
movl %r13d, %edx
subl %ecx, %edx
xorps %xmm1, %xmm1
cvtsi2ss %edx, %xmm1
movss %xmm1, (%rsp)
movss 0x1c(%rbx), %xmm0
mulss %xmm1, %xmm0
addss 0xc(%rbx), %xmm0
xorps %xmm3, %xmm3
cvtsi2ss %eax, %xmm3
movss %xmm3, 0xc(%rsp)
cvtss2sd %xmm0, %xmm0
movss 0x18(%rbx), %xmm1
movss 0x20(%rbx), %xmm2
mulss %xmm3, %xmm2
subss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x14c080(%r14,%r13,4), %xmm2
movq %r15, %rdi
leaq 0x22d8(%rip), %rsi      # 0x75a0
movb $0x3, %al
callq 0x1100
movss (%rsp), %xmm0
mulss 0x1c(%rbx), %xmm0
addss 0xc(%rbx), %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x18(%rbx), %xmm1
movss 0xc(%rsp), %xmm2
mulss 0x20(%rbx), %xmm2
subss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x14c080(%r14,%r13,4), %xmm2
movq %r12, %rdi
leaq 0x22aa(%rip), %rsi      # 0x75bb
movb $0x3, %al
callq 0x1100
incq %r13
cmpq %r13, %rbp
jne 0x5260
movq %r15, %rdi
callq 0x1080
movq %r12, %rdi
callq 0x1080
jmp 0x533b
callq 0x1b44
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)