Post Reply 
ZIPP: G1CMZ's Immensely Practical Package
10-21-2015, 09:08 AM
Post: #2
RE: ZIPP: G1CMZ's Immensely Practical Package
Version 0.1
Code:


#pragma mode( separator(.,;) integer(h32) )

 LOCAL ZIPPST:="ZIPP V 0.1 ";
 LOCAL SG:=" StephenG1CMZ";
 LOCAL CRID:=ZIPPST+"© 2015 "+SG;
 LOCAL NL:=CHAR(10);
 
 LOCAL CD2,CD1;
 EXPORT ZIPPRND;//USER ROUNDING

 LOCAL THSPD_M;
 LOCAL MEAS_INTERVAL_S;

 LOCAL TOMI:=1.60344;//MILES UK
 LOCAL TONM:=1.852;//NAUTI

 MSNK()
 BEGIN
   LOCAL SNK:=MOUSE();
 END;

 CONVERT_UNIT_GRP(unit,tname)
 BEGIN
  LOCAL x,menu,a1,a2,t;
  LOCAL HLP:=tname+":Enter value(s) using:";

  menu:=unit;//AUTO
  CHOOSE(CD2,"Units:"+tname,menu);
  IF CD2 THEN
   INPUT({{ x,[2],{45,20,3} }},"","Convert ",HLP+unit[CD2]);
   //DETECT ESC
   IF string(x,1) == "0" THEN RETURN; END;

   CHOOSE(CD1, "To Units:"+tname, menu);
   a2 := unit[CD2];
   a1 := unit[CD1];
   t := x + "*" + CONVERT(a2,a1);
   RETURN expr(t);
  END;
 END;

 EXPORT CONVERT_UNITS()
 BEGIN
  LOCAL CHSTYP;
  LOCAL TTL:="Unit types";
  LOCAL UTYP:={"Length","Area","Volume",
   "Time","Speed","Acceleration","Mass","Force",
   "Energy","Power","Pressure","Temperature:NO!",
   "Electricity","Light","Angle","Viscosity","Radiation"};

  LOCAL UL:={};

  CHOOSE(CHSTYP,TTL,UTYP); 
  CASE
   IF CHSTYP==1 THEN //LENGTH
    //CONVERT_Length();
    UL:={1_m,1_cm,1_mm,1_km,1_in,1_ft,1_yd,1_mile,1_nmi,1_au,1_lyr,1_pc,1_Å};
   END;
   IF CHSTYP==2 THEN //AREA
    UL:={1_(cm²),1_(m²),1_(km²),1_(in²),1_(ft²),1_(yd²),1_(mile²),1_(miUS²),1_a​cre,1_ha,1_a,1_b};//A:Are B:Barn
    //CONVERT_UNIT_GRP(UL);
   END;
   IF CHSTYP==3 THEN //VOLUME
    UL:={1_(cm^3),1_(m^3),1_ml,1_l,1_(in^3),1_(ft^3),1_(yd^3),1_ptUK,1_galUK,1_​galUS};
    //CONVERT_UNIT_GRP(UL);
   END;
   IF CHSTYP==4 THEN //TIME
    UL:={1_s,1_min,1_h,1_d,1_yr,1_Hz};
   END;
   IF CHSTYP==5 THEN //SPEED
    UL:={1_(cm/s),1_(m/s),1_kph,1_(km/h),1_(ft/s),1_mph,1_(mile/h),1_knot,1_(rad/s),1_(tr/min),1_(tr/s)};
   END;
   IF CHSTYP==6 THEN //ACCEL
    UL:={1_(m/s²),1_(ft/s²),1_grav,1_Gal,1_(rad/s²)};
   END;
   IF CHSTYP==7 THEN //MASS
    UL:={1_g,1_kg,1_oz,1_lb,1_tonUK,1_tonUS,1_mol,1_u,1_t};
   END;
   IF CHSTYP==8 THEN //FORCE
    UL:={1_(kg*m/s²),1_N,1_dyn,1_lbf,1_kip,1_gf,1_pdl};
   END;
   IF CHSTYP==9 THEN //ENERGY
    UL:={1_(kg*m²/s²),1_J,1_Wh,1_kWh,1_(ft*lbf),1_kcal,1_cal,1_eV,1_MeV,1_Btu,1_erg,1_thermUK,1_th​ermEC,1_thermUS};
   END;
   IF CHSTYP==10 THEN //POWER
    UL:={1_(kg*m²/s^3),1_W,1_MW,1_hp,1_(ft*lbf/s)};
   END;
   IF CHSTYP==11 THEN //PRESSURE
    UL:={1_(kg/(m*s²)),1_Pa,1_bar,1_atm,1_psi,1_torr,1_mmHg,1_inHg,1_inH2O};
   END;
   IF CHSTYP==13 THEN //ELEC
    UL:={1_A,1_V,1_C,1_Ohm,1_F,1_Fdy,1_Wb,1_H,1_mho,1_T,1_(A*h),1_S};
   END;
   IF CHSTYP==14 THEN //LIGHT:HP MISSING MOST UNITS
    UL:={1_cd,1_flam};
   END;
   IF CHSTYP==15 THEN //ANGL
    UL:={1_rad,1_deg,1_arcmin,1_arcs,1_tr};
   END;
   IF CHSTYP==16 THEN //VISCOSITY
    UL:={1_(m²/s),1_P,1_St};
   END;
   IF CHSTYP==17 THEN //RADIATION
    UL:={1_Bq,1_Ci,1_Gy,1_rd,1_rem,1_Sv,1_R};
   END;
   DEFAULT
    //DO NOT CONVERT_UNIT_GRP(UL);
  END;
  IF SIZE(UL)>0 THEN //AND CHSTYP>0
   MSGBOX(CONVERT_UNIT_GRP(UL,UTYP(CHSTYP)),1);
  END;
 END;


 INPUT_INTERVAL_H(TTL)
 BEGIN
  LOCAL HH,MM,SS;
  LOCAL LBL:={"HH","MM","SS"};
  LOCAL HLP:="HH MM SS:ETC";
  INPUT({HH,MM,SS},TTL,LBL,HLP,0,0);
  RETURN HH+(MM/60)+(SS/3600); 
 END;

 EXPORT MEASURE_INTERVAL_S()
 BEGIN
  LOCAL TICKB,TICKE,TICKL;
  LOCAL TS,KK;
  LOCAL MI:=0;
  LOCAL MST:="MEASURE SHORT INTERVAL"+NL;
  LOCAL MST1:="OK or Enter: Start"+NL;
  LOCAL MST2:="Enter:Enter HMS numerically"+NL;
  LOCAL MST3:="ANY KEY: End"+NL;
  //LOCAL CNW:="CONNECTIVITY:NO HP DATA";
  LOCAL ENINST:="Enter INTERVAL";
  
  TICKB:=MSGBOX(MST+MST1+MST2+MST3,1);
  IF TICKB THEN
   RECT();
   TICKB:=Ticks; TS:=Time;
   TICKL:=TICKB;
   REPEAT 
    MSNK;
    IF Ticks-TICKL≥1000 THEN
     TICKL:=Ticks;
     RECT();
     TEXTOUT_P(→HMS(ROUND((Ticks-TICKB)/1000,0)/3600),0,20);
     MSNK;
     TEXTOUT_P(TS+MST,0,180);
     TEXTOUT_P(MST2,0,200);
     TEXTOUT_P(MST3,0,220);

    END;
    WAIT(0.001);
    MSNK;
    KK:=GETKEY;
   UNTIL KK≥0;
   TICKE:=Ticks;
   MI:=(TICKE-TICKB)/1000;
   IF KK==30 THEN //ENTER
    MI:=3600*INPUT_INTERVAL_H(ENINST);
   END;
  END;
  RETURN MEAS_INTERVAL_S:=ROUND(MI,ZIPPRND);   
 END;

 THUNDER_DISTANCE_CALC_M(INTERVAL_S,TEMP_C)
 //INTERVAL
 //CENTIGRADE (NORMAL RANGE)
 BEGIN
  LOCAL DISTM;

  THSPD_M:=331.4+0.6*TEMP_C;//M/S
  DISTM:=INTERVAL_S*THSPD_M;
  RETURN ROUND(DISTM,ZIPPRND);
 END;

 EXPORT THUNDER_DISTANCE()
 BEGIN
  LOCAL OK;
  LOCAL THDST:={};
  LOCAL THDM,THDKM,THDMI,THDNM;
  LOCAL INTERVAL_S,TEMP_C;
  LOCAL TTL:="THUNDER DISTANCE"+SG;
  LOCAL LBL:={"Interval s","Temp C"};
  LOCAL HLP:={"Interval sound-light. (0:use measured value)","temp C eg 0..20:Ground −57: Aircraft"};
  OK:=INPUT({INTERVAL_S,TEMP_C},TTL,LBL,HLP,MEAS_INTERVAL_S,0);
  IF OK THEN
   IF INTERVAL_S≤0 THEN //IMPORT VALUE
    INTERVAL_S:=MEAS_INTERVAL_S;
   END;
   THDM:=THUNDER_DISTANCE_CALC_M(INTERVAL_S,TEMP_C);
   THDKM:=THDM/1000;
   THDMI:=THDKM/TOMI;
   THDNM:=THDKM/TONM;

   THDST(1):=ROUND(INTERVAL_S,0)+" s"+" @ "+ROUND(THSPD_M,ZIPPRND)+" m/s"+NL;
   THDST(2):=THDM+" m "+ROUND(THDKM,ZIPPRND)+" km"+NL;
   THDST(3):=ROUND(THDMI,ZIPPRND)+" milesUK"+NL;
   THDST(4):=ROUND(THDNM,ZIPPRND)+" Nautical Miles";
   MSGBOX(THDST(1)+THDST(2)+THDST(3)+THDST(4));
   RETURN THDST(2);
  END;
 END;

 ABOUT ()
 BEGIN
  LOCAL ST:="StephenG1CMZ is a programmer and can work to your requirements."+NL;
  LOCAL SZ:="ZIPP provides useful practical results.
Ask, if you need technical results."+NL;
  LOCAL THANX:="Thanks Han for the CONVERT syntax."+NL; 
  LOCAL LGL:="No liability is accepted.";
  PRINT(); PRINT(CRID);
  PRINT(ST+NL+SZ);
  PRINT(THANX);
  PRINT(LGL);
  WAIT;
 END;

 HELP ()
 BEGIN
  LOCAL ST:="To change the number of digits displayed:
 ZIPPRND:=n where n=−12..12"+NL;

  LOCAL CVT:="CONVERT
Note that not all units within a group can be converted.
Conversion between groups (eg length*length to area) is not implemented here."+NL;
  PRINT(); PRINT(CRID);
  PRINT(CVT+ST);
  WAIT;
 END;

 EXPORT G1CMZ_IMMENSELY_PRACTICAL_PACKAGE ()
 BEGIN
  LOCAL CHS;
  
  REPEAT 
   CHOOSE(CHS,CRID,{"ABOUT","HELP","CONVERT UNITS","MEASURE INTERVAL s","THUNDER DISTANCE","EXIT"});
   CASE
    IF CHS==1 THEN ABOUT() END;
    IF CHS==2 THEN HELP() END;
    IF CHS==3 THEN CONVERT_UNITS() END;
    IF CHS==4 THEN MSGBOX(MEASURE_INTERVAL_S()+" s",1) END;
    IF CHS==5 THEN THUNDER_DISTANCE() END;
    IF CHS==6 THEN CHS:=0 END;
    DEFAULT
   END;
   //WAIT;
  UNTIL CHS==0;

 END;

 EXPORT ZIPP()
 BEGIN
  G1CMZ_IMMENSELY_PRACTICAL_PACKAGE();
 END;

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: ZIPP: G1CMZ's Immensely Practical Package - StephenG1CMZ - 10-21-2015 09:08 AM



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