Post Reply 
A program to toggle between prefixes
04-23-2016, 09:09 PM
Post: #1
A program to toggle between prefixes
hi everybody,

I need an easy way to toggle between prefixes (a,f,p,n,µ,m ... k,M,G,T,P,E) and write them after a number.
For example:
I have 0.135 and I would like to toggle: 135 m, 135000 µ, 135000000 n ...
or I have 135000 and I would like to toggle 135 k, 0.135 M, 0.000135 G and so on...
This purpose having or not having regard to the unit of measure (i.e. V, F, ohm...), like in some Casio calculator (with the ←ENG and ENG→ buttons)...
I mean to toggle back and forward from any number in a simple way (like with user keystrokes or other way with *very few* keystroke pressing)...

Any idea?

Salvo

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
04-23-2016, 09:49 PM (This post was last modified: 04-23-2016 10:02 PM by StephenG1CMZ.)
Post: #2
RE: A program to toggle between prefixes
That sounds like it would be very useful to have.

Perhaps some of the code in my Z UNITS program will inspire someone to find a good solution.

That program supports prefixes, but as it stands it's not what you want:
1 - it is a standalone program (so you'd need to retype your number)
2 -- it is unit specific.

So, as it stands, the program should let you convert, say,
3*MEGA V to V (with my program recognising MEGA as a numerical value)
..but will only do the reverse
3 V to MV
If MV is a calculator-supported unit conversion.

But perhaps there is something in there that will help towards a better solution.

Stephen Lewkowicz (G1CMZ)
Visit this user's website Find all posts by this user
Quote this message in a reply
04-23-2016, 09:52 PM (This post was last modified: 04-23-2016 09:56 PM by salvomic.)
Post: #3
RE: A program to toggle between prefixes
(04-23-2016 09:49 PM)StephenG1CMZ Wrote:  That sounds like it would be very useful to have.

Perhaps some of the code in my Z UNITS program will inspire someone to find a good solution.

...

But perhaps there is something in there that will help.

Hi Stephen,
I'll see the code in your program, thank you.

Salvo

Update: checked, but I get error at line 224...

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
04-23-2016, 10:16 PM
Post: #4
RE: A program to toggle between prefixes
(04-23-2016 09:52 PM)salvomic Wrote:  
(04-23-2016 09:49 PM)StephenG1CMZ Wrote:  That sounds like it would be very useful to have.

Perhaps some of the code in my Z UNITS program will inspire someone to find a good solution.

...

But perhaps there is something in there that will help.

Hi Stephen,
I'll see the code in your program, thank you.

Salvo

Update: checked, but I get error at line 224...

I can't see line numbers on my Android, but at a guess that is a long line...
I have seen an issue before with cut and paste putting in the occasional wrong kind of Unicode space. Just deleting the space or deleting it and retyping it will probably make the error go away.

If that doesn't help, there is a slightly older version of Z UNITS within an old version of ZIPP - you could try that.

Stephen Lewkowicz (G1CMZ)
Visit this user's website Find all posts by this user
Quote this message in a reply
04-23-2016, 10:21 PM (This post was last modified: 04-23-2016 10:30 PM by salvomic.)
Post: #5
RE: A program to toggle between prefixes
(04-23-2016 10:16 PM)StephenG1CMZ Wrote:  I can't see line numbers on my Android, but at a guess that is a long line...

maybe the error is about here
Code:

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;

Better, I need something between your Z Units program and this ENG program (ENG) to toggle ENG powers and prefixes...

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
04-23-2016, 10:30 PM (This post was last modified: 04-23-2016 10:58 PM by StephenG1CMZ.)
Post: #6
RE: A program to toggle between prefixes
(04-23-2016 10:21 PM)salvomic Wrote:  
(04-23-2016 10:16 PM)StephenG1CMZ Wrote:  I can't see line numbers on my Android, but at a guess that is a long line...

maybe the error is about here
Code:

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;

I just checked it - there are about 6 lines that need changing.
All are spaces that shouldn't be there.
HLP3 (SL) should be HLP3(SL) (three lines, each with a differently positioned space)
a cre should be acre
1_ gal should be 1_gal
1_th erm should be 1_therm

When I download my version to Android, I see those extra spaces...
Hope it helps

Stephen Lewkowicz (G1CMZ)
Visit this user's website Find all posts by this user
Quote this message in a reply
04-23-2016, 10:40 PM
Post: #7
RE: A program to toggle between prefixes
there was some invisible spaces...

this should works
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;

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
04-23-2016, 11:12 PM
Post: #8
RE: A program to toggle between prefixes
For me, that version still has the unwanted visible spaces - or the Android is putting them back in. I find I need to manually edit the 6 lines after downloading.

Stephen Lewkowicz (G1CMZ)
Visit this user's website Find all posts by this user
Quote this message in a reply
04-24-2016, 07:26 AM
Post: #9
RE: A program to toggle between prefixes
(04-23-2016 11:12 PM)StephenG1CMZ Wrote:  For me, that version still has the unwanted visible spaces - or the Android is putting them back in. I find I need to manually edit the 6 lines after downloading.

maybe Android put in again the invisible space, I've pasted here in Mac OS X via Parallels Windows 10, as I do always...

Salvo

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
04-24-2016, 11:57 AM
Post: #10
RE: A program to toggle between prefixes
Hi Salvomic,

The scientific notation exponent on base 10 of a value could be matched with the corresponding value in an SI prefix list, and append the prefix abbreviation, or name, on returning corresponding value. I haven't coded a routine for this, but you might have some ideas to expand on this theme. Here is an SI prefix list you might find useful, (omitting 1e0, which could be the default case) :

Code:

SI:={ 1e-24,"y","yocto",
      1e-21,"z","zepto",
      1e-18,"a","atto",
      1e-15,"f","femto",
      1e-12,"p","pico",
      1e-9,"n","nano",
      1e-6,"u","micro",
      1e-3,"m","milli",
      1e-2,"c","centi",
      1e-1,"d","deci",
      1e1,"da","deca",
      1e2,"h","hecto",
      1e3,"k","kilo",
      1e6,"M","mega",
      1e9,"G","giga",
      1e12,"T","tera",
      1e15,"P","peta",
      1e18,"E","exa",
      1e21,"Z","zetta",
      1e24,"Y","yotta"
    };

-Dale-
Find all posts by this user
Quote this message in a reply
04-24-2016, 01:24 PM
Post: #11
RE: A program to toggle between prefixes
How about loading the number into a spreadsheet...
And having adjacent cells showing all the alternatives.
Not as easy as a built-in toggle, but it might help.

Apologies for cluttering up so much of this thread with my program.

Stephen Lewkowicz (G1CMZ)
Visit this user's website Find all posts by this user
Quote this message in a reply
04-24-2016, 09:16 PM (This post was last modified: 04-25-2016 02:43 PM by salvomic.)
Post: #12
RE: A program to toggle between prefixes
thank you Dale and Stephen,
I could do something like this code (modifying the program of user cclinus in this post

(this code begin to work like the original "ENG" simulation, that I've modified to handle from E-24 to E24)...
shift-Help / lower "ENG, shift-Help * increase, shift-Help + return the normal number, shift-Help - change "Exx" into prefix...
It's a first attempt...

Code:

// Program to toggle between  ←ENG and ENG→
// define keys / * + (toggle_eng_float)

reeng();

EXPORT ENGA(x)
BEGIN
LOCAL pos,s,i;
IF TYPE(x)==0 THEN
RETURN STRING(x,4,11);
END;

IF (TYPE(x)==2) THEN
  IF (INSTRING(x," ")) THEN x:= reeng(x); END;
END;

IF (TYPE(x)==2) AND (INSTRING(x,"ᴇ24")) THEN
RETURN x;
END;
IF (TYPE(x)==2) AND (INSTRING(x,"ᴇ24")==0) THEN
s:=x;
FOR i FROM 1 TO 3 DO
pos:=INSTRING(s,".");
s(pos):=s(pos-1);
s(pos-1):=".";
IF pos==2 THEN
s:="0"+s;
END;
END;
WHILE INSTRING(s,"0ᴇ") DO
s:=REPLACE(s,"0ᴇ","ᴇ")
END;
//
s:=REPLACE(s,"ᴇ21","ᴇ24");
s:=REPLACE(s,"ᴇ18","ᴇ21");
s:=REPLACE(s,"ᴇ15","ᴇ18");
s:=REPLACE(s,"ᴇ12","ᴇ15");
s:=REPLACE(s,"ᴇ9","ᴇ12");
s:=REPLACE(s,"ᴇ6","ᴇ9");
s:=REPLACE(s,"ᴇ3","ᴇ6");
s:=REPLACE(s,"ᴇ0","ᴇ3");
s:=REPLACE(s,"ᴇ−3","ᴇ0");
s:=REPLACE(s,"ᴇ−6","ᴇ−3");
s:=REPLACE(s,"ᴇ−9","ᴇ−6");
s:=REPLACE(s,"ᴇ−12","ᴇ−9");
s:=REPLACE(s,"ᴇ−15","ᴇ−12");
s:=REPLACE(s,"ᴇ−18","ᴇ−15");
s:=REPLACE(s,"ᴇ−21","ᴇ−18");
s:=REPLACE(s,"ᴇ−24","ᴇ−21");
RETURN s;
END;
END;

EXPORT ENGB(x)
BEGIN
LOCAL pos,s,i;
IF TYPE(x)==0 THEN
RETURN STRING(x,4,11);
END;

IF (TYPE(x)==2) THEN
  IF (INSTRING(x," ")) THEN x:= reeng(x); END;
END;

IF TYPE(x)==2 AND (INSTRING(x,"ᴇ−24"))THEN
RETURN x;
END;
IF TYPE(x)==2 AND (INSTRING(x,"ᴇ−24")==0)THEN
s:=x;
FOR i FROM 1 TO 3 DO
pos:=INSTRING(s,".");
IF s(pos+1)==7431 THEN
s:=REPLACE(s,".ᴇ","0.ᴇ");
ELSE
s(pos):=s(pos+1);
s(pos+1):=".";
IF (pos==2) AND (s(1)==48) THEN
s:=RIGHT(s,DIM(s)-1);
END;
END;
END;
WHILE INSTRING(s,"0ᴇ") DO
s:=REPLACE(s,"0ᴇ","ᴇ")
END;
//
s:=REPLACE(s,"ᴇ−21","ᴇ−24");
s:=REPLACE(s,"ᴇ−18","ᴇ−21");
s:=REPLACE(s,"ᴇ−15","ᴇ−18");
s:=REPLACE(s,"ᴇ−12","ᴇ−15");
s:=REPLACE(s,"ᴇ−9","ᴇ−12");
s:=REPLACE(s,"ᴇ−6","ᴇ−9");
s:=REPLACE(s,"ᴇ−3","ᴇ−6");
s:=REPLACE(s,"ᴇ0","ᴇ−3");
s:=REPLACE(s,"ᴇ3","ᴇ0");
s:=REPLACE(s,"ᴇ6","ᴇ3");
s:=REPLACE(s,"ᴇ9","ᴇ6");
s:=REPLACE(s,"ᴇ12","ᴇ9");
s:=REPLACE(s,"ᴇ15","ᴇ12");
s:=REPLACE(s,"ᴇ18","ᴇ15");
s:=REPLACE(s,"ᴇ21","ᴇ18");
s:=REPLACE(s,"ᴇ24","ᴇ21");
RETURN s;
END;
END;

EXPORT prefix(s)
BEGIN
LOCAL t;
IF TYPE(s)==0 THEN t:= STRING(s,4,11); ELSE t:= s; END;
t:=REPLACE(t,"ᴇ−24"," y");
t:=REPLACE(t,"ᴇ−21"," z");
t:=REPLACE(t,"ᴇ−18"," a");
t:=REPLACE(t,"ᴇ−15"," f");
t:=REPLACE(t,"ᴇ−12"," p");
t:=REPLACE(t,"ᴇ−9"," n");
t:=REPLACE(t,"ᴇ−6"," μ");
t:=REPLACE(t,"ᴇ−3"," m");
t:=REPLACE(t,"ᴇ3"," k");
t:=REPLACE(t,"ᴇ6"," M");
t:=REPLACE(t,"ᴇ9"," G");
t:=REPLACE(t,"ᴇ12"," T");
t:=REPLACE(t,"ᴇ15"," P");
t:=REPLACE(t,"ᴇ18"," E");
t:=REPLACE(t,"ᴇ21"," Z");
t:=REPLACE(t,"ᴇ24"," Y");
RETURN t;
END;

EXPORT reeng(s)
BEGIN
LOCAL t;
IF TYPE(s)==0 THEN t:= STRING(s,4,11); ELSE t:= s; END;
t:=REPLACE(t," y","ᴇ−24");
t:=REPLACE(t," z","ᴇ−21");
t:=REPLACE(t," a","ᴇ−18");
t:=REPLACE(t," f","ᴇ−15");
t:=REPLACE(t," p","ᴇ−12");
t:=REPLACE(t," n","ᴇ−9");
t:=REPLACE(t," μ","ᴇ−6");
t:=REPLACE(t," m","ᴇ−3");
t:=REPLACE(t," k","ᴇ3");
t:=REPLACE(t," M","ᴇ6");
t:=REPLACE(t," G","ᴇ9");
t:=REPLACE(t," T","ᴇ12");
t:=REPLACE(t," P","ᴇ15");
t:=REPLACE(t," E","ᴇ18");
t:=REPLACE(t," Z","ᴇ21");
t:=REPLACE(t," Y","ᴇ24");
RETURN t;
END;

with this code for the user key
Code:

// this require ENGA(), ENGB(), prefix(), reeng() in a program
KEY K_Mul()
BEGIN
RETURN "ENGA(Ans)";
END;

KEY K_Div()
BEGIN
RETURN "ENGB(Ans)";
END;

KEY K_Plus()
BEGIN
RETURN "EXPR(reeng(Ans))";
END;

KEY K_Minus()
BEGIN
RETURN "prefix(Ans)";
END;

But this code need to be modified in three ways:
1. deleting the leading zeroes at the end, i.e. "1.2530000000E9" should be "1.253E9" without zeroes...
2. avoiding to have ENGA(Ans), ENGB(Ans) and prefix(Ans): for a real "ENG key" simulation it would be better don't show them
3. implementing back and forward also for prefixes like in ←ENG and ENG→ of the (modified) original program (if one want to have both systems ENG and prefixes)

Any hints?

Salvo (IT9CLU)

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
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)