View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0001834 | CCdciel | General | public | 17-11-06 17:19 | 17-11-09 12:17 |
Reporter | han | Assigned To | Patrick Chevalley | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Product Version | 0.9 | ||||
Target Version | 1.0 | ||||
Summary | 0001834: PlateSolve2 doesn't work if in Windows a komma s separator is defined. | ||||
Description | PlateSolve2 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; | ||||
Tags | No tags attached. | ||||
has duplicate | 0001833 | closed | PlateSolve2 doesn't work if in Windows a komma s separator is defined. |
|
Above code is not ideal. Maybe it is better to approach it as follows: Var List: TStrings; command1 : string; begin .. .. ExtractStrings([','], [], PChar(command1),List); if list.count>= If the count is high then commas are used as decimal separator in the APM file and could be used to recombine the pieces. The only problem with the APM setup is when fraction of a value is zero, the commas will not be there. Wait with adding the code. Will rewrite it using ExtractStrings. Also have to check flipped again. |
|
So this works better. Will work comma en dot decimal separator. 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; List: TStrings; 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} begin List := TStringList.Create; try list.StrictDelimiter:=true;{only accept comma's} {now do line1} List.Clear; ExtractStrings([','], [], PChar(line1),List); if list.count<=3 then {commas between value, DOT as decimal separator} begin ra_radians:=strtofloat(list[0]); dec_radians:=strtofloat(list[1]); end else begin {commas between value, COMMA as decimal separator} ra_radians:=strtofloat(list[0]+'.'+list[1]); dec_radians:=strtofloat(list[2]+'.'+list[3]); end; {now do line2} List.Clear; ExtractStrings([','], [], PChar(line2),List); if list.count<=5 then {commas between value, DOT as decimal separator} begin pixel_size:=strtofloat(list[0]); crota2:=strtofloat(list[1]); flipped:=pos('-',list[2])=0;{from yx ratio. In apm file yx ratio is reported inverse compared with PlateSolve2 window} end else begin {commas between value, COMMA as decimal separator} pixel_size:=strtofloat(list[0]+'.'+list[1]); crota2:=strtofloat(list[2]+'.'+list[3]); flipped:=pos('-',list[4])=0;{from yx ratio. In apm file yx ratio is reported inverse compared with PlateSolve2 window, Reading y/x ratio is difficult with comma separators. It could be written as "1" or "-0,9999" or "1,0011". So line2 could contain 7 or 8 comma's!! Therefore check only for "-"} end; finally List.Free; end;{try} 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 by 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; |
|
Having the same character for the field separator and the decimal separator make a very weird file. Thank you to solve that. Applied your last version in revision 627: https://sourceforge.net/p/ccdciel/code/627 |
Date Modified | Username | Field | Change |
---|---|---|---|
17-11-06 17:19 | han | New Issue | |
17-11-06 17:30 | han | Note Added: 0004230 | |
17-11-07 02:18 | han | Note Edited: 0004230 | |
17-11-07 02:23 | han | Note Edited: 0004230 | |
17-11-07 03:35 | han | Note Added: 0004233 | |
17-11-07 03:36 | han | Note Edited: 0004233 | |
17-11-07 11:02 | Patrick Chevalley | Relationship added | has duplicate 0001833 |
17-11-07 11:45 | han | Note Edited: 0004233 | |
17-11-09 12:17 | Patrick Chevalley | Assigned To | => Patrick Chevalley |
17-11-09 12:17 | Patrick Chevalley | Status | new => resolved |
17-11-09 12:17 | Patrick Chevalley | Resolution | open => fixed |
17-11-09 12:17 | Patrick Chevalley | Target Version | => 1.0 |
17-11-09 12:17 | Patrick Chevalley | Note Added: 0004243 |