HP Forums
Z UNITS: A program for converting units - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP Prime Software Library (/forum-15.html)
+--- Thread: Z UNITS: A program for converting units (/thread-5245.html)



Z UNITS: A program for converting units - StephenG1CMZ - 11-30-2015 09:42 PM

In English and in French.
English:
This program allows the user to convert many (but not all) HP units, with support for SI prefixes.
It also defines some Planck units and converts data units.
If this program does not suit your needs, have a look at epp's CNV function.
Version 0.1: compiled using Android emulator 1.0.9
Code:



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

 LOCAL ZUST:="Z UNITS V 0.1 ";
 LOCAL SG:=" StephenG1CMZ";
 LOCAL CRID:=ZUST+"© 2015 "+SG;
 LOCAL NL:=CHAR(10);
 LOCAL OKC;

 LOCAL DEFLT_LANG();
 LOCAL SL:=DEFLT_LANG();

 LOCAL CDFROM,CDTO;
 EXPORT ZIPPROUND;//USER ROUNDING

 LOCAL MEAS_INTERVAL_S;
 LOCAL VBITS,VBPS,VS;
 //LOCAL TOMI:=1.60344;//MILES UK
 //LOCAL TONM:=1.852;//NAUTI
 
 //PLANCK NIST 2014
   //LOCAL PLANCK; //ANY OF...
   //UNUSED TO AVOID CONFUSION IN AREA/VOLUME:
   //USER MUST SPECIFY WHICH
 LOCAL PLANCK_GEV:=1.220910ᴇ19;
 LOCAL PLANCK_KG:=2.176470ᴇ−8;
 LOCAL PLANCK_K:=1.416808ᴇ32;
 LOCAL PLANCK_M:=1.616229ᴇ−35;
 LOCAL PLANCK_S:=5.39116ᴇ−44;

 //SI PREFIXES
 LOCAL YOTTA:=1ᴇ24;
 LOCAL ZETTA:=1ᴇ21;
 LOCAL EXA  :=1ᴇ18;
 LOCAL PETA :=1ᴇ15;
 LOCAL TERA :=1ᴇ12;
 LOCAL GIGA :=1ᴇ9;
 LOCAL MEGA :=1ᴇ6;
 LOCAL KILO :=1ᴇ3;
 LOCAL HECTO:=1ᴇ2;
 LOCAL DECA :=1ᴇ1;
 LOCAL DECI :=1ᴇ−1;
 LOCAL CENTI:=1ᴇ−2;
 LOCAL MILLI:=1ᴇ−3;
 LOCAL MICRO:=1ᴇ−6;
 LOCAL NANO :=1ᴇ−9;
 LOCAL PICO :=1ᴇ−12;
 LOCAL FEMTO:=1ᴇ−15;
 LOCAL ATTO :=1ᴇ−18;
 LOCAL ZEPTO:=1ᴇ−21;
 LOCAL YOCTO:=1ᴇ−24;

 //DATA UNITS:CAPACITY
 LOCAL UBITS:="bits";
 LOCAL UBY:="Bytes";
 LOCAL UCH:="Characters";//Characters
 //LOCAL UITEMS:="Items";//TRANSACTIONS
 LOCAL UWD:="Words(−.)";
 LOCAL BYZ:=8;//CHANGE IF U NEED STARTSTOP BITS
 LOCAL DATAS:={1,BYZ,2*BYZ,4*BYZ,8*BYZ}; //−1};
 //DATA UNITS:THROUGHPUT
 LOCAL UBPS:="bps";
 LOCAL UBYPS:="(Byte/s)";
 LOCAL UCPS:="(CPS)";
 LOCAL UWPM:="WPM(Morse)";
 LOCAL TML:={"s","s","s","s","s"};//SIZE MATCH
 
 //UNITS
 //LOCAL NMST:={" Nautical Miles",""," Miles Nautique"};
 LOCAL TKINDLST:={"Celcius (Centigrade)","Fahrenheit","kelvin","Planck"};
 
 LOCAL WSYS:={"System","","Système"};
 LOCAL LANGS:={"English","","Français"};
 LOCAL EN:=1; LOCAL FR:=3;
 //e233

 //WORDS
 //LOCAL WBINA:={"Binary","","Binaire"};
 LOCAL WCAPACITY:={"Capacity","","La Capacité"};
 LOCAL WRATE:={"Throughput","","Taux/Débit"};

 LOCAL WENTERZ:={"Enter","","Entrez"};
 LOCAL WHELP:={"Help","","Aide"};
 LOCAL WINTERVAL:={"Interval","","Intervalle"};
 LOCAL WPREFIX:={"Prefix","","Préfixe"};
 LOCAL WTIME:={"Time","","Temps"};
 LOCAL WUNITS:={"Units","","Unités"};
 LOCAL WTEMPE:={"Temperature","","Température"};
 LOCAL WCNVTT:={"Convert "+WTEMPE(EN),"","Convertir la "+WTEMPE(FR)};
 LOCAL WCNVTU:={"Convert Units","","Convertir des Unités","Konwersja Jednowstek"};
 LOCAL WDATAU:={"Data Units","","Les unités de données"};
 LOCAL WIGN:={"Ignored","","Ignoré"};
 LOCAL WNOPRFX:={"Do not use Prefix","","Ne pas utiliser Préfixe"};
 LOCAL WSOLVE:={"Solve for","","Résoudre pour"};
 LOCAL WVALU:={"Value","","La valeur"};
 LOCAL WNOO:={"/0","","/0"};

 LOCAL CHOICES:={{"ABOUT/"+WHELP(EN),"",WCNVTU(EN),"Measure Interval s and HMS->s","",LANGS,"EXIT"},
 {},
 {"A PROPOS/"+WHELP(FR),"",WCNVTU(FR),"Intervalle de Mesure s et HMS->s","",LANGS,"QUITTER"}};//FR:P
 
 LOCAL DATATYPES:={{WCAPACITY(EN),WRATE(EN),WTIME(EN)},{"","",""},
 {WCAPACITY(FR),WRATE(FR),WTIME(FR)}};

 EXPORT ABOUT ()
 BEGIN
  LOCAL ST:="StephenG1CMZ is a programmer and can work to your requirements."+NL;
  LOCAL SZ:="Z UNITS is a program for unit conversion.
"+NL;
  LOCAL THANX:="Thanks Han for the CONVERT syntax.
Thanks Primer."+NL; 
  LOCAL LGL:="No liability is accepted.";
  PRINT(); PRINT(CRID);
  PRINT(ST+NL+SZ);
  PRINT(THANX);
  PRINT(LGL);
  WAIT;
 END;

 RUP(RR)
 BEGIN //ROUNDUP:POSITIVEREAL ONLY
  RETURN IP(RR);IFTE(FP(RR),1,0);
 END;

 TEMP_F2C (FF)
 BEGIN
  RETURN (FF-32)*5/9;
 END;
 TEMP_C2F(CC)
 BEGIN
  RETURN (9/5)*CC+32;
 END;

 TEMP_K2C(KK)
 BEGIN
   RETURN KK-273.15;
 END;
 TEMP_C2K(CC)
 BEGIN
  RETURN CC+273.15;
 END;
 TEMP_P2K(PP)
 BEGIN
  RETURN PP*PLANCK_K;
 END;
 TEMP_K2P(KK)
 BEGIN
  RETURN KK/PLANCK_K;
 END;
 CONVERT_TEMP ()
 BEGIN
  LOCAL OK,TKIND;
  LOCAL TEMP,TEMP_C:=0;
    //INITIALISE TO AVOID ESCAPE RETURNING 0C=0F=0K
  LOCAL TEMP_F:=TEMP_C2F(TEMP_C),TEMP_K:=TEMP_C2K(TEMP_C);
  LOCAL TEMP_P:=TEMP_K2P(TEMP_K); 
  LOCAL TTL:=WCNVTT(SL);
  LOCAL LBL:={WUNITS(SL),WTEMPE(SL)};
  LOCAL HLP:=""; 
  
  OK:=INPUT({{TKIND,TKINDLST},TEMP},TTL,LBL,HLP,1,1);
  IF OK THEN
   CASE
    IF TKIND==1 THEN //C
     TEMP_C:=TEMP;
     TEMP_F:=TEMP_C2F(TEMP_C);
     TEMP_K:=TEMP_C2K(TEMP_C);
     TEMP_P:=TEMP_K2P(TEMP_K);
    END;
    IF TKIND==2 THEN //F
     TEMP_F:=TEMP;
     TEMP_C:=TEMP_F2C(TEMP_F);
     TEMP_K:=TEMP_C2K(TEMP_C);
     TEMP_P:=TEMP_K2P(TEMP_K);
    END;
    IF TKIND==3 THEN //K
     TEMP_K:=TEMP;
     TEMP_C:=TEMP_K2C(TEMP_K);
     TEMP_F:=TEMP_C2F(TEMP_C);
     TEMP_P:=TEMP_K2P(TEMP_K);
    END;
    IF TKIND==4 THEN //P
     TEMP_P:=TEMP;
     TEMP_K:=TEMP_P2K(TEMP_P);
     TEMP_C:=TEMP_K2C(TEMP_K);
     TEMP_F:=TEMP_C2F(TEMP_C);
    END;
    DEFAULT
   END;
  //ALGM VALID FOR 0..1PLANCK UNLIMITED
  END;

  RETURN {TEMP_C+TKINDLST(1),TEMP_F+TKINDLST(2),TEMP_K+TKINDLST(3)};//PLANCKS NOT SHOWN
 END;

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

 DATA_UNITS()
 BEGIN
  LOCAL VH,SI,NC,II,ST,NUM;
  LOCAL OK,CHS,TM,TMU,QTYU,THRU,VALU,SLV;
 //+64ETC NEEDS TIDYING
  LOCAL QTYTP:={UBITS,UBY,UBITS+16,UBITS+32,UBITS+64}; //,UWD};//BUG:SIZES MUST MATCH
  LOCAL THRUTP:={UBPS,UBYPS,UBPS+16+UCPS,UBPS+32,UBPS+64}; //,UWPM};
  LOCAL TTL:={"","",WNOPRFX(SL)};
  LOCAL LBL;//
  LOCAL HLP3:={{"","Select "+WPREFIX(EN),"Select Units","Select 2^10=1024 or 10^3=1000 (SI)","Select to solve for this unit type"},{"","","","",""},
   {"","Selectionnez "+WPREFIX(FR),"Selectionnez Unites","Selectionnez 2^10=1024 ou 10^3=1000 (SI)","Selectionnez à résoudre pour ce type d unité"}};
  LOCAL PFX,USEBIN;
  //LOCAL PFX0:={"No Prefix"};
  LOCAL PFXN,PFXNSTEP;
  LOCAL PFXS:={" ","[k|K]","M","G","T"};//,"G","T","P","E","Z"};
  LOCAL VALUES;//{}

  REPEAT

   OK:=CHOOSE(CHS,WDATAU(SL)+SG,DATATYPES(SL));
   IF OK THEN
    LBL:={WVALU(SL),WPREFIX(SL),DATATYPES(SL,CHS),"2^",WSOLVE(SL)};
    CASE
     IF CHS==1  THEN //CAPACITY
      OK:=INPUT({VALU,{PFX,PFXS},{QTYU,QTYTP},{USEBIN,1},{SLV,1}},TTL(1),LBL,HLP3​(SL),1,1);
      IF OK THEN
       PFXNSTEP:=IFTE(USEBIN,2^10,10^3);
       PFXN:=IFTE(USEBIN,2^(10*(PFX-1)),1000^(PFX-1)); 
       IF SLV THEN //B=BPS*S
        VBITS:=VS*VBPS;
       ELSE
        VBITS:=VALU*PFXN*DATAS(QTYU);
       END;
       VALUES:=VBITS/{DATAS};
       MSGBOX(VALUES); 
       VALUES:=VALUES(1);//UNLIST?
       REPEAT 
        OKC:=CHOOSE(NC,"",QTYTP);
        IF OKC THEN       
         NUM:=VALUES(NC);
         ST:="";
         FOR II FROM  1 TO SIZE(PFXS) DO
          ST:=ST+(NUM/(PFXNSTEP^(II-1)))+PFXS(II)+QTYTP(NC)+NL;
         END;
         MSGBOX(ST); 
        END;
       UNTIL OKC==0;

      END;
     END;
     IF CHS==2  THEN //THROUGHPUT
      OK:=INPUT({VALU,{PFX,PFXS},{THRU,THRUTP},{USEBIN,1},{SLV,1}},TTL(2),LBL,HLP​3(SL),1,1);
      IF OK THEN
       PFXNSTEP:=IFTE(USEBIN,2^10,10^3);
       PFXN:=IFTE(USEBIN,2^(10*(PFX-1)),1000^(PFX-1));
       IF SLV THEN //BPS=B/S
        IF VS==0 THEN
         MSGBOX(WNOO(SL));
         VBPS:=0;
        ELSE
         VBPS:=VBITS/VS;
        END;
       ELSE
        VBPS:=VALU*PFXN*DATAS(THRU);
       END;
       VALUES:=VBPS/{DATAS};
       MSGBOX(VALUES);
       VALUES:=VALUES(1);
       REPEAT
        OKC:=CHOOSE(NC,"",THRUTP);
        IF OKC THEN
         ST:="";
         NUM:=VALUES(NC);
         FOR II FROM 1 TO SIZE(PFXS)  DO
          ST:=ST+(NUM/(PFXNSTEP^(II-1)))+PFXS(II)+THRUTP(NC)+NL;
         END;
         MSGBOX(ST);
        END;
       UNTIL OKC==0;

      END;
     END;
     IF CHS==3 THEN //TIME    
      OK:=INPUT({VALU,{PFX,PFXS},{TMU,TML},{USEBIN,1},{SLV,1}},TTL(3),LBL,HLP3(SL​),1,1);  
      VALU:=IFTE(VALU==0,MEAS_INTERVAL_S,VALU);
    
      IF OK THEN
       PFXN:=IFTE(USEBIN,2^(10*(PFX-1)),1000^(PFX-1));
       IF PFXN==1 THEN
       ELSE //HOW
        MSGBOX(WPREFIX(SL)+" "+WIGN(SL)) ;
       END;
       IF SLV THEN //S=B/BPS
        //MSGBOX(VBITS);
        IF VBPS==0 THEN
         MSGBOX(WNOO(SL));
         VS:=0;
        ELSE
         VS:=VBITS/VBPS;
        END;
       ELSE
        VS:=VALU;
       END;
       VH:=VS/60/60;
       MSGBOX({VS,→HMS(VH)});
      END;  
     END;
     DEFAULT
    END;
   
   END;
  UNTIL CHS==0;
 END;

TRIMMENU(INL)
 BEGIN
  LOCAL II;
  LOCAL OUTL:={};

  FOR II FROM 1 TO SIZE(INL)  DO
   OUTL(II):=REPLACE(STRING(INL(II)),"1_","");
  END;
  RETURN OUTL;  
 END;

 CONVERT_UNIT_GRP(unit,tname)
 BEGIN
  LOCAL x,menu,a1,a2,t;
  LOCAL UF;
  LOCAL TTL:={"To use SI prefixes: INPUT PREFIXNAME","",
    "SI préfixe: Saisissez le nom du préfixe"};
  
  LOCAL EVUST:={
   ": Enter value(s) in: ","",
   ":Entrez la/les valeur(s) avec: "};//FR:P
  LOCAL HLP:=tname+EVUST(SL);
  LOCAL TOST:={"To ","","À "};
  LOCAL CNVRT:={"Convert","","Convertir"};

  menu:=TRIMMENU(unit);//AUTO
  CHOOSE(CDFROM,WUNITS(SL)+":"+tname,menu);
  IF CDFROM THEN
   UF:=REPLACE(STRING(unit[CDFROM]),"1_",""); //TRIM 1_
   INPUT({{ x,[2],{45,20,3} }},TTL(SL),CNVRT(SL),HLP+UF);
   //DETECT ESC
   IF string(x,1) == "0" THEN RETURN; END;
   
   CHOOSE(CDTO, TOST(SL)+WUNITS(SL)+":"+tname, menu);
   a2 := unit[CDFROM];
   a1 := unit[CDTO];
   t := x + "*" + CONVERT(a2,a1);
   
   RETURN expr(t);
  END;
 END;

 CONVERT_UNITS_HP()
 BEGIN
  LOCAL CHSTYP;
  LOCAL TTL:={"Unit types","","Types d'unités"};
  LOCAL UTYP:={{"Length","Area","Volume",
   "Time","Speed","Acceleration","Mass","Force",
   "Energy","Power","Pressure","Temperature:NO!",
   "Electricity","Light","Angle","Viscosity","Radiation"},
 {},
 {"Longueur","Surface","Volume",
    "Heure","Vitesse","Accélération","Masse","Force",
    "Energie","Puissance","Pression","Température:NON!",
    "Electricité","Lumière","Angle","Viscosité","Radiation"}};
 //TESTING:PUISSANCE(POWER) IS LONGEST INPUT STRING

  LOCAL UL:={};

  REPEAT
   CHOOSE(CHSTYP,TTL(SL),UTYP(SL)); 
   CASE
    IF CHSTYP==1 THEN //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
    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};
    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==12 THEN //TEMP
     //UL:={1_K,1_°C,1_°F};
    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
   END;
   IF SIZE(UL)>0 THEN //AND CHSTYP>0
     IF CHSTYP≤17 THEN //HP
      OKC:=MSGBOX(CONVERT_UNIT_GRP(UL,UTYP(SL,CHSTYP)),1);
     //ELSE //SL
     // CONVERT_GRP_SL(UL,UTYP(SL,CHSTYP));
     END;
   END;
  UNTIL OKC==0;
 END;

 Z_CONVERT_UNITS ()
 BEGIN
  LOCAL CHS,OKC;
  LOCAL TTL:=WCNVTU(SL)+SG;
  CHOOSE(CHS,TTL,{WCNVTT(SL),WCNVTU(SL),WDATAU(SL)});
  IF CHS THEN
    CASE
     IF CHS==1 THEN 
      REPEAT
       OKC:=MSGBOX(CONVERT_TEMP(),1); 
      UNTIL OKC==0;
     END;
     IF CHS==2 THEN CONVERT_UNITS_HP() END;
     IF CHS==3 THEN DATA_UNITS() END;
     DEFAULT
    END;
   END; 
 END;

 INPUT_INTERVAL_H(TTL)
 BEGIN
  LOCAL HH,MM,SS,OK;

  LOCAL LBL:={WINTERVAL(SL)+" HH",WINTERVAL(SL)+" MM",WINTERVAL(SL)+" SS"};
  LOCAL HLP1:={"Decimals & Fractions allowed","",
    "Décimaux et fractions autorisés"};//FR:P
  LOCAL HLP:={HLP1(SL),HLP1(SL),HLP1(SL)};

  OK:=INPUT({HH,MM,SS},TTL,LBL,HLP,0,0);
  IF OK THEN
   RETURN HH+(MM/60)+(SS/3600); 
  ELSE
   RETURN 0; //CANCEL
   //HOW TO SIGNAL CANCEL?
  END;
 END;

 MEASURE_INTERVAL_S()
 BEGIN
  LOCAL TICKB,TICKE,TICKL;
  LOCAL TS,KK;
  LOCAL MI:=0;
  
  LOCAL MST:={"MEASURE SHORT INTERVAL"+NL,"",
   "MESURE COURT INTERVALLE"+NL};
  LOCAL MST1:={"OK or Enter: Start"+NL,"",
   "OK ou Entrer: Commencez"+NL};
  LOCAL MST2:={"Enter:Enter HMS numerically"+NL,"",
   "Entrer: Entrez HMS numeriquement"+NL};
  LOCAL MST3:={"ANY KEY: End"+NL,"",
   "N importe quelle clé: Terminer"+NL};
  //LOCAL CNW:="CONNECTIVITY:NO HP DATA";
  
  TICKB:=MSGBOX(MST(SL)+MST1(SL)+MST2(SL)+MST3(SL),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(SL),0,180);
     TEXTOUT_P(MST2(SL),0,200);
     TEXTOUT_P(MST3(SL),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(WENTERZ(SL)+" "+WINTERVAL(SL));
    //IDEALLY IF A CANCEL IS DETECTED
    //OUGHT TO RESUME MEASURED TIMING
   END;
  END;
  MEAS_INTERVAL_S:=MI;
  RETURN ROUND(MI,ZIPPROUND);   
 END;
 
 Z_UNITS_HELP ()
 BEGIN
  LOCAL CHS,OK;
  //LOCAL HLPCHO:={"VARIABLES"};//NOT IMPLEMENTED
  LOCAL HLPCHO:={};
  LOCAL HC:=CONCAT(CHOICES(SL),HLPCHO);
  
  LOCAL SIPRFX:={"
Values may include SI prefixes.
ENTER IN UPPERCASE: Selecting Units/Prefix (Shift C) will not work."+NL,"",
"Les valeurs peuvent inclure des SI préfixes. Entrez en majuscule: Selection Unites/Préfixe (Decalage C) ne marchant pas."+NL};
 LOCAL SIPRFXEG:="
3         _m
3NANO     _m
3MILLI    _inch
1PLANCK_M _m";
 
  LOCAL ST:={"
To change the number of digits displayed:","","
Pour changez la précision affichée:"};//FR:P
  LOCAL STEG:="
@Home:
 ZIPPROUND:=n  [n=−12..12]"+NL;

  LOCAL CVT:={"
Note that not all units within a group can be converted. Conversion between groups (eg length*length to area) is not implemented here.
SI prefixes OK.
Lists and variables OK."+NL,"", "
Notez que toutes les unités d un groupe ne_peuvent pas etre convertis.
SI préfixes OK.
Listes et variables OK."+NL};

  LOCAL TRBY:="Traduit par "+SG+" et ......";

  PRINT(); PRINT(CRID);
 
  OK:=CHOOSE(CHS,WHELP(SL),HC);
  IF CHS THEN
   PRINT(HC(CHS));
   CASE
    IF CHS==1 THEN ABOUT() END;
    IF CHS==3 THEN 
     PRINT(CVT(SL));WAIT;
     OK:=MSGBOX(SIPRFX(SL),1);
     OK:=MSGBOX(SIPRFXEG,1);
    END;
    IF CHS==6 THEN PRINT(TRBY) END;
    IF CHS==8 THEN PRINT(ST(SL)+STEG) END;
    DEFAULT
   END;
   WAIT;
  END;
 END;

 DEFLT_LANG()
 BEGIN
  LOCAL DEF:=1;//PROG DEFAULT
  IF Language==1  OR Language==3 THEN
   DEF:=Language;
  END;
  RETURN DEF;
 END;

 SELECT_LANGUAGE()
 BEGIN
  LOCAL CHS;
  //LOCAL DEF:=1;//PROG DEFAULT IF LANG UNKNOWN
  
  CHOOSE(CHS,LANGS(SL),CONCAT(LANGS,{WSYS(SL)}));//CURRENT
  IF CHS AND CHS≠2 THEN
   SL:=CHS;
   IF CHS==4 THEN SL:=DEFLT_LANG(); END;
  END;
 END;

 Z_UNITS_DO ()
 BEGIN
  LOCAL CHS;

  SL:=DEFLT_LANG();
  REPEAT 
   CHOOSE(CHS,CRID,CHOICES(SL));
   CASE
    IF CHS==1 THEN Z_UNITS_HELP() END;
    IF CHS==3 THEN Z_CONVERT_UNITS() END;
    IF CHS==4 THEN 
     MSGBOX(MEASURE_INTERVAL_S()+" s",1);
     VS:=MEAS_INTERVAL_S;//?ALWAYS?OR ONLY WHEN 0?
    END;
   
    IF CHS==7 THEN CHS:=0 END;
    IF CHS==6 THEN SELECT_LANGUAGE() END;
    DEFAULT
   END;
   
  UNTIL CHS==0;

 END;

 EXPORT Z_UNITS()
 BEGIN
  Z_UNITS_DO();
 END;
Francais: pour convertir des unites.


RE: Z UNITS: A program for converting units - StephenG1CMZ - 04-24-2016 11:43 AM

Salvomic reported that this program does not compile.

The problem is 6 spurious spaces, which are visible on the Android emulator but not visible on some systems. Simply remove those spaces and it will work.

Change 3 lines containing variations of "HLP3 (SL)" to "HLP3(SL)" - the position of the space is different on each line.

Change "a cre" to "acre"
Change "1_ gal" to "1_gal"
Change "1_th erm" to "1_therm"

Apologies to Salvomic for cluttering up his thread with this issue.


RE: Z UNITS: A program for converting units - salvomic - 04-24-2016 08:23 PM

(04-24-2016 11:43 AM)StephenG1CMZ Wrote:  ...
Apologies to Salvomic for cluttering up his thread with this issue.

you're welcome, and thank you for the correction!
Salvo