// File: /workspace/github_c_makefile_star2_O2/josch[P]stride/rdmap.c
// Function: ReadPhiPsiMap
int ReadPhiPsiMap(char *MapFile, float ***PhiPsiMap, COMMAND *Cmd)
{

  int i, j, NFields, Cnt=0;
  FILE *fi;
  BUFFER Buffer;
  char *Fields[MAX_FIELD];

  Cmd->NPixel = 0;

  if( (fi = fopen(MapFile,"r")) != 0 ) {

    while( fgets(Buffer,BUFSZ,fi) != NULL ) {
      if( !(NFields = SplitString(Buffer,Fields,MAX_FIELD)) ) continue;
      if( Cmd->NPixel == 0 ) {
	if( !strcmp(tolostr(Fields[0]),"npixel") ) {
	  Cmd->NPixel = atoi(Fields[1]);
	  if( Cmd->NPixel < 1 || Cmd->NPixel > 1000 ) 
	    die("Wrong number of pixels in the PhiPsi Map file %s\n",MapFile);
	  *PhiPsiMap = FloatMatrix(Cmd->NPixel,Cmd->NPixel);
	}
      }
      else  {
	if( !strcmp(tolostr(Fields[0]),"pixel") ) {
	  if( (i = atoi(Fields[1])) >= 0 && i < Cmd->NPixel &&
	      (j = atoi(Fields[2])) >= 0 && j < Cmd->NPixel &&
	     Cnt ==  i*Cmd->NPixel+j &&  NFields >= 4 ) {
	    (*PhiPsiMap)[i][j] = atof(Fields[5]);
	    Cnt++;
	  }
	  else die("Error in the PhiPsi Map file %s\n",MapFile);
	}
      }
    }
    fclose(fi);
    Cmd->PhiPsiStep = (MAXPHIPSI - MINPHIPSI)/(float)Cmd->NPixel;
  }
  
  if( !Cmd->NPixel ) die("Error reading PhiPsiMap file %s\n",MapFile);

  return(Cmd->NPixel);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5c8, %rsp            # imm = 0x5C8
movq %rdx, %rbx
movq %rsi, %r14
andl $0x0, 0x1cf4(%rdx)
leaq 0x12748(%rip), %rsi     # 0x19a55
movq %rdi, 0x10(%rsp)
callq 0x21c0
testq %rax, %rax
je 0x74cc
movq %rax, %r12
movq %r14, 0x20(%rsp)
leaq 0x1c0(%rsp), %r13
leaq 0x30(%rsp), %rbp
pushq $0x32
popq %r15
movl $0x0, 0xc(%rsp)
movq %r13, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdx
callq 0x2130
testq %rax, %rax
je 0x74a4
movq %r13, %rdi
movq %rbp, %rsi
movl %r15d, %edx
callq 0x311c
testl %eax, %eax
je 0x7341
movl %eax, %r14d
movq %rbx, 0x28(%rsp)
movl 0x1cf4(%rbx), %ebx
movq 0x30(%rsp), %rdi
callq 0x46c8
movq %rax, %rdi
testl %ebx, %ebx
je 0x7409
leaq 0x11947(%rip), %rsi     # 0x18cd9
callq 0x2150
testl %eax, %eax
movq 0x28(%rsp), %rbx
jne 0x7341
movq 0x38(%rsp), %rdi
callq 0x2200
testl %eax, %eax
js 0x73f1
movl 0x1cf4(%rbx), %ecx
cmpl %ecx, %eax
jge 0x73f1
movq 0x40(%rsp), %rdi
movl %eax, 0x1c(%rsp)
movl %ecx, 0x8(%rsp)
callq 0x2200
movl 0x8(%rsp), %esi
testl %eax, %eax
sets %dl
cmpl %esi, %eax
setge %cl
orb %dl, %cl
movl 0x1c(%rsp), %ecx
jne 0x73f1
cmpl $0x4, %r14d
jl 0x73f1
imull %ecx, %esi
addl %eax, %esi
cmpl %esi, 0xc(%rsp)
je 0x746e
leaq 0x11919(%rip), %rdi     # 0x18d11
movq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x7c4c
jmp 0x7341
leaq 0x118c8(%rip), %rsi     # 0x18cd8
callq 0x2150
testl %eax, %eax
movq 0x28(%rsp), %rbx
jne 0x7341
movq 0x38(%rsp), %rdi
callq 0x2200
movl %eax, 0x1cf4(%rbx)
movl %eax, %ecx
movl $0xfffffc17, %edx       # imm = 0xFFFFFC17
addl %edx, %ecx
cmpl %edx, %ecx
ja 0x7458
leaq 0x11899(%rip), %rdi     # 0x18cdf
movq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x7c4c
movl 0x1cf4(%rbx), %eax
movl %eax, %edi
movl %eax, %esi
callq 0x5115
movq 0x20(%rsp), %rcx
movq %rax, (%rcx)
jmp 0x7341
movq 0x58(%rsp), %rdi
movl %ecx, %r14d
movl %eax, 0x8(%rsp)
callq 0x2080
cvtsd2ss %xmm0, %xmm0
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl %r14d, %ecx
movq (%rax,%rcx,8), %rax
movl 0x8(%rsp), %ecx
movss %xmm0, (%rax,%rcx,4)
incl 0xc(%rsp)
jmp 0x7341
movq %r12, %rdi
callq 0x20a0
movl 0x1cf4(%rbx), %eax
cvtsi2ss %eax, %xmm0
movss 0x11816(%rip), %xmm1    # 0x18cd4
divss %xmm0, %xmm1
movss %xmm1, 0x1d08(%rbx)
jmp 0x74d2
movl 0x1cf4(%rbx), %eax
testl %eax, %eax
jne 0x74ef
leaq 0x11855(%rip), %rdi     # 0x18d32
movq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0x7c4c
movl 0x1cf4(%rbx), %eax
addq $0x5c8, %rsp            # imm = 0x5C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq