Started debugging PARGEN.
[mipav.git] / mipav / src / gov / nih / mipav / model / algorithms / SymmsIntegralMapping.java
index 8c5db88..2cb707f 100644 (file)
@@ -92,7 +92,7 @@ public class SymmsIntegralMapping extends AlgorithmBase {
        // Holds text for real for types 3 and 4 and imaginary parts for type 3\r
        // Start imaginary text with ui. All text following ui is imaginary.\r
        String DEFN[] = new String[2 * MNARC];\r
-       private boolean traditionalInput = false;\r
+       private boolean traditionalInput = true;\r
        Scanner input = new Scanner(System.in);\r
        private double zzset[][] = new double[400][2];\r
        private int IBNDS[] = new int[5];\r
@@ -292,8 +292,10 @@ public class SymmsIntegralMapping extends AlgorithmBase {
        private double MD;\r
        private double HL;\r
        //From LEVCUR:\r
-       Vector<Double> Contour[];\r
-       Vector<Double>Ray[];\r
+       Vector<Double> Contour[]; // x y pairs\r
+       Vector<Double>Ray[]; // x y pairs\r
+       // From TSTPLT\r
+       Vector<Double>Boundary; // x y pairs\r
 \r
        public SymmsIntegralMapping() {\r
 \r
@@ -429,7 +431,9 @@ public class SymmsIntegralMapping extends AlgorithmBase {
                int IER[] = new int[1];\r
                int ORDRG[] = new int[1];\r
                int ORDSG[] = new int[1];\r
-               double ALPHA, PI, X, Y;\r
+               double X = 0.0;\r
+               double Y = 0.0;\r
+               double ALPHA, PI;\r
                // COMPLEX CENSY,RTUNI,U2\r
                double RTUNI[] = new double[2];\r
                double U2[] = new double[2];\r
@@ -447,6 +451,8 @@ public class SymmsIntegralMapping extends AlgorithmBase {
                final String TABC = "     +";\r
                final int CHNL = 20;\r
                // final int CHIN = 21;\r
+               String line;\r
+               String tokens[];\r
 \r
                File file;\r
                RandomAccessFile raFile = null;\r
@@ -485,7 +491,9 @@ public class SymmsIntegralMapping extends AlgorithmBase {
                } // if (traditionalInput)\r
 \r
                // **** WRITE THE SOURCE CODE FOR PARFUN\r
+               fileDir = "C:\\conformal mapping\\CONFPACK\\";\r
                file = new File(fileDir + FORTFL);\r
+               \r
                try {\r
                        raFile = new RandomAccessFile(file, "rw");\r
                } catch (IOException e) {\r
@@ -537,17 +545,26 @@ public class SymmsIntegralMapping extends AlgorithmBase {
                                        }\r
                                } // while (!validInput)\r
 \r
-                               System.out.println("What are the coordinates of the center of symmetry (X Y)?");\r
-                               CENSY[0] = input.nextDouble();\r
-                               CENSY[1] = input.nextDouble();\r
                                validInput = false;\r
                                while (!validInput) {\r
-                                       System.out.println("How many arcs are there on the fundamental boundary section?");\r
+                                   System.out.println("What are the coordinates of the center of symmetry (X,Y)?");\r
+                                   try {\r
+                                       line = input.next();\r
+                                       tokens = line.split(",");\r
+                                       CENSY[0] = Double.valueOf(tokens[0]);\r
+                                       CENSY[1] = Double.valueOf(tokens[0]);\r
+                                       validInput = true;\r
+                                   }\r
+                                   catch (Exception e) {};\r
+                               }\r
+                               validInput = false;\r
+                               while (!validInput) {\r
+                                       System.out.print("How many arcs are there on the fundamental boundary section?");\r
                                        NARCS = input.nextInt();\r
                                        if (NARCS <= MNARC - 1) {\r
                                                validInput = true;\r
                                        } else {\r
-                                               System.out.println("NARCS must be <= " + (MNARC - 1));\r
+                                               System.out.print("NARCS must be <= " + (MNARC - 1));\r
                                        }\r
                                } // while (!validInput)\r
                        } // if (SYMTY)\r
@@ -581,18 +598,45 @@ public class SymmsIntegralMapping extends AlgorithmBase {
                                } // while (!validInput)\r
                                if (TYPE == 1) {\r
                                        ARCTY[IA - 1] = TYPE;\r
-                                       System.out.println("What are the coordinates of the initial point on the line (X Y)?");\r
-                                       STAPT[IA - 1][0] = input.nextDouble();\r
-                                       STAPT[IA - 1][1] = input.nextDouble();\r
+                                       validInput = false;\r
+                                       while (!validInput) {\r
+                                               try {\r
+                                                       System.out.println("What are the coordinates of the initial point on the line (X,Y)?");\r
+                                               line = input.next();\r
+                                               tokens = line.split(",");\r
+                                               STAPT[IA - 1][0] = Double.valueOf(tokens[0]);\r
+                                               STAPT[IA - 1][1] = Double.valueOf(tokens[1]);\r
+                                               validInput = true;\r
+                                               }\r
+                                               catch (Exception e) {};\r
+                                       }\r
                                } // if (TYPE == 1)\r
                                else if (TYPE == 2) {\r
                                        ARCTY[IA - 1] = TYPE;\r
-                                       System.out.println("What are the coordinates of the initial point on the circle (X Y)?");\r
-                                       STAPT[IA - 1][0] = input.nextDouble();\r
-                                       STAPT[IA - 1][1] = input.nextDouble();\r
-                                       System.out.println("What are the coordinates of the center of the circle (X Y)?");\r
-                                       X = input.nextDouble();\r
-                                       Y = input.nextDouble();\r
+                                       validInput = false;\r
+                                       while (!validInput) {\r
+                                               try {\r
+                                                       System.out.println("What are the coordinates of the initial point on the circle (X,Y)?");\r
+                                               line = input.next();\r
+                                               tokens = line.split(",");\r
+                                               STAPT[IA - 1][0] = Double.valueOf(tokens[0]);\r
+                                               STAPT[IA - 1][1] = Double.valueOf(tokens[1]);\r
+                                               validInput = true;\r
+                                               }\r
+                                               catch (Exception e) {};\r
+                                       }\r
+                                       validInput = false;\r
+                                       while (!validInput) {\r
+                                               try {\r
+                                                       System.out.println("What are the coordinates of the center of the circle (X,Y)?");\r
+                                               line = input.next();\r
+                                               tokens = line.split(",");\r
+                                               X = Double.valueOf(tokens[0]);\r
+                                               Y = Double.valueOf(tokens[1]);\r
+                                               validInput = true;\r
+                                               }\r
+                                               catch (Exception e) {};\r
+                                       }\r
                                        System.out.println("What is the signed angle subtended at center (in units of PI)?");\r
                                        ALPHA = input.nextDouble();\r
                                        GMCO = GMCO + 1;\r
@@ -605,16 +649,34 @@ public class SymmsIntegralMapping extends AlgorithmBase {
                                } // else if (TYPE == 2)\r
                                else if ((TYPE == 3) || (TYPE == 4)) {\r
                                        ARCTY[IA - 1] = TYPE;\r
-                                       System.out.println("What are the coordinates of the initial point on the curve (X Y)?");\r
-                                       STAPT[IA - 1][0] = input.nextDouble();\r
-                                       STAPT[IA - 1][1] = input.nextDouble();\r
-                                       if (TYPE == 3) {\r
-                                               System.out.println("Enter the initial and final parameter values (X Y)");\r
-                                       } else {\r
-                                               System.out.println("Enter the initial and final polar values (in angles of PI) (X Y)");\r
+                                       validInput = false;\r
+                                       while (!validInput) {\r
+                                               try {\r
+                                                       System.out.println("What are the coordinates of the initial point on the curve (X,Y)?");\r
+                                               line = input.next();\r
+                                               tokens = line.split(",");\r
+                                               STAPT[IA - 1][0] = Double.valueOf(tokens[0]);\r
+                                               STAPT[IA - 1][1] = Double.valueOf(tokens[1]);\r
+                                               validInput = true;\r
+                                               }\r
+                                               catch (Exception e) {};\r
+                                       }\r
+                                       validInput = false;\r
+                                       while (!validInput) {\r
+                                               try {\r
+                                                       if (TYPE == 3) {\r
+                                                               System.out.println("Enter the initial and final parameter values (X,Y)");\r
+                                                       } else {\r
+                                                               System.out.println("Enter the initial and final polar values (in angles of PI) (X,Y)");\r
+                                                       }\r
+                                               line = input.next();\r
+                                               tokens = line.split(",");\r
+                                               X = Double.valueOf(tokens[0]);\r
+                                               Y = Double.valueOf(tokens[1]);\r
+                                               validInput = true;\r
+                                               }\r
+                                               catch (Exception e) {};\r
                                        }\r
-                                       X = input.nextDouble();\r
-                                       Y = input.nextDouble();\r
                                        GMCO = GMCO + 1;\r
                                        PGM[IA - 1] = GMCO;\r
                                        if (TYPE == 4) {\r
@@ -628,15 +690,15 @@ public class SymmsIntegralMapping extends AlgorithmBase {
                                        }\r
                                        for (J = 1; J <= 2; J++) {\r
                                                if (J == 1 && TYPE == 3) {\r
-                                                       System.out.println("ENTER JAVA EXPRESSION ENDING IN // FOR PARFUN");\r
+                                                       System.out.println("ENTER JAVA EXPRESSION WITH NO SPACES ENDING IN // FOR PARFUN");\r
                                                        System.out.println("PUT REAL PART ui IMAGINARY PART");\r
                                                } else if (J == 2 && TYPE == 3) {\r
-                                                       System.out.println("ENTER JAVA EXPRESSION ENDING IN // FOR DPARFN");\r
+                                                       System.out.println("ENTER JAVA EXPRESSION WITH NO SPACES ENDING IN // FOR DPARFN");\r
                                                        System.out.println("PUT REAL PART ui IMAGINARY PART");\r
                                                } else if (J == 1 && TYPE == 4) {\r
-                                                       System.out.println("ENTER JAVA EXPRESSION ENDING IN // FOR RADIUS");\r
+                                                       System.out.println("ENTER JAVA EXPRESSION WITH NO SPACES ENDING IN // FOR RADIUS");\r
                                                } else {\r
-                                                       System.out.println("ENTER JAVA EXPRESSION ENDING IN // FOR RADIUS DERIVATIVE");\r
+                                                       System.out.println("ENTER JAVA EXPRESSION WITH NO SPACES ENDING IN // FOR RADIUS DERIVATIVE");\r
                                                }\r
 \r
                                                TXCO = TXCO + 1;\r
@@ -668,9 +730,18 @@ public class SymmsIntegralMapping extends AlgorithmBase {
                        } // for (IA = 1; IA <= NARCS; IA++)\r
 \r
                        if (SYMTY) {\r
-                               System.out.println("ENTER THE COORDINATES OF FINAL POINT ON THIS LAST ARC (X Y)");\r
-                               STAPT[NARCS][0] = input.nextDouble();\r
-                               STAPT[NARCS][1] = input.nextDouble();\r
+                               validInput = false;\r
+                               while (!validInput) {\r
+                                       try {\r
+                                               System.out.println("ENTER THE COORDINATES OF FINAL POINT ON THIS LAST ARC (X,Y)");\r
+                                       line = input.next();\r
+                                       tokens = line.split(",");\r
+                                       STAPT[NARCS][0] = Double.valueOf(tokens[0]);\r
+                                       STAPT[NARCS][1] = Double.valueOf(tokens[1]);\r
+                                       validInput = true;\r
+                                       }\r
+                                       catch (Exception e) {};\r
+                               }\r
                        } else {\r
                                STAPT[NARCS][0] = STAPT[0][0];\r
                                STAPT[NARCS][1] = STAPT[0][1];\r
@@ -1284,13 +1355,24 @@ public class SymmsIntegralMapping extends AlgorithmBase {
                                for (K = IA; K <= STAPT.length; K++) {\r
                                        STAPT2[K - IA] = STAPT[K - 1];\r
                                }\r
-                               RGM2 = new double[RGM.length - I + 1];\r
-                               for (K = I; K <= RGM.length; K++) {\r
-                                       RGM2[K - I] = RGM[K - 1];\r
+                               if (ARCTY[IA-1] != 1) {\r
+                                       RGM2 = new double[RGM.length - I + 1];\r
+                                       for (K = I; K <= RGM.length; K++) {\r
+                                               RGM2[K - I] = RGM[K - 1];\r
+                                       }\r
                                }\r
-                               DEFN2 = new String[DEFN.length - J + 1];\r
-                               for (K = J; K <= DEFN.length; K++) {\r
-                                       DEFN2[K - J] = DEFN[K - 1];\r
+                               else {\r
+                                       RGM2 = null;\r
+                               }\r
+                               if ((ARCTY[IA-1] == 3) || (ARCTY[IA-1] == 4)) {\r
+                                       DEFN2 = new String[DEFN.length - J + 1];\r
+                                       for (K = J; K <= DEFN.length; K++) {\r
+                                               DEFN2[K - J] = DEFN[K - 1];\r
+                                       }\r
+                               }\r
+                               else {\r
+                                       // DEFN2 goes to TXT in PTFUN1 which is not used for TYPES 1 and 2\r
+                                       DEFN2 = null;\r
                                }\r
                                if (NARCS == 1) {\r
                                        PTFUN1(ARCTY[IA - 1], STAPT2, RGM2, NTX[IA - 1], DEFN2, CHNL, CHTT, VAR, REDD, raFile);\r
@@ -1617,17 +1699,32 @@ public class SymmsIntegralMapping extends AlgorithmBase {
                                        STAPT2[K - IA][0] = STAPT[K - 1][0];\r
                                        STAPT2[K - IA][1] = STAPT[K - 1][1];\r
                                }\r
-                               RGM2 = new double[RGM.length - I + 1];\r
-                               for (K = I; K <= RGM.length; K++) {\r
-                                       RGM2[K - I] = RGM[K - 1];\r
+                               if ((ARCTY[IA-1] == 2) || ((!NUMDER[IA-1]) && ((ARCTY[IA-1] == 3) || (ARCTY[IA-1] == 4)))) {\r
+                                       RGM2 = new double[RGM.length - I + 1];\r
+                                       for (K = I; K <= RGM.length; K++) {\r
+                                               RGM2[K - I] = RGM[K - 1];\r
+                                       }\r
+                               }\r
+                               else {\r
+                                       RGM2 = null;\r
+                               }\r
+                               if ((!NUMDER[IA-1]) && (ARCTY[IA-1] == 4)) {\r
+                                       DEFN2 = new String[DEFN.length - J1 + 1];\r
+                                       for (K = J1; K <= DEFN.length; K++) {\r
+                                               DEFN2[K - J1] = DEFN[K - 1];\r
+                                       }\r
+                               }\r
+                               else {\r
+                                       DEFN2 = null;\r
                                }\r
-                               DEFN2 = new String[DEFN.length - J1 + 1];\r
-                               for (K = J1; K <= DEFN.length; K++) {\r
-                                       DEFN2[K - J1] = DEFN[K - 1];\r
+                               if ((!NUMDER[IA-1]) && ((ARCTY[IA-1] == 3) || (ARCTY[IA-1] == 4))) {\r
+                                       DEFN3 = new String[DEFN.length - J2 + 1];\r
+                                       for (K = J2; K <= DEFN.length; K++) {\r
+                                               DEFN3[K - J2] = DEFN[K - 1];\r
+                                       }\r
                                }\r
-                               DEFN3 = new String[DEFN.length - J2 + 1];\r
-                               for (K = J2; K <= DEFN.length; K++) {\r
-                                       DEFN3[K - J2] = DEFN[K - 1];\r
+                               else {\r
+                                       DEFN3 = null;\r
                                }\r
                                if (NARCS == 1) {\r
                                        PTFUN2(ARCTY[IA - 1], STAPT2, RGM2, N1, DEFN2, N2, DEFN3, CHNL, CHTT, VAR, " 1", NUMDER[IA - 1],\r
@@ -1742,7 +1839,7 @@ public class SymmsIntegralMapping extends AlgorithmBase {
                                        raFile.writeBytes(TXT1[I - 1]);\r
                                }\r
                                raFile.writeBytes(";\n");\r
-                               raFile.writeBytes("      ZDEr = ");\r
+                               raFile.writeBytes("      ZDER = ");\r
                                for (I = 1; I <= NTX2; I++) {\r
                                        raFile.writeBytes(TXT2[I - 1]);\r
                                }\r
@@ -14445,7 +14542,7 @@ public class SymmsIntegralMapping extends AlgorithmBase {
        IER[0]=0;\r
     } // private void BMCAP1\r
        \r
-       @SuppressWarnings("unchecked")\r
+       @SuppressWarnings({ "unchecked", "unchecked" })\r
        private void LEVCUR(int NCONT, double RADII[], int NARGS, double THETA[], double RAD1[],\r
         double RAD2[], double PSD[], double MINPD[], double MAXPD[], String NEWD[], int IER[]) {\r
                \r
@@ -15119,10 +15216,12 @@ public class SymmsIntegralMapping extends AlgorithmBase {
         final int MNARC = 200;\r
         final int NH = 4;\r
         int IMX = 0;\r
-               int I,IA,L;\r
+        // int L;\r
+               int I,IA;\r
                final double DTOL = 0.1;\r
-        double A1,DIFF,ERR,HH,MINC,R1MACH,RMAX,RMEAN,RMIN,T,TINC,\r
-            TOL1,TMX,TSD;\r
+               double TINC = 0.0;\r
+               double TMX = 0.0;\r
+        double A1,DIFF,ERR,HH,MINC,RMAX,RMEAN,RMIN,T,TOL1,TSD;\r
         double TT[] = new double[2];\r
         //REAL TT(2)\r
         double C1[] = new double[2];\r
@@ -15139,6 +15238,9 @@ public class SymmsIntegralMapping extends AlgorithmBase {
         boolean LNSEG[]  = new boolean[MNARC];\r
         double PIN[] = new double[2];\r
         double POUT[];\r
+        double cr[] = new double[1];\r
+        double ci[] = new double[1];\r
+        Boundary = new Vector<Double>();\r
         //EXTERNAL DPARFN,LINSEG,PARFUN,R1MACH,WRHEAD,WRTAIL,ZDPARF\r
 \r
         // WRITE CONFPACK HEADING\r
@@ -15248,12 +15350,14 @@ public class SymmsIntegralMapping extends AlgorithmBase {
         // TESTING\r
 \r
         MXDIF[0]=0.0;\r
-        /*for (IA=1; IA <= NARCS; IA++) {\r
+        for (IA=1; IA <= NARCS; IA++) {\r
             TT[0]=-1.0;\r
             PIN[0] = TT[0];\r
             PIN[1] = 0.0;\r
             ZZ[0]=PARFUN(IA,PIN);\r
             //WRITE(CHNL,'(2E16.7)') ZZ(1)\r
+            Boundary.add(ZZ[0][0]);\r
+            Boundary.add(ZZ[0][1]);\r
             if (IA==1) {\r
                ZZ0[0]=ZZ[0][0];\r
                ZZ0[1]=ZZ[0][1];\r
@@ -15286,8 +15390,8 @@ public class SymmsIntegralMapping extends AlgorithmBase {
                         Preferences.debug("              ***DPARFN=(0.,0.)***\n", Preferences.DEBUG_ALGORITHM);\r
                         System.out.println("                             ARC: " + IA); \r
                         Preferences.debug("                             ARC: " + IA + "\n", Preferences.DEBUG_ALGORITHM);\r
-                        System.out.println("STANDARDISED PARAMETER VALUE: " + TT[0][0] + " , " + TT[0][1]);\r
-                        Preferences.debug("STANDARDISED PARAMETER VALUE: " + TT[0][0] + " , " + TT[0][1] + "\n", Preferences.DEBUG_ALGORITHM);\r
+                        System.out.println("STANDARDISED PARAMETER VALUE: " + TT[0]);\r
+                        Preferences.debug("STANDARDISED PARAMETER VALUE: " + TT[0] + "\n", Preferences.DEBUG_ALGORITHM);\r
                         WRTAIL(7,0,IER[0],null);\r
                         return;\r
                     } // if (A1 == 0.0)\r
@@ -15299,73 +15403,93 @@ public class SymmsIntegralMapping extends AlgorithmBase {
                         Preferences.debug("PATHOLOGICALLY SMALL DERIVATIVE ON ARC " + IA + "\n", Preferences.DEBUG_ALGORITHM);\r
                         WARND=true;\r
                     } // if (A1 <= TOL1 && !WARND)\r
-C\r
-        IF (FIRST) THEN\r
-          TINC=RMEAN/A1\r
-          TINC=MAX(TINC,MINC)\r
-          FIRST=.FALSE.\r
-        ENDIF\r
-C\r
-        ERR=ABS(1E+0-NDZZ/DZZ)\r
-        IF (ERR.GT.MXDIF) THEN\r
-          MXDIF=ERR\r
-          IMX=IA\r
-          TMX=TT(1)\r
-        ENDIF\r
+\r
+                    if (FIRST) {\r
+                        TINC=RMEAN/A1;\r
+                        TINC=Math.max(TINC,MINC);\r
+                        FIRST=false;\r
+                    } // if (FIRST)\r
+\r
+                    zdiv(NDZZ[0],NDZZ[1],DZZ[0],DZZ[1],cr,ci);\r
+                    ERR = zabs(1.0 - cr[0], -ci[0]);\r
+                    if (ERR > MXDIF[0]) {\r
+                        MXDIF[0]=ERR;\r
+                        IMX=IA;\r
+                        TMX=TT[0];\r
+                    } // if (ERR > MXDIF[0])\r
                 } // for (I=1; I <= 2; I++)\r
-C\r
-      IF (.NOT.LNSEG(IA)) THEN\r
-C\r
-C****     DETERMINE THE NEXT BOUNDARY POINT TO BE PLOTTED\r
-C\r
-40        CONTINUE\r
-        TT(2)=TT(1)+TINC\r
-        IF (TT(2) .GE. 1E+0) THEN\r
-          TT(2)=1E+0\r
-          ATEND=.TRUE.\r
-        ELSE\r
-          ATEND=.FALSE.\r
-        ENDIF\r
-C\r
-        ZZ(2)=PARFUN(IA,CMPLX(TT(2)))\r
-        DIFF=ABS(ZZ(2)-ZZ(1))\r
-        IF (DIFF.EQ.0E+0 .AND. .NOT.ATEND) THEN\r
-          TINC=MAX(MINC,2*TINC)\r
-          GOTO 40\r
-        ENDIF\r
-C\r
-        IF (DIFF.GT.RMAX .OR. (DIFF.LT.RMIN .AND. .NOT.ATEND)) THEN\r
-          TINC=RMEAN*TINC/DIFF\r
-          TINC=MAX(TINC,MINC)\r
-          GOTO 40\r
-        ENDIF\r
-C\r
-        WRITE(CHNL,'(2E16.7)') ZZ(2)\r
-        IF (.NOT. ATEND) THEN\r
-          ZZ(1)=ZZ(2)\r
-          TT(1)=TT(2)\r
-          continue;\r
-        ENDIF\r
-      ENDIF\r
-      break;\r
+\r
+                if (!LNSEG[IA-1]) {\r
+\r
+                       // DETERMINE THE NEXT BOUNDARY POINT TO BE PLOTTED\r
+\r
+                       while (true) {\r
+                        TT[1]=TT[0]+TINC;\r
+                        if (TT[1] >= 1.0) {\r
+                            TT[1]=1.0;\r
+                            ATEND=true;\r
+                        }\r
+                        else {\r
+                            ATEND=false;\r
+                        }\r
+\r
+                        PIN[0] = TT[1];\r
+                        PIN[1] = 0.0;\r
+                        ZZ[1]=PARFUN(IA,PIN);\r
+                       DIFF=zabs(ZZ[1][0]-ZZ[0][0],ZZ[1][1]-ZZ[0][1]);\r
+                       if (DIFF == 0.0 && !ATEND) {\r
+                           TINC=Math.max(MINC,2*TINC);\r
+                           continue;\r
+                       } // if (DIFF == 0.0 && !ATEND) \r
+\r
+                       if (DIFF > RMAX || (DIFF < RMIN && !ATEND)) {\r
+                           TINC=RMEAN*TINC/DIFF;\r
+                           TINC=Math.max(TINC,MINC);\r
+                           continue;\r
+                       } // if (DIFF > RMAX || (DIFF < RMIN && !ATEND))\r
+                       break;\r
+                       } // while (true)\r
+\r
+                    // WRITE(CHNL,'(2E16.7)') ZZ(2)\r
+                       Boundary.add(ZZ[1][0]);\r
+                       Boundary.add(ZZ[1][1]);\r
+                    if (!ATEND) {\r
+                       ZZ[0][0] = ZZ[1][0];\r
+                       ZZ[0][1] = ZZ[1][1];\r
+                       TT[0]=TT[1];\r
+                        continue;\r
+                    } // if (!ATEND)\r
+                } // if (!LNSEG[IA-1])\r
+                break;\r
             } // while(true)\r
-C\r
+\r
         } // for (IA=1; IA <= NARCS; IA++)\r
-    IF (LNSEG(NARCS)) WRITE(CHNL,'(2E16.7)') ZZ0\r
-    CLOSE(CHNL)   \r
-C\r
-    IF (MXDIF .GT. DTOL) THEN\r
-      WRITE(*,*)\r
-      WRITE(*,2) 'POSSIBLE PARFUN/DPARFN INCONSISTECY ON ARC:',IMX\r
-      WRITE(*,3) 'OCCURS AT STANDARDISED PARAMETER VALUE:',TMX\r
-      WRITE(*,3) 'RELATIVE FINITE DIFF ERROR:',MXDIF \r
-    ELSE\r
-      WRITE(*,*)\r
-      WRITE(*,1) 'PARFUN AND DPARFN ARE CONSISTENT:'\r
-    ENDIF\r
-C\r
-999   CALL WRTAIL(7,0,IER)\r
-C */\r
+        if (LNSEG[NARCS-1]) {\r
+               //WRITE(CHNL,'(2E16.7)') ZZ0\r
+               Boundary.add(ZZ0[0]);\r
+               Boundary.add(ZZ0[1]);\r
+        }\r
+    \r
+\r
+        if (MXDIF[0] > DTOL) {\r
+            System.out.println();\r
+            Preferences.debug("\n",Preferences.DEBUG_ALGORITHM);\r
+            System.out.println("POSSIBLE PARFUN/DPARFN INCONSISTECY ON ARC: " + IMX);\r
+            Preferences.debug("POSSIBLE PARFUN/DPARFN INCONSISTECY ON ARC: " + IMX + "\n",Preferences.DEBUG_ALGORITHM);\r
+            System.out.println("OCCURS AT STANDARDISED PARAMETER VALUE: " + TMX);\r
+            Preferences.debug("OCCURS AT STANDARDISED PARAMETER VALUE: " + TMX + "\n", Preferences.DEBUG_ALGORITHM);\r
+            System.out.println("RELATIVE FINITE DIFF ERROR: " + MXDIF[0]);\r
+            Preferences.debug("RELATIVE FINITE DIFF ERROR: " + MXDIF[0] + "\n", Preferences.DEBUG_ALGORITHM);\r
+        } // if (MXDIF[0] > DTOL)\r
+        else {\r
+            System.out.println();\r
+            Preferences.debug("\n", Preferences.DEBUG_ALGORITHM);\r
+            System.out.println("PARFUN AND DPARFN ARE CONSISTENT:");\r
+            Preferences.debug("PARFUN AND DPARFN ARE CONSISTENT:\n", Preferences.DEBUG_ALGORITHM);\r
+        }\r
+\r
+        WRTAIL(7,0,IER[0],null);\r
\r
     } // private void TSTPLT\r
        \r
        \r