HP Forums
Help, I have a syntax error - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Help, I have a syntax error (/thread-4850.html)



Help, I have a syntax error - Powersoft - 10-01-2015 06:20 PM

Hello,

In this small code part I get an error.
The error is on the "else" and I marked the code.
Please have a look. I could not find the error.

Thanks for any help.

Jan



B23p_T(T);
p4_T(T);

//********************************************************************************​***************************
//*3 Region Selection
//********************************************************************************​***************************
//*3.1 Regions as a function of pT
EXPORT region_pT(p, T)
BEGIN
LOCAL dummy,ps;
IF T > 1073.15 AND p < 10 AND T < 2273.15 AND p > 0.000611 THEN
dummy := 5;
ELSE
IF T <= 1073.15 AND T > 273.15 AND p <= 100 AND p > 0.000611 THEN
IF T > 623.15 THEN
IF p > B23p_T(T) THEN
dummy := 3;
IF T < 647.096 THEN
ps := p4_T(T);
IF abs(p - ps) < 0.00001 THEN
dummy := 4;
END;
END;
ELSE
dummy := 2;
END;
ELSE
ps := p4_T(T);
IF abs(p - ps) < 0.00001 THEN
dummy := 4;
ELSE IF p > ps THEN
dummy := 1;
ELSE
dummy := 2;
END;
END;
ELSE <== ERROR ?????????
dummy := 0; //**Error, Outside valid area
END;
END;
RETURN dummy;
END;


RE: Help, I have a syntax error - Han - 10-01-2015 06:25 PM

(10-01-2015 06:20 PM)Powersoft Wrote:  
Code:

//********************************************************************************​***************************
//*3 Region Selection
//********************************************************************************​***************************
//*3.1 Regions as a function of pT
EXPORT region_pT(p, T)
BEGIN
LOCAL dummy,ps;
IF T > 1073.15 AND p < 10 AND T < 2273.15 AND p > 0.000611 THEN
    dummy := 5;
ELSE 
  IF T <= 1073.15 AND T > 273.15 AND p <= 100 AND p > 0.000611 THEN
    IF T > 623.15 THEN
        IF p > B23p_T(T) THEN
            dummy := 3;
            IF T < 647.096 THEN
                ps := p4_T(T);
                IF abs(p - ps) < 0.00001 THEN
                    dummy := 4;
                END;
            END;
        ELSE
            dummy := 2;
        END;
    ELSE
        ps := p4_T(T);
        IF abs(p - ps) < 0.00001  THEN
            dummy := 4;
        ELSE IF p > ps THEN // <-- here is your problem; IF THEN without END
            dummy := 1;
        ELSE
            dummy := 2;
        END;
    END;
  ELSE  <==  ERROR ?????????
    dummy := 0; //**Error, Outside valid area
  END;
END;
RETURN dummy;
END;

IF THEN without END nested inside and ELSE statement... I commented the spot within your code


RE: Help, I have a syntax error - Powersoft - 10-01-2015 06:41 PM

Han thanks, but I'm lost in space.

This is my original Matlab code, but I have some problems with
the "elseif"
Please can you help me with this?

Cheers

Jan

Code:

function region_pT = region_pT(p, T)
if T > 1073.15 && p < 10 && T < 2273.15 && p > 0.000611 
    region_pT = 5;
elseif T <= 1073.15 && T > 273.15 && p <= 100 && p > 0.000611 
    if T > 623.15 
        if p > B23p_T(T) 
            region_pT = 3;
            if T < 647.096 
                ps = p4_T(T);
                if abs(p - ps) < 0.00001
                    region_pT = 4;
                end
            end
        else
            region_pT = 2;
        end
    else
        ps = p4_T(T);
        if abs(p - ps) < 0.00001 
            region_pT = 4;
        elseif p > ps
            region_pT = 1;
        else
            region_pT = 2;
        end
    end
else
    region_pT = 0; %**Error, Outside valid area
end



RE: Help, I have a syntax error - Han - 10-01-2015 06:58 PM

It's explained here: https://nf.nci.org.au/facilities/software/Matlab/techdoc/ref/elseif.html

Try:

Code:

//********************************************************************************​​***************************
//*3 Region Selection
//********************************************************************************​​***************************
//*3.1 Regions as a function of pT
EXPORT region_pT(p, T)
BEGIN
LOCAL dummy,ps;
IF T > 1073.15 AND p < 10 AND T < 2273.15 AND p > 0.000611 THEN
    dummy := 5;
ELSE 
  IF T <= 1073.15 AND T > 273.15 AND p <= 100 AND p > 0.000611 THEN
    IF T > 623.15 THEN
        IF p > B23p_T(T) THEN
            dummy := 3;
            IF T < 647.096 THEN
                ps := p4_T(T);
                IF abs(p - ps) < 0.00001 THEN
                    dummy := 4;
                END;
            END;
        ELSE
            dummy := 2;
        END;
    ELSE
        ps := p4_T(T);
        IF abs(p - ps) < 0.00001  THEN
            dummy := 4;
        ELSE 
            IF p > ps THEN
                dummy := 1;
            ELSE
                dummy := 2;
            END;
        END;
    END;
  ELSE  
    dummy := 0; //**Error, Outside valid area
  END;
END;
RETURN dummy;
END;