5bf635ca1878e8e07942aea6ca20d32e6441b2e9
[mipav.git] / mipav / src / gov / nih / mipav / model / algorithms / SymmsIntegralMapping.java
1 package gov.nih.mipav.model.algorithms;\r
2 \r
3 import java.io.File;\r
4 import java.io.IOException;\r
5 import java.io.RandomAccessFile;\r
6 import java.util.Scanner;\r
7 import java.util.Vector;\r
8 \r
9 import gov.nih.mipav.model.structures.ModelImage;\r
10 import gov.nih.mipav.model.structures.jama.GeneralizedEigenvalue;\r
11 import gov.nih.mipav.model.structures.jama.LinearEquations2;\r
12 import gov.nih.mipav.view.MipavUtil;\r
13 import gov.nih.mipav.view.Preferences;\r
14 \r
15 public class SymmsIntegralMapping extends AlgorithmBase {\r
16         String fileDir;\r
17 \r
18         // EPS returns the distance from 1.0 to the next larger double-precision\r
19         // number, that is, eps = 2^-52.\r
20         private double EPS;\r
21         // Filename to receive FORTRAN output code\r
22         private String FORTFL = null;\r
23         // Does the domain have any symmetry?\r
24         private boolean SYMTY;\r
25         // If SYMTY is true, are there any reflectional symmetries?\r
26         private boolean REFLN;\r
27         // If SYMTY is true, what are the coordinates of the center of symmetry?\r
28         private final int MNARC = 100;\r
29         private double CENSY[] = new double[2];\r
30         // If SYMTY is true, number of arcs on the fundamental boundary section\r
31         // If SYMTY is false, number of arcs on the boundary\r
32         // NARCS <= MNARC-1 = 99\r
33         private int NARCS;\r
34         // NUMDER is of length MNARC\r
35         // NUMDER is initially false\r
36         private boolean NUMDER[] = new boolean[MNARC];\r
37         // ARCTY is of length MNARC\r
38         // Type of arc, 1 = LINE SEGMENT, 2 = CIRCULAR ARC SEGMENT, 3 = CARTESIAN\r
39         // PARAMETRIC FUNCTION\r
40         // 4 = POLAR FUNCTION\r
41         private int ARCTY[] = new int[MNARC];\r
42         // STAPT is of length MNARC,2\r
43         // Initial point on line, initial point on circle, or initial point on curve\r
44         // IF (SYMTY) THEN\r
45         // WRITE(*,*) 'COORDINATES OF FINAL POINT ON THIS ARC?'\r
46         // STAPT[NARCS]=CMPLX(FINAL X point, FINAL Y point)\r
47         // ELSE\r
48         // STAPT[NARCS]=STAPT[1]\r
49         // ENDIF\r
50         private double STAPT[][] = new double[MNARC][2];\r
51         // Start with GMCO = 0\r
52         // For types 2, 3, and 4 increment GMCO and put\r
53         // GMCO=GMCO+1\r
54         // PGM[IA-1]=GMCO where IA is the number of the curve from 1 to NARCS\r
55         // For type 2 circular arc:\r
56         // RGM[GMCO-1]= X center of circle\r
57         // GMCO=GMCO+1\r
58         // RGM[GMCO-1]= Y center of circle\r
59         // GMCO=GMCO+1\r
60         // RGM[GMCO-1]=ALPHA*PI where alpha is the signed angle subtended at center\r
61         // in units of PI\r
62         // ALPHA is positive for CCW and negative for CW.\r
63         // For type 3 CARTESIAN PARAMETRIC FUNCTION:\r
64         // RGM[GMCO-1]= initial parameter value\r
65         // GMCO=GMCO+1\r
66         // RGM[GMCO-1]= final parameter value\r
67         // For type 4 polar function:\r
68         // RGM[GMCO-1]= (initial polar angle in units of PI) *PI\r
69         // GMCO=GMCO+1\r
70         // RGM[GMCO-1]= (final polar angle in units of PI) *PI\r
71         // PGM is of length MNARC\r
72         private int PGM[] = new int[MNARC];\r
73         // RGM is of length 3*MNARC\r
74         private double RGM[] = new double[3 * MNARC];\r
75         // Start with TXCO = 0\r
76         // For types 3 and 4\r
77         // For each IA = 1 to NARCS do J = 1,2\r
78         // TXCO=TXCO+1\r
79         // PTX[IA-1+(J-1)*MNARC]=TXCO\r
80         // DEFN[TXCO-1][0]= TXT for real part\r
81         // DEFN[TXCO-1][1] = TXT for imaginary part\r
82         // where TXT = A COMPLEX EXPRESSION for TYPE 3 and a REAL EXPRESSION FOR\r
83         // TYPE 4\r
84         // for J = 1 and TYPE = 3 JAVA EXPRESSION FOR PARFUN\r
85         // for J = 2 and TYPE = 3 JAVA EXPRESSION FOR DPARFN\r
86         // for J = 1 and TYPE = 4 JAVA EXPRESSION FOR RADIUS\r
87         // for J = 2 and TYPE = 4 JAVA EXPRESSION FOR RADIUS DERIVATIVE\r
88         // PTX is of length 2*MNARC\r
89         private int PTX[] = new int[2 * MNARC];\r
90         private int NTX[] = new int[2 * MNARC];\r
91         // CHARACTER DEFN(MNARC*2)*72\r
92         // Holds text for real for types 3 and 4 and imaginary parts for type 3\r
93         // Start imaginary text with ui. All text following ui is imaginary.\r
94         String DEFN[] = new String[2 * MNARC];\r
95         private boolean traditionalInput = true;\r
96         Scanner input = new Scanner(System.in);\r
97         private double zzset[][] = new double[400][2];\r
98         private int IBNDS[] = new int[5];\r
99         private int IGEOM[] = new int[4]; // Written in original JAPHYC\r
100         private int PARNT[] = new int[IBNDS[0]]; // Written in original JAPHYC\r
101         private double RGEOM[] = new double[2]; // Written in original JAPHYC\r
102         private double HALEN[] = new double[IBNDS[0]]; // Written in original JAPHYC\r
103         private double MIDPT[] = new double[IBNDS[0]]; // Written in original JAPHYC\r
104         private double VTARG[] = new double[IBNDS[0]]; // Written in original JPAHYC\r
105         private int ISNPH[] = new int[6]; // Written in original JAPHYC\r
106         private int DGPOL[] = new int[IBNDS[0]]; // Written in original JAPHYC\r
107         private int JATYP[] = new int[IBNDS[0]]; // Written in original JAPHYC\r
108         private int LOSUB[] = new int[IBNDS[0]]; // Written in original JAPHYC\r
109         // Parts of RSNPH\r
110         private int NQPTS;\r
111         private int NJIND = NARCS + 1;\r
112         private int TNGQP = NQPTS * NJIND;\r
113         private int MNEQN;\r
114         private double ACOEF[] = new double[TNGQP]; // Written in original JAPHYC\r
115         private double BCOEF[] = new double[TNGQP]; // Written in original JAPHYC\r
116         private double AICOF[] = new double[TNGQP]; // Written in original JAPHYC\r
117         private double BICOF[] = new double[TNGQP]; // Written in original JAPHYC\r
118         private double QUPTS[] = new double[TNGQP]; // Written in original JAPHYC\r
119         private double QUWTS[] = new double[TNGQP]; // Written in original JAPHYC\r
120         private double H0VAL[] = new double[NJIND]; // Written in original JAPHYC\r
121         private double HIVAL[] = new double[NJIND]; // Written in original JAPHYC\r
122         private double JACIN[] = new double[NJIND]; // Written in original JAPHYC\r
123         private double ERARC[] = new double[IBNDS[0]]; // Written in original JAPHYC\r
124         private double BCFSN[] = new double[MNEQN]; // Written in original JAPHYC\r
125         private double SOLUN[] = new double[MNEQN]; // Written in original JAPHYC\r
126         // Parts of IWORK\r
127         private int IPIVT[] = new int[MNEQN];\r
128         private int LOQSB[] = new int[IBNDS[1]];\r
129         private int NQUAD[] = new int[IBNDS[1]];\r
130         private int HISUB[] = new int[IBNDS[0]];\r
131         private int LOTES[] = new int[IBNDS[0]];\r
132         private int HITES[] = new int[IBNDS[0]];\r
133         private int AXION[] = new int[IBNDS[0]];\r
134         private int NEWDG[] = new int[IBNDS[0]];\r
135         private int ICOPY[] = new int[IBNDS[0]];\r
136         private int LOOLD[] = new int[IBNDS[0]];\r
137         private int HIOLD[] = new int[IBNDS[0]];\r
138         // Parts of RWORK\r
139         private double WORK2[] = new double[MNEQN];\r
140         private double COLPR[] = new double[MNEQN];\r
141         private double A1COF[] = new double[IBNDS[1]];\r
142         private double B1COF[] = new double[IBNDS[1]];\r
143         private double TOLOU[] = new double[IBNDS[1]];\r
144         private double XIDST[] = new double[2 * IBNDS[1]];\r
145         private double XENPT[] = new double[IBNDS[2]];\r
146         private double QCOMX[] = new double[IBNDS[3]];\r
147         private double QCOMW[] = new double[IBNDS[3]];\r
148         private double RCOPY[] = new double[IBNDS[0]];\r
149         private double NEWHL[] = new double[IBNDS[0]];\r
150         private double AQCOF[] = new double[TNGQP];\r
151         private double BQCOF[] = new double[TNGQP];\r
152         private double CQCOF[] = new double[TNGQP];\r
153         private double COLSC[] = new double[TNGQP];\r
154         private double RIGLL[] = new double[TNGQP];\r
155         private double WORK[] = new double[2 * NQPTS];\r
156         private double DIAG[] = new double[NQPTS];\r
157         private double SDIAG[] = new double[NQPTS];\r
158         private double WORKT[] = new double[2 * NQPTS * NQPTS];\r
159         private double WORKQ[] = new double[NQPTS * NQPTS];\r
160         // Parts of ZWORK\r
161         private double ZCOLL[][] = new double[MNEQN][2];\r
162         private double XIVAL[][] = new double[2 * IBNDS[1]][2];\r
163         // Parts of LWORK\r
164         private boolean NEWQU[] = new boolean[IBNDS[1]];\r
165         private boolean LCOPY[] = new boolean[IBNDS[0]];\r
166         private boolean PNEWQ[] = new boolean[IBNDS[0]];\r
167         private boolean LNSEG[] = new boolean[IBNDS[0]];\r
168 \r
169         // CENTR - COMPLEX\r
170         // THE POINT IN THE PHYSICAL PLANE THAT IS TO BE\r
171         // MAPPED TO THE CENTRE OF THE UNIT DISC. FOR\r
172         // EXTERIOR DOMAINS CENTR MUST BE SOME POINT IN THE\r
173         // COMPLEMENTARY INTERIOR PHYSICAL DOMAIN.\r
174         // IN CASE ABS(ISYGP).GT.1 THEN CENTR MUST ALSO BE\r
175         // A CENTRE OF SYMMETRY FOR THE PHYSICAL DOMAIN.\r
176         private double CENTR[] = new double[2]; // Written in original JAPHYC\r
177         // INTER - LOGICAL\r
178         // TRUE IF THE PHYSICAL DOMAIN IS INTERIOR, FALSE\r
179         // OTHERWISE.\r
180         private boolean INTER; // Written in in original JAPHYC\r
181 \r
182         // COMMON /FNDEF/\r
183         private double BETA;\r
184         private double A1;\r
185         private double B1;\r
186         private double P0VAL;\r
187         private double SCALE;\r
188         private int TYPE;\r
189 \r
190         // From GQPHYC:\r
191         // IQUPH - INTEGER ARRAY\r
192         // AN INTEGER VECTOR OF SIZE AT LEAST 2*IBNDS(1) + 4,\r
193         // WHERE IBNDS(1) (=IGEOM(4)) IS THE VALUE PREVIOUSLY\r
194         // SUPPLIED TO JAPHYC; IQUPH STORES POINTERS TO\r
195         // ACCESS RQUPH AND ZQUPH.\r
196         private int IQUPH[] = new int[4];\r
197         private int LQSBF[] = new int[IBNDS[0]];\r
198         private int NPPQF[] = new int[IBNDS[0]];\r
199         // MQUPH - INTEGER\r
200         // THE MAXIMUM NUMBER OF QUADRATURE POINTS ALLOWED\r
201         // IN THE FINAL GLOBAL RULE. (THE VALUE OF THIS\r
202         // ARGUMENT IS LINKED TO THOSE OF ARGUMENTS NQPTS\r
203         // AND IBNDS(1) PREVIOUSLY SUPPLIED TO JAPHYC VIA\r
204         // MQUPH <= (MQIN1-1)*NQPTS*IBNDS(1))\r
205         private int MQUPH;\r
206         // RQUPH - REAL ARRAY\r
207         // A REAL VECTOR OF SIZE AT LEAST 3*MQUPH + 1; STORES\r
208         // THE REAL QUADRATURE DATA.\r
209         private double RQUPH[] = new double[1];\r
210         private double TPPQF[] = new double[MQUPH];\r
211         private double TRRAD[] = new double[MQUPH];\r
212         private double WPPQF[] = new double[MQUPH];\r
213         // ZQUPH - COMPLEX ARRAY\r
214         // A COMPLEX VECTOR OF SIZE AT LEAST MQUPH + 1;\r
215         // STORES THE QUADRATURE POINTS ON THE PHYSICAL\r
216         // BOUNDARY.\r
217         private double FACTR[] = new double[2]; // At first location of ZQUPH\r
218         private double ZPPQF[][] = new double[MQUPH][2];\r
219         // From JACANP:\r
220         // ISNCA - INTEGER ARRAY\r
221         // AN INTEGER VECTOR OF SIZE AT LEAST\r
222         // 4*IBNDS(1) + 6 ;\r
223         // ISNCA MAINLY STORES POINTERS TO ACCESS RSNCA AND\r
224         // ZSNCA.\r
225         private int ISNCA[] = new int[6];\r
226         private int DGPOC[] = new int[IBNDS[0]];\r
227         private int JTYPC[] = new int[IBNDS[0]];\r
228         private int LSUBC[] = new int[IBNDS[0]];\r
229         private int PRNSA[] = new int[IBNDS[0]];\r
230         // RSNCA - REAL ARRAY\r
231         // A REAL VECTOR OF SIZE AT LEAST\r
232         // 2*IBNDS(1) + (4 + 6*NQPTS)*(NARCS + 1) + 2,\r
233         // WHERE NARCS, NQPTS ARE INPUT ARGUMENTS TO JAPHYC.\r
234         // (NOTE: NARCS=IGEOM(1), NQPTS=IGEOM(2))\r
235         // STORES DATA RELATING TO THREE-TERM RECURRENCE\r
236         // SCHEMES, ELEMENTARY GAUSS-JACOBI QUADRATURE RULES,\r
237         // AND THE ARGUMENTS OF SUB-ARC ENDPOINTS ON THE UNIT\r
238         // DISC.\r
239         private double RSNCA[] = new double[1];\r
240         private double ACOFC[] = new double[TNGQP];\r
241         private double BCOFC[] = new double[TNGQP];\r
242         private double AICOC[] = new double[TNGQP];\r
243         private double BICOC[] = new double[TNGQP];\r
244         private double QUPTC[] = new double[TNGQP];\r
245         private double QUWTC[] = new double[TNGQP];\r
246         private double H0VLC[] = new double[NJIND];\r
247         private double HIVLC[] = new double[NJIND];\r
248         private double JAINC[] = new double[NJIND];\r
249         private double COARG[] = new double[NJIND];\r
250         private double PHPAS[] = new double[IBNDS[0]];\r
251         private double VARGC[] = new double[IBNDS[0]];\r
252         // ZSNCA - COMPLEX ARRAY\r
253         // Also called CSNCA elsewhere\r
254         // A COMPLEX VECTOR OF SIZE AT LEAST 2*IBNDS(2) + 1;\r
255         // STORES THE JACOBI COEFFICIENTS FOR THE COMPLEX\r
256         // (INVERSE) BOUNDARY CORRESPONDENCE FUNCTION AND\r
257         // ITS DERIVATIVE.\r
258         private double ZSNCA[] = new double[2]; // At first location of ZSNCA\r
259         private double BFSNC[][] = new double[IBNDS[1]][2];\r
260         private double SOLNC[][] = new double[IBNDS[1]][2];\r
261         // From GQCANP:\r
262         // MQIN1 - INTEGER\r
263         // DEFINES THE NUMBER OF PANELS ALLOWED IN A\r
264         // COMPOSITE RULE. SPECIFICALLY, MQIN1 = 1 + (THE\r
265         // MAXIMUM NUMBER OF PANELS IN A COMPOSITE RULE FOR\r
266         // A SINGLE SUB-ARC ON THE BOUNDARY)\r
267         private int MQIN1;\r
268         // MQUCA - INTEGER\r
269         // THE MAXIMUM NUMBER OF QUADRATURE POINTS ALLOWED\r
270         // IN THE FINAL GLOBAL RULE. THE VALUE OF THIS\r
271         // ARGUMENT IS LINKED TO THOSE OF ARGUMENTS NQPTS\r
272         // AND IBNDS(1) PREVIOUSLY SUPPLIED TO JACANP VIA\r
273         // MQUCA <= (MQIN1-1)*NQPTS*IBNDS(1). (NOTE THAT\r
274         // NQPTS = ISNCA(2) 'JACANP'IBNDS(1) =ISNCA(5) )\r
275         private int MQUCA = (MQIN1 - 1) * NQPTS * IBNDS[0];\r
276         // IQUCA - INTEGER ARRAY\r
277         // AN INTEGER VECTOR OF SIZE AT LEAST 2*IBNDS(1) + 4,\r
278         // WHERE IBNDS(1) (=ISNCA(5)) IS THE VALUE PREVIOUSLY\r
279         // SUPPLIED TO JACANP; IQUCA MAINLY STORES POINTERS\r
280         // TO ACCESS ZQUCA.\r
281         private int IQUCA[] = new int[4];\r
282         private int LQSBG[] = new int[IBNDS[0]];\r
283         private int NPPQG[] = new int[IBNDS[0]];\r
284         // ZQUCA - COMPLEX ARRAY\r
285         // A COMPLEX VECTOR OF SIZE AT LEAST 2*MQUCA+1;\r
286         // STORES THE QUADRATURE POINTS AND WEIGHTS.\r
287         private double ZQUCA[] = new double[2]; // At first location of ZQUCA\r
288         private double WPPQG[][] = new double[MQUCA][2];\r
289         private double ZPPQG[][] = new double[MQUCA][2];\r
290         // COMMON /DSDTDA/PT,MD,HL\r
291         private int PT;\r
292         private double MD;\r
293         private double HL;\r
294         //From LEVCUR:\r
295         Vector<Double> Contour[]; // x y pairs\r
296         Vector<Double>Ray[]; // x y pairs\r
297         // From TSTPLT\r
298         Vector<Double>Boundary; // x y pairs\r
299 \r
300         public SymmsIntegralMapping() {\r
301 \r
302         }\r
303 \r
304         public SymmsIntegralMapping(ModelImage destImg, ModelImage srcImg, String FORTFL, boolean SYMTY, boolean REFLN,\r
305                         double CENSY[], int NARCS, boolean NUMDER[], int ARCTY[], double STAPT[][], int PGM[], double RGM[],\r
306                         int PTX[], int NTX[], String DEFN[]) {\r
307                 super(destImg, srcImg);\r
308                 this.FORTFL = FORTFL;\r
309                 this.SYMTY = SYMTY;\r
310                 this.REFLN = REFLN;\r
311                 this.CENSY = CENSY;\r
312                 this.NARCS = NARCS;\r
313                 this.NUMDER = NUMDER;\r
314                 this.ARCTY = ARCTY;\r
315                 this.STAPT = STAPT;\r
316                 this.PGM = PGM;\r
317                 this.RGM = RGM;\r
318                 this.PTX = PTX;\r
319                 this.NTX = NTX;\r
320                 this.DEFN = DEFN;\r
321         }\r
322 \r
323         public void runAlgorithm() {\r
324                 fileDir = srcImage.getFileInfo(0).getFileDirectory();\r
325 \r
326                 // eps returns the distance from 1.0 to the next larger double-precision\r
327                 // number, that is, eps = 2^-52.\r
328                 // epsilon = D1MACH(4)\r
329                 // Machine epsilon is the smallest positive epsilon such that\r
330                 // (1.0 + epsilon) != 1.0.\r
331                 // epsilon = 2**(1 - doubleDigits) = 2**(1 - 53) = 2**(-52)\r
332                 // epsilon = 2.2204460e-16\r
333                 // epsilon is called the largest relative spacing\r
334                 EPS = 1.0;\r
335                 double neweps = 1.0;\r
336 \r
337                 while (true) {\r
338 \r
339                         if (1.0 == (1.0 + neweps)) {\r
340                                 break;\r
341                         } else {\r
342                                 EPS = neweps;\r
343                                 neweps = neweps / 2.0;\r
344                         }\r
345                 } // while(true)\r
346         }\r
347 \r
348         public void PARGEN() {\r
349                 // .......................................................................\r
350                 // AN INTERACTIVE PREPROCESSOR TO HELP THE C O N F P A C K USER\r
351                 // GENERATE THE FORTRAN CODE DEFINING THE BOUNDARY PARAMETRISATION\r
352                 // AND ITS DERIVATIVE.\r
353                 //\r
354                 // THE FOLLOWING CONVENTIONS ARE ASSUMED:\r
355                 //\r
356                 // ** IF A QUESTION REQUIRES A YES OR NO ANSWER, THE DETECTION OF 'Y' OR\r
357                 // 'y' IN THE FIRST 6 INPUT CHARACTERS IS TAKEN AS YES, ANYTHING ELSE\r
358                 // AS NO.\r
359                 //\r
360                 // ** WHEN ASKED FOR COORDINATES, THIS ALWAYS MEANS CARTESIAN COORDIN-\r
361                 // ATES AND THESE SHOULD BE SUPPLIED AS TWO REAL NUMBERS, AS EITHER\r
362                 //\r
363                 // X,Y OR X Y\r
364                 //\r
365                 // WITHOUT PARENTHESES.\r
366                 //\r
367                 // ** FOUR TYPES OF ARCS ARE CURRENTLY TREATED, WITH NUMERICAL CODES TO\r
368                 // DENOTE THE TYPE AS FOLLOWS:\r
369                 // 1:= LINE SEGMENT.\r
370                 // 2:= CIRCULAR ARC SEGMENT.\r
371                 // CONVENTIONS:\r
372                 // 1 - THE ANGLE SUBTENDED AT THE CENTRE IS POSITIVE FOR\r
373                 // ANTICLOCKWISE TRAVERSAL OF THE ARC AND NEGATIVE FOR\r
374                 // CLOCKWISE TRAVERSAL.\r
375                 // 3:= THE USER IS ASKED TO SUPPLY THE FORTRAN 77 ARITHMETIC\r
376                 // EXPRESSIONS WHICH DEFINE THE CARTESIAN PARAMETRIC FUNCTION\r
377                 // AND THE DERIVATIVE OF THIS FUNCTION.\r
378                 // CONVENTIONS:\r
379                 // 1 - THE PARAMETER MUST BE DENOTED BY T.\r
380                 // 2 - THE REAL CONSTANT PI=3.14159.. AND THE COMPLEX CONSTANT\r
381                 // UI=(0.0,1.0) MAY BE USED IN THE ARITHMETIC EXPRESSIONS.\r
382                 // 4:= THE USER IS ASKED TO SUPPLY THE FORTRAN 77 ARITHMETIC\r
383                 // EXPRESSIONS WHICH DEFINE THE POLAR COORDINATE AS A FUNCTION\r
384                 // OF POLAR ANGLE AND THE DERIVATIVE OF THIS FUNCTION.\r
385                 // CONVENTIONS:\r
386                 // 1 - THE POLAR ANGLE MUST BE DENOTED BY T.\r
387                 // 2 - THE REAL CONSTANT PI=3.14159.. MAY BE USED IN THE ARITH-\r
388                 // METIC EXPRESSIONS.\r
389                 // 3 - PARGEN ASSIGNS THE EXPRESSION FOR THE RADIUS TO THE\r
390                 // COMPLEX VARIABLE ZRAD; IF REQUIRED THE USER MAY THERE-\r
391                 // FORE USE THE VARIABLE ZRAD IN THE EXPRESSION FOR THE\r
392                 // DERIVATIVE OF THE RADIUS WRT POLAR ANGLE\r
393                 // IN ADDITION, FOR TYPES 3 AND 4, THE FOLLOWING CONVENTIONS HOLD:\r
394                 // 1 - ONLY USE UP TO 66 CHARACTERS PER LINE.\r
395                 // 2 - IF THE EXPRESSION OCCUPIES MORE THAN ONE LINE THEN THERE\r
396                 // IS NO NEED TO SUPPLY ANY CONTINUATION CHARACTER.\r
397                 // 3 - ONLY USE THOSE FORTRAN 77 INTRINSIC MATHS FUNCTIONS\r
398                 // WHICH ACCEPT COMPLEX ARGUMENTS AND ARE ANALYTIC; I.E.,\r
399                 // IN STANDARD FORTRAN,\r
400                 // SQRT, EXP, LOG, SIN, COS\r
401                 // 4 - THE WHOLE EXPRESSION SHOULD BE TERMINATED WITH A\r
402                 // REPEATED DIVISION SIGN, I.E. //.\r
403                 //\r
404                 // ** THE CODE ISN'T VERY ROBUST IN THAT THERE IS LITTLE PROVISION FOR\r
405                 // INTERACTIVE CORRECTION OF ERRORS. HOWEVER, ALL THE USER'S INPUT\r
406                 // IS AUTOMATICALLY OUTPUT TO A FILE NAMED pgenin. IF THE USER\r
407                 // REALISES THAT AN ITEM HAS BEEN INPUT INCORRECTLY, THE BEST POLICY\r
408                 // IS TO CARRY ON TO THE END OF THE INPUT PHASE AND THEN TERMINATE\r
409                 // THE EXECUTION; THE FILE pgenin CAN BE EDITED, RENAMED AND\r
410                 // SUBMITTED AS STANDARD INPUT FOR A SECOND RUN OF PARGEN.\r
411                 // (THE SUGGESTION TO RENAME IS TO AVOID ANY POSSIBLE DIFFICULTY\r
412                 // ARISING FROM READING THE FILE AS STANDARD INPUT WHILST ALSO\r
413                 // WRITING OUTPUT TO THE SAME FILE.)\r
414                 // IF THE USER REALISES ONLY AT A LATER STAGE (E.G. IN PLOTTING THE\r
415                 // BOUNDARY) THAT AN ITEM HAS BEEN INPUT INCORRECTLY THEN pgenin\r
416                 // MAY STILL BE AVAILABLE FOR RE-USE AS ABOVE.\r
417                 //\r
418                 // SUBROUTINES OR FUNCTIONS NEEDED\r
419                 // - THE CONFPACK LIBRARY.\r
420                 // - THE REAL FUNCTION R1MACH.\r
421                 //\r
422                 // .......................................................................\r
423                 // AUTHOR: DAVID HOUGH, COVENTRY POLYTECHNIC, UK\r
424                 // LAST UPDATE: 15 FEB 1991\r
425                 // .......................................................................\r
426                 //\r
427                 // LOCAL VARIABLES\r
428                 //\r
429                 int GMCO, IA, I, J, L, SW, TXCO;\r
430                 int TYPE = 1;\r
431                 int IER[] = new int[1];\r
432                 int ORDRG[] = new int[1];\r
433                 int ORDSG[] = new int[1];\r
434                 double X = 0.0;\r
435                 double Y = 0.0;\r
436                 double ALPHA = 0.0;\r
437                 double PI;\r
438                 // COMPLEX CENSY,RTUNI,U2\r
439                 double RTUNI[] = new double[2];\r
440                 double U2[] = new double[2];\r
441                 // CHARACTER TXT*72,TABC*6,FORTFL*72,CH*2,SIG(10)*2,WID(10)*2,REDD*6,\r
442                 // +FMT1*8,FMT2*9\r
443                 String TXT = null;\r
444                 String CH;\r
445                 String SIG[] = new String[] { "7", "8", "9", "10", "11", "12", "13", "14", "15", "16" };\r
446                 String WID[] = new String[] { "15", "16", "17", "18", "19", "20", "21", "22", "23", "24" };\r
447                 String REDD;\r
448                 // String FMT1;\r
449                 // String FMT2;\r
450 \r
451                 // PARAMETER (MNARC=100,TABC=' +',CHNL=20,CHIN=21)\r
452                 final String TABC = "     +";\r
453                 final int CHNL = 20;\r
454                 // final int CHIN = 21;\r
455                 String line;\r
456                 String tokens[];\r
457 \r
458                 File file;\r
459                 RandomAccessFile raFile = null;\r
460                 boolean validInput;\r
461                 String junk;\r
462 \r
463                 // EXTERNAL CHRIN,HEADER,R1MACH,SYINF1,WRFUN1,WRFUN2,WRHEAD,WRSYM1,\r
464                 // +WRSYM2,WRSYM3,WRTAIL\r
465 \r
466                 WRHEAD(6, 0, null);\r
467 \r
468                 PI = Math.PI;\r
469 \r
470                 // **** DETERMINE NUMBER OF SIGNIFICANT FIGURES REQUIRED TO MATCH\r
471                 // MACHINE\r
472                 // **** PRECISION AND SET UP POINTER SW TO SIG AND WID\r
473 \r
474                 SW = (int) (-Math.log10(EPS)) + 2;\r
475                 if (SW <= 7) {\r
476                         SW = 1;\r
477                 } else if (SW >= 16) {\r
478                         SW = 10;\r
479                 } else {\r
480                         SW = SW - 6;\r
481                 }\r
482 \r
483                 // **** SET UP THE EDIT DESCRIPTOR AND FORMAT SPECIFICATION FOR FLOATING\r
484                 // **** POINT OUTPUT\r
485 \r
486                 REDD = "E" + WID[SW - 1] + "." + SIG[SW - 1];\r
487                 // FMT1="("+REDD+")";\r
488                 // FMT2="(2"+REDD+")";\r
489                 if (traditionalInput) {\r
490                         System.out.println("ENTER FILENAME TO RECEIVE OUTPUT JAVA CODE");\r
491                         FORTFL = input.next();\r
492                 } // if (traditionalInput)\r
493 \r
494                 // **** WRITE THE SOURCE CODE FOR PARFUN\r
495                 fileDir = "C:\\conformal mapping\\CONFPACK\\";\r
496                 file = new File(fileDir + FORTFL);\r
497                 \r
498                 try {\r
499                         raFile = new RandomAccessFile(file, "rw");\r
500                 } catch (IOException e) {\r
501                         MipavUtil.displayError("IOException " + e + " on raFile = new RandomAccessFile(file, rw)");\r
502                         System.exit(-1);\r
503                 }\r
504                 // Necessary so that if this is an overwritten file there isn't any\r
505                 // junk at the end\r
506                 try {\r
507                         raFile.setLength(0);\r
508                 } catch (IOException e) {\r
509                         MipavUtil.displayError("IOException " + e + " on raFile.setLength(0)");\r
510                         System.exit(-1);\r
511                 }\r
512 \r
513                 // OPEN(CHNL,FILE=FORTFL)\r
514 \r
515                 if (traditionalInput) {\r
516                         validInput = false;\r
517                         while (!validInput) {\r
518                                 System.out.println("DOES THE DOMAIN HAVE ANY SYMMETRY (Y/N)?");\r
519                                 String sym = input.next();\r
520                                 String firstSym = sym.substring(0, 1);\r
521                                 if (firstSym.equalsIgnoreCase("Y")) {\r
522                                         SYMTY = true;\r
523                                         validInput = true;\r
524                                 } else if (firstSym.equalsIgnoreCase("N")) {\r
525                                         SYMTY = false;\r
526                                         validInput = true;\r
527                                 } else {\r
528                                         System.out.println(sym + " is not a valid response");\r
529                                 }\r
530                         } // while (!validInput)\r
531 \r
532                         if (SYMTY) {\r
533                                 validInput = false;\r
534                                 while (!validInput) {\r
535                                         System.out.println("ARE THERE ANY REFLECTIONAL SYMMETRIES (Y/N)?");\r
536                                         String ref = input.next();\r
537                                         String firstRef = ref.substring(0, 1);\r
538                                         if (firstRef.equalsIgnoreCase("Y")) {\r
539                                                 REFLN = true;\r
540                                                 validInput = true;\r
541                                         } else if (firstRef.equalsIgnoreCase("N")) {\r
542                                                 REFLN = false;\r
543                                                 validInput = true;\r
544                                         } else {\r
545                                                 System.out.println(ref + " is not a valid response");\r
546                                         }\r
547                                 } // while (!validInput)\r
548 \r
549                                 validInput = false;\r
550                                 while (!validInput) {\r
551                                     System.out.println("What are the coordinates of the center of symmetry (X,Y)?");\r
552                                     try {\r
553                                         line = input.next();\r
554                                         tokens = line.split(",");\r
555                                         CENSY[0] = Double.valueOf(tokens[0]);\r
556                                         CENSY[1] = Double.valueOf(tokens[0]);\r
557                                         validInput = true;\r
558                                     }\r
559                                     catch (Exception e) {};\r
560                                 }\r
561                                 validInput = false;\r
562                                 while (!validInput) {\r
563                                         System.out.println("How many arcs are there on the fundamental boundary section?");\r
564                                         NARCS = input.nextInt();\r
565                                         if (NARCS <= MNARC - 1) {\r
566                                                 validInput = true;\r
567                                         } else {\r
568                                                 System.out.print("NARCS must be <= " + (MNARC - 1));\r
569                                         }\r
570                                 } // while (!validInput)\r
571                         } // if (SYMTY)\r
572                         else { // !SYMTY\r
573                                 validInput = false;\r
574                                 while (!validInput) {\r
575                                         System.out.println("How many arcs are there on the boundary?");\r
576                                         NARCS = input.nextInt();\r
577                                         if (NARCS <= MNARC - 1) {\r
578                                                 validInput = true;\r
579                                         } else {\r
580                                                 System.out.println("NARCS must be <= " + (MNARC - 1));\r
581                                         }\r
582                                 } // while (!validInput)\r
583                         } // else !SYMTY\r
584 \r
585                         GMCO = 0;\r
586                         TXCO = 0;\r
587 \r
588                         for (IA = 1; IA <= NARCS; IA++) {\r
589                                 NUMDER[IA - 1] = false;\r
590                                 validInput = false;\r
591                                 while (!validInput) {\r
592                                         System.out.println("ENTER THE TYPE OF ARC(1-4) for ARC NUMBER " + IA);\r
593                                         try {\r
594                                             TYPE = input.nextInt();\r
595                                                 if ((TYPE >= 1) && (TYPE <= 4)) {\r
596                                                         validInput = true;\r
597                                                 } else {\r
598                                                         System.out.println("TYPE MUST BE BETWEEN 1 and 4");\r
599                                                 }\r
600                                         }\r
601                                         catch (Exception e) {};\r
602                                 } // while (!validInput)\r
603                                 if (TYPE == 1) {\r
604                                         ARCTY[IA - 1] = TYPE;\r
605                                         validInput = false;\r
606                                         while (!validInput) {\r
607                                                 try {\r
608                                                         System.out.println("What are the coordinates of the initial point on the line (X,Y)?");\r
609                                                 line = input.next();\r
610                                                 tokens = line.split(",");\r
611                                                 STAPT[IA - 1][0] = Double.valueOf(tokens[0]);\r
612                                                 STAPT[IA - 1][1] = Double.valueOf(tokens[1]);\r
613                                                 validInput = true;\r
614                                                 }\r
615                                                 catch (Exception e) {};\r
616                                         }\r
617                                 } // if (TYPE == 1)\r
618                                 else if (TYPE == 2) {\r
619                                         ARCTY[IA - 1] = TYPE;\r
620                                         validInput = false;\r
621                                         while (!validInput) {\r
622                                                 try {\r
623                                                         System.out.println("What are the coordinates of the initial point on the circle (X,Y)?");\r
624                                                 line = input.next();\r
625                                                 tokens = line.split(",");\r
626                                                 STAPT[IA - 1][0] = Double.valueOf(tokens[0]);\r
627                                                 STAPT[IA - 1][1] = Double.valueOf(tokens[1]);\r
628                                                 validInput = true;\r
629                                                 }\r
630                                                 catch (Exception e) {};\r
631                                         }\r
632                                         validInput = false;\r
633                                         while (!validInput) {\r
634                                                 try {\r
635                                                         System.out.println("What are the coordinates of the center of the circle (X,Y)?");\r
636                                                 line = input.next();\r
637                                                 tokens = line.split(",");\r
638                                                 X = Double.valueOf(tokens[0]);\r
639                                                 Y = Double.valueOf(tokens[1]);\r
640                                                 validInput = true;\r
641                                                 }\r
642                                                 catch (Exception e) {};\r
643                                         }\r
644                                         validInput = false;\r
645                                         while (!validInput) {\r
646                                                 try {\r
647                                                      System.out.println("What is the signed angle subtended at center (in units of PI)?");\r
648                                                      ALPHA = input.nextDouble();\r
649                                                      validInput = true;\r
650                                                 }\r
651                                                 catch (Exception e) {};\r
652                                         }\r
653                                         GMCO = GMCO + 1;\r
654                                         PGM[IA - 1] = GMCO;\r
655                                         RGM[GMCO - 1] = X;\r
656                                         GMCO = GMCO + 1;\r
657                                         RGM[GMCO - 1] = Y;\r
658                                         GMCO = GMCO + 1;\r
659                                         RGM[GMCO - 1] = ALPHA * PI;\r
660                                 } // else if (TYPE == 2)\r
661                                 else if ((TYPE == 3) || (TYPE == 4)) {\r
662                                         ARCTY[IA - 1] = TYPE;\r
663                                         validInput = false;\r
664                                         while (!validInput) {\r
665                                                 try {\r
666                                                         System.out.println("What are the coordinates of the initial point on the curve (X,Y)?");\r
667                                                 line = input.next();\r
668                                                 tokens = line.split(",");\r
669                                                 STAPT[IA - 1][0] = Double.valueOf(tokens[0]);\r
670                                                 STAPT[IA - 1][1] = Double.valueOf(tokens[1]);\r
671                                                 validInput = true;\r
672                                                 }\r
673                                                 catch (Exception e) {};\r
674                                         }\r
675                                         validInput = false;\r
676                                         while (!validInput) {\r
677                                                 try {\r
678                                                         if (TYPE == 3) {\r
679                                                                 System.out.println("Enter the initial and final parameter values (X,Y)");\r
680                                                         } else {\r
681                                                                 System.out.println("Enter the initial and final polar values (in angles of PI) (X,Y)");\r
682                                                         }\r
683                                                 line = input.next();\r
684                                                 tokens = line.split(",");\r
685                                                 X = Double.valueOf(tokens[0]);\r
686                                                 Y = Double.valueOf(tokens[1]);\r
687                                                 validInput = true;\r
688                                                 }\r
689                                                 catch (Exception e) {};\r
690                                         }\r
691                                         GMCO = GMCO + 1;\r
692                                         PGM[IA - 1] = GMCO;\r
693                                         if (TYPE == 4) {\r
694                                                 RGM[GMCO - 1] = X * PI;\r
695                                                 GMCO = GMCO + 1;\r
696                                                 RGM[GMCO - 1] = Y * PI;\r
697                                         } else {\r
698                                                 RGM[GMCO - 1] = X;\r
699                                                 GMCO = GMCO + 1;\r
700                                                 RGM[GMCO - 1] = Y;\r
701                                         }\r
702                                         for (J = 1; J <= 2; J++) {\r
703                                                 if (J == 1 && TYPE == 3) {\r
704                                                         System.out.println("ENTER JAVA EXPRESSION WITH NO SPACES ENDING IN // FOR PARFUN");\r
705                                                         System.out.println("PUT REAL PART ui IMAGINARY PART");\r
706                                                 } else if (J == 2 && TYPE == 3) {\r
707                                                         System.out.println("ENTER JAVA EXPRESSION WITH NO SPACES ENDING IN // FOR DPARFN");\r
708                                                         System.out.println("PUT REAL PART ui IMAGINARY PART");\r
709                                                         System.out.println("ALTERNATIVELY JUST ENTER // FOR NUMERICAL DERIVATIVE");\r
710                                                 } else if (J == 1 && TYPE == 4) {\r
711                                                         System.out.println("ENTER JAVA EXPRESSION WITH NO SPACES ENDING IN // FOR RADIUS");\r
712                                                 } else {\r
713                                                         System.out.println("ENTER JAVA EXPRESSION WITH NO SPACES ENDING IN // FOR RADIUS DERIVATIVE");\r
714                                                         System.out.println("ALTERNATIVELY JUST ENTER // FOR NUMERICAL DERIVATIVE");\r
715                                                 }\r
716                                                 // Java does not allow operator overloading, so you can't do a cos(t)*sin(t) for complex t.\r
717                                                 System.out.println("Expand cos(complex T[]) as Math.cos(T[0])*Math.cosh(T[1]) - i*Math.sin(T[0])*Math.sinh(T[1])");\r
718                                                 System.out.println("Expand sin(complex T[]) as Math.sin(T[0])*Math.cosh(T[1]) + i*Math.cos(T[0])*Math.sinh(T[1])");\r
719 \r
720                                                 TXCO = TXCO + 1;\r
721                                                 PTX[IA - 1 + (J - 1) * MNARC] = TXCO;\r
722                                                 I = 1;\r
723 \r
724                                                 L = -1;\r
725                                                 while (L == -1) {\r
726                                                         TXT = input.next();\r
727                                                         L = TXT.indexOf("//");\r
728                                                         if (L == -1) {\r
729                                                                 DEFN[TXCO - 1] = TXT;\r
730                                                                 I = I + 1;\r
731                                                                 TXCO = TXCO + 1;\r
732                                                         } // if (L == -1)\r
733                                                 } // while (L == -1)\r
734                                                 NTX[IA - 1 + (J - 1) * MNARC] = I;\r
735                                                 if ((L == 0) && (I == 1)) {\r
736                                                         // If just // on first line, use numerical derivative for DPARFN or RADIUS DERIVATIVE in PTFUN2\r
737                                                         DEFN[TXCO - 1] = "";\r
738                                                         NUMDER[IA - 1] = true;\r
739                                                 } else if (L == 0) {\r
740                                                         DEFN[TXCO-1] = "";\r
741                                                 } else {\r
742                                                         DEFN[TXCO - 1] = TXT.substring(0, L);\r
743                                                 }\r
744                                                 if ((J == 1) && (TYPE == 4)) {\r
745                                                         System.out.println("(... = ZRAD)");\r
746                                                 }\r
747                                         } // for (J = 1; J <= 2; J++)\r
748                                 } // else if ((TYPE == 3) || (TYPE == 4))\r
749                         } // for (IA = 1; IA <= NARCS; IA++)\r
750 \r
751                         if (SYMTY) {\r
752                                 validInput = false;\r
753                                 while (!validInput) {\r
754                                         try {\r
755                                                 System.out.println("ENTER THE COORDINATES OF FINAL POINT ON THIS LAST ARC (X,Y)");\r
756                                         line = input.next();\r
757                                         tokens = line.split(",");\r
758                                         STAPT[NARCS][0] = Double.valueOf(tokens[0]);\r
759                                         STAPT[NARCS][1] = Double.valueOf(tokens[1]);\r
760                                         validInput = true;\r
761                                         }\r
762                                         catch (Exception e) {};\r
763                                 }\r
764                         } else {\r
765                                 STAPT[NARCS][0] = STAPT[0][0];\r
766                                 STAPT[NARCS][1] = STAPT[0][1];\r
767                         }\r
768 \r
769                         validInput = false;\r
770                         while (!validInput) {\r
771                                 System.out.println("END OF INPUT PHASE; CONTINUE WITH PROCESSING (Y/N)?");\r
772                                 String term = input.next();\r
773                                 String firstTerm = term.substring(0, 1);\r
774                                 if (firstTerm.equalsIgnoreCase("Y")) {\r
775                                         validInput = true;\r
776                                 } else if (firstTerm.equalsIgnoreCase("N")) {\r
777                                         validInput = true;\r
778                                         setCompleted(false);\r
779                                         try {\r
780                                                 raFile.close();\r
781                                         } catch (IOException e) {\r
782 \r
783                                         }\r
784                                         return;\r
785                                 } else {\r
786                                         System.out.println(term + " is not a valid response");\r
787                                 }\r
788                         } // while (!validInput)\r
789                 } // if (traditionalInput)\r
790                 HEADER("PARFUN", REDD, raFile);\r
791                 \r
792                 if (SYMTY) {\r
793                         SYINF1(ORDRG, ORDSG, RTUNI, U2, REFLN, CENSY, STAPT[0], STAPT[NARCS], IER);\r
794                         if (IER[0] > 0) {\r
795                                 WRTAIL(6, 0, IER[0], null);\r
796                                 return;\r
797                         }\r
798                         System.out.println("\nN O T E : THE ORDER OF THE SYMMETRY GROUP IS " + ORDSG);\r
799                         if (REFLN) {\r
800                                 System.out.println("          ISYGP = " + (-ORDSG[0]));\r
801                         } else {\r
802                                 System.out.println("          ISYGP = " + (ORDSG[0]));\r
803                         }\r
804                         WRSYM1(NARCS, ORDRG[0], ORDSG[0], RTUNI, U2, CENSY, REFLN, true, REDD, CHNL, raFile);\r
805                         if (REFLN) {\r
806                                 CH = "TS";\r
807                         } else {\r
808                                 CH = "TT";\r
809                         }\r
810                         WRFUN1(NARCS, STAPT, ARCTY, PGM, RGM, PTX, NTX, DEFN, CHNL, "IB", CH, "ZETA  ", REDD, raFile);\r
811                         WRSYM2(NARCS, ORDRG[0], CENSY, REFLN, CHNL, raFile);\r
812                 } else {\r
813                         WRFUN1(NARCS, STAPT, ARCTY, PGM, RGM, PTX, NTX, DEFN, CHNL, "IA", "TT", "PARFUN", REDD, raFile);\r
814                 }\r
815 \r
816                 try {\r
817                         raFile.writeBytes("//\n");\r
818                         raFile.writeBytes("}\n");\r
819 \r
820                         // **** WRITE THE SOURCE CODE FOR DPARFN\r
821 \r
822                         raFile.writeBytes("//...........................................\n");\r
823                 } catch (IOException e) {\r
824                         MipavUtil.displayError("IOException " + e + " in PARGEN");\r
825                         System.exit(-1);\r
826                 }\r
827                 HEADER("DPARFN", REDD, raFile);\r
828                 if (SYMTY) {\r
829                         WRSYM1(NARCS, ORDRG[0], ORDSG[0], RTUNI, U2, CENSY, REFLN, false, REDD, CHNL, raFile);\r
830                         if (REFLN) {\r
831                                 CH = "TS";\r
832                         } else {\r
833                                 CH = "TT";\r
834                         }\r
835                         WRFUN2(NARCS, MNARC, STAPT, ARCTY, PGM, RGM, PTX, NTX, DEFN, CHNL, "IB", CH, "ZETA  ", NUMDER, REDD,\r
836                                         raFile);\r
837                         WRSYM3(NARCS, ORDRG[0], REFLN, CHNL, raFile);\r
838                 } // if (SYMTY)\r
839                 else {\r
840                         WRFUN2(NARCS, MNARC, STAPT, ARCTY, PGM, RGM, PTX, NTX, DEFN, CHNL, "IA", "TT", "DPARFN", NUMDER, REDD,\r
841                                         raFile);\r
842                 }\r
843 \r
844                 try {\r
845                         raFile.writeBytes("//\n");\r
846                         raFile.writeBytes("}\n");\r
847                         raFile.close();\r
848                 } catch (IOException e) {\r
849                         MipavUtil.displayError("IOException " + e + " in PARGEN");\r
850                         System.exit(-1);\r
851                 }\r
852                 WRTAIL(6, 0, IER[0], null);\r
853 \r
854         } // public void PARGEN\r
855 \r
856         private void HEADER(String TXT, String REDD, RandomAccessFile raFile) {\r
857 \r
858                 String TAB6 = "      ";\r
859 \r
860                 String LINE = TAB6 + "private double[] " + TXT + "(int IA, double TT[]) {\n";\r
861                 try {\r
862                         raFile.writeBytes(LINE);\r
863 \r
864                 LINE = TAB6 + "double " + TXT + "ANS[] = new double[2];\n";\r
865                 raFile.writeBytes(LINE);\r
866                 LINE = TAB6 + "double ZRAD[] = new double[2];\n";\r
867                 raFile.writeBytes(LINE);\r
868                 LINE = TAB6 + "int IA;\n";\r
869                 raFile.writeBytes(LINE);\r
870                 LINE = TAB6 + "double T[] = new double[2];\n";\r
871                 raFile.writeBytes(LINE);\r
872                 LINE = TAB6 + "double TT[] = new double[2];\n";\r
873                 raFile.writeBytes(LINE);\r
874 \r
875                         raFile.writeBytes("      double PI = " + Math.PI + ";\n");\r
876                         raFile.writeBytes("//\n");\r
877                 } catch (IOException e) {\r
878                         MipavUtil.displayError("IOException " + e + " in HEADER");\r
879                         System.exit(-1);\r
880                 }\r
881 \r
882         } // private void HEADER\r
883 \r
884         private void SYINF1(int ORDRG[], int ORDSG[], double RTUNI[], double U2[], boolean REFLN, double Z0[], double Z1[],\r
885                         double Z2[], int IER[]) {\r
886                 // COMPLEX RTUNI,U2,Z0,Z1,Z2\r
887 \r
888                 // **** GIVEN Z0,THE CENTRE OF SYMMETRY, Z1 AND Z2, THE INITIAL AND\r
889                 // FINAL\r
890                 // **** POINTS ON THE FUNDAMENTAL BOUNDARY SECTION, REFLN, WHICH IS TRUE\r
891                 // **** IF THE SYMMETRY GROUP HAS IMPROPER ROTATIONAL ELEMENTS\r
892                 // **** (I.E. REFLECTIONAL SYMMETRIES), THIS ROUTINE COMPUTES\r
893                 // **** ORDRG - THE ORDER OF THE SUBGROUP OF PROPER ROTATIONS (THIS IS\r
894                 // THE\r
895                 // **** ORDER OF THE SYMMETRY GROUP IF REFLN=.FALSE.)\r
896                 // **** ORDSG - THE ORDER OF THE FULL SYMMETRY GROUP, EITHER ORDRG OR\r
897                 // **** 2*ORDRG DEPENDING ON WHETHER REFLN IS .FALSE. OR .TRUE.\r
898                 // **** RTUNI - THE ROOT OF UNITY FROM WHICH THE PROPER ROTATIONAL\r
899                 // SUBROUP\r
900                 // **** IS GENERATED\r
901                 // **** U2 - THE ADDITIONAL IN-PLANE ROTATION WHICH, WHEN COMBINED WITH\r
902                 // **** CONJUGATION, DEFINES THE IMPROPER ROTATION FOR THE CASE\r
903                 // **** REFLN=.TRUE.\r
904 \r
905                 // LOCAL VARIABLES\r
906 \r
907                 double ALPHA, PI, SQRTEPS;\r
908                 // COMPLEX CT,U\r
909                 double CT[] = new double[2];\r
910                 double U[] = new double[2];\r
911                 double cr[] = new double[1];\r
912                 double ci[] = new double[1];\r
913 \r
914                 PI = Math.PI;\r
915                 SQRTEPS = Math.sqrt(EPS);\r
916                 CT[0] = Z2[0] - Z0[0];\r
917                 CT[1] = Z2[1] - Z0[1];\r
918                 double ABSCT = zabs(CT[0], CT[1]);\r
919                 if (ABSCT < SQRTEPS) {\r
920                         IER[0] = 56;\r
921                         return;\r
922                 }\r
923                 U[0] = CT[0] / ABSCT;\r
924                 U[1] = CT[1] / ABSCT;\r
925                 zmlt(U[0], U[1], U[0], U[1], cr, ci);\r
926                 U2[0] = cr[0];\r
927                 U2[1] = ci[0];\r
928 \r
929                 zmlt(Z1[0] - Z0[0], Z1[1] - Z0[1], U[0], -U[1], cr, ci);\r
930                 CT[0] = cr[0];\r
931                 CT[1] = ci[0];\r
932                 ABSCT = zabs(CT[0], CT[1]);\r
933                 if (ABSCT < SQRTEPS) {\r
934                         IER[0] = 57;\r
935                         return;\r
936                 }\r
937                 ALPHA = Math.atan2(CT[1], CT[0]);\r
938                 ALPHA = Math.abs(ALPHA);\r
939 \r
940                 if (REFLN) {\r
941                         ORDRG[0] = (int) Math.round(PI / ALPHA);\r
942                         ORDSG[0] = 2 * ORDRG[0];\r
943                 } else {\r
944                         ORDRG[0] = 2 * (int) Math.round(PI / ALPHA);\r
945                         ORDSG[0] = ORDRG[0];\r
946                 }\r
947 \r
948                 ALPHA = 2.0 * PI / (double) (ORDRG[0]);\r
949                 RTUNI[0] = Math.cos(ALPHA);\r
950                 RTUNI[1] = Math.sin(ALPHA);\r
951 \r
952                 // NORMAL EXIT\r
953 \r
954                 IER[0] = 0;\r
955                 return;\r
956         } // private void SYINF1\r
957 \r
958         // COMPLEX FUNCTION PARFUN(I,T)\r
959         // INTEGER I\r
960         // COMPLEX T\r
961         // \r
962         double[] PARFUN(int I, double T[]) {\r
963 \r
964                 // DUMMY FUNCTION TO AID LINK-LOADING OF PARGEN\r
965 \r
966                 double result[] = new double[] { 1.0, 0.0 };\r
967                 return result;\r
968         } // double[] PARFUN\r
969 \r
970         // COMPLEX FUNCTION DPARFN(I,T)\r
971         // INTEGER I\r
972         // COMPLEX T\r
973         double[] DPARFN(int I, double T[]) {\r
974 \r
975                 // DUMMY FUNCTION TO AID LINK-LOADING OF PARGEN\r
976 \r
977                 double result[] = new double[] { 1.0, 0.0 };\r
978                 return result;\r
979         } // double[] DPARFN\r
980 \r
981         private void WRHEAD(int I, int CHNL, RandomAccessFile raFile) {\r
982 \r
983                 // **** WRITE A HEADING FOR THE MAIN CONFPACK MODULES JAPHYC (I=1),\r
984                 // **** GQPHYC (I=2), JACANP (I=3), GQCANP (I=4), CNDPLT (I=5), THE\r
985                 // **** PARAMETRIC FUNCTION GENERATOR PARGEN (I=6),THE PARAMETRIC\r
986                 // FUNCTION\r
987                 // **** TESTER TSTPLT (I=7) AND THE LEVEL CURVE ROUTINE LEVCUR (I=8). IF\r
988                 // **** CHNL=0 THEN WRITE ON THE STANDARD OUTPUT CHANNEL, OTHERWISE\r
989                 // WRITE\r
990                 // **** ON THE CHANNEL SPECIFIED BY CHNL.\r
991                 //\r
992                 // LOCAL VARIABLES\r
993                 //\r
994                 String DOTS = ".................................................";\r
995                 String CPHEAD = ": C O N F P A C K    M O D U L E    ";\r
996                 String MOD[] = new String[] { "J A P H Y C :", "G Q P H Y C :", "J A C A N P :", "G Q C A N P :",\r
997                                 "C N D P L T :", "P A R G E N :", "T S T P L T :", "L E V C U R :" };\r
998                 String TXT = CPHEAD + MOD[I - 1];\r
999 \r
1000                 if (CHNL == 0 || CHNL == 6) {\r
1001                         System.out.println("\n\n      " + DOTS + "\n      " + TXT + "\n      " + DOTS);\r
1002                 } else {\r
1003                         try {\r
1004                                 raFile.writeBytes("\n\n      //" + DOTS + "\n      //" + TXT + "\n      //" + DOTS + "\n");\r
1005                         } catch (IOException e) {\r
1006                                 MipavUtil.displayError("IOException " + e + " on raFile.writeBytes in WRHEAD");\r
1007                                 System.exit(-1);\r
1008                         }\r
1009                 }\r
1010                 return;\r
1011         } // private void WRHEAD\r
1012 \r
1013         private void WRTAIL(int I, int CHNL, int IER, RandomAccessFile raFile) {\r
1014 \r
1015                 //\r
1016                 // **** WRITE A CLOSING MESSAGE FOR THE MAIN CONFPACK MODULES JAPHYC\r
1017                 // (I=1)\r
1018                 // **** GQPHYC (I=2), JACANP (I=3), GQCANP (I=4), CNDPLT (I=5), THE\r
1019                 // PARA-\r
1020                 // **** METRIC FUNCTION GENERATOR PARGEN (I=6), THE PARAMETRIC FUNCTION\r
1021                 // **** TESTER TSTPLT (I=7) AND THE LEVEL CURVE ROUTINE LEVCUR (I=8). IF\r
1022                 // **** CHNL=0 THEN WRITE ON THE STANDARD OUTPUT CHANNEL, OTHERWISE\r
1023                 // WRITE\r
1024                 // **** ON THE CHANNEL SPECIFIED BY CHNL. THE TEXT OF THE MESSAGE IS\r
1025                 // **** DETERMINED BY THE ERROR NUMBER IER VIA THE SUBROUTINE IERTXT.\r
1026 \r
1027                 // LOCAL VARIABLES\r
1028 \r
1029                 String MOD[] = new String[] { "J A P H Y C :", "G Q P H Y C :", "J A C A N P :", "G Q C A N P :",\r
1030                                 "C N D P L T :", "P A R G E N :", "T S T P L T :", "L E V C U R :" };\r
1031                 String GOOD = "  NORMAL EXIT";\r
1032                 String BAD = "  ABNORMAL EXIT";\r
1033                 String LINE = "__________________________________________________________________&";\r
1034 \r
1035                 String TXT, TXT2;\r
1036                 if (IER == 0) {\r
1037                         TXT = MOD[I - 1] + GOOD;\r
1038                 } else {\r
1039                         TXT = MOD[I - 1] + BAD;\r
1040                 }\r
1041                 TXT2 = IERTXT(IER);\r
1042 \r
1043                 if ((CHNL == 0) || (CHNL == 6)) {\r
1044                         System.out.println("\n\n      " + TXT);\r
1045                         System.out.println("      " + TXT2);\r
1046                         System.out.println(LINE);\r
1047                 } else {\r
1048                         try {\r
1049                                 raFile.writeBytes("\n\n      //" + TXT + "\n");\r
1050                                 raFile.writeBytes("      //" + TXT2 + "\n");\r
1051                                 raFile.writeBytes("//" + LINE + "\n");\r
1052                         } catch (IOException e) {\r
1053                                 MipavUtil.displayError("IOException " + e + " in WRTAIL");\r
1054                                 System.exit(-1);\r
1055                         }\r
1056                 }\r
1057                 return;\r
1058         }\r
1059 \r
1060         private String IERTXT(int IER) {\r
1061 \r
1062                 // **** SUPPLY ERROR MESSAGE TEXT FOR ERROR NUMBER IER\r
1063                 String result = null;\r
1064                 if (IER == 0) {\r
1065                         result = " ";\r
1066                 } else if (IER == 1) {\r
1067                         result = "PARAMETER IBNDS[0] IS TOO SMALL AT START OF JAPHYC";\r
1068                 } else if (IER == 2) {\r
1069                         result = "PARAMETER IBNDS[1] IS TOO SMALL AT START OF JAPHYC";\r
1070                 } else if (IER == 3) {\r
1071                         result = "NQPTS < 1 AT START OF JAPHYC";\r
1072                 } else if (IER == 4) {\r
1073                         result = "FAILURE TO CONVERGE IN EIGSYS; CAN''T SET UP BASIC QUADRATURE RULES";\r
1074                 } else if (IER == 5) {\r
1075                         result = "PARAMETER MNQPT IN IGNLVL MUST BE INCREASED TO AT LEAST NQPTS";\r
1076                 } else if (IER == 6) {\r
1077                         result = "FAILURE TO CONVERGE IN IMTQLH; CAN''T SET UP IGNORE LEVELS";\r
1078                 } else if (IER == 7) {\r
1079                         result = "FAILURE TO CONVERGE IN IMTQLH; CAN''T SET UP COLLOCATION POINTS";\r
1080                 } else if (IER == 8) {\r
1081                         result = "ARGUMENT MNEQN IS TOO SMALL AT START OF JAPHYC";\r
1082                 } else if (IER == 9) {\r
1083                         result = "PARAMETER IBNDS[3] IS TOO SMALL AT START OF JAPHYC";\r
1084                 } else if (IER == 10) {\r
1085                         result = "PARAMETER NMAX IN SUBIN7 MUST BE INCREASED TO AT LEAST 2*NQPTS";\r
1086                 } else if (IER == 11) {\r
1087                         result = "PARAMETER IBNDS[2] IS TOO SMALL AT START OF JAPHYC";\r
1088                 } else if (IER == 12) {\r
1089                         result = "PARAMETER NC IN DEJAC7 AND DELEG7 MUST BE INCREASED";\r
1090                 } else if (IER == 13) {\r
1091                         result = "PARAMETER NR IN DEJAC7 AND DELEG7 MUST BE >= (NQPTS -1)";\r
1092                 } else if (IER == 14) {\r
1093                         result = "A CORNER ANGLE IS TOO SMALL; MAY CAUSE OVERFLOW IN GAMMA FUNCTION";\r
1094                 } else if (IER == 15) {\r
1095                         result = "SINGULAR COLLOCATION MATRIX";\r
1096                 } else if (IER == 16) {\r
1097                         result = "COLLOCATION MATRIX IS EFFECTIVELY SINGULAR";\r
1098                 } else if (IER == 17) {\r
1099                         result = "NUMBER OF SUBARCS EXCEEDS IBNDS[0] DURING REFINEMENT";\r
1100                 } else if (IER == 18) {\r
1101                         result = "NUMBER OF EQUATIONS EXCEEDS MNEQN DURING REFINEMENT";\r
1102                 } else if (IER == 19) {\r
1103                         result = "TOTAL NUMBER OF QUADRATURE PTS EXCEEDS IBNDS[3] DURING REFINEMENT";\r
1104                 } else if (IER == 20) {\r
1105                         result = "NUMBER OF QUADRATURE PANELS EXCEEDS IBNDS[2] DURING REFINEMENT";\r
1106                 } else if (IER == 21) {\r
1107                         result = "FAILURE TO CONVERGE IN IMTQLH; CAN''T SET UP TEST POINTS";\r
1108                 } else if (IER == 22) {\r
1109                         result = "ARGUMENT MQUPH OF GQPHYC MUST BE INCREASED";\r
1110                 } else if (IER == 23) {\r
1111                         result = "PARAMETER MNCOF IN POPQF1 MUST BE >= NQPTS";\r
1112                 } else if (IER == 24) {\r
1113                         result = "NUMBER OF QUADRATURE PANELS EXCEEDS MQIN1 IN GQPHYC";\r
1114                 } else if (IER == 25) {\r
1115                         result = "PARAMETER MNXI IN DEPPJ8 AND DEPPL8 MUST BE INCREASED";\r
1116                 } else if (IER == 26) {\r
1117                         result = "PARAMETER MAXNZ IN DEPPJ9 AND DEPPL9 MUST BE INCREASED";\r
1118                 } else if (IER == 27) {\r
1119                         result = "PARAMETER MXNQD IN PHTCA1 MUST BE INCREASED";\r
1120                 } else if (IER == 28) {\r
1121                         result = "PARAMETER MXCOF IN PHTCA1 MUST BE INCREASED";\r
1122                 } else if (IER == 29) {\r
1123                         result = "PARAMETER MQIN1 IN PHTCA1 MUST BE INCREASED";\r
1124                 } else if (IER == 30) {\r
1125                         result = "PARAMETER MNDG IN JCFIM5 MUST BE INCREASED";\r
1126                 } else if (IER == 31) {\r
1127                         result = "PARAMETER MNQD IN JCFIM5 MUST BE INCREASED";\r
1128                 } else if (IER == 32) {\r
1129                         result = "ARGUMENT IBNDS[1] SUPPLIED TO JACANP MUST BE INCREASED";\r
1130                 } else if (IER == 33) {\r
1131                         result = "ARGUMENT IBNDS[0] SUPPLIED TO JACANP MUST BE INCREASED";\r
1132                 } else if (IER == 34) {\r
1133                         result = "FN HAS SAME SIGN AT INTERVAL ENDS IN BISNEW; CAN''T SOLVE BCF EQN";\r
1134                 } else if (IER == 35) {\r
1135                         result = "DERIVATIVE OF BCF IS ZERO IN BISNEW; CAN''T SOLVE BCF EQN";\r
1136                 } else if (IER == 36) {\r
1137                         result = "ELEMENT OF ARGUMENT ARRAY SVAL IN RHOFN IS +-1; CAN''T CONTINUE";\r
1138                 } else if (IER == 37) {\r
1139                         result = "PARAMETER MXNQD IN CINRAD MUST BE INCREASED";\r
1140                 } else if (IER == 38) {\r
1141                         result = "PARAMETER MXCOF IN CINRAD MUST BE INCREASED";\r
1142                 } else if (IER == 39) {\r
1143                         result = "CENTRE POINT IS PATHOLOGICALLY CLOSE TO BOUNDARY;CAN''T CONTINUE";\r
1144                 } else if (IER == 40) {\r
1145                         result = "PARAMETER MQIN1 IN CINRAD MUST BE INCREASED";\r
1146                 } else if (IER == 41) {\r
1147                         result = "ARGUMENT MQUCA OF GQCANP MUST BE INCREASED";\r
1148                 } else if (IER == 42) {\r
1149                         result = "PARAMETER MNCOF IN POPQG1 MUST BE >= NQPTS";\r
1150                 } else if (IER == 43) {\r
1151                         result = "NUMBER OF QUADRATURE PANELS EXCEEDS MQIN1 IN GQCANP";\r
1152                 } else if (IER == 44) {\r
1153                         result = "PARAMETER MNCOF IN BMPHC1 MUST BE >= NQPTS";\r
1154                 } else if (IER == 45) {\r
1155                         result = "ARGUMENTS IARC, PHYPT OF BMPHYC DON''T DEFINE A BOUNDARY POINT";\r
1156                 } else if (IER == 46) {\r
1157                         result = "PARAMETER MNCOF IN BMCAP1 MUST BE >= NQPTS";\r
1158                 } else if (IER == 47) {\r
1159                         result = "PARAMETER MXNQD IN CATPH4 MUST BE INCREASED";\r
1160                 } else if (IER == 48) {\r
1161                         result = "PARAMETER MNCOF IN CATPH4 MUST BE >= NQPTS";\r
1162                 } else if (IER == 49) {\r
1163                         result = "PARAMETER MQIN1 IN CATPH4 MUST BE INCREASED";\r
1164                 } else if (IER == 50) {\r
1165                         result = "PARAMETER MXCOF IN DIAGN3 MUST BE >= NQPTS";\r
1166                 } else if (IER == 51) {\r
1167                         result = "NON-ANALYTIC ARC DETECTED IN DIAGN3";\r
1168                 } else if (IER == 52) {\r
1169                         result = "PARAMETER MAXSA IN CNDPLT MUST BE INCREASED";\r
1170                 } else if (IER == 53) {\r
1171                         result = "OVERFLOW EXPECTED IN IGNLVL; A CORNER ANGLE IS TOO SMALL";\r
1172                 } else if (IER == 54) {\r
1173                         result = "PARAMETER MXCO IN AXION1 MUST BE INCREASED";\r
1174                 } else if (IER == 55) {\r
1175                         result = "NARCS ISN''T AN INTEGER MULTIPLE OF THE ORDER OF THE SYMMETRY GROUP";\r
1176                 } else if (IER == 56) {\r
1177                         result = "CENTRE OF SYMMETRY IS PATHOLOGICALLY CLOSE TO LAST POINT ON FBS";\r
1178                 } else if (IER == 57) {\r
1179                         result = "CENTRE OF SYMMETRY IS PATHOLOGICALLY CLOSE TO FIRST POINT ON FBS";\r
1180                 } else if (IER == 58) {\r
1181                         result = "NUMBER OF ARCS IS TOO BIG; INCREASE PARAMETER MNARC IN PARGEN";\r
1182                 } else if (IER == 59) {\r
1183                         result = "NUMBER OF ARCS IS TOO BIG; INCREASE PARAMETER MNARC IN TSTPLT";\r
1184                 } else if (IER == 60) {\r
1185                         result = "NON-ANALYTIC ARC (DPARFN=(0.,0.)) DETECTED IN TSTPLT";\r
1186                 } else {\r
1187                         result = "UNRECOGNIZED ERROR NUMBER IN IERTXT ROUTINE !!";\r
1188                 }\r
1189                 return result;\r
1190         }\r
1191 \r
1192         private void WRSYM1(int NARCS, int ORDRG, int ORDSG, double[] RTUNI, double[] U2, double[] CENSY, boolean REFLN,\r
1193                         boolean PARFUN, String REDD, int CHNL, RandomAccessFile raFile) {\r
1194                 // COMPLEX RTUNI,U2,CENSY\r
1195 \r
1196                 // **** TO WRITE THE DIMENSION AND PARAMETER STATEMENTS AND THE CODE TO\r
1197                 // **** TO REDUCE A GIVEN ARC NUMBER TO ITS SYMMETRIC COUNTERPART ON THE\r
1198                 // **** FUNDAMENTAL BOUNDARY SECTION.\r
1199 \r
1200                 // .......................................................................\r
1201                 // AUTHOR: DAVID HOUGH, ETH, ZUERICH\r
1202                 // LAST UPDATE: 4 AUG 1990\r
1203                 // .......................................................................C\r
1204                 // LOCAL VARIABLES\r
1205 \r
1206                 int I;\r
1207                 double R, A;\r
1208                 // COMPLEX ZT\r
1209                 double ZT[] = new double[2];\r
1210                 boolean NEEDC;\r
1211                 // String FMT;\r
1212                 double cr[] = new double[1];\r
1213                 double ci[] = new double[1];\r
1214 \r
1215                 // FMT="(A12,"+REDD+",A1,"+REDD+",A2)";\r
1216 \r
1217                 try {\r
1218                         if (PARFUN) {\r
1219                                 NEEDC = ((CENSY[0] != 0.0) || (CENSY[1] != 0.0));\r
1220                                 if (NEEDC || REFLN) {\r
1221                                         raFile.writeBytes("      PARAMETER (\n");\r
1222                                         if (NEEDC && REFLN) {\r
1223                                                 R = U2[0];\r
1224                                                 A = U2[1];\r
1225                                                 raFile.writeBytes("U2[0] = " + R + ";\n");\r
1226                                                 raFile.writeBytes("U2[1] = " + A + ";\n");\r
1227                                                 R = CENSY[0];\r
1228                                                 A = CENSY[1];\r
1229                                                 raFile.writeBytes("ZCEN[0] = " + R + ";\n");\r
1230                                                 raFile.writeBytes("ZCEN[1] = " + A + ";)\n");\r
1231                                         } // if (NEEDC && REFLN)\r
1232                                         else if (NEEDC && (!REFLN)) {\r
1233                                                 R = CENSY[0];\r
1234                                                 A = CENSY[1];\r
1235                                                 raFile.writeBytes("ZCEN[0] = " + R + ";\n");\r
1236                                                 raFile.writeBytes("ZCEN[1] = " + A + ";)\n");\r
1237                                         } // else if (NEEDC && (!REFLN))\r
1238                                         else {\r
1239                                                 R = U2[0];\r
1240                                                 A = U2[1];\r
1241                                                 raFile.writeBytes("U2[0] = " + R + ";\n");\r
1242                                                 raFile.writeBytes("U2[1] = " + A + ";)\n");\r
1243                                         } // else\r
1244                                         raFile.writeBytes("//\n");\r
1245                                 } // if (NEEDC || REFLN)\r
1246                         } else if (REFLN) {\r
1247                                 R = U2[0];\r
1248                                 A = U2[1];\r
1249                                 raFile.writeBytes("      PARAMETER (\n");\r
1250                                 raFile.writeBytes("U2[0] = " + R + ";\n");\r
1251                                 raFile.writeBytes("U2[1] = " + A + ";)\n");\r
1252                                 raFile.writeBytes("//\n");\r
1253                         }\r
1254 \r
1255                         // FMT="(A7,"+REDD+",A1,"+REDD+",A2)";\r
1256 \r
1257                         if (ORDRG >= 2) {\r
1258                                 raFile.writeBytes("double WW[] = new double[" + (ORDRG - 1) + "];\n");\r
1259                                 ZT[0] = 1.0;\r
1260                                 ZT[1] = 0.0;\r
1261                                 for (I = 0; I < ORDRG - 2; I++) {\r
1262                                         zmlt(ZT[0], ZT[1], RTUNI[0], RTUNI[1], cr, ci);\r
1263                                         ZT[0] = cr[0];\r
1264                                         ZT[1] = ci[0];\r
1265                                         raFile.writeBytes("WW[" + I + "][0] = " + ZT[0] + ";\n");\r
1266                                         raFile.writeBytes("WW[" + I + "][1] = " + ZT[1] + ";\n");\r
1267                                 }\r
1268                                 zmlt(ZT[0], ZT[1], RTUNI[0], RTUNI[1], cr, ci);\r
1269                                 ZT[0] = cr[0];\r
1270                                 ZT[1] = ci[0];\r
1271                                 raFile.writeBytes("WW[" + I + "][0] = " + ZT[0] + ";\n");\r
1272                                 raFile.writeBytes("WW[" + I + "][1] = " + ZT[1] + ";)\n");\r
1273                                 raFile.writeBytes("//\n");\r
1274                         } // if (ORDRG >= 2)\r
1275 \r
1276                         if (ORDRG > 19) {\r
1277                                 System.out.println("\n");\r
1278                                 System.out.println("             ****WARNING****");\r
1279                                 System.out.println("MORE THAN 19 CONTINUTATION LINES HAVE BEEN WRITTEN");\r
1280                         }\r
1281 \r
1282                         if (REFLN) {\r
1283                                 if (ORDRG > 1) {\r
1284                                         if (NARCS > 1) {\r
1285                                                 I = 2 * NARCS;\r
1286                                                 raFile.writeBytes("IB = IA%" + I + ";\n");\r
1287                                                 raFile.writeBytes("if (IB == 0) IB = " + I + ";\n");\r
1288                                                 I = I + 1;\r
1289                                                 raFile.writeBytes("if (IB > " + NARCS + ") {\n");\r
1290                                                 raFile.writeBytes("    IB = " + I + " - IB;\n");\r
1291                                                 raFile.writeBytes("    TS[0] = -TT[0];\n");\r
1292                                                 raFile.writeBytes("    TS[1] = TT[1]);\n");\r
1293                                                 raFile.writeBytes("}\n");\r
1294                                                 raFile.writeBytes("else {\n");\r
1295                                                 raFile.writeBytes("    TS[0] = TT[0];\n");\r
1296                                                 raFile.writeBytes("    TS[1] = TT[1];\n");\r
1297                                                 raFile.writeBytes("}\n");\r
1298                                         } // if (NARCS > 1)\r
1299                                         else {\r
1300                                                 raFile.writeBytes("if ((IA%2) == 0) {\n");\r
1301                                                 raFile.writeBytes("    TS[0] = -TT[0];\n");\r
1302                                                 raFile.writeBytes("    TS[1] = TT[1];\n");\r
1303                                                 raFile.writeBytes("}\n");\r
1304                                                 raFile.writeBytes("else {\n");\r
1305                                                 raFile.writeBytes("    TS[0] = TT[0];\n");\r
1306                                                 raFile.writeBytes("    TS[1] = TT[1];\n");\r
1307                                                 raFile.writeBytes("}\n");\r
1308                                         } // else\r
1309                                 } // if (ORDRG > 1)\r
1310                                 else {\r
1311                                         if (NARCS > 1) {\r
1312                                                 I = 2 * NARCS + 1;\r
1313                                                 raFile.writeBytes("if (IA > " + NARCS + "){\n");\r
1314                                                 raFile.writeBytes("    IB = " + I + " -IA;\n");\r
1315                                                 raFile.writeBytes("    TS[0] = -TT[0];\n");\r
1316                                                 raFile.writeBytes("    TS[1] = TT[1]);\n");\r
1317                                                 raFile.writeBytes("}\n");\r
1318                                                 raFile.writeBytes("else {\n");\r
1319                                                 raFile.writeBytes("    IB = IA;\n");\r
1320                                                 raFile.writeBytes("    TS[0] = TT[0];\n");\r
1321                                                 raFile.writeBytes("    TS[1] = TT[1];\n");\r
1322                                                 raFile.writeBytes("}\n");\r
1323                                         } // if (NARCS)\r
1324                                         else {\r
1325                                                 raFile.writeBytes("if (IA == 2) {\n");\r
1326                                                 raFile.writeBytes("    TS[0] = -TT[0];\n");\r
1327                                                 raFile.writeBytes("    TS[1] = TT[1]);\n");\r
1328                                                 raFile.writeBytes("}\n");\r
1329                                                 raFile.writeBytes("else {\n");\r
1330                                                 raFile.writeBytes("    TS[0] = TT[0];\n");\r
1331                                                 raFile.writeBytes("    TS[1] = TT[1];\n");\r
1332                                                 raFile.writeBytes("}\n");\r
1333                                         } // else\r
1334                                 } // else\r
1335                         } // if (REFLN)\r
1336                         else if (NARCS > 1) {\r
1337                                 raFile.writeBytes("IB = IA%" + NARCS + ";\n");\r
1338                                 raFile.writeBytes("if (IB == 0) IB = " + NARCS + ";\n");\r
1339                         } // else if (NARCS > 1)\r
1340 \r
1341                         raFile.writeBytes("//\n");\r
1342                 } // try\r
1343                 catch (IOException e) {\r
1344                         MipavUtil.displayError("IOException " + e + " in WRSYM1");\r
1345                         System.exit(-1);\r
1346                 }\r
1347 \r
1348         }\r
1349 \r
1350         private void WRFUN1(int NARCS, double STAPT[][], int ARCTY[], int PGM[], double RGM[], int PTX[], int NTX[],\r
1351                         String DEFN[], int CHNL, String CHIA, String CHTT, String VAR, String REDD, RandomAccessFile raFile) {\r
1352                 // COMPLEX STAPT(*)\r
1353                 // CHARACTER DEFN(*)*72,CHIA*2,CHTT*2,VAR*6,REDD*6\r
1354 \r
1355                 // **** TO WRITE THE SOURCE CODE FOR PARFUN IN THE CASE WHERE NO\r
1356                 // **** SYMMETRY IS INVOLVED.\r
1357 \r
1358                 // .......................................................................\r
1359                 // AUTHOR: DAVID HOUGH, ETH, ZUERICH\r
1360                 // LAST UPDATE: 4 AUG 1990\r
1361                 // .......................................................................\r
1362 \r
1363                 // LOCAL VARIABLES\r
1364 \r
1365                 int IA, I, J, K;\r
1366                 // CHARACTER TX1*16,TX2*21,FMT1*11,FMT2*11\r
1367                 String TX1, TX2;\r
1368                 // String FMT1,FMT2;\r
1369                 // EXTERNAL PTFUN1\r
1370                 TX1 = "      if(" + CHIA + " == ";\r
1371                 TX2 = "      else if(" + CHIA + " == ";\r
1372                 // FMT1="(A16,I3,A6)";\r
1373                 // FMT2="(A21,I3,A6)";\r
1374                 double STAPT2[][];\r
1375                 double RGM2[];\r
1376                 String DEFN2[];\r
1377 \r
1378                 try {\r
1379                         for (IA = 1; IA <= NARCS; IA++) {\r
1380                                 I = PGM[IA - 1];\r
1381                                 J = PTX[IA - 1];\r
1382                                 STAPT2 = new double[STAPT.length - IA + 1][2];\r
1383                                 for (K = IA; K <= STAPT.length; K++) {\r
1384                                         STAPT2[K - IA] = STAPT[K - 1];\r
1385                                 }\r
1386                                 if (ARCTY[IA-1] != 1) {\r
1387                                         RGM2 = new double[RGM.length - I + 1];\r
1388                                         for (K = I; K <= RGM.length; K++) {\r
1389                                                 RGM2[K - I] = RGM[K - 1];\r
1390                                         }\r
1391                                 }\r
1392                                 else {\r
1393                                         RGM2 = null;\r
1394                                 }\r
1395                                 if ((ARCTY[IA-1] == 3) || (ARCTY[IA-1] == 4)) {\r
1396                                         DEFN2 = new String[DEFN.length - J + 1];\r
1397                                         for (K = J; K <= DEFN.length; K++) {\r
1398                                                 DEFN2[K - J] = DEFN[K - 1];\r
1399                                         }\r
1400                                 }\r
1401                                 else {\r
1402                                         // DEFN2 goes to TXT in PTFUN1 which is not used for TYPES 1 and 2\r
1403                                         DEFN2 = null;\r
1404                                 }\r
1405                                 if (NARCS == 1) {\r
1406                                         PTFUN1(ARCTY[IA - 1], STAPT2, RGM2, NTX[IA - 1], DEFN2, CHNL, CHTT, VAR, REDD, raFile);\r
1407                                 } else {\r
1408                                         if (IA == 1) {\r
1409                                                 raFile.writeBytes(TX1 + IA + ") {\n");\r
1410                                         } else if (IA == NARCS) {\r
1411                                                 raFile.writeBytes("      else {\n");\r
1412                                         } else {\r
1413                                                 raFile.writeBytes(TX2 + IA + ") {\n");\r
1414                                         }\r
1415                                         PTFUN1(ARCTY[IA - 1], STAPT2, RGM2, NTX[IA - 1], DEFN2, CHNL, CHTT, VAR, REDD, raFile);\r
1416                                         if (IA == NARCS)\r
1417                                                 raFile.writeBytes("      }\n");\r
1418                                 } // else\r
1419                         } // for (IA=1; IA <= NARCS; IA++)\r
1420                 } // try\r
1421                 catch (IOException e) {\r
1422                         MipavUtil.displayError("IOException " + e + " in WRFUN1");\r
1423                         System.exit(-1);\r
1424                 }\r
1425 \r
1426         } // private void WRFUN1\r
1427 \r
1428         private void PTFUN1(int TYPE, double STAPT[][], double RGM[], int NTX, String TXT[], int CHNL, String CHTT,\r
1429                         String VAR, String REDD, RandomAccessFile raFile) {\r
1430         // When TT goes from -1,0 to 1,0 T[0] traces out the original parameterization of the curve\r
1431                 // COMPLEX STAPT(*)\r
1432                 // CHARACTER TXT(*)*72,CHTT*2,VAR*6,REDD*6\r
1433 \r
1434                 // .......................................................................\r
1435                 // AUTHOR: DAVID HOUGH, ETH, ZUERICH\r
1436                 // LAST UPDATE: 8 AUG 1990\r
1437                 // .......................................................................C\r
1438                 // **** LOCAL VARIABLES\r
1439 \r
1440                 int I;\r
1441                 double HA, MD, RAD;\r
1442                 double C1[] = new double[2];\r
1443                 double C2[] = new double[2];\r
1444                 double CENTR[] = new double[2];\r
1445                 String PAD = "          ";\r
1446                 // COMPLEX C1,C2,CENTR\r
1447                 // String TX1, TX1B, TX2;\r
1448                 // String TX2B, CTX1B, FMT1, FMT2, FMT3, FMT4, FMT5;\r
1449                 // CHARACTER TX1*4,TX1B*5,TX2*13,TX2B*14,CTX1B*10,\r
1450                 // +FMT1*25,FMT2*25,FMT3*14,FMT4*25,FMT5*24\r
1451 \r
1452                 // TX1 = "+"+CHTT+"*";\r
1453                 // TX1B = TX1 + "(";\r
1454                 // CTX1B=" " + TX1B;\r
1455                 // TX2=" "+VAR+" = ";\r
1456                 // TX2B=TX2+"(";\r
1457 \r
1458                 // FMT1='(A14,'//REDD//',A1,'//REDD//',A2)'\r
1459                 // FMT2='(A10,'//REDD//',A1,'//REDD//',A1)'\r
1460                 // FMT3='(A6,'//REDD//',A1)'\r
1461                 // FMT4='(A14,'//REDD//',A5,'//REDD//',A3)'\r
1462                 // FMT5='(A8,'//REDD//',A5,'//REDD//',A1)'\r
1463 \r
1464                 try {\r
1465                         if (TYPE == 1) {\r
1466                                 C1[0] = 0.5 * (STAPT[1][0] + STAPT[0][0]);\r
1467                                 C1[1] = 0.5 * (STAPT[1][1] + STAPT[0][1]);\r
1468                                 C2[0] = 0.5 * (STAPT[1][0] - STAPT[0][0]);\r
1469                                 C2[1] = 0.5 * (STAPT[1][1] - STAPT[0][1]);\r
1470                                 raFile.writeBytes("//\n");\r
1471                                 raFile.writeBytes(\r
1472                                                 PAD + VAR + "ANS[0] = " + C1[0] + "+" + CHTT + "[0]*(" + C2[0] + ") - " + CHTT + "[1]*(" + C2[1] + ");\n");\r
1473                                 raFile.writeBytes(\r
1474                                                 PAD + VAR + "ANS[1] = " + C1[1] + "+" + CHTT + "[0]*(" + C2[1] + ") + " + CHTT + "[1]*(" + C2[0] + ");\n");\r
1475                                 raFile.writeBytes("//\n");\r
1476                         } // if (TYPE == 1)\r
1477                         else if (TYPE == 2) {\r
1478                                 CENTR[0] = RGM[0];\r
1479                                 CENTR[1] = RGM[1];\r
1480                                 C1[0] = STAPT[0][0] - CENTR[0];\r
1481                                 C1[1] = STAPT[0][1] - CENTR[1];\r
1482                                 HA = 0.5 * RGM[2];\r
1483                                 MD = Math.atan2(C1[1], C1[0]) + HA;\r
1484                                 RAD = zabs(C1[0], C1[1]);\r
1485                                 raFile.writeBytes("//\n");\r
1486                                 raFile.writeBytes(PAD + VAR + "ANS[0] = " + CENTR[0] + "+" + RAD + " * " + "Math.exp(-" + CHTT + "[1]*(" + HA\r
1487                                                 + "))*" + "Math.cos(" + MD + "+" + CHTT + "[0]*(" + HA + "));\n");\r
1488                                 raFile.writeBytes(PAD + VAR + "ANS[1] = " + CENTR[1] + "+" + RAD + " * " + "Math.exp(-" + CHTT + "[1]*(" + HA\r
1489                                                 + "))*" + "Math.sin(" + MD + "+" + CHTT + "[0]*(" + HA + "));\n");\r
1490                                 raFile.writeBytes("//\n");\r
1491                         } // else if (TYPE == 2)\r
1492                         else if (TYPE == 3) {\r
1493                                 MD = 0.5 * (RGM[1] + RGM[0]);\r
1494                                 HA = 0.5 * (RGM[1] - RGM[0]);\r
1495                                 raFile.writeBytes("//\n");\r
1496                                 raFile.writeBytes(PAD + "T[0] = " + MD + "+" + CHTT + "[0] * (" + HA + ");\n");\r
1497                                 raFile.writeBytes(PAD + "T[1] = " + CHTT + "[1] * (" + HA + ");\n");\r
1498 \r
1499                                 if (TXT[0].toLowerCase().indexOf("ui") == 0) {\r
1500                                     raFile.writeBytes(PAD + VAR + "ANS[0] = 0.0;\n");\r
1501                                 }\r
1502                                 else {\r
1503                                         // NTX = 1 if statements are entered without newlines for\r
1504                                         // multiple lines\r
1505                                         raFile.writeBytes(PAD + VAR + "ANS[0] = ");\r
1506                                         for (I = 1; I <= NTX; I++) {\r
1507                                                 int index = TXT[I - 1].toLowerCase().indexOf("ui");\r
1508                                                 if (index == 0) {\r
1509                                                         raFile.writeBytes(";\n");\r
1510                                                         break;\r
1511                                                 }\r
1512                                                 String realString = null;\r
1513                                                 if (index == -1) {\r
1514                                                         realString = TXT[I-1];\r
1515                                                 }\r
1516                                                 else {\r
1517                                                         realString = TXT[I - 1].substring(0, index);    \r
1518                                                 }\r
1519                                                 if ((I > 1) && (realString != null) && (realString.length() != 0)) {\r
1520                                                         raFile.writeBytes("\n" + PAD);\r
1521                                                 }\r
1522                                                 if ((realString != null) && (realString.length() != 0)) {\r
1523                                                     raFile.writeBytes(realString);\r
1524                                                 }\r
1525                                                 if ((I == NTX) || (index > 0)) {\r
1526                                                         raFile.writeBytes(";\n");\r
1527                                                         break;\r
1528                                                 }\r
1529                                         }\r
1530                                 }\r
1531                                 boolean uifound = false;\r
1532                                 String imagString = null;\r
1533                                 boolean firstImagStringWritten = false;\r
1534                                 for (I = 1; I <= NTX; I++) {\r
1535                                         if (!uifound) {\r
1536                                         int index = TXT[I-1].toLowerCase().indexOf("ui");\r
1537                                             if (index >= 0) {\r
1538                                                 uifound = true;\r
1539                                                 raFile.writeBytes(PAD + VAR + "ANS[1] = ");\r
1540                                                 if (index + 2 < TXT[I-1].length()) {\r
1541                                                         imagString = TXT[I - 1].substring(index + 2);\r
1542                                                             raFile.writeBytes(imagString);\r
1543                                                             firstImagStringWritten = true;\r
1544                                                             if (I == NTX) {\r
1545                                                                 raFile.writeBytes(";\n");\r
1546                                                             }\r
1547                                                 } // if (index + 2 < TXT[I-1].length())\r
1548                                             } // if (index >= 0)\r
1549                                     } // if (!uifound) {\r
1550                                     else {\r
1551                                         imagString = TXT[I-1];\r
1552                                         if (!firstImagStringWritten) {\r
1553                                                 raFile.writeBytes(imagString);\r
1554                                         }\r
1555                                         else if ((imagString != null) && (imagString.length() != 0)) {\r
1556                                             raFile.writeBytes(PAD + imagString);\r
1557                                         }\r
1558                                         firstImagStringWritten = true;\r
1559                                             if (I == NTX) {\r
1560                                                 raFile.writeBytes(";\n");\r
1561                                             }\r
1562                                     }\r
1563                                 } // for (I = 1; I <= NTX; I++)\r
1564                                 if (!uifound) {\r
1565                                     raFile.writeBytes(PAD + VAR + "ANS[1] = 0.0;\n");\r
1566                                 }\r
1567                                 raFile.writeBytes("//\n");\r
1568                         } // else if (TYPE == 3)\r
1569                         else {\r
1570                                 MD = 0.5 * (RGM[1] + RGM[0]);\r
1571                                 HA = 0.5 * (RGM[1] - RGM[0]);\r
1572                                 raFile.writeBytes("//\n");\r
1573                                 raFile.writeBytes(PAD + "T[0] = " + MD + "+" + CHTT + "[0] * (" + HA + ");\n");\r
1574                                 raFile.writeBytes(PAD + "T[1] = " + CHTT + "[1] * (" + HA + ");\n");\r
1575                                 if (TXT[0].toLowerCase().indexOf("ui") == 0) {\r
1576                                     raFile.writeBytes(PAD + "ZRAD[0] = 0.0;\n");\r
1577                                 }\r
1578                                 else {\r
1579                                         // NTX = 1 if statements are entered without newlines for\r
1580                                         // multiple lines\r
1581                                         raFile.writeBytes(PAD + "ZRAD[0] = ");\r
1582                                         for (I = 1; I <= NTX; I++) {\r
1583                                                 int index = TXT[I - 1].toLowerCase().indexOf("ui");\r
1584                                                 if (index == 0) {\r
1585                                                         raFile.writeBytes(";\n");\r
1586                                                         break;\r
1587                                                 }\r
1588                                                 String realString = null;\r
1589                                                 if (index == -1) {\r
1590                                                         realString = TXT[I-1];\r
1591                                                 }\r
1592                                                 else {\r
1593                                                         realString = TXT[I - 1].substring(0, index);    \r
1594                                                 }\r
1595                                                 if ((I > 1) && (realString != null) && (realString.length() != 0)) {\r
1596                                                         raFile.writeBytes("\n" + PAD);\r
1597                                                 }\r
1598                                                 if ((realString != null) && (realString.length() != 0)) {\r
1599                                                     raFile.writeBytes(realString);\r
1600                                                 }\r
1601                                                 if ((I == NTX) || (index > 0)) {\r
1602                                                         raFile.writeBytes(";\n");\r
1603                                                         break;\r
1604                                                 }\r
1605                                         }\r
1606                                 }\r
1607                                 boolean uifound = false;\r
1608                                 String imagString = null;\r
1609                                 boolean firstImagStringWritten = false;\r
1610                                 for (I = 1; I <= NTX; I++) {\r
1611                                         if (!uifound) {\r
1612                                         int index = TXT[I-1].toLowerCase().indexOf("ui");\r
1613                                             if (index >= 0) {\r
1614                                                 uifound = true;\r
1615                                                 raFile.writeBytes(PAD + "ZRAD[1] = ");\r
1616                                                 if (index + 2 < TXT[I-1].length()) {\r
1617                                                         imagString = TXT[I - 1].substring(index + 2);\r
1618                                                             raFile.writeBytes(imagString);\r
1619                                                             firstImagStringWritten = true;\r
1620                                                             if (I == NTX) {\r
1621                                                                 raFile.writeBytes(";\n");\r
1622                                                             }\r
1623                                                 } // if (index + 2 < TXT[I-1].length())\r
1624                                             } // if (index >= 0)\r
1625                                     } // if (!uifound) {\r
1626                                     else {\r
1627                                         imagString = TXT[I-1];\r
1628                                         if (!firstImagStringWritten) {\r
1629                                                 raFile.writeBytes(imagString);\r
1630                                         }\r
1631                                         else if ((imagString != null) && (imagString.length() != 0)) {\r
1632                                             raFile.writeBytes(PAD + imagString);\r
1633                                         }\r
1634                                         firstImagStringWritten = true;\r
1635                                             if (I == NTX) {\r
1636                                                 raFile.writeBytes(";\n");\r
1637                                             }\r
1638                                     }\r
1639                                 } // for (I = 1; I <= NTX; I++)\r
1640                                 if (!uifound) {\r
1641                                     raFile.writeBytes(PAD + "ZRAD[1] = 0.0;\n");\r
1642                                 }\r
1643                                 raFile.writeBytes(PAD + VAR + "ANS[0] = ZRAD[0]*Math.exp(-T[1])*Math.cos(T[0]) - ZRAD[1]*Math.exp(-T[1])*Math.sin(T[0]);\n");\r
1644                                 raFile.writeBytes(PAD + VAR + "ANS[1] = ZRAD[0]*Math.exp(-T[1])*Math.sin(T[0]) + ZRAD[1]*Math.exp(-T[1])*Math.cos(T[0]);\n");\r
1645                                 raFile.writeBytes("//\n");\r
1646                         }\r
1647                         raFile.writeBytes(PAD + "return " + VAR + "ANS;\n");\r
1648                 } // try\r
1649                 catch (IOException e) {\r
1650                         MipavUtil.displayError("IOException " + e + " in PTFUN1");\r
1651                         System.exit(-1);\r
1652                 }\r
1653 \r
1654         } // private void PTFUN1\r
1655 \r
1656         private void WRSYM2(int NARCS, int ORDRG, double CENSY[], boolean REFLN, int CHNL, RandomAccessFile raFile) {\r
1657 \r
1658                 // COMPLEX CENSY\r
1659 \r
1660                 // **** TO WRITE THE CODE TO RECOVER THE BOUNDARY POINT FROM ITS\r
1661                 // SYMMETRIC\r
1662                 // **** COUNTERPART ON THE FUNDAMENTAL BOUNDARY SECTION.\r
1663 \r
1664                 // .......................................................................\r
1665                 // AUTHOR: DAVID HOUGH, ETH, ZUERICH\r
1666                 // LAST UPDATE: 4 AUG 1990\r
1667                 // .......................................................................C\r
1668                 // LOCAL VARIABLES\r
1669 \r
1670                 int I;\r
1671                 boolean NEEDC;\r
1672 \r
1673                 NEEDC = ((CENSY[0] != 0.0) || (CENSY[1] != 0.0));\r
1674                 try {\r
1675                         raFile.writeBytes("//\n");\r
1676 \r
1677                         if (REFLN) {\r
1678                                 if (ORDRG > 1) {\r
1679                                         I = 2 * NARCS;\r
1680                                         if (NARCS > 1) {\r
1681                                                 raFile.writeBytes("IS = (IA-IB)%" + I + ";\n");\r
1682                                                 raFile.writeBytes("IR = (IA-IB-IS)/" + I + ";\n");\r
1683                                         } // if (NARCS > 1)\r
1684                                         else {\r
1685                                                 raFile.writeBytes("IS = (IA-1)%2;\n");\r
1686                                                 raFile.writeBytes("IR = (IA-1-IS)/2;\n");\r
1687                                         }\r
1688                                         raFile.writeBytes("if ((IR == 0) && (IS == 0)) {\n");\r
1689                                         raFile.writeBytes("    PARFUN[0] = ZETA[0];\n");\r
1690                                         raFile.writeBytes("    PARFUN[1] = ZETA[1];\n");\r
1691                                         raFile.writeBytes("}\n");\r
1692                                         raFile.writeBytes("else if ((IR > 0) && (IS == 0)) {\n");\r
1693                                         if (NEEDC) {\r
1694                                                 raFile.writeBytes("    PARFUN[0] = ZCEN[0] + WW[IR-1][0]*(ZETA[0] - ZCEN[0]) - "\r
1695                                                                 + "WW[IR-1][1]*(ZETA[1] - ZCEN[1]);\n");\r
1696                                                 raFile.writeBytes("    PARFUN[1] = ZCEN[1] + WW[IR-1][0]*(ZETA[1] - ZCEN[1]) + "\r
1697                                                                 + "WW[IR-1][1]*(ZETA[0] - ZCEN[0]);\n");\r
1698                                         } // if (NEEDC)\r
1699                                         else {\r
1700                                                 raFile.writeBytes("PARFUN[0] = WW[IR-1][0]*ZETA[0] - WW[IR-1][1]*ZETA[1];\n");\r
1701                                         }\r
1702                                         raFile.writeBytes("else if ((IR == 0) && (IS > 0)) {\n");\r
1703                                         if (NEEDC) {\r
1704                                                 raFile.writeBytes(\r
1705                                                                 "    PARFUN[0] = ZCEN[0] + U2[0]*(ZETA[0]-ZCEN[0]) + " + "U2[1]*(ZETA[1]-ZCEN[1]);\n");\r
1706                                                 raFile.writeBytes(\r
1707                                                                 "    PARFUN[1] = ZCEN[1] - U2[0]*(ZETA[1]-ZCEN[1]) + " + "U2[1]*(ZETA[0]-ZCEN[0]);\n");\r
1708                                         } else {\r
1709                                                 raFile.writeBytes("    PARFUN[0] = U2[0]*ZETA[0] + U2[1]*ZETA[1];\n");\r
1710                                                 raFile.writeBytes("    PARFUN[1] = -U2[0]*ZETA[1] + U2[1]*ZETA[0];\n");\r
1711                                         }\r
1712                                         raFile.writeBytes("}\n");\r
1713                                         raFile.writeBytes("else {\n");\r
1714                                         if (NEEDC) {\r
1715                                                 raFile.writeBytes("double realPart = U2[0]*WW[IR-1][0] - U2[1]*WW[IR-1][1];\n");\r
1716                                                 raFile.writeBytes("double imagPart = U2[0]*WW[IR-1][1] + U2[1]*WW[IR-1][0];\n");\r
1717                                                 raFile.writeBytes("PARFUN[0] = ZCEN[0] + realPart*(ZETA[0]-ZCEN[0]) + "\r
1718                                                                 + "imagPart*(ZETA[1]-ZCEN[1]);\n");\r
1719                                                 raFile.writeBytes("PARFUN[1] = ZCEN[1] - realPart*(ZETA[1]-ZCEN[1]) + "\r
1720                                                                 + "imagPart*(ZETA[0]-ZCEN[0]);\n");\r
1721                                         } else {\r
1722                                                 raFile.writeBytes("double realPart = U2[0]*WW[IR-1][0] - U2[1]*WW[IR-1][1];\n");\r
1723                                                 raFile.writeBytes("double imagPart = U2[0]*WW[IR-1][1] + U2[1]*WW[IR-1][0];\n");\r
1724                                                 raFile.writeBytes("PARFUN[0] = realPart * ZETA[0] + imagPart * ZETA[1];\n");\r
1725                                                 raFile.writeBytes("PARFUN[1] = -realPart * ZETA[1] + imagPart * ZETA[0];\n");\r
1726                                         }\r
1727                                         raFile.writeBytes("}\n");\r
1728                                 } // if (ORDRG > 1)\r
1729                                 else { // ORDRG <= 1\r
1730                                         if (NARCS > 1) {\r
1731                                                 raFile.writeBytes("IS = IA - IB;\n");\r
1732                                         } else {\r
1733                                                 raFile.writeBytes("IS = IA - 1;\n");\r
1734                                         }\r
1735                                         raFile.writeBytes("if (IS == 0) {\n");\r
1736                                         raFile.writeBytes("    PARFUN[0] = ZETA[0];\n");\r
1737                                         raFile.writeBytes("    PARFUN[1] = ZETA[1];\n");\r
1738                                         raFile.writeBytes("}\n");\r
1739                                         raFile.writeBytes("else {\n");\r
1740                                         if (NEEDC) {\r
1741                                                 raFile.writeBytes(\r
1742                                                                 "    PARFUN[0] = ZCEN[0] + U2[0]*(ZETA[0]-ZCEN[0]) + " + "U2[1]*(ZETA[1]-ZCEN[1]);\n");\r
1743                                                 raFile.writeBytes(\r
1744                                                                 "    PARFUN[1] = ZCEN[1] - U2[0]*(ZETA[1]-ZCEN[1]) + " + "U2[1]*(ZETA[0]-ZCEN[0]);\n");\r
1745                                         } else {\r
1746                                                 raFile.writeBytes("    PARFUN[0] = U2[0]*(ZETA[0]-ZCEN[0]) + " + "U2[1]*(ZETA[1]-ZCEN[1]);\n");\r
1747                                                 raFile.writeBytes(\r
1748                                                                 "    PARFUN[1] =  -U2[0]*(ZETA[1]-ZCEN[1]) + " + "U2[1]*(ZETA[0]-ZCEN[0]);\n");\r
1749                                         }\r
1750                                         raFile.writeBytes("}\n");\r
1751                                 } // else ORDRG <= 1\r
1752                         } // if (REFLN)\r
1753                         else { // !REFLN\r
1754                                 if (NARCS > 1) {\r
1755                                         raFile.writeBytes("IR = (IA - IB)/" + NARCS + ";\n");\r
1756                                 } else {\r
1757                                         raFile.writeBytes("IR = IA - 1;\n");\r
1758                                 }\r
1759                                 raFile.writeBytes("if (IR == 0) {\n");\r
1760                                 raFile.writeBytes("PARFUN[0] = ZETA[0]);\n");\r
1761                                 raFile.writeBytes("PARFUN[1] = ZETA[1]);\n");\r
1762                                 raFile.writeBytes("}\n");\r
1763                                 raFile.writeBytes("else {\n");\r
1764                                 if (NEEDC) {\r
1765                                         raFile.writeBytes("    PARFUN[0] = ZCEN[0] + WW[IR-1][0]*(ZETA[0] - ZCEN[0]) - "\r
1766                                                         + "WW[IR-1][1]*(ZETA[1] - ZCEN[1]);\n");\r
1767                                         raFile.writeBytes("    PARFUN[1] = ZCEN[1] + WW[IR-1][0]*(ZETA[1] - ZCEN[1]) + "\r
1768                                                         + "WW[IR-1][1]*(ZETA[0] - ZCEN[0]);\n");\r
1769                                 } else {\r
1770                                         raFile.writeBytes("    PARFUN[0] = WW[IR-1][0]*(ZETA[0] - ZCEN[0]) - "\r
1771                                                         + "WW[IR-1][1]*(ZETA[1] - ZCEN[1]);\n");\r
1772                                         raFile.writeBytes("    PARFUN[1] = WW[IR-1][0]*(ZETA[1] - ZCEN[1]) + "\r
1773                                                         + "WW[IR-1][1]*(ZETA[0] - ZCEN[0]);\n");\r
1774                                 }\r
1775                                 raFile.writeBytes("}\n");\r
1776                         } // else !REFLN\r
1777                 } // try\r
1778                 catch (IOException e) {\r
1779                         MipavUtil.displayError("IOException " + e + " in WRSYM2");\r
1780                         System.exit(-1);\r
1781                 }\r
1782 \r
1783         } // private void WRSYM2\r
1784 \r
1785         private void WRFUN2(int NARCS, int MNARC, double STAPT[][], int ARCTY[], int PGM[], double RGM[], int PTX[],\r
1786                         int NTX[], String DEFN[], int CHNL, String CHIA, String CHTT, String VAR, boolean NUMDER[], String REDD,\r
1787                         RandomAccessFile raFile) {\r
1788 \r
1789                 // COMPLEX STAPT(*)\r
1790                 // CHARACTER DEFN(*)*72,CHIA*2,CHTT*2,VAR*6,REDD*6\r
1791 \r
1792                 // **** TO WRITE THE SOURCE CODE FOR DPARFN IN THE CASE WHERE NO\r
1793                 // **** SYMMETRY IS INVOLVED.\r
1794 \r
1795                 // .......................................................................\r
1796                 // AUTHOR: DAVID HOUGH, ETH, ZUERICH\r
1797                 // LAST UPDATE: 4 AUG 1990\r
1798                 // .......................................................................\r
1799 \r
1800                 // LOCAL VARIABLES\r
1801 \r
1802                 int IA, I, J1, J2, N1, N2;\r
1803                 String TX1, TX2;\r
1804                 // String FMT1, FMT2;\r
1805                 // CHARACTER TX1*16,TX2*21,FMT1*11,FMT2*11\r
1806                 // EXTERNAL PTFUN2\r
1807                 double STAPT2[][];\r
1808                 double RGM2[];\r
1809                 String DEFN2[];\r
1810                 String DEFN3[];\r
1811                 int K;\r
1812 \r
1813                 TX1 = "      if (" + CHIA + " == ";\r
1814                 TX2 = "      else if (" + CHIA + " == ";\r
1815                 // FMT1="(A16,I3,A6)";\r
1816                 // FMT2="(A21,I3,A6)";\r
1817 \r
1818                 try {\r
1819                         for (IA = 1; IA <= NARCS; IA++) {\r
1820                                 I = PGM[IA - 1];\r
1821                                 J1 = PTX[IA - 1];\r
1822                                 J2 = PTX[IA + MNARC - 1];\r
1823                                 N1 = NTX[IA - 1];\r
1824                                 N2 = NTX[IA + MNARC - 1];\r
1825                                 STAPT2 = new double[STAPT.length - IA + 1][2];\r
1826                                 for (K = IA; K <= STAPT.length; K++) {\r
1827                                         STAPT2[K - IA][0] = STAPT[K - 1][0];\r
1828                                         STAPT2[K - IA][1] = STAPT[K - 1][1];\r
1829                                 }\r
1830                                 if ((ARCTY[IA-1] == 2) || ((!NUMDER[IA-1]) && ((ARCTY[IA-1] == 3) || (ARCTY[IA-1] == 4)))) {\r
1831                                         RGM2 = new double[RGM.length - I + 1];\r
1832                                         for (K = I; K <= RGM.length; K++) {\r
1833                                                 RGM2[K - I] = RGM[K - 1];\r
1834                                         }\r
1835                                 }\r
1836                                 else {\r
1837                                         RGM2 = null;\r
1838                                 }\r
1839                                 if ((!NUMDER[IA-1]) && (ARCTY[IA-1] == 4)) {\r
1840                                         DEFN2 = new String[DEFN.length - J1 + 1];\r
1841                                         for (K = J1; K <= DEFN.length; K++) {\r
1842                                                 DEFN2[K - J1] = DEFN[K - 1];\r
1843                                         }\r
1844                                 }\r
1845                                 else {\r
1846                                         DEFN2 = null;\r
1847                                 }\r
1848                                 if ((!NUMDER[IA-1]) && ((ARCTY[IA-1] == 3) || (ARCTY[IA-1] == 4))) {\r
1849                                         DEFN3 = new String[DEFN.length - J2 + 1];\r
1850                                         for (K = J2; K <= DEFN.length; K++) {\r
1851                                                 DEFN3[K - J2] = DEFN[K - 1];\r
1852                                         }\r
1853                                 }\r
1854                                 else {\r
1855                                         DEFN3 = null;\r
1856                                 }\r
1857                                 if (NARCS == 1) {\r
1858                                         PTFUN2(ARCTY[IA - 1], STAPT2, RGM2, N1, DEFN2, N2, DEFN3, CHNL, CHTT, VAR, " 1", NUMDER[IA - 1],\r
1859                                                         REDD, raFile);\r
1860                                 } else {\r
1861                                         if (IA == 1) {\r
1862                                                 raFile.writeBytes(TX1 + IA + ") {\n");\r
1863                                         } else if (IA == NARCS) {\r
1864                                                 raFile.writeBytes("      else {\n");\r
1865                                         } else {\r
1866                                                 raFile.writeBytes(TX2 + IA + ") {\n");\r
1867                                         }\r
1868                                         PTFUN2(ARCTY[IA - 1], STAPT2, RGM2, N1, DEFN2, N2, DEFN3, CHNL, CHTT, VAR, CHIA, NUMDER[IA - 1],\r
1869                                                         REDD, raFile);\r
1870                                         if (IA == NARCS) {\r
1871                                                 raFile.writeBytes("      }\n");\r
1872                                         }\r
1873                                 } // else\r
1874                         } // for (IA=1; IA <= NARCS; IA++)\r
1875                 } // try\r
1876                 catch (IOException e) {\r
1877                         MipavUtil.displayError("IOException " + e + " in WRFUN2");\r
1878                         System.exit(-1);\r
1879                 }\r
1880 \r
1881         } // private void WRFUN2\r
1882 \r
1883         private void PTFUN2(int TYPE, double STAPT[][], double RGM[], int NTX1, String TXT1[], int NTX2, String TXT2[],\r
1884                         int CHNL, String CHTT, String VAR, String CHIA, boolean NUMDER, String REDD, RandomAccessFile raFile) {\r
1885                 // COMPLEX STAPT(*)\r
1886                 // CHARACTER TXT1(*)*72,TXT2(*)*72,CHTT*2,VAR*6,CHIA*2,REDD*6\r
1887 \r
1888                 // .......................................................................\r
1889                 // AUTHOR: DAVID HOUGH, ETH, ZUERICH\r
1890                 // LAST UPDATE: 8 AUG 1990\r
1891                 // .......................................................................C\r
1892                 // **** LOCAL VARIABLES\r
1893 \r
1894                 int I;\r
1895                 double HA, MD, RAD, A, R;\r
1896                 double C1[] = new double[2];\r
1897                 double CENTR[] = new double[2];\r
1898                 String PAD = "          ";\r
1899                 // COMPLEX C1,CENTR\r
1900                 // String TX1, TX1B, TX2, TX2B, TX3, FMT1, FMT2, FMT3, FMT4, FMT5;\r
1901                 // CHARACTER TX1*4,TX1B*5,TX2*13,TX2B*14,TX3*39,\r
1902                 // FMT1*25,FMT2*15,FMT3*15,FMT4*25,FMT5*24\r
1903                 // String TX3R, TX3I;\r
1904 \r
1905                 // TX1 = "+"+CHTT+"*";\r
1906                 // TX1B = TX1 + "(";\r
1907                 // TX2 = " "+VAR+" = ";\r
1908                 // TX2B = TX2 + "(";\r
1909                 // TX3R = " "+VAR+"[0] = (ZDER * Math.cos(T) - ZRAD * Math.sin(T))*(";\r
1910                 // TX3I = " "+VAR+"[1] = (ZDER * Math.sin(T) + ZRAD * Math.cos(T))*(";\r
1911                 // TX3=TX2//'(ZDER+UI*ZRAD)*EXP(UI*T)*('\r
1912 \r
1913                 // FMT1='(A14,'//REDD//',A1,'//REDD//',A2)'\r
1914                 // FMT2='(A39,'//REDD//',A1)'\r
1915                 // FMT3='(A13,'//REDD//',A2)'\r
1916                 // FMT4='(A14,'//REDD//',A5,'//REDD//',A3)'\r
1917                 // FMT5='(A8,'//REDD//',A5,'//REDD//',A1)'\r
1918 \r
1919                 try {\r
1920                         if (TYPE == 1) {\r
1921                                 C1[0] = 0.5 * (STAPT[1][0] - STAPT[0][0]);\r
1922                                 C1[1] = 0.5 * (STAPT[1][1] - STAPT[0][1]);\r
1923                                 raFile.writeBytes("//\n");\r
1924                                 R = C1[0];\r
1925                                 A = C1[1];\r
1926                                 raFile.writeBytes(PAD + VAR + "ANS[0] = " + R + ";\n");\r
1927                                 raFile.writeBytes(PAD + VAR + "ANS[1] = " + A + ";\n");\r
1928                                 raFile.writeBytes("//\n");\r
1929                         } // if (TYPE == 1)\r
1930                         else if (TYPE == 2) {\r
1931                                 CENTR[0] = RGM[0];\r
1932                                 CENTR[1] = RGM[1];\r
1933                                 C1[0] = STAPT[0][0] - CENTR[0];\r
1934                                 C1[1] = STAPT[0][1] - CENTR[1];\r
1935                                 HA = 0.5 * RGM[2];\r
1936                                 MD = Math.atan2(C1[1], C1[0]) + HA;\r
1937                                 RAD = zabs(C1[0], C1[1]);\r
1938                                 raFile.writeBytes("//\n");\r
1939                                 raFile.writeBytes(\r
1940                                                 PAD + VAR + "ANS[0] = (-" + RAD + ")*(" + HA + ")*Math.exp((-"+CHTT + "[1])*(" + HA +"))*Math.sin(" + MD + "+" + CHTT + "[0]*(" + HA + "));\n");\r
1941                                 raFile.writeBytes(PAD + VAR + "ANS[1] = (" + RAD + ")*(" + HA + ")*Math.exp((-"+CHTT + "[1])*Math.cos(" + MD + "+" + CHTT + "[0]*(" + HA + "));\n");\r
1942                                 raFile.writeBytes("//\n");\r
1943                         } // else if (TYPE == 2)\r
1944                         else if (NUMDER) {\r
1945                                 // Use numerical derivative if no analytical expression is supplied for TYPE == 3 or TYPE == 4.\r
1946                                 raFile.writeBytes("//\n");\r
1947                                 raFile.writeBytes(PAD + VAR + "ANS = ZDPARF(" + CHIA + "," + CHTT + ");\n");\r
1948                                 raFile.writeBytes("//\n");\r
1949                         } // else if (NUMDER)\r
1950                         else if (TYPE == 3) {\r
1951                                 MD = 0.5 * (RGM[1] + RGM[0]);\r
1952                                 HA = 0.5 * (RGM[1] - RGM[0]);\r
1953                                 raFile.writeBytes("//\n");\r
1954                                 raFile.writeBytes(PAD + "T[0] = " + MD + "+" + CHTT + "[0]*(" + HA + ");\n");\r
1955                                 raFile.writeBytes(PAD + "T[1] = " + CHTT + "[1]*(" + HA + ");\n");\r
1956                                 if (TXT2[0].toLowerCase().indexOf("ui") == 0) {\r
1957                                     raFile.writeBytes(PAD + VAR + "ANS[0] = 0.0;\n");\r
1958                                 }\r
1959                                 else {\r
1960                                         // NTX2 = 1 if statements are entered without newlines for\r
1961                                         // multiple lines\r
1962                                         raFile.writeBytes(PAD + VAR + "ANS[0] = " + HA + "*(");\r
1963                                         for (I = 1; I <= NTX2; I++) {\r
1964                                                 int index = TXT2[I - 1].toLowerCase().indexOf("ui");\r
1965                                                 if (index == 0) {\r
1966                                                         raFile.writeBytes(");\n");\r
1967                                                         break;\r
1968                                                 }\r
1969                                                 String realString = null;\r
1970                                                 if (index == -1) {\r
1971                                                         realString = TXT2[I-1];\r
1972                                                 }\r
1973                                                 else {\r
1974                                                         realString = TXT2[I - 1].substring(0, index);   \r
1975                                                 }\r
1976                                                 if ((I > 1) && (realString != null) && (realString.length() != 0)) {\r
1977                                                         raFile.writeBytes("\n" + PAD);\r
1978                                                 }\r
1979                                                 if ((realString != null) && (realString.length() != 0)) {\r
1980                                                     raFile.writeBytes(realString);\r
1981                                                 }\r
1982                                                 if ((I == NTX2) || (index > 0)) {\r
1983                                                         raFile.writeBytes(";\n");\r
1984                                                         break;\r
1985                                                 }\r
1986                                         }\r
1987                                 }\r
1988                                 boolean uifound = false;\r
1989                                 String imagString = null;\r
1990                                 boolean firstImagStringWritten = false;\r
1991                                 for (I = 1; I <= NTX2; I++) {\r
1992                                         if (!uifound) {\r
1993                                         int index = TXT2[I-1].toLowerCase().indexOf("ui");\r
1994                                             if (index >= 0) {\r
1995                                                 uifound = true;\r
1996                                                 raFile.writeBytes(PAD + VAR + "ANS[1] = " + HA + "*(");\r
1997                                                 if (index + 2 < TXT2[I-1].length()) {\r
1998                                                         imagString = TXT2[I - 1].substring(index + 2);\r
1999                                                             raFile.writeBytes(imagString);\r
2000                                                             firstImagStringWritten = true;\r
2001                                                             if (I == NTX2) {\r
2002                                                                 raFile.writeBytes(");\n");\r
2003                                                             }\r
2004                                                 } // if (index + 2 < TXT2[I-1].length())\r
2005                                             } // if (index >= 0)\r
2006                                     } // if (!uifound) {\r
2007                                     else {\r
2008                                         imagString = TXT2[I-1];\r
2009                                         if (!firstImagStringWritten) {\r
2010                                                 raFile.writeBytes(imagString);\r
2011                                         }\r
2012                                         else if ((imagString != null) && (imagString.length() != 0)) {\r
2013                                             raFile.writeBytes(PAD + imagString);\r
2014                                         }\r
2015                                         firstImagStringWritten = true;\r
2016                                             if (I == NTX2) {\r
2017                                                 raFile.writeBytes(");\n");\r
2018                                             }\r
2019                                     }\r
2020                                 } // for (I = 1; I <= NTX2; I++)\r
2021                                 if (!uifound) {\r
2022                                     raFile.writeBytes(PAD + VAR + "ANS[1] = 0.0;\n");\r
2023                                 }\r
2024                                 raFile.writeBytes("//\n");\r
2025                         } // else if (TYPE == 3)\r
2026                         else {\r
2027                                 MD = 0.5 * (RGM[1] + RGM[0]);\r
2028                                 HA = 0.5 * (RGM[1] - RGM[0]);\r
2029                                 raFile.writeBytes("//\n");\r
2030                                 raFile.writeBytes(PAD + "T[0] = " + MD + "+" + CHTT + "[0]*(" + HA + ");\n");\r
2031                                 raFile.writeBytes(PAD + "T[1] = " + CHTT + "[1]*(" + HA + ");\n");\r
2032                                 if (TXT1[0].toLowerCase().indexOf("ui") == 0) {\r
2033                                     raFile.writeBytes(PAD + "ZRAD[0] = 0.0;\n");\r
2034                                 }\r
2035                                 else {\r
2036                                         // NTX = 1 if statements are entered without newlines for\r
2037                                         // multiple lines\r
2038                                         raFile.writeBytes(PAD + "ZRAD[0] = ");\r
2039                                         for (I = 1; I <= NTX1; I++) {\r
2040                                                 int index = TXT1[I - 1].toLowerCase().indexOf("ui");\r
2041                                                 if (index == 0) {\r
2042                                                         raFile.writeBytes(";\n");\r
2043                                                         break;\r
2044                                                 }\r
2045                                                 String realString = null;\r
2046                                                 if (index == -1) {\r
2047                                                         realString = TXT1[I-1];\r
2048                                                 }\r
2049                                                 else {\r
2050                                                         realString = TXT1[I - 1].substring(0, index);   \r
2051                                                 }\r
2052                                                 if ((I > 1) && (realString != null) && (realString.length() != 0)) {\r
2053                                                         raFile.writeBytes("\n" + PAD);\r
2054                                                 }\r
2055                                                 if ((realString != null) && (realString.length() != 0)) {\r
2056                                                     raFile.writeBytes(realString);\r
2057                                                 }\r
2058                                                 if ((I == NTX1) || (index > 0)) {\r
2059                                                         raFile.writeBytes(";\n");\r
2060                                                         break;\r
2061                                                 }\r
2062                                         }\r
2063                                 }\r
2064                                 boolean uifound = false;\r
2065                                 String imagString = null;\r
2066                                 boolean firstImagStringWritten = false;\r
2067                                 for (I = 1; I <= NTX1; I++) {\r
2068                                         if (!uifound) {\r
2069                                         int index = TXT1[I-1].toLowerCase().indexOf("ui");\r
2070                                             if (index >= 0) {\r
2071                                                 uifound = true;\r
2072                                                 raFile.writeBytes(PAD + "ZRAD[1] = ");\r
2073                                                 if (index + 2 < TXT1[I-1].length()) {\r
2074                                                         imagString = TXT1[I - 1].substring(index + 2);\r
2075                                                             raFile.writeBytes(imagString);\r
2076                                                             firstImagStringWritten = true;\r
2077                                                             if (I == NTX1) {\r
2078                                                                 raFile.writeBytes(";\n");\r
2079                                                             }\r
2080                                                 } // if (index + 2 < TXT1[I-1].length())\r
2081                                             } // if (index >= 0)\r
2082                                     } // if (!uifound) {\r
2083                                     else {\r
2084                                         imagString = TXT1[I-1];\r
2085                                         if (!firstImagStringWritten) {\r
2086                                                 raFile.writeBytes(imagString);\r
2087                                         }\r
2088                                         else if ((imagString != null) && (imagString.length() != 0)) {\r
2089                                             raFile.writeBytes(PAD + imagString);\r
2090                                         }\r
2091                                         firstImagStringWritten = true;\r
2092                                             if (I == NTX1) {\r
2093                                                 raFile.writeBytes(";\n");\r
2094                                             }\r
2095                                     }\r
2096                                 } // for (I = 1; I <= NTX1; I++)\r
2097                                 if (!uifound) {\r
2098                                     raFile.writeBytes(PAD + "ZRAD[1] = 0.0;\n");\r
2099                                 }\r
2100                                 \r
2101                                 if (TXT2[0].toLowerCase().indexOf("ui") == 0) {\r
2102                                     raFile.writeBytes(PAD + "ZDER[0] = 0.0;\n");\r
2103                                 }\r
2104                                 else {\r
2105                                         // NTX2 = 1 if statements are entered without newlines for\r
2106                                         // multiple lines\r
2107                                         raFile.writeBytes(PAD + "ZDER[0] = ");\r
2108                                         for (I = 1; I <= NTX2; I++) {\r
2109                                                 int index = TXT2[I - 1].toLowerCase().indexOf("ui");\r
2110                                                 if (index == 0) {\r
2111                                                         raFile.writeBytes(";\n");\r
2112                                                         break;\r
2113                                                 }\r
2114                                                 String realString = null;\r
2115                                                 if (index == -1) {\r
2116                                                         realString = TXT2[I-1];\r
2117                                                 }\r
2118                                                 else {\r
2119                                                         realString = TXT2[I - 1].substring(0, index);   \r
2120                                                 }\r
2121                                                 if ((I > 1) && (realString != null) && (realString.length() != 0)) {\r
2122                                                         raFile.writeBytes("\n" + PAD);\r
2123                                                 }\r
2124                                                 if ((realString != null) && (realString.length() != 0)) {\r
2125                                                     raFile.writeBytes(realString);\r
2126                                                 }\r
2127                                                 if ((I == NTX2) || (index > 0)) {\r
2128                                                         raFile.writeBytes(";\n");\r
2129                                                         break;\r
2130                                                 }\r
2131                                         }\r
2132                                 }\r
2133                                 uifound = false;\r
2134                                 imagString = null;\r
2135                                 firstImagStringWritten = false;\r
2136                                 for (I = 1; I <= NTX2; I++) {\r
2137                                         if (!uifound) {\r
2138                                         int index = TXT2[I-1].toLowerCase().indexOf("ui");\r
2139                                             if (index >= 0) {\r
2140                                                 uifound = true;\r
2141                                                 raFile.writeBytes(PAD + "ZDER[1] = ");\r
2142                                                 if (index + 2 < TXT2[I-1].length()) {\r
2143                                                         imagString = TXT2[I - 1].substring(index + 2);\r
2144                                                             raFile.writeBytes(imagString);\r
2145                                                             firstImagStringWritten = true;\r
2146                                                             if (I == NTX2) {\r
2147                                                                 raFile.writeBytes(";\n");\r
2148                                                             }\r
2149                                                 } // if (index + 2 < TXT2[I-1].length())\r
2150                                             } // if (index >= 0)\r
2151                                     } // if (!uifound) {\r
2152                                     else {\r
2153                                         imagString = TXT2[I-1];\r
2154                                         if (!firstImagStringWritten) {\r
2155                                                 raFile.writeBytes(imagString);\r
2156                                         }\r
2157                                         else if ((imagString != null) && (imagString.length() != 0)) {\r
2158                                             raFile.writeBytes(PAD + imagString);\r
2159                                         }\r
2160                                         firstImagStringWritten = true;\r
2161                                             if (I == NTX2) {\r
2162                                                 raFile.writeBytes(";\n");\r
2163                                             }\r
2164                                     }\r
2165                                 } // for (I = 1; I <= NTX2; I++)\r
2166                                 if (!uifound) {\r
2167                                     raFile.writeBytes(PAD + "ZDER[1] = 0.0;\n");\r
2168                                 }\r
2169                                 \r
2170                                 \r
2171                                 raFile.writeBytes(PAD + VAR + "ANS[0] = ((ZDER[0] - ZRAD[1])* Math.cos(T[0]) - (ZRAD[0] + ZDER[1])* Math.sin(T[0]))*Math.exp(-T[1])*(" + HA + ");\n");\r
2172                                 raFile.writeBytes(PAD + VAR + "ANS[1] = ((ZDER[0] - ZRAD[1])* Math.sin(T[0]) + (ZRAD[0] + ZDER[1])* Math.cos(T[0]))*Math.exp(-T[1])*(" + HA + ");\n");\r
2173                                 raFile.writeBytes("//\n");\r
2174                         } // else\r
2175                         raFile.writeBytes(PAD + "return " + VAR + "ANS;\n");\r
2176                 } // try\r
2177                 catch (IOException e) {\r
2178                         MipavUtil.displayError("IOException " + e + " in PTFUN2");\r
2179                         System.exit(-1);\r
2180                 }\r
2181 \r
2182         }\r
2183 \r
2184         private void WRSYM3(int NARCS, int ORDRG, boolean REFLN, int CHN, RandomAccessFile raFile) {\r
2185 \r
2186                 // **** TO WRITE THE CODE TO RECOVER THE DERIVATIVE FROM ITS SYMMETRIC\r
2187                 // **** COUNTERPART ON THE FUNDAMENTAL BOUNDARY SECTION.\r
2188 \r
2189                 // .......................................................................\r
2190                 // AUTHOR: DAVID HOUGH, ETH, ZUERICH\r
2191                 // LAST UPDATE: 4 AUG 1990\r
2192                 // .......................................................................C\r
2193                 // LOCAL VARIABLES\r
2194 \r
2195                 int I;\r
2196 \r
2197                 try {\r
2198                         raFile.writeBytes("//\n");\r
2199 \r
2200                         if (REFLN) {\r
2201                                 if (ORDRG > 1) {\r
2202                                         I = 2 * NARCS;\r
2203                                         if (NARCS > 1) {\r
2204                                                 raFile.writeBytes("      IS = (IA-IB)%" + I + ";\n");\r
2205                                                 raFile.writeBytes("      IR=(IA-IB-IS)/" + I + ";\n");\r
2206                                         } else {\r
2207                                                 raFile.writeBytes("      IS=(IA-1)%2;\n");\r
2208                                                 raFile.writeBytes("      IR=(IA-1-IS)/2;\n");\r
2209                                         }\r
2210                                         raFile.writeBytes("      if ((IR == 0) && (IS == 0)) {\n");\r
2211                                         raFile.writeBytes("          DPARFN[0] =ZETA[0];\n");\r
2212                                         raFile.writeBytes("          DPARFN[1] =ZETA[1];\n");\r
2213                                         raFile.writeBytes("      }\n");\r
2214                                         raFile.writeBytes("      else if ((IR > 0) && (IS == 0)) {\n");\r
2215                                         raFile.writeBytes("          DPARFN[0] = WW[IR-1][0]*ZETA[0] - WW[IR-1][1]*ZETA[1];\n");\r
2216                                         raFile.writeBytes("          DPARFN[1] = WW[IR-1][0]*ZETA[1] + WW[IR-1][1]*ZETA[0];\n");\r
2217                                         raFile.writeBytes("      }\n");\r
2218                                         raFile.writeBytes("       else if ((IR == 0 && (IS > 0)) {\n");\r
2219                                         raFile.writeBytes("           DPARFN[0] = -U2[0]*ZETA[0] -U2[1]*ZETA[1];\n");\r
2220                                         raFile.writeBytes("           DPARFN[1] = U2[0]*ZETA[1] -U2[1]*ZETA[0];\n");\r
2221                                         raFile.writeBytes("       }\n");\r
2222                                         raFile.writeBytes("       else {\n");\r
2223                                         raFile.writeBytes("           double realPart = -U2[0]*WW[IR-1][0] + U2[1]*WW[IR-1][1]);\n");\r
2224                                         raFile.writeBytes("           double imagPart = -U2[0]*WW[IR-1][1] + U2[1]*WW[IR-1][0]);\n");\r
2225                                         raFile.writeBytes("           DPARFN[0] = realPart*ZETA[0] + imagPart*ZETA[1]);\n");\r
2226                                         raFile.writeBytes("           DPARFN[1] = imagPart*ZETA[0] - realPart*ZETA[1]);\n");\r
2227                                         raFile.writeBytes("       }\n");\r
2228                                 } // if (ORDRG > 1)\r
2229                                 else {\r
2230                                         if (NARCS > 1) {\r
2231                                                 raFile.writeBytes("      IS=IA-IB;\n");\r
2232                                         } else {\r
2233                                                 raFile.writeBytes("      IS=IA-1;\n");\r
2234                                         }\r
2235                                         raFile.writeBytes("      if (IS == 0) {\n");\r
2236                                         raFile.writeBytes("          DPARFN[0] = ZETA[0]\n");\r
2237                                         raFile.writeBytes("          DPARFN[0] = ZETA[0]\n");\r
2238                                         raFile.writeBytes("      }\n");\r
2239                                         raFile.writeBytes("         else {\n");\r
2240                                         raFile.writeBytes("             DPARFN[0] = -U2[0]*ZETA[0] + U2[1]*ZETA[1]);\n");\r
2241                                         raFile.writeBytes("             DPARFN[1] = U2[0]*ZETA[1] - U2[1]*ZETA[0]);\n");\r
2242                                         raFile.writeBytes("         }\n");\r
2243                                 } // else\r
2244                         } // if (REFLN)\r
2245                         else {\r
2246                                 if (NARCS > 1) {\r
2247                                         raFile.writeBytes("      IR=(IA-IB)/" + NARCS + ";\n");\r
2248                                 } else {\r
2249                                         raFile.writeBytes("      IR=IA-1;\n");\r
2250                                 }\r
2251                                 raFile.writeBytes("      if (IR == 0) {\n");\r
2252                                 raFile.writeBytes("          DPARFN[0] = ZETA[0];\n");\r
2253                                 raFile.writeBytes("          DPARFN[1] = ZETA[1];\n");\r
2254                                 raFile.writeBytes("      }\n");\r
2255                                 raFile.writeBytes("      else {\n");\r
2256                                 raFile.writeBytes("          DPARFN[0]= WW[IR-1][0]*ZETA[0] - WW[IR-1][1]*ZETA[1];\n");\r
2257                                 raFile.writeBytes("          DPARFN[1]= WW[IR-1][0]*ZETA[1] + WW[IR-1][1]*ZETA[0];\n");\r
2258                                 raFile.writeBytes("      }\n");\r
2259                         }\r
2260                 } // try\r
2261                 catch (IOException e) {\r
2262                         MipavUtil.displayError("IOException " + e + " in WRSYM3");\r
2263                         System.exit(-1);\r
2264                 }\r
2265 \r
2266         } // private void WRSYM3\r
2267 \r
2268         private void TSTPLT(String JBNM, double MXMIS, double MXDIF, int NARCS, double PSD, double MINPD, double MAXPD,\r
2269                         int CHNL, int IER[]) {\r
2270                 // CHARACTER*4 JBNM\r
2271 \r
2272                 // ......................................................................\r
2273 \r
2274                 // 1. TSTPLT\r
2275                 // TESTS THE PARAMETRIC FUNCTION ROUTINES PARFUN AND DPARFN\r
2276                 // FOR CONSISTENCY AND OUTPUTS BOUNDARY POINTS FOR PLOTTING.\r
2277 \r
2278                 // 2. PURPOSE\r
2279                 // THE ROUTINE FIRST CHECKS THAT THE PARAMETRIC FUNCTION\r
2280                 // ROUTINE PARFUN IS CONSISTENT WITH RESPECT TO ITS DEFINITION\r
2281                 // OF ANY CORNERS ON THE BOUNDARY. THIS IS DONE BY CHECKING\r
2282                 // THAT THE COMPUTED POINT AT THE END OF EACH ARC MATCHES THE\r
2283                 // COMPUTED POINT AT THE START OF THE NEXT ONE. IF ALL THE\r
2284                 // RELATIVE MISFIT ERRORS AT CORNERS ARE LESS THAN\r
2285                 // 10*(UNIT ROUNDOFF) THEN ALL CORNERS ARE CONSIDERED TO FIT\r
2286                 // SATISFACTORILY, OTHERWISE THE MAXIMUM RELATIVE MISFIT\r
2287                 // ERROR IS REPORTED.\r
2288 \r
2289                 // THE SECOND PURPOSE OF THE ROUTINE IS TO OUTPUT TO A DATA\r
2290                 // FILE THE COORDINATES OF A NUMBER OF POINTS ON THE BOUNDARY.\r
2291                 // THE BOUNDARY POINTS ARE SELECTED ADAPTIVELY TO MEET THE\r
2292                 // PLOTTING RESOLUTION SPECIFICATIONS DEFINED BY THE ARGUMENTS\r
2293                 // PSD,MINPD,MAXPD (SEE BELOW). THE HOPE IS THAT THE USER MAY\r
2294                 // EASILY FEED THESE DATA POINTS TO HIS LOCAL GRAPH PLOTTING\r
2295                 // ROUTINES SO AS TO CONSTRUCT A PLOT OF THE BOUNDARY. THIS\r
2296                 // WILL PROVIDE AN ESSENTIAL VISUAL CHECK ON THE VALIDITY OF\r
2297                 // THE ROUTINE PARFUN. THE OUTPUT DATA FILE IS AUTOMATICALLY\r
2298                 // NAMED <JBNM>zz.\r
2299 \r
2300                 // THE THIRD PURPOSE OF THE ROUTINE IS TO CHECK PARFUN AND\r
2301                 // DPARFN FOR MUTUAL CONSISTECY. THIS IS DONE BY COMPUTING\r
2302                 // TWO POINT FINITE DIFFERENCE APPROXIMATIONS TO DPARFN.\r
2303                 // THESE DIFFERENCE APPROXIMATIONS ARE COMPUTED AT EACH BOUND-\r
2304                 // ARY POINT THAT IS OUTPUT FOR PLOTTING AND ALSO AT NEARBY\r
2305                 // POINTS WHICH LIE JUST O F F THE BOUNDARY. THIS LATTER\r
2306