View Issue Details

IDProjectCategoryView StatusLast Update
0001833CCdciel[All Projects] Generalpublic17-11-07 11:02
ReporterhanAssigned To 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionduplicate 
Product Version0.9 
Target VersionFixed in Version 
Summary0001833: PlateSolve2 doesn't work if in Windows a komma s separator is defined.
DescriptionPlateSolve2 follows Windows definition of decimal separator. I little awkward since it is difficult to get info out of the APM file with comma's as separator and also as decimal separator. Also the yx ratio can be reported as a single 1 or as 1,0011. Below the code to fix. Only the decimal separator detection has to be done in the startup phase of CCDciel.
Also a sample file with yx ratio=1, difficult to detect.

 comma_sep:=(FormatSettings.decimalseparator=',');{. or , settings country settings}
 { to be detected before setting forcing dot separator since it is used by PlateSolve2 for producing APM file};


procedure TAstrometry_engine.Apm2Wcs;
// communicated by Han Kleijn
var
  i,pos1,pos2,pos3,sign : integer;
  f : textfile;
  line1, line2,line3 :string;
  hdr: THeaderBlock;
  fwcs: file of THeaderBlock;
  ra_radians,dec_radians,pixel_size,crota1,crota2,cdelt1,cdelt2:double;
  cd1_1,cd1_2,cd2_1,cd2_2: double;
  flipped: boolean;

  function strtofloat2(s:string): double;{accept either dot or komma as decimal seperator}
  var
    error1:integer;
  begin
     s:=StringReplace(s,',','.',[]); {replaces comma by dot}
     val(s,result,error1);
     if error1<>0 then result:=0;
  end;
begin
  assign(f,apmfile);
  // Reopen the file for reading
  Reset(f);
  while not Eof(f) do
  begin
    readln(f,line1);
    readln(f,line2);
    readln(f,line3);
  end;
  closefile(f);
  if length(line3)=20 then {valid solution}
  if length(line3)=20 then {valid solution}
  begin
    pos1:=posex(',',line1,1); {variable length and decimal sign=comma complicates readout}
    if comma_sep then pos1:=posex(',',line1,pos1+1); {take next comma}
    pos2:=posex(',',line1,pos1+1);
    if comma_sep then pos2:=posex(',',line1,pos2+1); {take next comma}

    ra_radians:=strtofloat2(copy(line1,1,pos1-1));{contains . or , depending on country settings}
    dec_radians:=strtofloat2(copy(line1,pos1+1,pos2-pos1-1));

    pos1:=posex(',',line2,1); {variable length and decimal sign=comma complicates readout}
    if comma_sep then pos1:=posex(',',line2,pos1+1); {take next comma}
    pos2:=posex(',',line2,pos1+1);
    if comma_sep then pos2:=posex(',',line2,pos2+1); {take next comma}
    pos3:=posex(',',line2,pos2+1);

    pixel_size:=strtofloat2(copy(line2,1,pos1-1));
    crota2:=strtofloat2(copy(line2,pos1+1,pos2-pos1-1));
    flipped:= line2[pos3+1]<>'-';{y/x ratio, if positive then flipped. For comma separators could be written as "1" or "-0,9999" or "1,0011". So line2 could contain 7 or 8 comma's!! Therefore check only for "-"}

    {in apm file yx ratio is reported inverse compared with PlateSolve2 window}
    if flipped then
    begin
      cdelt1:=-pixel_size/3600;
      cdelt2:=+pixel_size/3600;
    end
    else
    begin
      cdelt1:=+pixel_size/3600;
      cdelt2:=+pixel_size/3600;
      crota2:=180-crota2; {Non-standard angle reporting in Platesolve2}
    end;
    crota1:=crota2; { coordinate grid is not skewed= > crota1=crota2}

    // old_to_new_WCS
    cd1_1:=cdelt1*cos(crota1*pi/180);
    if cdelt1>=0 then sign:=+1 else sign:=-1;
    cd1_2:=abs(cdelt2)*sign*sin(crota1*pi/180);
    if cdelt2>=0 then sign:=+1 else sign:=-1;
    cd2_1:=-abs(cdelt1)*sign*sin(crota2*pi/180);
    cd2_2:= cdelt2*cos(crota2*pi/180);

    // write header
    for i:=1 to 36 do
    hdr[i]:=blank80;
    hdr[1] := 'COMMENT Solved by Platesolve 2'+blank80;
    hdr[2] := 'CTYPE1 = '+#39+'RA---TAN'+#39+' / first parameter RA , projection TANgential'+blank80;
    hdr[3] := 'CTYPE2 = '+#39+'DEC--TAN'+#39+' / second parameter DEC, projection TANgential'+blank80;
    hdr[4] := 'CUNIT1 = '+#39+'deg '+#39+' / Unit of coordinate '+blank80;
    hdr[5] := 'CRPIX1 = '+FormatFloat(e6, 0.5+Fiwidth/2)+' / X of reference pixel '+blank80;
    hdr[6] := 'CRPIX2 = '+FormatFloat(e6, 0.5+Fiheight/2)+' / Y of reference pixel '+blank80;
    hdr[7] := 'CRVAL1 = '+FormatFloat(e6,ra_radians*rad2deg)+' / RA of reference pixel (deg) '+blank80;
    hdr[8] := 'CRVAL2 = '+FormatFloat(e6,dec_radians*rad2deg)+' / DEC of reference pixel (deg) '+blank80;
    hdr[9] := 'CDELT1 = '+FormatFloat(e6,cdelt1)+' / X pixel size (deg) '+blank80;
    hdr[10] := 'CDELT2 = '+FormatFloat(e6,cdelt2)+' / Y pixel size (deg) '+blank80;
    hdr[11] := 'CROTA1 = '+FormatFloat(e6,crota1)+' / Image twist of X axis (deg) '+blank80;
    hdr[12] := 'CROTA2 = '+FormatFloat(e6,crota2)+' / Image twist of Y axis (deg) '+blank80;
    hdr[13] := 'CD1_1 = '+FormatFloat(e6,cd1_1)+' / CD matrix to convert (x,y) to (Ra, Dec) '+blank80;
    hdr[14] := 'CD1_2 = '+FormatFloat(e6,cd1_2)+' / CD matrix to convert (x,y) to (Ra, Dec) '+blank80;
    hdr[15] := 'CD2_1 = '+FormatFloat(e6,cd2_1)+' / CD matrix to convert (x,y) to (Ra, Dec) '+blank80;
    hdr[16] := 'CD2_2 = '+FormatFloat(e6,cd2_2)+' / CD matrix to convert (x,y) to (Ra, Dec) '+blank80;
    hdr[17] := 'END'+blank80;

    // write wcs file
    assign(fwcs,wcsfile);
    Rewrite(fwcs,1);
    BlockWrite(fwcs,hdr,sizeof(THeaderBlock));
    CloseFile(fwcs);

    // mark as solved
    AssignFile(f,ChangeFileExt(FInFile,'.solved'));
    rewrite(f);
    write(f,' ');
    CloseFile(f);
  end;
end;





TagsNo tags attached.

Relationships

duplicate of 0001834 resolvedPatrick Chevalley PlateSolve2 doesn't work if in Windows a komma s separator is defined. 

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
17-11-06 17:17 han New Issue
17-11-07 11:02 Patrick Chevalley Status new => closed
17-11-07 11:02 Patrick Chevalley Resolution open => duplicate
17-11-07 11:02 Patrick Chevalley Relationship added duplicate of 0001834