Porting continues.
authorilb@NIH.GOV <ilb@NIH.GOV@ba61647d-9d00-f842-95cd-605cb4296b96>
Thu, 21 Dec 2017 21:58:34 +0000 (21:58 +0000)
committerilb@NIH.GOV <ilb@NIH.GOV@ba61647d-9d00-f842-95cd-605cb4296b96>
Thu, 21 Dec 2017 21:58:34 +0000 (21:58 +0000)
git-svn-id: https://citdcbmipav.cit.nih.gov/repos-pub/mipav/trunk@15318 ba61647d-9d00-f842-95cd-605cb4296b96

mipav/src/gov/nih/mipav/model/algorithms/SymmsIntegralMapping.java

index 1ffc512..d133cc7 100644 (file)
@@ -3,6 +3,7 @@ package gov.nih.mipav.model.algorithms;
 import java.io.File;\r
 import java.io.IOException;\r
 import java.io.RandomAccessFile;\r
+import java.util.Scanner;\r
 \r
 import gov.nih.mipav.model.structures.ModelImage;\r
 import gov.nih.mipav.view.MipavUtil;\r
@@ -13,12 +14,13 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
        // EPS returns the distance from 1.0 to the next larger double-precision number, that is, eps = 2^-52.\r
     private double EPS;\r
     // Filename to receive FORTRAN output code\r
-    private String FORTFL;\r
+    private String FORTFL = null;\r
     // Does the domain have any symmetry?\r
     private boolean SYMTY;\r
     // If SYMTY is true, are there any reflectional symmetries?\r
     private boolean REFLN;\r
     // If SYMTY is true, what are the coordinates of the center of symmetry?\r
+    private final int MNARC = 100;\r
     private double CENSY[] = new double[2];\r
     // If SYMTY is true, number of arcs on the fundamental boundary section\r
     // If SYMTY is false, number of arcs on the boundary\r
@@ -26,11 +28,11 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
     private int NARCS;\r
     // NUMDER is of length MNARC\r
     // NUMDER is initially false\r
-    private boolean NUMDER[];\r
+    private boolean NUMDER[] = new boolean[MNARC];\r
     // ARCTY is of length MNARC\r
     // Type of arc, 1 = LINE SEGMENT, 2 = CIRCULAR ARC SEGMENT, 3 = CARTESIAN PARAMETRIC FUNCTION\r
     // 4 = POLAR FUNCTION\r
-    private int ARCTY[];\r
+    private int ARCTY[] = new int[MNARC];\r
     // STAPT is of length MNARC,2\r
     // Initial point on line, initial point on circle, or initial point on curve\r
     // IF (SYMTY) THEN\r
@@ -39,7 +41,7 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
     //ELSE\r
     // STAPT[NARCS]=STAPT[1]\r
     //ENDIF\r
-    private double STAPT[][];\r
+    private double STAPT[][] = new double[MNARC][2];\r
     // Start with GMCO = 0\r
     // For types 2, 3, and 4 increment GMCO and put\r
     //GMCO=GMCO+1\r
@@ -60,9 +62,9 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
     // GMCO=GMCO+1\r
     // RGM[GMCO-1]= (final polar angle in units of PI) *PI\r
     // PGM is of length MNARC\r
-    private int PGM[];\r
+    private int PGM[] = new int[MNARC];\r
     // RGM is of length 3*MNARC\r
-    private double RGM[];\r
+    private double RGM[] = new double[3*MNARC];\r
     // Start with TXCO = 0\r
     // For types 3 and 4\r
     // For each IA = 1 to NARCS do J = 1,2\r
@@ -70,21 +72,28 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
     //PTX[IA-1+(J-1)*MNARC]=TXCO\r
     // DEFN[TXCO-1][0]= TXT for real part\r
     // DEFN[TXCO-1][1] = TXT for imaginary part\r
-    // where TXT = A COMPLEX EXPRESSION\r
+    // where TXT = A COMPLEX EXPRESSION for TYPE 3 and a REAL EXPRESSION FOR TYPE 4\r
     // for J = 1 and TYPE = 3 JAVA EXPRESSION FOR PARFUN\r
     // for J = 2 and TYPE = 3 JAVA EXPRESSION FOR DPARFN\r
     // for J = 1 and TYPE = 4 JAVA EXPRESSION FOR RADIUS\r
     // for J = 2 and TYPE = 4 JAVA EXPRESSION FOR RADIUS DERIVATIVE\r
     // PTX is of length 2*MNARC\r
-    private int PTX[];\r
+    private int PTX[] = new int[2*MNARC];\r
+    private int NTX[]= new int[2*MNARC];\r
+    //CHARACTER DEFN(MNARC*2)*72\r
+    // 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
+    Scanner input = new Scanner(System.in);\r
     \r
        public SymmsIntegralMapping() {\r
                \r
        }\r
        \r
        public SymmsIntegralMapping(ModelImage destImg, ModelImage srcImg, String FORTFL, boolean SYMTY,\r
-                       boolean REFLN, double CENSY[], int NARCS, boolean NUMDER[], double STAPT[][],\r
-                       int PGM[], double RGM[], int PTX[]) {\r
+                       boolean REFLN, double CENSY[], int NARCS, boolean NUMDER[], int ARCTY[], double STAPT[][],\r
+                       int PGM[], double RGM[], int PTX[], int NTX[], String DEFN[]) {\r
            super(destImg, srcImg);\r
            this.FORTFL = FORTFL;\r
            this.SYMTY = SYMTY;\r
@@ -92,10 +101,13 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
            this.CENSY = CENSY;\r
            this.NARCS = NARCS;\r
            this.NUMDER = NUMDER;\r
+           this.ARCTY = ARCTY;\r
            this.STAPT = STAPT;\r
            this.PGM = PGM;\r
            this.RGM = RGM;\r
            this.PTX = PTX;\r
+           this.NTX = NTX;\r
+           this.DEFN = DEFN;\r
        }\r
        \r
        public void runAlgorithm() {\r
@@ -205,7 +217,8 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
        //     LOCAL VARIABLES\r
        //\r
              int GMCO,IA,I,J,L,SW,\r
-                 TXCO,TYPE;\r
+                 TXCO;\r
+             int TYPE = 1;\r
              int IER[] = new int[1];\r
              int ORDRG[] = new int[1];\r
              int ORDSG[] = new int[1];\r
@@ -217,7 +230,6 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
             // CHARACTER TXT*72,TABC*6,FORTFL*72,CH*2,SIG(10)*2,WID(10)*2,REDD*6,\r
             //+FMT1*8,FMT2*9\r
              String TXT;\r
-             String FORTFL;\r
              String CH;\r
              String SIG[] = new String[]{"7","8","9","10","11","12","13","14","15","16"};\r
              String WID[] = new String[]{"15","16","17","18","19","20","21","22","23","24"};\r
@@ -226,16 +238,13 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
              String FMT2;\r
        \r
              //PARAMETER (MNARC=100,TABC='     +',CHNL=20,CHIN=21)\r
-             final int MNARC = 100;\r
              final String TABC = "     +";\r
              final int CHNL = 20;\r
              final int CHIN = 21;\r
-             int NTX[] = new int[2*MNARC];\r
-             //CHARACTER DEFN(MNARC*2)*72\r
-             // Holds text for real and imaginary parts\r
-             String DEFN[][]= new String[2*MNARC][2];\r
+             \r
              File file;\r
              RandomAccessFile raFile = null;\r
+             boolean validInput;\r
        \r
              //EXTERNAL CHRIN,HEADER,R1MACH,SYINF1,WRFUN1,WRFUN2,WRHEAD,WRSYM1,\r
              //+WRSYM2,WRSYM3,WRTAIL\r
@@ -263,10 +272,15 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
                \r
                  REDD="E"+WID[SW-1]+"."+SIG[SW-1]; \r
                  FMT1="("+REDD+")";\r
-                 FMT2="(2"+REDD+")"; \r
+                 FMT2="(2"+REDD+")";\r
+                 \r
+                 if (traditionalInput) {\r
+                     System.out.println("ENTER FILENAME TO RECEIVE OUTPUT JAVA CODE");  \r
+                     FORTFL = input.next();\r
+                 } // if (traditionalInput)\r
              \r
              //**** WRITE THE SOURCE CODE FOR PARFUN\r
-             file = new File(fileDir + "FORTFL");\r
+             file = new File(fileDir + FORTFL);\r
              try {\r
                  raFile = new RandomAccessFile(file, "rw");\r
              }\r
@@ -285,8 +299,214 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
              }\r
 \r
              //OPEN(CHNL,FILE=FORTFL)\r
+             \r
+             if (traditionalInput) {\r
+                 validInput = false;\r
+                 while (!validInput) {\r
+                     System.out.println("DOES THE DOMAIN HAVE ANY SYMMETRY (Y/N)?");\r
+                     String sym = input.next();\r
+                     String firstSym = sym.substring(0,1);\r
+                     if (firstSym.equalsIgnoreCase("Y")) {\r
+                         SYMTY = true;\r
+                         validInput = true;\r
+                     }\r
+                     else if (firstSym.equalsIgnoreCase("N")) {\r
+                         SYMTY = false;\r
+                         validInput = true;\r
+                     }\r
+                     else {\r
+                         System.out.println(sym + " is not a valid response");\r
+                     }\r
+                 } // while (!validInput)\r
+                 \r
+                 if (SYMTY) {\r
+                         validInput = false;\r
+                         while (!validInput) {\r
+                             System.out.println("ARE THERE ANY REFLECTIONAL SYMMETRIES (Y/N)?");\r
+                             String ref = input.next();\r
+                             String firstRef = ref.substring(0,1);\r
+                             if (firstRef.equalsIgnoreCase("Y")) {\r
+                                 REFLN = true;\r
+                                 validInput = true;\r
+                             }\r
+                             else if (firstRef.equalsIgnoreCase("N")) {\r
+                                 REFLN = false;\r
+                                 validInput = true;\r
+                             }\r
+                             else {\r
+                                 System.out.println(ref + " is not a valid response");\r
+                             }\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
+                             NARCS = input.nextInt();\r
+                             if (NARCS <= MNARC-1) {\r
+                                 validInput = true;\r
+                             }\r
+                             else {\r
+                                 System.out.println("NARCS must be <= " + (MNARC-1));\r
+                             }\r
+                         } // while (!validInput)\r
+                 } // if (SYMTY)\r
+                 else { // !SYMTY\r
+                         validInput = false;\r
+                         while (!validInput) {\r
+                                 System.out.println("How many arcs are there on the boundary?");\r
+                                 NARCS = input.nextInt();\r
+                                 if (NARCS <= MNARC-1) {\r
+                                 validInput = true;\r
+                             }\r
+                             else {\r
+                                 System.out.println("NARCS must be <= " + (MNARC-1));\r
+                             }\r
+                         } // while (!validInput)\r
+                 } // else !SYMTY\r
+                 \r
+                 GMCO = 0;\r
+                 TXCO = 0;\r
+                 \r
+                 for (IA = 1; IA <= NARCS; IA++) {\r
+                           NUMDER[IA-1] = false; \r
+                           validInput = false;\r
+                           while (!validInput) {\r
+                               System.out.println("ENTER THE TYPE OF ARC(1-4) for ARC NUMBER " + IA);\r
+                               TYPE = input.nextInt();\r
+                               if ((TYPE >= 1) && (TYPE <= 4)) {\r
+                                       validInput = true;\r
+                               }\r
+                               else {\r
+                                       System.out.println("TYPE MUST BE BETWEEN 1 and 4");\r
+                               }\r
+                           } // 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
+                           } // 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
+                               System.out.println("What is the signed angle subtended at center (in units of PI)?");\r
+                               ALPHA = input.nextDouble();\r
+                               GMCO=GMCO+1;\r
+                               PGM[IA-1]=GMCO;\r
+                               RGM[GMCO-1]=X;\r
+                               GMCO=GMCO+1;\r
+                               RGM[GMCO-1]=Y;\r
+                               GMCO=GMCO+1;\r
+                               RGM[GMCO-1]=ALPHA*PI;\r
+                           } // 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
+                               }\r
+                               else {\r
+                                       System.out.println("Enter the initial and final polar values (in angles of PI) (X Y)");\r
+                               }\r
+                               X = input.nextDouble();\r
+                               Y = input.nextDouble();\r
+                               GMCO=GMCO+1;\r
+                               PGM[IA-1]=GMCO;\r
+                               if (TYPE == 4) {\r
+                                 RGM[GMCO-1]=X*PI;\r
+                                 GMCO=GMCO+1;\r
+                                 RGM[GMCO-1]=Y*PI;\r
+                               }\r
+                               else {\r
+                                 RGM[GMCO-1]=X;\r
+                                 GMCO=GMCO+1;\r
+                                 RGM[GMCO-1]=Y;\r
+                               }\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("PUT REAL PART ui IMAGINARY PART");\r
+                                       }\r
+                                       else if (J == 2 && TYPE == 3) {          \r
+                                       System.out.println("ENTER JAVA EXPRESSION ENDING IN // FOR DPARFN");\r
+                                       System.out.println("PUT REAL PART ui IMAGINARY PART");\r
+                                       }\r
+                                       else if (J == 1 && TYPE == 4) {\r
+                                       System.out.println("ENTER JAVA EXPRESSION ENDING IN // FOR RADIUS");\r
+                                       }\r
+                                       else {\r
+                                       System.out.println("ENTER JAVA EXPRESSION ENDING IN // FOR RADIUS DERIVATIVE");\r
+                                       }\r
+                     \r
+                                   TXCO=TXCO+1;\r
+                                   PTX[IA-1+(J-1)*MNARC]=TXCO;\r
+                                   I=1;\r
+       \r
+                                   TXT = input.next();\r
+                                   L = -1;\r
+                                   while (L == -1) {\r
+                                           L = TXT.indexOf("//");\r
+                                           if (L == -1) {\r
+                                               DEFN[TXCO-1]=TABC+TXT;\r
+                                               I=I+1;\r
+                                               TXCO=TXCO+1;\r
+                                           } // if (L == -1)\r
+                                   } // while (L == -1)\r
+                                   NTX[IA-1+(J-1)*MNARC]=I;\r
+                                   if (L == 0) {\r
+                                       DEFN[TXCO-1]=TABC;\r
+                                       NUMDER[IA-1] = true;\r
+                                   }\r
+                                   else {\r
+                                       DEFN[TXCO-1]=TABC+TXT.substring(0,L);\r
+                                   }\r
+                            if ((J == 1) && (TYPE == 4)) {\r
+                               System.out.println("(... = ZRAD)");\r
+                            }\r
+                               } // for (J = 1; J <= 2; J++)\r
+                           } // else if ((TYPE == 3) || (TYPE == 4))\r
+                 } // 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
+                 }\r
+                 else {\r
+                     STAPT[NARCS][0]=STAPT[0][0];\r
+                     STAPT[NARCS][1]=STAPT[0][1];\r
+                 }\r
+              \r
+                 validInput = false;\r
+                     while (!validInput) {\r
+                     System.out.println("END OF INPUT PHASE; CONTINUE WITH PROCESSING (Y/N)?");\r
+                     String term = input.next();\r
+                     String firstTerm = term.substring(0,1);\r
+                     if (firstTerm.equalsIgnoreCase("Y")) {\r
+                         validInput = true;\r
+                     }\r
+                     else if (firstTerm.equalsIgnoreCase("N")) {\r
+                         validInput = true;\r
+                         setCompleted(false);\r
+                         return;\r
+                     }\r
+                     else {\r
+                         System.out.println(term + " is not a valid response");\r
+                     }\r
+                 } // while (!validInput)\r
+             } // if (traditionalInput)\r
              HEADER("PARFUN",REDD,raFile);\r
-             /*if (SYMTY) {\r
+             if (SYMTY) {\r
                SYINF1(ORDRG,ORDSG,RTUNI,U2,REFLN,CENSY,STAPT[0],\r
                           STAPT[NARCS],IER);\r
                if (IER[0] > 0) {\r
@@ -312,32 +532,40 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
                WRSYM2(NARCS,ORDRG[0],CENSY,REFLN,CHNL, raFile);\r
              }\r
              else {\r
-               CALL WRFUN1(NARCS,STAPT,ARCTY,PGM,RGM,PTX,NTX,DEFN,CHNL,\r
-            +             'IA','TT','PARFUN',REDD)\r
+               WRFUN1(NARCS,STAPT,ARCTY,PGM,RGM,PTX,NTX,DEFN,CHNL,\r
+                      "IA","TT","PARFUN",REDD,raFile);\r
              }\r
-       C\r
-             WRITE(CHNL,'(A1)') 'C'\r
-             WRITE(CHNL,'(A9)') '      END'\r
-       C\r
-       C**** WRITE THE SOURCE CODE FOR DPARFN\r
-       C\r
-             WRITE(CHNL,'(A40)') 'C...........................................'\r
-             CALL HEADER('DPARFN',REDD,CHNL)\r
-             IF (SYMTY) THEN\r
-               CALL WRSYM1(NARCS,ORDRG,ORDSG,RTUNI,U2,CENSY,REFLN,.FALSE.,REDD,\r
-            +              CHNL)\r
-               IF (REFLN) THEN\r
-                 CH='TS'\r
-               ELSE\r
-                 CH='TT'\r
-               ENDIF\r
-               CALL WRFUN2(NARCS,MNARC,STAPT,ARCTY,PGM,RGM,PTX,NTX,DEFN,\r
-            +              CHNL,'IB',CH,'ZETA  ',NUMDER,REDD)\r
+       \r
+             try {\r
+                 raFile.writeBytes("//\n");\r
+                 raFile.writeBytes("}\n");\r
+         \r
+                // **** WRITE THE SOURCE CODE FOR DPARFN\r
+            \r
+                raFile.writeBytes("//...........................................\n");\r
+             }\r
+             catch (IOException e) {\r
+                 MipavUtil.displayError("IOException " + e + " in PARGEN");\r
+                 System.exit(-1);\r
+             }\r
+             HEADER("DPARFN",REDD,raFile);\r
+             /*if (SYMTY) {\r
+               WRSYM1(NARCS,ORDRG[0],ORDSG[0],RTUNI,U2,CENSY,REFLN,false,REDD,\r
+                      CHNL, raFile);\r
+               if (REFLN) {\r
+                 CH="TS";\r
+               }\r
+               else {\r
+                 CH="TT";\r
+               }\r
+               WRFUN2(NARCS,MNARC,STAPT,ARCTY,PGM,RGM,PTX,NTX,DEFN,\r
+                          CHNL,"IB",CH,"ZETA  ",NUMDER,REDD, raFile);\r
                CALL WRSYM3(NARCS,ORDRG,REFLN,CHNL)\r
-             ELSE\r
+             } // if (SYMTY)\r
+             else {\r
                CALL WRFUN2(NARCS,MNARC,STAPT,ARCTY,PGM,RGM,PTX,NTX,DEFN,\r
             +              CHNL,'IA','TT','DPARFN',NUMDER,REDD)\r
-             ENDIF\r
+             }\r
        C\r
              WRITE(CHNL,'(A1)') 'C'\r
              WRITE(CHNL,'(A9)') '      END'\r
@@ -906,7 +1134,7 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
       }\r
 \r
       private void WRFUN1(int NARCS,double STAPT[][],int ARCTY[],int PGM[], \r
-                 double RGM[], int PTX[], int NTX[], String DEFN[][],\r
+                 double RGM[], int PTX[], int NTX[], String DEFN[],\r
                  int CHNL, String CHIA, String CHTT, String VAR, String REDD, RandomAccessFile raFile) {\r
           //COMPLEX STAPT(*)\r
           //CHARACTER DEFN(*)*72,CHIA*2,CHTT*2,VAR*6,REDD*6\r
@@ -931,7 +1159,7 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
           FMT2="(A21,I3,A6)";\r
           double STAPT2[][];\r
           double RGM2[];\r
-          String DEFN2[][];\r
+          String DEFN2[];\r
                \r
          try {\r
                  for (IA=1; IA <= NARCS; IA++) {\r
@@ -945,10 +1173,9 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
                          for (K = I; K <= RGM.length; K++) {\r
                                  RGM2[K-I] = RGM[K-1];\r
                          }\r
-                         DEFN2 = new String[DEFN.length-J+1][2];\r
+                         DEFN2 = new String[DEFN.length-J+1];\r
                          for (K = J; K <= DEFN.length; K++) {\r
-                                 DEFN2[K-J][0] = DEFN[K-1][0];\r
-                                 DEFN2[K-J][1] = DEFN[K-1][1];\r
+                                 DEFN2[K-J] = DEFN[K-1];\r
                          }\r
                          if (NARCS == 1) {\r
                              PTFUN1(ARCTY[IA-1],STAPT2,RGM2,NTX[IA-1],DEFN2,\r
@@ -978,7 +1205,7 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
       } // private void WRFUN1\r
 \r
       private void PTFUN1(int TYPE, double STAPT[][], double RGM[],int NTX,\r
-                 String TXT[][],int CHNL, String CHTT,String VAR, String REDD,\r
+                 String TXT[],int CHNL, String CHTT,String VAR, String REDD,\r
                  RandomAccessFile raFile) {\r
       \r
           //COMPLEX STAPT(*)\r
@@ -1048,12 +1275,33 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
         raFile.writeBytes(VAR + "[0] = ");\r
         // NTX = 1 if statements are entered without newlines for multiple lines\r
         for (I  = 1; I <= NTX; I++) {\r
-               raFile.writeBytes(TXT[I-1][0]);\r
+               int index = TXT[I-1].indexOf("ui");\r
+               String realString = null;\r
+               if (index == -1) {\r
+                       realString = TXT[I-1];\r
+               }\r
+               else {\r
+                       realString = TXT[I-1].substring(0, index);\r
+               }\r
+               if ((index == -1) || (index > 0)) {\r
+                   raFile.writeBytes(realString);\r
+               }\r
+               if (I == NTX) {\r
+                       raFile.writeBytes(";\n");\r
+               }\r
         }\r
         raFile.writeBytes(VAR + "[1] = ");\r
         // NTX = 1 if statements are entered without newlines for multiple lines\r
         for (I  = 1; I <= NTX; I++) {\r
-               raFile.writeBytes(TXT[I-1][1]);\r
+               int index = TXT[I-1].indexOf("ui");\r
+               String imagString = null;\r
+               if ((index >= 0) && (index+2 < TXT[I-1].length())) {\r
+                       imagString = TXT[I-1].substring(index+2);\r
+                       raFile.writeBytes(imagString);\r
+               }\r
+               if (I == NTX) {\r
+                       raFile.writeBytes(";\n");\r
+               }\r
         }\r
         raFile.writeBytes("//\n");\r
       } // else if (TYPE == 3)\r
@@ -1063,18 +1311,13 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
         raFile.writeBytes("//\n");\r
         raFile.writeBytes("T[0] = " + MD + "+" + CHTT + "[0] * " + HA + ";\n");\r
         raFile.writeBytes("T[1] = " + MD + "+" + CHTT + "[1] * " + HA + ";\n");\r
-        raFile.writeBytes("     ZRAD[0] = ");\r
+        raFile.writeBytes("     ZRAD = ");\r
         // NTX = 1 if statements are entered without newlines for multiple lines\r
         for (I  = 1; I <= NTX; I++) {\r
-               raFile.writeBytes(TXT[I-1][0]);\r
+               raFile.writeBytes(TXT[I-1]);\r
         }\r
-        raFile.writeBytes("     ZRAD[1] = ");\r
-        // NTX = 1 if statements are entered without newlines for multiple lines\r
-        for (I  = 1; I <= NTX; I++) {\r
-               raFile.writeBytes(TXT[I-1][1]);\r
-        }\r
-        raFile.writeBytes(VAR + "[0] = Math.exp(-T[1])*(ZRAD[0] * Math.cos(T[0]) - ZRAD[1] * Math.sin(T[0]));\n");\r
-        raFile.writeBytes(VAR + "[1] = Math.exp(-T[1])*(ZRAD[0] * Math.sin(T[0]) + ZRAD[1] * Math.cos(T[0]));\n");\r
+        raFile.writeBytes(VAR + "[0] = Math.exp(-T[1])*(ZRAD * Math.cos(T[0]));\n");\r
+        raFile.writeBytes(VAR + "[1] = Math.exp(-T[1])*(ZRAD * Math.sin(T[0]));\n");\r
         raFile.writeBytes("//\n");\r
       }\r
       } // try \r
@@ -1221,6 +1464,172 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
 \r
       } // private void WRSYM2\r
 \r
+      private void WRFUN2(int NARCS,int MNARC, double STAPT[][], int ARCTY[], int PGM[],double RGM[],\r
+                 int PTX[],int NTX[],String DEFN[],int CHNL,String CHIA,String CHTT, String VAR,\r
+                 boolean NUMDER[], String REDD, RandomAccessFile raFile) {\r
+  \r
+          // COMPLEX STAPT(*)\r
+         // CHARACTER DEFN(*)*72,CHIA*2,CHTT*2,VAR*6,REDD*6\r
+               \r
+          //**** TO WRITE THE SOURCE CODE FOR DPARFN IN THE CASE WHERE NO\r
+         //**** SYMMETRY IS INVOLVED.\r
+               \r
+         //.......................................................................\r
+         //     AUTHOR: DAVID HOUGH, ETH, ZUERICH\r
+         //     LAST UPDATE: 4 AUG 1990\r
+         //.......................................................................\r
+               \r
+         //     LOCAL VARIABLES\r
+               \r
+         int IA,I,J1,J2,N1,N2;\r
+         String TX1, TX2, FMT1, FMT2;\r
+         //CHARACTER TX1*16,TX2*21,FMT1*11,FMT2*11\r
+         //EXTERNAL PTFUN2\r
+         double STAPT2[][];\r
+         double RGM2[];\r
+         String DEFN2[];\r
+         String DEFN3[];\r
+         int K;\r
+               \r
+          TX1="      if ("+CHIA+" == ";\r
+         TX2="      else if ("+CHIA+" == ";\r
+         FMT1="(A16,I3,A6)";\r
+         FMT2="(A21,I3,A6)";\r
+               \r
+         try {\r
+         for (IA=1; IA <= NARCS; IA++) {\r
+                       I=PGM[IA-1];\r
+                       J1=PTX[IA-1];\r
+                       J2=PTX[IA+MNARC-1];\r
+                       N1=NTX[IA-1];\r
+                       N2=NTX[IA+MNARC-1];\r
+                       STAPT2 = new double[STAPT.length-IA+1][2];\r
+                       for (K = IA; K <= STAPT.length; K++) {\r
+                               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
+                       }\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
+                       DEFN3 = new String[DEFN.length-J2+1];\r
+                       for (K = J2; K <= DEFN.length; K++) {\r
+                               DEFN3[K-J2] = DEFN[K-1];\r
+                       }\r
+                       if (NARCS == 1) {\r
+                         PTFUN2(ARCTY[IA-1],STAPT2,RGM2,N1,DEFN2,\r
+                                   N2,DEFN3,CHNL,CHTT,VAR," 1",NUMDER[IA-1],REDD,raFile);\r
+                       }\r
+                       else { \r
+                         if (IA == 1) {\r
+                               raFile.writeBytes(TX1 + IA + ") {\n");\r
+                         }\r
+                         else if (IA == NARCS) {\r
+                               raFile.writeBytes("      else {\n");\r
+                         }\r
+                         else {\r
+                               raFile.writeBytes(TX2 + IA + ") {\n");\r
+                         }\r
+                         PTFUN2(ARCTY[IA-1],STAPT2,RGM2,N1,DEFN2,\r
+                                N2,DEFN3,CHNL,CHTT,VAR,CHIA,NUMDER[IA-1],REDD,raFile);\r
+                         if (IA == NARCS) {\r
+                                 raFile.writeBytes("      }\n");\r
+                         }\r
+                       } // else\r
+         } // for (IA=1; IA <= NARCS; IA++)\r
+         } // try \r
+         catch (IOException e) {\r
+                 MipavUtil.displayError("IOException " + e + " in WRFUN2");\r
+                 System.exit(-1);\r
+         }\r
+               \r
+      } // private void WRFUN2\r
+      \r
+      private void PTFUN2(int TYPE,double STAPT[][], double RGM[],int NTX1, String TXT1[],int NTX2,\r
+          String TXT2[],int CHNL, String CHTT, String VAR, String CHIA, boolean NUMDER, String REDD,\r
+          RandomAccessFile raFile) {\r
+          //COMPLEX STAPT(*)\r
+          //CHARACTER TXT1(*)*72,TXT2(*)*72,CHTT*2,VAR*6,CHIA*2,REDD*6\r
+               /*C\r
+               C.......................................................................\r
+               C     AUTHOR: DAVID HOUGH, ETH, ZUERICH\r
+               C     LAST UPDATE: 8 AUG 1990\r
+               C.......................................................................C\r
+               C**** LOCAL VARIABLES\r
+               C\r
+                     INTEGER I\r
+                     REAL HA,MD,RAD,A,R\r
+                     COMPLEX C1,CENTR\r
+                     CHARACTER TX1*4,TX1B*5,TX2*13,TX2B*14,TX3*39,\r
+                    +FMT1*25,FMT2*15,FMT3*15,FMT4*25,FMT5*24\r
+               C\r
+                     TX1='+'//CHTT//'*'\r
+                     TX1B=TX1//'('\r
+                     TX2='      '//VAR//'='\r
+                     TX2B=TX2//'('\r
+                     TX3=TX2//'(ZDER+UI*ZRAD)*EXP(UI*T)*('\r
+               C\r
+                     FMT1='(A14,'//REDD//',A1,'//REDD//',A2)'\r
+                     FMT2='(A39,'//REDD//',A1)'\r
+                     FMT3='(A13,'//REDD//',A2)'\r
+                     FMT4='(A14,'//REDD//',A5,'//REDD//',A3)'\r
+                     FMT5='(A8,'//REDD//',A5,'//REDD//',A1)'\r
+               C\r
+                     IF (TYPE.EQ.1) THEN\r
+                       C1=5E-1*(STAPT(2)-STAPT(1))\r
+                       WRITE(CHNL,'(A1)') 'C'\r
+                       R=REAL(C1)\r
+                       A=AIMAG(C1)\r
+                       WRITE(CHNL,FMT1) TX2B,R,',',A,') '\r
+                       WRITE(CHNL,'(A1)') 'C'\r
+                     ELSE IF (TYPE.EQ.2) THEN\r
+                       CENTR=CMPLX(RGM(1),RGM(2))\r
+                       C1=STAPT(1)-CENTR\r
+                       HA=5E-1*RGM(3)\r
+                       MD=ATAN2(AIMAG(C1),REAL(C1))+HA\r
+                       RAD=ABS(C1)\r
+                       WRITE(CHNL,'(A1)') 'C' \r
+                       WRITE(CHNL,FMT4) TX2,RAD,'*UI*(',HA,') *'\r
+                       WRITE(CHNL,FMT4) '     +EXP(UI*(',MD,TX1B,HA,')))'\r
+                       WRITE(CHNL,'(A1)') 'C'  \r
+                     ELSE IF (NUMDER) THEN\r
+                       WRITE(CHNL,'(A1)') 'C'\r
+                       WRITE(CHNL,'(A26)') TX2,'ZDPARF(',CHIA,',',CHTT,')'     \r
+                       WRITE(CHNL,'(A1)') 'C'\r
+                     ELSE IF (TYPE.EQ.3) THEN\r
+                       MD=5E-1*(RGM(2)+RGM(1))\r
+                       HA=5E-1*(RGM(2)-RGM(1))\r
+                       WRITE(CHNL,'(A1)') 'C'\r
+                       WRITE(CHNL,FMT5) '      T=',MD,TX1B,HA,')'\r
+                       WRITE(CHNL,FMT3) TX2,HA,'*('\r
+                       DO 10 I=1,NTX2\r
+                         WRITE(CHNL,'(A72)') TXT2(I)\r
+               10      CONTINUE\r
+                       WRITE(CHNL,'(A7)') '     +)'\r
+                       WRITE(CHNL,'(A1)') 'C'\r
+                     ELSE\r
+                       MD=5E-1*(RGM(2)+RGM(1))\r
+                       HA=5E-1*(RGM(2)-RGM(1))\r
+                       WRITE(CHNL,'(A1)') 'C'\r
+                       WRITE(CHNL,FMT5) '      T=',MD,TX1B,HA,')'\r
+                       WRITE(CHNL,'(A11)') '      ZRAD='\r
+                       DO 20 I=1,NTX1\r
+                         WRITE(CHNL,'(A72)') TXT1(I)\r
+               20      CONTINUE\r
+                       WRITE(CHNL,'(A11)') '      ZDER='\r
+                       DO 30 I=1,NTX2\r
+                         WRITE(CHNL,'(A72)') TXT2(I)\r
+               30      CONTINUE\r
+                       WRITE(CHNL,FMT2) TX3,HA,')'\r
+                       WRITE(CHNL,'(A1)') 'C'\r
+                     ENDIF\r
+               C*/\r
+               }\r
+\r
 \r
       \r
       /**\r