// File: /workspace/github_c_makefile_star2_O2/PoulinV[P]AxiCLASS/build/../source/output.c
// Function: output_distortions
int output_distortions(
                       struct distortions * psd,
                       struct output * pop
                       ) {

  /** Local variables*/
  FileName file_name_heat, file_name_distortion;
  FILE * out_heat, * out_distortion;

  char titles_heat[_MAXTITLESTRINGLENGTH_]={0};
  char titles_distortion[_MAXTITLESTRINGLENGTH_]={0};

  double * data_heat, * data_distortion;
  int size_data_heat, size_data_distortion;
  int number_of_titles_heat, number_of_titles_distortion;

  if (pop->write_distortions==_TRUE_ && psd->has_distortions == _TRUE_){

    /* File name */
    class_sprintf(file_name_heat,"%s%s",pop->root,"sd_heating.dat");

    /* Titles */
    class_call(distortions_output_heat_titles(psd,titles_heat),
               psd->error_message,
               pop->error_message);
    number_of_titles_heat = get_number_of_titles(titles_heat);

    /* Data array */
    size_data_heat = number_of_titles_heat*psd->z_size;
    class_alloc(data_heat,
                sizeof(double)*size_data_heat,
                pop->error_message);
    class_call(distortions_output_heat_data(psd,
                                            number_of_titles_heat,
                                            data_heat),
               psd->error_message,
               pop->error_message);

    /* File IO */
    class_open(out_heat,
               file_name_heat,
               "w",
               pop->error_message);

    if (pop->write_header == _TRUE_){
      fprintf(out_heat,"# Heat is d(Q/rho)/dz\n");
      fprintf(out_heat,"# LHeat is d(Q/rho)/dlnz\n");
      fprintf(out_heat,"#\n");
    }

    output_print_data(out_heat,
                      titles_heat,
                      data_heat,
                      size_data_heat);
    free(data_heat);
    fclose(out_heat);

    /* File name */
    class_sprintf(file_name_distortion,"%s%s",pop->root,"sd_distortions.dat");

    /* Titles */
    class_call(distortions_output_sd_titles(psd,titles_distortion),
               psd->error_message,
               pop->error_message);
    number_of_titles_distortion = get_number_of_titles(titles_distortion);

    /* Data array */
    size_data_distortion = number_of_titles_distortion*psd->x_size;
    class_alloc(data_distortion,
                sizeof(double)*size_data_distortion,
                pop->error_message);
    class_call(distortions_output_sd_data(psd,
                                          number_of_titles_distortion,
                                          data_distortion),
               psd->error_message,
               pop->error_message);

    /* File IO */
    class_open(out_distortion,
               file_name_distortion,
               "w",
               pop->error_message);

    if (pop->write_header == _TRUE_){
      fprintf(out_distortion,"# SD_tot is the amplitude of the overall spectral distortion (SD)\n");
      fprintf(out_distortion,"# The SD[i] are the amplitudes of the individual SDs\n");
      fprintf(out_distortion,"# The SDs are given in units [10^-26 W m^-2 Hz^-1 sr^-1] \n");
      fprintf(out_distortion,"#\n");
    }

    output_print_data(out_distortion,
                      titles_distortion,
                      data_distortion,
                      size_data_distortion);
    free(data_distortion);
    fclose(out_distortion);
  }

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4888, %rsp           # imm = 0x4888
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x2940(%rsp), %rdi
xorl %ebp, %ebp
movl $0x1f40, %edx           # imm = 0x1F40
xorl %esi, %esi
callq 0x8220
leaq 0xa00(%rsp), %rdi
movl $0x1f40, %edx           # imm = 0x1F40
xorl %esi, %esi
callq 0x8220
cmpw $0x1, 0x41c(%rbx)
jne 0xe38a3
cmpl $0x1, 0xcd0(%r14)
jne 0xe38a3
leaq 0x4332d(%rip), %r15     # 0x126700
leaq 0x4413f(%rip), %r12     # 0x127519
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
leaq 0x100(%rsp), %rdi
movq %r15, %rdx
movq %rbx, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x8580
leaq 0x2940(%rsp), %rsi
movq %r14, %rdi
callq 0xc5fb0
cmpl $0x1, %eax
jne 0xe346c
addq $0x1602, %r14           # imm = 0x1602
leaq 0x1fc2(%rip), %rsi      # 0xe53f0
leaq 0x440f3(%rip), %rdx     # 0x127528
leaq 0x200(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
addq $0x420, %rbx            # imm = 0x420
leaq 0x1bdc(%rip), %rsi      # 0xe5034
leaq 0x440f9(%rip), %rdx     # 0x127558
movq %rbx, %rdi
movl $0x5e5, %ecx            # imm = 0x5E5
jmp 0xe375c
leaq 0x2940(%rsp), %rdi
callq 0x2e156
movl %eax, %ebp
movslq 0x330(%r14), %rax
movslq %ebp, %r15
imulq %rax, %r15
leaq (,%r15,8), %r13
movq %r13, %rdi
callq 0x8490
testq %rax, %rax
je 0xe3503
movq %rax, %r12
movq %r14, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0xc6041
cmpl $0x1, %eax
jne 0xe3548
addq $0x1602, %r14           # imm = 0x1602
leaq 0x1f2b(%rip), %rsi      # 0xe53f0
leaq 0x440a9(%rip), %rdx     # 0x127575
leaq 0x200(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
addq $0x420, %rbx            # imm = 0x420
leaq 0x1b45(%rip), %rsi      # 0xe5034
leaq 0x44062(%rip), %rdx     # 0x127558
movq %rbx, %rdi
movl $0x5f1, %ecx            # imm = 0x5F1
jmp 0xe375c
leaq 0x1afa(%rip), %rsi      # 0xe5004
leaq 0x4405a(%rip), %rdx     # 0x12756b
leaq 0x200(%rsp), %r14
movq %r14, %rdi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2e014
addq $0x420, %rbx            # imm = 0x420
leaq 0x1b00(%rip), %rsi      # 0xe5034
leaq 0x4401d(%rip), %rdx     # 0x127558
movq %rbx, %rdi
movl $0x5ec, %ecx            # imm = 0x5EC
jmp 0xe3896
leaq 0x4e92(%rip), %rsi      # 0xe83e1
leaq 0x100(%rsp), %rdi
callq 0x8420
testq %rax, %rax
je 0xe3679
movq %rax, %r13
cmpw $0x1, 0x408(%rbx)
jne 0xe35b4
leaq 0x44049(%rip), %rdi     # 0x1275c2
pushq $0x16
popq %rsi
pushq $0x1
popq %rbp
movq %rbp, %rdx
movq %r13, %rcx
callq 0x8700
leaq 0x44048(%rip), %rdi     # 0x1275d9
pushq $0x19
popq %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x8700
leaq 0x1ddf7(%rip), %rdi     # 0x10139d
pushq $0x2
popq %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x8700
leaq 0x2940(%rsp), %rsi
movq %r13, %rdi
movq %r12, %rdx
movl %r15d, %ecx
callq 0xe4991
movq %r12, %rdi
callq 0x8430
movq %r13, %rdi
callq 0x83c0
leaq 0x4311f(%rip), %r15     # 0x126700
leaq 0x4400b(%rip), %r12     # 0x1275f3
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
movq %rsp, %rdi
movq %r15, %rdx
movq %rbx, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x8580
leaq 0xa00(%rsp), %rsi
movq %r14, %rdi
callq 0xc60a3
cmpl $0x1, %eax
jne 0xe36ca
addq $0x1602, %r14           # imm = 0x1602
leaq 0x1db5(%rip), %rsi      # 0xe53f0
leaq 0x43fc4(%rip), %rdx     # 0x127606
leaq 0x200(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
addq $0x420, %rbx            # imm = 0x420
leaq 0x19cf(%rip), %rsi      # 0xe5034
leaq 0x43eec(%rip), %rdx     # 0x127558
movq %rbx, %rdi
movl $0x60c, %ecx            # imm = 0x60C
jmp 0xe375c
leaq 0x4328(%rip), %rsi      # 0xe79a8
leaq 0x43f32(%rip), %rdx     # 0x1275b9
leaq 0x1dc66(%rip), %r8      # 0x1012f4
leaq 0x200(%rsp), %r14
leaq 0x100(%rsp), %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
addq $0x420, %rbx            # imm = 0x420
leaq 0x197e(%rip), %rsi      # 0xe5034
leaq 0x43e9b(%rip), %rdx     # 0x127558
movq %rbx, %rdi
movl $0x5f7, %ecx            # imm = 0x5F7
jmp 0xe3896
leaq 0xa00(%rsp), %rdi
callq 0x2e156
movl %eax, %ebp
movslq 0x368(%r14), %rax
movslq %ebp, %r15
imulq %rax, %r15
leaq (,%r15,8), %r13
movq %r13, %rdi
callq 0x8490
testq %rax, %rax
je 0xe3764
movq %rax, %r12
movq %r14, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0xc61f6
cmpl $0x1, %eax
jne 0xe37a9
addq $0x1602, %r14           # imm = 0x1602
leaq 0x1ccd(%rip), %rsi      # 0xe53f0
leaq 0x43f20(%rip), %rdx     # 0x12764a
leaq 0x200(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
addq $0x420, %rbx            # imm = 0x420
leaq 0x18e7(%rip), %rsi      # 0xe5034
leaq 0x43e04(%rip), %rdx     # 0x127558
movq %rbx, %rdi
movl $0x618, %ecx            # imm = 0x618
movq %r15, %r8
jmp 0xe3899
leaq 0x1899(%rip), %rsi      # 0xe5004
leaq 0x43ec8(%rip), %rdx     # 0x12763a
leaq 0x200(%rsp), %r14
movq %r14, %rdi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2e014
addq $0x420, %rbx            # imm = 0x420
leaq 0x189f(%rip), %rsi      # 0xe5034
leaq 0x43dbc(%rip), %rdx     # 0x127558
movq %rbx, %rdi
movl $0x613, %ecx            # imm = 0x613
jmp 0xe3896
leaq 0x4c31(%rip), %rsi      # 0xe83e1
movq %rsp, %rdi
callq 0x8420
testq %rax, %rax
je 0xe384f
movq %rax, %r14
cmpw $0x1, 0x408(%rbx)
jne 0xe3825
leaq 0x43ed2(%rip), %rdi     # 0x1276a7
pushq $0x42
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
movq %r14, %rcx
callq 0x8700
leaq 0x43efd(%rip), %rdi     # 0x1276ea
pushq $0x35
popq %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x8700
leaq 0x43f1e(%rip), %rdi     # 0x127720
pushq $0x3a
popq %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x8700
leaq 0x1db86(%rip), %rdi     # 0x10139d
pushq $0x2
popq %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x8700
leaq 0xa00(%rsp), %rsi
movq %r14, %rdi
movq %r12, %rdx
movl %r15d, %ecx
callq 0xe4991
movq %r12, %rdi
callq 0x8430
movq %r14, %rdi
callq 0x83c0
xorl %ebp, %ebp
jmp 0xe38a3
leaq 0x4152(%rip), %rsi      # 0xe79a8
leaq 0x43e3b(%rip), %rdx     # 0x127698
leaq 0x1da90(%rip), %r8      # 0x1012f4
leaq 0x200(%rsp), %r14
movq %rsp, %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
addq $0x420, %rbx            # imm = 0x420
leaq 0x17ad(%rip), %rsi      # 0xe5034
leaq 0x43cca(%rip), %rdx     # 0x127558
movq %rbx, %rdi
movl $0x61e, %ecx            # imm = 0x61E
movq %r14, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %rbp
movl %ebp, %eax
addq $0x4888, %rsp           # imm = 0x4888
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq