// File: /workspace/github_c_makefile_star2_O2/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:
movaps 0x28e4(%rip), %xmm1     # 0x74b0
andps %xmm0, %xmm1
movss 0x28e9(%rip), %xmm2     # 0x74c0
ucomiss %xmm1, %xmm2
jbe 0x4d5f
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rcx, %rbx
movq %rsi, %r12
movq %rdi, %r14
movl 0x298100(%rdi), %ebp
cvtss2sd %xmm0, %xmm0
movsd %xmm0, (%rsp)
leaq 0x298c(%rip), %rsi      # 0x759c
xorl %r15d, %r15d
leaq 0xe0(%rsp), %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x1170
leaq 0x297a(%rip), %rsi      # 0x75a6
leaq 0x10(%rsp), %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x1170
movq 0x53b6(%rip), %r13      # 0x9ff8
movq (%r13), %rdi
leaq 0x289d(%rip), %r12      # 0x74ea
movq %r12, %rsi
movsd (%rsp), %xmm0
leaq 0xe0(%rsp), %rdx
movb $0x1, %al
callq 0x10f0
movq (%r13), %rdi
movq %r12, %rsi
movsd (%rsp), %xmm0
leaq 0x10(%rsp), %rdx
movb $0x1, %al
callq 0x10f0
leaq 0x198c(%rip), %r13      # 0x660f
leaq 0xe0(%rsp), %rdi
movq %r13, %rsi
callq 0x1150
movq %rax, %r12
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x1150
movq %rax, %r13
testl %ebp, %ebp
cmovlel %r15d, %ebp
cmpq %r15, %rbp
je 0x4d7b
movl %r15d, %eax
cltd
idivl (%rbx)
cvtsi2ss %edx, %xmm1
movss %xmm1, (%rsp)
movss 0x1c(%rbx), %xmm0
mulss %xmm1, %xmm0
addss 0xc(%rbx), %xmm0
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
cvtss2sd 0x14c080(%r14,%r15,4), %xmm2
movq %r12, %rdi
leaq 0x28a6(%rip), %rsi      # 0x75b0
movb $0x3, %al
callq 0x10f0
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
cvtss2sd 0x14c080(%r14,%r15,4), %xmm2
movq %r13, %rdi
leaq 0x287b(%rip), %rsi      # 0x75cb
movb $0x3, %al
callq 0x10f0
incq %r15
jmp 0x4cac
movq 0x5292(%rip), %rax      # 0x9ff8
movq (%rax), %rcx
leaq 0x2870(%rip), %rdi      # 0x75e0
pushq $0x21
popq %rsi
pushq $0x1
popq %rdx
jmp 0x1190
movq %r12, %rdi
callq 0x1080
movq %r13, %rdi
callq 0x1080
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq