Post Reply 
Observatories
01-16-2017, 06:26 PM
Post: #1
Observatories
This program attempts to parse the observatories file from the Minor Planets Centre and map their locations.

But I'm not convinced by the map.

The map was done quickly, so I wouldn't be surprised to find it upside down (why is 0 at the top of computer screens???).

One complication with the original data is that latitudes are given as a composite value (lat*elevation), but I assume that will be a good enough approximation.

Eventually, I intend to incorporate this into my GEODATA program and/or an astronomical app.

If anyone who knows where the observatories are can indicate whether that map looks reasonable it would be appreciated - I was assuming it would look more like a world map...maybe my expectations were wrong, or do I have a bug in my handling of the coordinates.

Stephen Lewkowicz (G1CMZ)
Visit this user's website Find all posts by this user
Quote this message in a reply
01-16-2017, 06:28 PM
Post: #2
RE: Observatories
Version 0.001

Code:


 // OBSERVATORIES V0.001 2017 StephenG1CMZ

 LOCAL LF:=CHAR(10);
 LOCAL FS:=Notes("OBSERVATORIES.MPC");
 
 //CUSTOMISE
 LOCAL SHOWPROGRESS:=0;

 LOCAL LINES;
 LOCAL ZNAN;
 LOCAL OBSCODE,OBSFULLNAME;
 LOCAL OBSNUMI;
 LOCAL OBSCODES:={},OBSFULLNAMES:={};
 LOCAL OBSLNGS:={};
 LOCAL OBSLATS:={};

 LOCAL LINESPOS:={};
 
 LOCAL NUM1,NUM2,NUM3,NUM3SIGN;
 LOCAL LNGNUM;
 LOCAL LATCOS,LATSIN,LAT;

 IZWHITE(ST)
 BEGIN
  LOCAL WHITESP:=" ";
  LOCAL POS:=1;
  IF DIM(ST)==0 THEN
  MSGBOX("EMPTY");
   RETURN 1;
  END;

  WHILE INSTRING(WHITESP,MID(ST,POS,1)) AND POS≤DIM(ST)  DO
   POS:=POS+1;
  END;
  RETURN (POS>DIM(ST)); //1=WHITESPACE ELSE 0 
 END;

 PARSE_OBS(ALINE)
 BEGIN
  OBSCODE:=MID(ALINE,1,4);
  IF SHOWPROGRESS THEN
   DRAWMENU(OBSCODE);
  END;
  //IF MID(OBSCODE,4)==" " THEN
  //ELSE
  // MSGBOX("BAD OBSCODE "+ASC(MID(OBSCODE,4)));
  // RECT_P();
  // END;
  //PRINT(ALINE);
   
  IF OBSCODE=="Code" THEN
   //HEADR LINE
  ELSE
   ZNAN:=0;
   NUM1:=(MID(ALINE,4,10));
   IF IZWHITE(NUM1) THEN
    //PRINT(".");
    NUM1:="0";ZNAN:=1; //NAN
    //DEBUG;
   END;
   LNGNUM:=EXPR(NUM1);
   IF ZNAN THEN
    LAT:=0;
   ELSE
    NUM2:=MID(ALINE,4+10,8);
    NUM3SIGN:=MID(ALINE,4+10+8,1);
    NUM3:=MID(ALINE,4+10+8+1,8);
    //LATCOS:=ACOS(EXPR(NUM2));
    LATCOS:=EXPR(NUM2);
    //PRINT(LATCOS);DEBUG;
    //PRINT(NUM3);
    LATSIN:=(180/π)*ASIN(EXPR(NUM3));
    //LAT:=(LATCOS+LATSIN)/2;
   END;
   IF NUM3SIGN=="-" THEN
    LATSIN:=−LATSIN;
   END;
   //
   LAT:=LATSIN;
   OBSFULLNAME:=MID(ALINE,32-1);
   //PRINT(MID(ALINE,1,4)+" "+OBSNAME);
   OBSCODES(OBSNUMI):=OBSCODE;
   OBSFULLNAMES(OBSNUMI):=OBSFULLNAME;
   OBSLNGS(OBSNUMI):=LNGNUM;
   OBSLATS(OBSNUMI):=LAT;
   IF OBSCODE=="007 " AND 0 THEN
    MSGBOX("48-50= "+→HMS(LAT));
   END;
   OBSNUMI:=OBSNUMI+1;
  END;
 END;

 EXPORT READ_ALL_OBS(ST)
 BEGIN
  LOCAL LFOFFSET,CH;
  LOCAL FRM,TOO;
  LOCAL TMP;
  LINESPOS:={0};
  LINES:=1; OBSNUMI:=1;
  IF SHOWPROGRESS OR 1 THEN
   DRAWMENU("Loading");
  END;
  REPEAT
   LFOFFSET:=INSTRING(MID(ST,LINESPOS(LINES)+1),LF);
   IF LFOFFSET THEN
    LINESPOS(LINES+1):=LINESPOS(LINES)+LFOFFSET;
    CH:= MID(ST,LINESPOS(LINES+1),1);
    IF CH==LF THEN
    ELSE
      MSGBOX("BAD LF"+CH);
    END;
    FRM:=LINESPOS(LINES)+1;
    TOO:=LINESPOS(LINES+1);
    PARSE_OBS(MID(ST,FRM,TOO-FRM));
    IF MID(ST,FRM,1)=="Z" AND 0 THEN
     PRINT("LINE"+LINES+"FRM"+FRM+"TO"+TOO);
     PRINT("CODE: "+MID(ST,FRM,4));
     PRINT(MID(ST,FRM,TOO-FRM));
    END;
    LINES:=LINES+1;
    //WAIT;
   END;
  UNTIL LFOFFSET==0;
  //DEBUG;
  //FINAL LINE IF LAST LF MISSING
  FRM:=LINESPOS(LINES)+1;
  TOO:=SIZE(ST)-FRM;
  PARSE_OBS(MID(ST,FRM,TOO));
 //PRINT("SIZE "+SIZE(ST));
  //PRINT("Lines: "+LINES);
 END;

 QUICKPLOT()
 BEGIN
  LOCAL II,XX,YY;
  RECT_P();
  //(NEEDS ":0-360=-180,180 ETC
  //MSGBOX(SIZE(OBSFULLNAMES));
  FOR II FROM 1  TO SIZE(OBSFULLNAMES) DO
   XX:=OBSLNGS(II);
   XX:=IFTE(XX>180,−(360-XX),XX);
   XX:=(320/360)*OBSLNGS(II);
   YY:=(240/180)*(OBSLATS(II)+90);
   RECT_P(XX,YY,XX,YY,RGB(255,0,0),RGB(99,99,99)); 
  END;
  DRAWMENU("DONE");
  
 END;

 VERY_INFO()
 BEGIN
  WAIT;
  PRINT("Found "+SIZE(OBSCODES)+" Observatories");
 END;

 PROGRAMR_INFO()
 //USE FOR DISPLAY SIZING
 BEGIN
  LOCAL II,ML,LONGNAME;
  PRINT("Longitudes:"+MIN(OBSLNGS)+".."+MAX(OBSLNGS));
  PRINT("Latitudes: "+MIN(OBSLATS)+".."+MAX(OBSLATS));
  ML:=0;
  FOR II FROM 1 TO SIZE(OBSFULLNAMES) DO
   IF DIM(OBSFULLNAMES(II))>ML THEN
    ML:=DIM(OBSFULLNAMES(II));
    LONGNAME:=OBSFULLNAMES(II);
   END;
  END;
  PRINT("LONGFULLNAME "+ML);
  PRINT(LONGNAME);
  WAIT;
  TEXTOUT_P(LONGNAME,0,200,3);//3 IS LARGEST FONT TO FIT NAME ON 1 LINE
 END;

 EXPORT OBS()
 BEGIN
  LOCAL TBEG;
  PRINT();
  //MSGBOX(IZWHITE(" B   "));
  TBEG:=TICKS;
  READ_ALL_OBS(FS);
  TBEG:=TICKS-TBEG;
  PRINT((TBEG/1000)+" s");
  VERY_INFO();
  PROGRAMR_INFO();
  //MSGBOX("DONE");
  WAIT;
  QUICKPLOT();
  WAIT;
 END;

Stephen Lewkowicz (G1CMZ)
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)