// File: /workspace/github_c_makefile_star2_O1/PoulinV[P]AxiCLASS/build/../source/distortions.c
// Function: distortions_read_sd_data
int distortions_read_sd_data(struct precision * ppr,
                             struct distortions * psd){

  /** Define local variables */
  FILE * infile;
  DetectorFileName sd_file;
  char line[_LINE_LENGTH_MAX_];
  char * left;
  int headlines = 0;
  int index_x,index_k;

  /** Open file */
  class_sprintf(sd_file,"%s/%s_distortions_shapes.dat",ppr->sd_external_path, psd->sd_detector_name);
  class_open(infile, sd_file, "r", psd->error_message);

  /** Read header */
  psd->PCA_Nnu = 0;
  while (fgets(line,_LINE_LENGTH_MAX_-1,infile) != NULL) {
    headlines++;

    /* Eliminate blank spaces at beginning of line */
    left=line;
    while (left[0]==' ') {
      left++;
    }

    if (left[0] > 39) {
      /** Read number of lines, infer size of arrays and allocate them */
      class_test(sscanf(line, "%d %d", &psd->PCA_Nnu, &psd->S_vec_size) != 2,
                 psd->error_message,
                 "could not header (number of lines, number of multipoles) at line %i in file '%s' \n",headlines,sd_file);

      class_alloc(psd->PCA_nu, psd->PCA_Nnu*sizeof(double), psd->error_message);
      class_alloc(psd->PCA_G_T, psd->PCA_Nnu*sizeof(double), psd->error_message);
      class_alloc(psd->PCA_Y_SZ, psd->PCA_Nnu*sizeof(double), psd->error_message);
      class_alloc(psd->PCA_M_mu, psd->PCA_Nnu*sizeof(double), psd->error_message);

      class_alloc(psd->S_vec, psd->PCA_Nnu*psd->S_vec_size*sizeof(double), psd->error_message);
      break;
    }
  }

  /** Read parameters */
  for (index_x=0; index_x<psd->PCA_Nnu; ++index_x){
    class_test(fscanf(infile,"%le",
                      &(psd->PCA_nu[index_x]))!=1,                                                  // [GHz]
               psd->error_message,
               "Could not read z at line %i in file '%s'",index_x+headlines,sd_file);
    class_test(fscanf(infile,"%le",
                      &(psd->PCA_G_T[index_x]))!=1,                                                 // [10^-18 W/(m^2 Hz sr)]
               psd->error_message,
               "Could not read f_g at line %i in file '%s'",index_x+headlines,sd_file);
    psd->PCA_G_T[index_x] /= (psd->DI_units*1.e18);                                                 // [-]
    class_test(fscanf(infile,"%le",
                      &(psd->PCA_Y_SZ[index_x]))!=1,                                                // [10^-18 W/(m^2 Hz sr)]
               psd->error_message,
               "Could not read f_y at line %i in file '%s'",index_x+headlines,sd_file);
    psd->PCA_Y_SZ[index_x] /= (psd->DI_units*1.e18);                                                // [-]
    class_test(fscanf(infile,"%le",
                      &(psd->PCA_M_mu[index_x]))!=1,                                                // [10^-18 W/(m^2 Hz sr)]
               psd->error_message,
               "Could not read f_mu at line %i in file '%s'",index_x+headlines,sd_file);
    psd->PCA_M_mu[index_x] /= (psd->DI_units*1.e18);                                                // [-]
    for (index_k=0; index_k<psd->S_vec_size; ++index_k){
      class_test(fscanf(infile,"%le",
                        &(psd->S_vec[index_k*psd->PCA_Nnu+index_x]))!=1,                            // [10^-18 W/(m^2 Hz sr)]
                 psd->error_message,
                 "Could not read E vector at line %i in file '%s'",index_x+headlines,sd_file);
      psd->S_vec[index_k*psd->PCA_Nnu+index_x] /= (psd->DI_units*1.e18);                            // [-]
    }

  }

  fclose(infile);

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1688, %rsp           # imm = 0x1688
movq %rsi, %rbx
leaq 0x928(%rdi), %r15
leaq 0x26c(%rsi), %r12
leaq 0x5bdc2(%rip), %r13     # 0x12ab13
xorl %r14d, %r14d
xorl %edi, %edi
xorl %esi, %esi
movq %r13, %rdx
movq %r15, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
leaq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rdx
movq %r15, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x8550
leaq 0x40ff8(%rip), %rsi     # 0x10fd84
movq %rbp, %rdi
callq 0x8400
testq %rax, %rax
je 0xcf060
movq %rax, %r15
leaq 0xc78(%rbx), %r12
movl $0x0, 0xc78(%rbx)
leaq 0x1280(%rsp), %r13
movq %r13, %rdi
movl $0x3ff, %esi            # imm = 0x3FF
movq %r15, %rdx
callq 0x8540
testq %rax, %rax
je 0xceea5
movq %r13, %rcx
movb (%rcx), %al
incq %rcx
cmpb $0x20, %al
je 0xcedd5
incl %r14d
cmpb $0x28, %al
jl 0xcedb9
leaq 0xcc0(%rbx), %rcx
leaq 0x41f90(%rip), %rsi     # 0x110d83
leaq 0x1280(%rsp), %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x8390
cmpl $0x2, %eax
jne 0xcf0ae
movslq 0xc78(%rbx), %r13
leaq (,%r13,8), %rbp
movq %rbp, %rdi
callq 0x8460
movq %rax, 0xc70(%rbx)
testq %rax, %rax
je 0xcf17d
movq %rbp, %rdi
callq 0x8460
movq %rax, 0xc80(%rbx)
testq %rax, %rax
je 0xcf1c6
movq %rbp, %rdi
callq 0x8460
movq %rax, 0xc90(%rbx)
testq %rax, %rax
je 0xcf20f
movq %rbp, %rdi
callq 0x8460
movq %rax, 0xca0(%rbx)
testq %rax, %rax
je 0xcf3fc
movslq 0xcc0(%rbx), %rbp
imulq %r13, %rbp
leaq (,%rbp,8), %rdi
callq 0x8460
movq %rax, 0xcb0(%rbx)
testq %rax, %rax
je 0xcf442
movq %r12, 0x8(%rsp)
cmpl $0x0, (%r12)
jle 0xcf051
leaq 0x5acae(%rip), %r13     # 0x129b6a
xorl %r12d, %r12d
leaq (,%r12,8), %rbp
movq 0xc70(%rbx), %rdx
addq %rbp, %rdx
movq %r15, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x8690
cmpl $0x1, %eax
jne 0xcf258
movq 0xc80(%rbx), %rdx
addq %rbp, %rdx
movq %r15, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x8690
cmpl $0x1, %eax
jne 0xcf2c1
movsd 0x388(%rbx), %xmm0
movsd 0x59f59(%rip), %xmm1    # 0x128e70
mulsd %xmm1, %xmm0
movq 0xc80(%rbx), %rax
movsd (%rax,%r12,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax,%r12,8)
movq 0xc90(%rbx), %rdx
addq %rbp, %rdx
movq %r15, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x8690
cmpl $0x1, %eax
jne 0xcf32a
movsd 0x388(%rbx), %xmm0
mulsd 0x59f0e(%rip), %xmm0    # 0x128e70
movq 0xc90(%rbx), %rax
movsd (%rax,%r12,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax,%r12,8)
addq 0xca0(%rbx), %rbp
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x8690
cmpl $0x1, %eax
jne 0xcf393
movsd 0x388(%rbx), %xmm0
mulsd 0x59ec7(%rip), %xmm0    # 0x128e70
movq 0xca0(%rbx), %rax
movsd (%rax,%r12,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax,%r12,8)
cmpl $0x0, 0xcc0(%rbx)
jle 0xcf03d
xorl %ebp, %ebp
movl 0xc78(%rbx), %eax
imull %ebp, %eax
addl %r12d, %eax
movslq %eax, %rdx
shlq $0x3, %rdx
addq 0xcb0(%rbx), %rdx
movq %r15, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x8690
cmpl $0x1, %eax
jne 0xcf114
movsd 0x388(%rbx), %xmm0
movsd 0x59e65(%rip), %xmm1    # 0x128e70
mulsd %xmm1, %xmm0
movq 0xcb0(%rbx), %rax
movl 0xc78(%rbx), %ecx
imull %ebp, %ecx
addl %r12d, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax,%rcx,8)
incl %ebp
cmpl 0xcc0(%rbx), %ebp
jl 0xcefcb
incq %r12
movq 0x8(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %r12
jl 0xceebf
movq %r15, %rdi
callq 0x83a0
xorl %eax, %eax
jmp 0xcf493
leaq 0x24971(%rip), %rsi     # 0xf39d8
leaq 0x5a9ec(%rip), %rdx     # 0x129a5a
leaq 0x24998(%rip), %r8      # 0xf3a0d
leaq 0x280(%rsp), %r14
leaq 0x10(%rsp), %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c2c
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x21f9a(%rip), %rsi     # 0xf1034
leaq 0x5ba8f(%rip), %rdx     # 0x12ab30
movq %rbx, %rdi
movl $0x67a, %ecx            # imm = 0x67A
jmp 0xcf484
leaq 0x5b4c0(%rip), %rsi     # 0x12a575
leaq 0x280(%rsp), %r15
leaq 0x10(%rsp), %rcx
movq %r15, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x30c2c
leaq 0x21fac(%rip), %rsi     # 0xf1082
leaq 0x5ba6c(%rip), %rdx     # 0x12ab49
leaq 0xa80(%rsp), %r14
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30c2c
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x21f34(%rip), %rsi     # 0xf1034
leaq 0x5ba29(%rip), %rdx     # 0x12ab30
movq %rbx, %rdi
movl $0x68b, %ecx            # imm = 0x68B
jmp 0xcf484
addl %r12d, %r14d
leaq 0x5b6b2(%rip), %rsi     # 0x12a7d0
leaq 0x280(%rsp), %r15
leaq 0x10(%rsp), %rcx
movq %r15, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x30c2c
leaq 0x21f43(%rip), %rsi     # 0xf1082
leaq 0x5bb48(%rip), %rdx     # 0x12ac8e
leaq 0xa80(%rsp), %r14
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30c2c
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x21ecb(%rip), %rsi     # 0xf1034
leaq 0x5b9c0(%rip), %rdx     # 0x12ab30
movq %rbx, %rdi
movl $0x6b0, %ecx            # imm = 0x6B0
jmp 0xcf484
shll $0x3, %r13d
leaq 0x21e7c(%rip), %rsi     # 0xf1004
leaq 0x5b9f6(%rip), %rdx     # 0x12ab85
leaq 0x280(%rsp), %r14
movq %r14, %rdi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x30c2c
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x21e82(%rip), %rsi     # 0xf1034
leaq 0x5b977(%rip), %rdx     # 0x12ab30
movq %rbx, %rdi
movl $0x68d, %ecx            # imm = 0x68D
jmp 0xcf484
shll $0x3, %r13d
leaq 0x21e33(%rip), %rsi     # 0xf1004
leaq 0x5b9b9(%rip), %rdx     # 0x12ab91
leaq 0x280(%rsp), %r14
movq %r14, %rdi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x30c2c
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x21e39(%rip), %rsi     # 0xf1034
leaq 0x5b92e(%rip), %rdx     # 0x12ab30
movq %rbx, %rdi
movl $0x68e, %ecx            # imm = 0x68E
jmp 0xcf484
shll $0x3, %r13d
leaq 0x21dea(%rip), %rsi     # 0xf1004
leaq 0x5b97d(%rip), %rdx     # 0x12ab9e
leaq 0x280(%rsp), %r14
movq %r14, %rdi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x30c2c
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x21df0(%rip), %rsi     # 0xf1034
leaq 0x5b8e5(%rip), %rdx     # 0x12ab30
movq %rbx, %rdi
movl $0x68f, %ecx            # imm = 0x68F
jmp 0xcf484
addl %r12d, %r14d
leaq 0x5b3ee(%rip), %rsi     # 0x12a650
leaq 0x280(%rsp), %r15
leaq 0x10(%rsp), %rcx
movq %r15, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x30c2c
leaq 0x21dff(%rip), %rsi     # 0xf1082
leaq 0x5b93b(%rip), %rdx     # 0x12abc5
leaq 0xa80(%rsp), %r14
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30c2c
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x21d87(%rip), %rsi     # 0xf1034
leaq 0x5b87c(%rip), %rdx     # 0x12ab30
movq %rbx, %rdi
movl $0x69c, %ecx            # imm = 0x69C
jmp 0xcf484
addl %r12d, %r14d
leaq 0x5b3e4(%rip), %rsi     # 0x12a6af
leaq 0x280(%rsp), %r15
leaq 0x10(%rsp), %rcx
movq %r15, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x30c2c
leaq 0x21d96(%rip), %rsi     # 0xf1082
leaq 0x5b903(%rip), %rdx     # 0x12abf6
leaq 0xa80(%rsp), %r14
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30c2c
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x21d1e(%rip), %rsi     # 0xf1034
leaq 0x5b813(%rip), %rdx     # 0x12ab30
movq %rbx, %rdi
movl $0x6a0, %ecx            # imm = 0x6A0
jmp 0xcf484
addl %r12d, %r14d
leaq 0x5b3db(%rip), %rsi     # 0x12a70f
leaq 0x280(%rsp), %r15
leaq 0x10(%rsp), %rcx
movq %r15, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x30c2c
leaq 0x21d2d(%rip), %rsi     # 0xf1082
leaq 0x5b8cc(%rip), %rdx     # 0x12ac28
leaq 0xa80(%rsp), %r14
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30c2c
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x21cb5(%rip), %rsi     # 0xf1034
leaq 0x5b7aa(%rip), %rdx     # 0x12ab30
movq %rbx, %rdi
movl $0x6a5, %ecx            # imm = 0x6A5
jmp 0xcf484
addl %r12d, %r14d
leaq 0x5b3d2(%rip), %rsi     # 0x12a76f
leaq 0x280(%rsp), %r15
leaq 0x10(%rsp), %rcx
movq %r15, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x30c2c
leaq 0x21cc4(%rip), %rsi     # 0xf1082
leaq 0x5b896(%rip), %rdx     # 0x12ac5b
leaq 0xa80(%rsp), %r14
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30c2c
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x21c4c(%rip), %rsi     # 0xf1034
leaq 0x5b741(%rip), %rdx     # 0x12ab30
movq %rbx, %rdi
movl $0x6aa, %ecx            # imm = 0x6AA
jmp 0xcf484
shll $0x3, %r13d
leaq 0x21bfd(%rip), %rsi     # 0xf1004
leaq 0x5b79e(%rip), %rdx     # 0x12abac
leaq 0x280(%rsp), %r14
movq %r14, %rdi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x30c2c
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x21c03(%rip), %rsi     # 0xf1034
leaq 0x5b6f8(%rip), %rdx     # 0x12ab30
movq %rbx, %rdi
movl $0x690, %ecx            # imm = 0x690
jmp 0xcf484
shll $0x3, %ebp
leaq 0x21bb8(%rip), %rsi     # 0xf1004
leaq 0x5b767(%rip), %rdx     # 0x12abba
leaq 0x280(%rsp), %r14
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x30c2c
addq $0x1602, %rbx           # imm = 0x1602
leaq 0x21bbf(%rip), %rsi     # 0xf1034
leaq 0x5b6b4(%rip), %rdx     # 0x12ab30
movq %rbx, %rdi
movl $0x692, %ecx            # imm = 0x692
movq %r14, %r8
xorl %eax, %eax
callq 0x30c2c
movl $0x1, %eax
addq $0x1688, %rsp           # imm = 0x1688
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq