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

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

index 4ac6e3f..1ffc512 100644 (file)
@@ -68,8 +68,9 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
     // For each IA = 1 to NARCS do J = 1,2\r
     //TXCO=TXCO+1\r
     //PTX[IA-1+(J-1)*MNARC]=TXCO\r
-    // DEFN[TXCO-1]= TXT  \r
-    // where TXT =\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
     // 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
@@ -231,7 +232,8 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
              final int CHIN = 21;\r
              int NTX[] = new int[2*MNARC];\r
              //CHARACTER DEFN(MNARC*2)*72\r
-             String DEFN[] = new String[2*MNARC];\r
+             // Holds text for real and imaginary parts\r
+             String DEFN[][]= new String[2*MNARC][2];\r
              File file;\r
              RandomAccessFile raFile = null;\r
        \r
@@ -307,7 +309,7 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
                }\r
                WRFUN1(NARCS,STAPT,ARCTY,PGM,RGM,PTX,NTX,DEFN,CHNL,\r
                         "IB",CH,"ZETA  ",REDD, raFile);\r
-               CALL WRSYM2(NARCS,ORDRG,CENSY,REFLN,CHNL)\r
+               WRSYM2(NARCS,ORDRG[0],CENSY,REFLN,CHNL, raFile);\r
              }\r
              else {\r
                CALL WRFUN1(NARCS,STAPT,ARCTY,PGM,RGM,PTX,NTX,DEFN,CHNL,\r
@@ -349,15 +351,16 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
 \r
     String TAB6="      ";\r
 \r
-    String LINE=TAB6+"COMPLEX FUNCTION "+TXT+"(IA,TT)";\r
+    String LINE=TAB6+"private void "+TXT+"(int IA, double TT[]) {\n";\r
     try {\r
     raFile.writeBytes(LINE);\r
 \r
-    LINE=TAB6+"IMPLICIT REAL(A-H,O-S),INTEGER(I-N),COMPLEX(T-Z)";\r
+    LINE="//" + TAB6+"IMPLICIT REAL(A-H,O-S),INTEGER(I-N),COMPLEX(T-Z)\n";\r
     raFile.writeBytes(LINE);\r
 \r
-    raFile.writeBytes("      PARAMETER (PI="+Math.PI+",UI=(0.0,1.0))");\r
-    raFile.writeBytes("C");\r
+    raFile.writeBytes("      double PI = "+Math.PI+ ";\n");\r
+    raFile.writeBytes("      double UI[] = new double[]{0.0,1.0};\n");\r
+    raFile.writeBytes("//\n");\r
     }\r
     catch (IOException e) {\r
        MipavUtil.displayError("IOException " + e + " in HEADER");\r
@@ -491,7 +494,7 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
           }\r
           else {\r
                  try {\r
-                     raFile.writeBytes("\n\n      "+DOTS+"\n      "+TXT+"\n      "+DOTS+"\n");\r
+                     raFile.writeBytes("\n\n      //"+DOTS+"\n      //"+TXT+"\n      //"+DOTS+"\n");\r
                  }\r
                  catch (IOException e) {\r
                          MipavUtil.displayError("IOException " + e + " on raFile.writeBytes in WRHEAD");\r
@@ -538,9 +541,9 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
      }\r
      else {\r
        try {\r
-            raFile.writeBytes("\n\n      "+TXT+"\n");\r
-            raFile.writeBytes("      "+TXT2+"\n");\r
-            raFile.writeBytes(LINE+"\n");\r
+            raFile.writeBytes("\n\n      //"+TXT+"\n");\r
+            raFile.writeBytes("      //"+TXT2+"\n");\r
+            raFile.writeBytes("//"+LINE+"\n");\r
        }\r
        catch(IOException e) {\r
                MipavUtil.displayError("IOException " + e + " in WRTAIL");\r
@@ -770,7 +773,7 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
                \r
                try {\r
                        if (PARFUN) {\r
-                               NEEDC = ((CENSY[0] != 0.0) && (CENSY[1] != 0.0));\r
+                               NEEDC = ((CENSY[0] != 0.0) || (CENSY[1] != 0.0));\r
                            if (NEEDC || REFLN) {\r
                                raFile.writeBytes("      PARAMETER (\n");\r
                                if (NEEDC && REFLN) {\r
@@ -903,7 +906,7 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
       }\r
 \r
       private void WRFUN1(int NARCS,double STAPT[][],int ARCTY[],int PGM[], \r
-                 int 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
@@ -918,7 +921,7 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
        \r
          //     LOCAL VARIABLES\r
        \r
-          int IA,I,J;\r
+          int IA,I,J,K;\r
          //CHARACTER TX1*16,TX2*21,FMT1*11,FMT2*11\r
           String TX1,TX2,FMT1,FMT2;\r
          // EXTERNAL PTFUN1\r
@@ -926,13 +929,29 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
          TX2 = "     else if("+CHIA+ " == ";\r
           FMT1="(A16,I3,A6)";\r
           FMT2="(A21,I3,A6)";\r
+          double STAPT2[][];\r
+          double RGM2[];\r
+          String DEFN2[][];\r
                \r
-        /* try {\r
+         try {\r
                  for (IA=1; IA <= NARCS; IA++) {\r
                      I=PGM[IA-1];\r
                          J=PTX[IA-1];\r
+                         STAPT2 = new double[STAPT.length-IA+1][2];\r
+                         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
+                         }\r
+                         DEFN2 = new String[DEFN.length-J+1][2];\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
+                         }\r
                          if (NARCS == 1) {\r
-                             PTFUN1(ARCTY[IA-1],STAPT[IA-1],RGM[I-1],NTX[IA-1],DEFN[J-1],\r
+                             PTFUN1(ARCTY[IA-1],STAPT2,RGM2,NTX[IA-1],DEFN2,\r
                                         CHNL,CHTT,VAR,REDD, raFile);\r
                          }\r
                          else {\r
@@ -945,7 +964,7 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
                                  else {\r
                                          raFile.writeBytes(TX2 + IA + ") {\n");\r
                                  }\r
-                                 PTFUN1(ARCTY[IA-1],STAPT[IA-1],RGM[I-1],NTX[IA-1],DEFN[J-1],\r
+                                 PTFUN1(ARCTY[IA-1],STAPT2,RGM2,NTX[IA-1],DEFN2,\r
                                         CHNL,CHTT,VAR,REDD, raFile);\r
                                  if (IA == NARCS) raFile.writeBytes("      }\n");\r
                          } // else\r
@@ -954,12 +973,12 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
          catch (IOException e) {\r
              MipavUtil.displayError("IOException " + e + " in WRFUN1");\r
              System.exit(-1);\r
-         }*/\r
+         }\r
                \r
       } // 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
+      private void PTFUN1(int TYPE, double STAPT[][], double RGM[],int NTX,\r
+                 String TXT[][],int CHNL, String CHTT,String VAR, String REDD,\r
                  RandomAccessFile raFile) {\r
       \r
           //COMPLEX STAPT(*)\r
@@ -993,7 +1012,8 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
       //FMT4='(A14,'//REDD//',A5,'//REDD//',A3)'\r
       //FMT5='(A8,'//REDD//',A5,'//REDD//',A1)'\r
 \r
-      /*if (TYPE == 1) {\r
+      try {\r
+      if (TYPE == 1) {\r
        C1[0] = 0.5*(STAPT[1][0] + STAPT[0][0]);\r
        C1[1] = 0.5*(STAPT[1][1] + STAPT[0][1]);\r
         C2[0] = 0.5*(STAPT[1][0] - STAPT[0][0]);\r
@@ -1005,7 +1025,7 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
       } // if (TYPE == 1)\r
       else if (TYPE == 2) {\r
        CENTR[0] = RGM[0];\r
-       CENTR[1] = RGN[1];\r
+       CENTR[1] = RGM[1];\r
         C1[0] = STAPT[0][0] - CENTR[0];\r
         C1[1] = STAPT[0][1] - CENTR[1];\r
         HA=0.5*RGM[2];\r
@@ -1022,30 +1042,186 @@ public class SymmsIntegralMapping extends AlgorithmBase  {
         MD=0.5*(RGM[1]+RGM[0]);\r
         HA=0.5*(RGM[1]-RGM[0]);\r
         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("T[0] = " + MD + "+" + CHTT + "[0] * " + HA + ";\n");\r
+        raFile.writeBytes("T[1] = " + MD + "+" + CHTT + "[1] * " + HA + ";\n");\r
         \r
-        WRITE(CHNL,'(A13)') TX2\r
-        DO 10 I=1,NTX\r
-          WRITE(CHNL,'(A72)') TXT(I)\r
-10      CONTINUE\r
-        WRITE(CHNL,'(A1)') 'C'\r
+        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
+        }\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
+        }\r
+        raFile.writeBytes("//\n");\r
       } // else if (TYPE == 3)\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,NTX\r
-          WRITE(CHNL,'(A72)') TXT(I)\r
-20      CONTINUE\r
-        WRITE(CHNL,'(A13,A14)') TX2,'ZRAD*EXP(UI*T)'\r
-        WRITE(CHNL,'(A1)') 'C'\r
-      ENDIF\r
-C*/\r
+      else {\r
+       MD=0.5*(RGM[1]+RGM[0]);\r
+        HA=0.5*(RGM[1]-RGM[0]);\r
+        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
+        // 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
+        }\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("//\n");\r
+      }\r
+      } // try \r
+      catch (IOException e) {\r
+         MipavUtil.displayError("IOException " + e + " in PTFUN1");\r
+         System.exit(-1);\r
       }\r
 \r
+      } // private void PTFUN1\r
+      \r
+\r
+      private void WRSYM2(int NARCS,int ORDRG, double CENSY[], boolean REFLN,int CHNL, RandomAccessFile raFile) {\r
+     \r
+          //COMPLEX CENSY\r
+\r
+          // **** TO WRITE THE CODE TO RECOVER THE BOUNDARY POINT FROM ITS SYMMETRIC\r
+          // **** COUNTERPART ON THE FUNDAMENTAL BOUNDARY SECTION.\r
+\r
+          //.......................................................................\r
+          // AUTHOR: DAVID HOUGH, ETH, ZUERICH\r
+          // LAST UPDATE: 4 AUG 1990\r
+          // .......................................................................C\r
+          // LOCAL VARIABLES\r
+\r
+          int I;\r
+          boolean NEEDC;\r
+  \r
+          NEEDC = ((CENSY[0] != 0.0) || (CENSY[1] != 0.0));\r
+          try {\r
+                 raFile.writeBytes("//\n");\r
+\r
+              if (REFLN) {\r
+                  if (ORDRG > 1) {\r
+                      I=2*NARCS;\r
+                      if (NARCS > 1) {\r
+                         raFile.writeBytes("IS = (IA-IB)%"+I+";\n");\r
+                          raFile.writeBytes("IR = (IA-IB-IS)/" + I + ";\n");\r
+                      } // if (NARCS > 1)\r
+                      else {\r
+                         raFile.writeBytes("IS = (IA-1)%2;\n");\r
+                          raFile.writeBytes("IR = (IA-1-IS)/2;\n");\r
+                      }\r
+                      raFile.writeBytes("if ((IR == 0) && (IS == 0)) {\n");\r
+                      raFile.writeBytes("    PARFUN[0] = ZETA[0];\n");\r
+                      raFile.writeBytes("    PARFUN[1] = ZETA[1];\n");\r
+                      raFile.writeBytes("}\n");\r
+                      raFile.writeBytes("else if ((IR > 0) && (IS == 0)) {\n");\r
+                      if (NEEDC) {\r
+                         raFile.writeBytes("    PARFUN[0] = ZCEN[0] + WW[IR-1][0]*(ZETA[0] - ZCEN[0]) - "\r
+                                       + "WW[IR-1][1]*(ZETA[1] - ZCEN[1]);\n");\r
+                         raFile.writeBytes("    PARFUN[1] = ZCEN[1] + WW[IR-1][0]*(ZETA[1] - ZCEN[1]) + "\r
+                                       + "WW[IR-1][1]*(ZETA[0] - ZCEN[0]);\n");\r
+                       } // if (NEEDC)\r
+                      else {\r
+                         raFile.writeBytes("PARFUN[0] = WW[IR-1][0]*ZETA[0] - WW[IR-1][1]*ZETA[1];\n");\r
+                      }\r
+                      raFile.writeBytes("else if ((IR == 0) && (IS > 0)) {\n");\r
+                      if (NEEDC) {\r
+                          raFile.writeBytes("    PARFUN[0] = ZCEN[0] + U2[0]*(ZETA[0]-ZCEN[0]) + " +\r
+                                         "U2[1]*(ZETA[1]-ZCEN[1]);\n");\r
+                          raFile.writeBytes("    PARFUN[1] = ZCEN[1] - U2[0]*(ZETA[1]-ZCEN[1]) + " +\r
+                                         "U2[1]*(ZETA[0]-ZCEN[0]);\n");\r
+                      }\r
+                      else {\r
+                         raFile.writeBytes("    PARFUN[0] = U2[0]*ZETA[0] + U2[1]*ZETA[1];\n");\r
+                         raFile.writeBytes("    PARFUN[1] = -U2[0]*ZETA[1] + U2[1]*ZETA[0];\n");\r
+                      }\r
+                      raFile.writeBytes("}\n");\r
+                      raFile.writeBytes("else {\n");\r
+                      if (NEEDC) {\r
+                          raFile.writeBytes("double realPart = U2[0]*WW[IR-1][0] - U2[1]*WW[IR-1][1];\n");\r
+                          raFile.writeBytes("double imagPart = U2[0]*WW[IR-1][1] + U2[1]*WW[IR-1][0];\n");\r
+                          raFile.writeBytes("PARFUN[0] = ZCEN[0] + realPart*(ZETA[0]-ZCEN[0]) + " +\r
+                                       "imagPart*(ZETA[1]-ZCEN[1]);\n");\r
+                          raFile.writeBytes("PARFUN[1] = ZCEN[1] - realPart*(ZETA[1]-ZCEN[1]) + " +\r
+                                       "imagPart*(ZETA[0]-ZCEN[0]);\n");\r
+                      }\r
+                      else {\r
+                         raFile.writeBytes("double realPart = U2[0]*WW[IR-1][0] - U2[1]*WW[IR-1][1];\n");\r
+                          raFile.writeBytes("double imagPart = U2[0]*WW[IR-1][1] + U2[1]*WW[IR-1][0];\n");\r
+                          raFile.writeBytes("PARFUN[0] = realPart * ZETA[0] + imagPart * ZETA[1];\n");\r
+                          raFile.writeBytes("PARFUN[1] = -realPart * ZETA[1] + imagPart * ZETA[0];\n");\r
+                      }\r
+                      raFile.writeBytes("}\n");\r
+                  } // if (ORDRG > 1)\r
+                  else { // ORDRG <= 1\r
+                      if (NARCS > 1) {\r
+                         raFile.writeBytes("IS = IA - IB;\n");\r
+                      }\r
+                      else {\r
+                         raFile.writeBytes("IS = IA - 1;\n");\r
+                      }\r
+                      raFile.writeBytes("if (IS == 0) {\n");\r
+                      raFile.writeBytes("    PARFUN[0] = ZETA[0];\n");\r
+                      raFile.writeBytes("    PARFUN[1] = ZETA[1];\n");\r
+                      raFile.writeBytes("}\n");\r
+                      raFile.writeBytes("else {\n");\r
+                      if (NEEDC) {\r
+                         raFile.writeBytes("    PARFUN[0] = ZCEN[0] + U2[0]*(ZETA[0]-ZCEN[0]) + " +\r
+                                         "U2[1]*(ZETA[1]-ZCEN[1]);\n");\r
+                          raFile.writeBytes("    PARFUN[1] = ZCEN[1] - U2[0]*(ZETA[1]-ZCEN[1]) + " +\r
+                                         "U2[1]*(ZETA[0]-ZCEN[0]);\n");\r
+                      }\r
+                      else {\r
+                         raFile.writeBytes("    PARFUN[0] = U2[0]*(ZETA[0]-ZCEN[0]) + " +\r
+                                         "U2[1]*(ZETA[1]-ZCEN[1]);\n");\r
+                          raFile.writeBytes("    PARFUN[1] =  -U2[0]*(ZETA[1]-ZCEN[1]) + " +\r
+                                         "U2[1]*(ZETA[0]-ZCEN[0]);\n");\r
+                      }\r
+                      raFile.writeBytes("}\n");\r
+                  } // else ORDRG <= 1\r
+              } // if (REFLN)\r
+              else { // !REFLN\r
+                  if (NARCS > 1) {\r
+                         raFile.writeBytes("IR = (IA - IB)/" + NARCS + ";\n");\r
+                  }\r
+                  else {\r
+                         raFile.writeBytes("IR = IA - 1;\n");\r
+                  }\r
+                  raFile.writeBytes("if (IR == 0) {\n");\r
+                  raFile.writeBytes("PARFUN[0] = ZETA[0]);\n");\r
+                  raFile.writeBytes("PARFUN[1] = ZETA[1]);\n");\r
+                  raFile.writeBytes("}\n");\r
+                  raFile.writeBytes("else {\n");\r
+                  if (NEEDC) {\r
+                         raFile.writeBytes("    PARFUN[0] = ZCEN[0] + WW[IR-1][0]*(ZETA[0] - ZCEN[0]) - "\r
+                                       + "WW[IR-1][1]*(ZETA[1] - ZCEN[1]);\n");\r
+                         raFile.writeBytes("    PARFUN[1] = ZCEN[1] + WW[IR-1][0]*(ZETA[1] - ZCEN[1]) + "\r
+                                       + "WW[IR-1][1]*(ZETA[0] - ZCEN[0]);\n");\r
+                  }\r
+                  else {\r
+                         raFile.writeBytes("    PARFUN[0] = WW[IR-1][0]*(ZETA[0] - ZCEN[0]) - "\r
+                                       + "WW[IR-1][1]*(ZETA[1] - ZCEN[1]);\n");\r
+                      raFile.writeBytes("    PARFUN[1] = WW[IR-1][0]*(ZETA[1] - ZCEN[1]) + "\r
+                                       + "WW[IR-1][1]*(ZETA[0] - ZCEN[0]);\n");\r
+                  }\r
+                  raFile.writeBytes("}\n");\r
+              } // else !REFLN\r
+          } // try\r
+          catch(IOException e) {\r
+                 MipavUtil.displayError("IOException " + e + " in WRSYM2");\r
+                 System.exit(-1);\r
+          }\r
+\r
+      } // private void WRSYM2\r
+\r
+\r
       \r
       /**\r
        * zabs computes the absolute value or magnitude of a double precision complex variable zr + j*zi.\r