PARGEN and supporting routines corrected so that ex01.f and ex03.f are correctly...
[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                 boolean writeReturn;\r
449                 // String FMT1;\r
450                 // String FMT2;\r
451 \r
452                 // PARAMETER (MNARC=100,TABC=' +',CHNL=20,CHIN=21)\r
453                 final String TABC = "     +";\r
454                 final int CHNL = 20;\r
455                 // final int CHIN = 21;\r
456                 String line;\r
457                 String tokens[];\r
458 \r
459                 File file;\r
460                 RandomAccessFile raFile = null;\r
461                 boolean validInput;\r
462                 String junk;\r
463 \r
464                 // EXTERNAL CHRIN,HEADER,R1MACH,SYINF1,WRFUN1,WRFUN2,WRHEAD,WRSYM1,\r
465                 // +WRSYM2,WRSYM3,WRTAIL\r
466 \r
467                 WRHEAD(6, 0, null);\r
468 \r
469                 PI = Math.PI;\r
470 \r
471                 // **** DETERMINE NUMBER OF SIGNIFICANT FIGURES REQUIRED TO MATCH\r
472                 // MACHINE\r
473                 // **** PRECISION AND SET UP POINTER SW TO SIG AND WID\r
474 \r
475                 SW = (int) (-Math.log10(EPS)) + 2;\r
476                 if (SW <= 7) {\r
477                         SW = 1;\r
478                 } else if (SW >= 16) {\r
479                         SW = 10;\r
480                 } else {\r
481                         SW = SW - 6;\r
482                 }\r
483 \r
484                 // **** SET UP THE EDIT DESCRIPTOR AND FORMAT SPECIFICATION FOR FLOATING\r
485                 // **** POINT OUTPUT\r
486 \r
487                 REDD = "E" + WID[SW - 1] + "." + SIG[SW - 1];\r
488                 // FMT1="("+REDD+")";\r
489                 // FMT2="(2"+REDD+")";\r
490                 if (traditionalInput) {\r
491                         System.out.println("ENTER FILENAME TO RECEIVE OUTPUT JAVA CODE");\r
492                         FORTFL = input.next();\r
493                 } // if (traditionalInput)\r
494 \r
495                 // **** WRITE THE SOURCE CODE FOR PARFUN\r
496                 fileDir = "C:\\conformal mapping\\CONFPACK\\";\r
497                 file = new File(fileDir + FORTFL);\r
498                 \r
499                 try {\r
500                         raFile = new RandomAccessFile(file, "rw");\r
501                 } catch (IOException e) {\r
502                         MipavUtil.displayError("IOException " + e + " on raFile = new RandomAccessFile(file, rw)");\r
503                         System.exit(-1);\r
504                 }\r
505                 // Necessary so that if this is an overwritten file there isn't any\r
506                 // junk at the end\r
507                 try {\r
508                         raFile.setLength(0);\r
509                 } catch (IOException e) {\r
510                         MipavUtil.displayError("IOException " + e + " on raFile.setLength(0)");\r
511                         System.exit(-1);\r
512                 }\r
513 \r
514                 // OPEN(CHNL,FILE=FORTFL)\r
515 \r
516                 if (traditionalInput) {\r
517                         validInput = false;\r
518                         while (!validInput) {\r
519                                 System.out.println("DOES THE DOMAIN HAVE ANY SYMMETRY (Y/N)?");\r
520                                 String sym = input.next();\r
521                                 String firstSym = sym.substring(0, 1);\r
522                                 if (firstSym.equalsIgnoreCase("Y")) {\r
523                                         SYMTY = true;\r
524                                         validInput = true;\r
525                                 } else if (firstSym.equalsIgnoreCase("N")) {\r
526                                         SYMTY = false;\r
527                                         validInput = true;\r
528                                 } else {\r
529                                         System.out.println(sym + " is not a valid response");\r
530                                 }\r
531                         } // while (!validInput)\r
532 \r
533                         if (SYMTY) {\r
534                                 validInput = false;\r
535                                 while (!validInput) {\r
536                                         System.out.println("ARE THERE ANY REFLECTIONAL SYMMETRIES (Y/N)?");\r
537                                         String ref = input.next();\r
538                                         String firstRef = ref.substring(0, 1);\r
539                                         if (firstRef.equalsIgnoreCase("Y")) {\r
540                                                 REFLN = true;\r
541                                                 validInput = true;\r
542                                         } else if (firstRef.equalsIgnoreCase("N")) {\r
543                                                 REFLN = false;\r
544                                                 validInput = true;\r
545                                         } else {\r
546                                                 System.out.println(ref + " is not a valid response");\r
547                                         }\r
548                                 } // while (!validInput)\r
549 \r
550                                 validInput = false;\r
551                                 while (!validInput) {\r
552                                     System.out.println("What are the coordinates of the center of symmetry (X,Y)?");\r
553                                     try {\r
554                                         line = input.next();\r
555                                         tokens = line.split(",");\r
556                                         CENSY[0] = Double.valueOf(tokens[0]);\r
557                                         CENSY[1] = Double.valueOf(tokens[0]);\r
558                                         validInput = true;\r
559                                     }\r
560                                     catch (Exception e) {};\r
561                                 }\r
562                                 validInput = false;\r
563                                 while (!validInput) {\r
564                                         System.out.println("How many arcs are there on the fundamental boundary section?");\r
565                                         NARCS = input.nextInt();\r
566                                         if (NARCS <= MNARC - 1) {\r
567                                                 validInput = true;\r
568                                         } else {\r
569                                                 System.out.print("NARCS must be <= " + (MNARC - 1));\r
570                                         }\r
571                                 } // while (!validInput)\r
572                         } // if (SYMTY)\r
573                         else { // !SYMTY\r
574                                 validInput = false;\r
575                                 while (!validInput) {\r
576                                         System.out.println("How many arcs are there on the boundary?");\r
577                                         NARCS = input.nextInt();\r
578                                         if (NARCS <= MNARC - 1) {\r
579                                                 validInput = true;\r
580                                         } else {\r
581                                                 System.out.println("NARCS must be <= " + (MNARC - 1));\r
582                                         }\r
583                                 } // while (!validInput)\r
584                         } // else !SYMTY\r
585 \r
586                         GMCO = 0;\r
587                         TXCO = 0;\r
588 \r
589                         for (IA = 1; IA <= NARCS; IA++) {\r
590                                 NUMDER[IA - 1] = false;\r
591                                 validInput = false;\r
592                                 while (!validInput) {\r
593                                         System.out.println("ENTER THE TYPE OF ARC(1-4) for ARC NUMBER " + IA);\r
594                                         try {\r
595                                             TYPE = input.nextInt();\r
596                                                 if ((TYPE >= 1) && (TYPE <= 4)) {\r
597                                                         validInput = true;\r
598                                                 } else {\r
599                                                         System.out.println("TYPE MUST BE BETWEEN 1 and 4");\r
600                                                 }\r
601                                         }\r
602                                         catch (Exception e) {};\r
603                                 } // while (!validInput)\r
604                                 if (TYPE == 1) {\r
605                                         ARCTY[IA - 1] = TYPE;\r
606                                         validInput = false;\r
607                                         while (!validInput) {\r
608                                                 try {\r
609                                                         System.out.println("What are the coordinates of the initial point on the line (X,Y)?");\r
610                                                 line = input.next();\r
611                                                 tokens = line.split(",");\r
612                                                 STAPT[IA - 1][0] = Double.valueOf(tokens[0]);\r
613                                                 STAPT[IA - 1][1] = Double.valueOf(tokens[1]);\r
614                                                 validInput = true;\r
615                                                 }\r
616                                                 catch (Exception e) {};\r
617                                         }\r
618                                 } // if (TYPE == 1)\r
619                                 else if (TYPE == 2) {\r
620                                         ARCTY[IA - 1] = TYPE;\r
621                                         validInput = false;\r
622                                         while (!validInput) {\r
623                                                 try {\r
624                                                         System.out.println("What are the coordinates of the initial point on the circle (X,Y)?");\r
625                                                 line = input.next();\r
626                                                 tokens = line.split(",");\r
627                                                 STAPT[IA - 1][0] = Double.valueOf(tokens[0]);\r
628                                                 STAPT[IA - 1][1] = Double.valueOf(tokens[1]);\r
629                                                 validInput = true;\r
630                                                 }\r
631                                                 catch (Exception e) {};\r
632                                         }\r
633                                         validInput = false;\r
634                                         while (!validInput) {\r
635                                                 try {\r
636                                                         System.out.println("What are the coordinates of the center of the circle (X,Y)?");\r
637                                                 line = input.next();\r
638                                                 tokens = line.split(",");\r
639                                                 X = Double.valueOf(tokens[0]);\r
640                                                 Y = Double.valueOf(tokens[1]);\r
641                                                 validInput = true;\r
642                                                 }\r
643                                                 catch (Exception e) {};\r
644                                         }\r
645                                         validInput = false;\r
646                                         while (!validInput) {\r
647                                                 try {\r
648                                                      System.out.println("What is the signed angle subtended at center (in units of PI)?");\r
649                                                      ALPHA = input.nextDouble();\r
650                                                      validInput = true;\r
651                                                 }\r
652                                                 catch (Exception e) {};\r
653                                         }\r
654                                         GMCO = GMCO + 1;\r
655                                         PGM[IA - 1] = GMCO;\r
656                                         RGM[GMCO - 1] = X;\r
657                                         GMCO = GMCO + 1;\r
658                                         RGM[GMCO - 1] = Y;\r
659                                         GMCO = GMCO + 1;\r
660                                         RGM[GMCO - 1] = ALPHA * PI;\r
661                                 } // else if (TYPE == 2)\r
662                                 else if ((TYPE == 3) || (TYPE == 4)) {\r
663                                         ARCTY[IA - 1] = TYPE;\r
664                                         validInput = false;\r
665                                         while (!validInput) {\r
666                                                 try {\r
667                                                         System.out.println("What are the coordinates of the initial point on the curve (X,Y)?");\r
668                                                 line = input.next();\r
669                                                 tokens = line.split(",");\r
670                                                 STAPT[IA - 1][0] = Double.valueOf(tokens[0]);\r
671                                                 STAPT[IA - 1][1] = Double.valueOf(tokens[1]);\r
672                                                 validInput = true;\r
673                                                 }\r
674                                                 catch (Exception e) {};\r
675                                         }\r
676                                         validInput = false;\r
677                                         while (!validInput) {\r
678                                                 try {\r
679                                                         if (TYPE == 3) {\r
680                                                                 System.out.println("Enter the initial and final parameter values (X,Y)");\r
681                                                         } else {\r
682                                                                 System.out.println("Enter the initial and final polar values (in angles of PI) (X,Y)");\r
683                                                         }\r
684                                                 line = input.next();\r
685                                                 tokens = line.split(",");\r
686                                                 X = Double.valueOf(tokens[0]);\r
687                                                 Y = Double.valueOf(tokens[1]);\r
688                                                 validInput = true;\r
689                                                 }\r
690                                                 catch (Exception e) {};\r
691                                         }\r
692                                         GMCO = GMCO + 1;\r
693                                         PGM[IA - 1] = GMCO;\r
694                                         if (TYPE == 4) {\r
695                                                 RGM[GMCO - 1] = X * PI;\r
696                                                 GMCO = GMCO + 1;\r
697                                                 RGM[GMCO - 1] = Y * PI;\r
698                                         } else {\r
699                                                 RGM[GMCO - 1] = X;\r
700                                                 GMCO = GMCO + 1;\r
701                                                 RGM[GMCO - 1] = Y;\r
702                                         }\r
703                                         for (J = 1; J <= 2; J++) {\r
704                                                 // With spaces the output is correct but put on multiple lines.\r
705                                                 if (J == 1 && TYPE == 3) {\r
706                                                         System.out.println("ENTER JAVA EXPRESSION WITH NO SPACES ENDING IN // FOR PARFUN");\r
707                                                         System.out.println("PUT REAL PART ui IMAGINARY PART");\r
708                                                 } else if (J == 2 && TYPE == 3) {\r
709                                                         System.out.println("ENTER JAVA EXPRESSION WITH NO SPACES ENDING IN // FOR DPARFN");\r
710                                                         System.out.println("PUT REAL PART ui IMAGINARY PART");\r
711                                                         System.out.println("ALTERNATIVELY JUST ENTER // FOR NUMERICAL DERIVATIVE");\r
712                                                 } else if (J == 1 && TYPE == 4) {\r
713                                                         System.out.println("ENTER JAVA EXPRESSION WITH NO SPACES ENDING IN // FOR RADIUS");\r
714                                                 } else {\r
715                                                         System.out.println("ENTER JAVA EXPRESSION WITH NO SPACES ENDING IN // FOR RADIUS DERIVATIVE");\r
716                                                         System.out.println("ALTERNATIVELY JUST ENTER // FOR NUMERICAL DERIVATIVE");\r
717                                                 }\r
718                                                 // Java does not allow operator overloading, so you can't do a cos(t)*sin(t) for complex t.\r
719                                                 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
720                                                 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
721 \r
722                                                 TXCO = TXCO + 1;\r
723                                                 PTX[IA - 1 + (J - 1) * MNARC] = TXCO;\r
724                                                 I = 1;\r
725 \r
726                                                 L = -1;\r
727                                                 while (L == -1) {\r
728                                                         TXT = input.next();\r
729                                                         L = TXT.indexOf("//");\r
730                                                         if (L == -1) {\r
731                                                                 DEFN[TXCO - 1] = TXT;\r
732                                                                 I = I + 1;\r
733                                                                 TXCO = TXCO + 1;\r
734                                                         } // if (L == -1)\r
735                                                 } // while (L == -1)\r
736                                                 NTX[IA - 1 + (J - 1) * MNARC] = I;\r
737                                                 if ((L == 0) && (I == 1)) {\r
738                                                         // If just // on first line, use numerical derivative for DPARFN or RADIUS DERIVATIVE in PTFUN2\r
739                                                         DEFN[TXCO - 1] = "";\r
740                                                         NUMDER[IA - 1] = true;\r
741                                                 } else if (L == 0) {\r
742                                                         DEFN[TXCO-1] = "";\r
743                                                 } else {\r
744                                                         DEFN[TXCO - 1] = TXT.substring(0, L);\r
745                                                 }\r
746                                                 if ((J == 1) && (TYPE == 4)) {\r
747                                                         System.out.println("(... = ZRAD)");\r
748                                                 }\r
749                                         } // for (J = 1; J <= 2; J++)\r
750                                 } // else if ((TYPE == 3) || (TYPE == 4))\r
751                         } // for (IA = 1; IA <= NARCS; IA++)\r
752 \r
753                         if (SYMTY) {\r
754                                 validInput = false;\r
755                                 while (!validInput) {\r
756                                         try {\r
757                                                 System.out.println("ENTER THE COORDINATES OF FINAL POINT ON THIS LAST ARC (X,Y)");\r
758                                         line = input.next();\r
759                                         tokens = line.split(",");\r
760                                         STAPT[NARCS][0] = Double.valueOf(tokens[0]);\r
761                                         STAPT[NARCS][1] = Double.valueOf(tokens[1]);\r
762                                         validInput = true;\r
763                                         }\r
764                                         catch (Exception e) {};\r
765                                 }\r
766                         } else {\r
767                                 STAPT[NARCS][0] = STAPT[0][0];\r
768                                 STAPT[NARCS][1] = STAPT[0][1];\r
769                         }\r
770 \r
771                         validInput = false;\r
772                         while (!validInput) {\r
773                                 System.out.println("END OF INPUT PHASE; CONTINUE WITH PROCESSING (Y/N)?");\r
774                                 String term = input.next();\r
775                                 String firstTerm = term.substring(0, 1);\r
776                                 if (firstTerm.equalsIgnoreCase("Y")) {\r
777                                         validInput = true;\r
778                                 } else if (firstTerm.equalsIgnoreCase("N")) {\r
779                                         validInput = true;\r
780                                         setCompleted(false);\r
781                                         try {\r
782                                                 raFile.close();\r
783                                         } catch (IOException e) {\r
784 \r
785                                         }\r
786                                         return;\r
787                                 } else {\r
788                                         System.out.println(term + " is not a valid response");\r
789                                 }\r
790                         } // while (!validInput)\r
791                 } // if (traditionalInput)\r
792                 HEADER("PARFUN", REDD, raFile);\r
793                 \r
794                 if (SYMTY) {\r
795                         SYINF1(ORDRG, ORDSG, RTUNI, U2, REFLN, CENSY, STAPT[0], STAPT[NARCS], IER);\r
796                         if (IER[0] > 0) {\r
797                                 WRTAIL(6, 0, IER[0], null);\r
798                                 return;\r
799                         }\r
800                         System.out.println("\nN O T E : THE ORDER OF THE SYMMETRY GROUP IS " + ORDSG[0]);\r
801                         if (REFLN) {\r
802                                 System.out.println("          ISYGP = " + (-ORDSG[0]));\r
803                         } else {\r
804                                 System.out.println("          ISYGP = " + (ORDSG[0]));\r
805                         }\r
806                         WRSYM1(NARCS, ORDRG[0], ORDSG[0], RTUNI, U2, CENSY, REFLN, true, REDD, CHNL, raFile);\r
807                         if (REFLN) {\r
808                                 CH = "TS";\r
809                         } else {\r
810                                 CH = "TT";\r
811                         }\r
812                         writeReturn = false;\r
813                         WRFUN1(NARCS, STAPT, ARCTY, PGM, RGM, PTX, NTX, DEFN, CHNL, "IB", CH, "ZETA", REDD, raFile, writeReturn);\r
814                         WRSYM2(NARCS, ORDRG[0], CENSY, REFLN, CHNL, raFile);\r
815                 } else {\r
816                         writeReturn = true;\r
817                         WRFUN1(NARCS, STAPT, ARCTY, PGM, RGM, PTX, NTX, DEFN, CHNL, "IA", "TT", "PARFUNANS", REDD, raFile, writeReturn);\r
818                 }\r
819 \r
820                 try {\r
821                         raFile.writeBytes("//\n");\r
822                         raFile.writeBytes("}\n");\r
823 \r
824                         // **** WRITE THE SOURCE CODE FOR DPARFN\r
825 \r
826                         raFile.writeBytes("//...........................................\n");\r
827                 } catch (IOException e) {\r
828                         MipavUtil.displayError("IOException " + e + " in PARGEN");\r
829                         System.exit(-1);\r
830                 }\r
831                 HEADER("DPARFN", REDD, raFile);\r
832                 if (SYMTY) {\r
833                         WRSYM1(NARCS, ORDRG[0], ORDSG[0], RTUNI, U2, CENSY, REFLN, false, REDD, CHNL, raFile);\r
834                         if (REFLN) {\r
835                                 CH = "TS";\r
836                         } else {\r
837                                 CH = "TT";\r
838                         }\r
839                         writeReturn = false;\r
840                         WRFUN2(NARCS, MNARC, STAPT, ARCTY, PGM, RGM, PTX, NTX, DEFN, CHNL, "IB", CH, "ZETA", NUMDER, REDD,\r
841                                         raFile, writeReturn);\r
842                         WRSYM3(NARCS, ORDRG[0], REFLN, CHNL, raFile);\r
843                 } // if (SYMTY)\r
844                 else {\r
845                         writeReturn = true;\r
846                         WRFUN2(NARCS, MNARC, STAPT, ARCTY, PGM, RGM, PTX, NTX, DEFN, CHNL, "IA", "TT", "DPARFNANS", NUMDER, REDD,\r
847                                         raFile, writeReturn);\r
848                 }\r
849 \r
850                 try {\r
851                         raFile.writeBytes("//\n");\r
852                         raFile.writeBytes("}\n");\r
853                         raFile.close();\r
854                 } catch (IOException e) {\r
855                         MipavUtil.displayError("IOException " + e + " in PARGEN");\r
856                         System.exit(-1);\r
857                 }\r
858                 WRTAIL(6, 0, IER[0], null);\r
859 \r
860         } // public void PARGEN\r
861 \r
862         private void HEADER(String TXT, String REDD, RandomAccessFile raFile) {\r
863 \r
864                 String TAB6 = "      ";\r
865 \r
866                 String LINE = TAB6 + "private double[] " + TXT + "(int IA, double TT[]) {\n";\r
867                 try {\r
868                         raFile.writeBytes(LINE);\r
869 \r
870                 LINE = TAB6 + "double " + TXT + "ANS[] = new double[2];\n";\r
871                 raFile.writeBytes(LINE);\r
872                 LINE = TAB6 + "double ZRAD[] = new double[2];\n";\r
873                 raFile.writeBytes(LINE);\r
874                 LINE = TAB6 + "int IA;\n";\r
875                 raFile.writeBytes(LINE);\r
876                 LINE = TAB6 + "double T[] = new double[2];\n";\r
877                 raFile.writeBytes(LINE);\r
878                 LINE = TAB6 + "double TT[] = new double[2];\n";\r
879                 raFile.writeBytes(LINE);\r
880 \r
881                         raFile.writeBytes("      double PI = " + Math.PI + ";\n");\r
882                         raFile.writeBytes("//\n");\r
883                 } catch (IOException e) {\r
884                         MipavUtil.displayError("IOException " + e + " in HEADER");\r
885                         System.exit(-1);\r
886                 }\r
887 \r
888         } // private void HEADER\r
889 \r
890         private void SYINF1(int ORDRG[], int ORDSG[], double RTUNI[], double U2[], boolean REFLN, double Z0[], double Z1[],\r
891                         double Z2[], int IER[]) {\r
892                 // COMPLEX RTUNI,U2,Z0,Z1,Z2\r
893 \r
894                 // **** GIVEN Z0,THE CENTRE OF SYMMETRY, Z1 AND Z2, THE INITIAL AND\r
895                 // FINAL\r
896                 // **** POINTS ON THE FUNDAMENTAL BOUNDARY SECTION, REFLN, WHICH IS TRUE\r
897                 // **** IF THE SYMMETRY GROUP HAS IMPROPER ROTATIONAL ELEMENTS\r
898                 // **** (I.E. REFLECTIONAL SYMMETRIES), THIS ROUTINE COMPUTES\r
899                 // **** ORDRG - THE ORDER OF THE SUBGROUP OF PROPER ROTATIONS (THIS IS\r
900                 // THE\r
901                 // **** ORDER OF THE SYMMETRY GROUP IF REFLN=.FALSE.)\r
902                 // **** ORDSG - THE ORDER OF THE FULL SYMMETRY GROUP, EITHER ORDRG OR\r
903                 // **** 2*ORDRG DEPENDING ON WHETHER REFLN IS .FALSE. OR .TRUE.\r
904                 // **** RTUNI - THE ROOT OF UNITY FROM WHICH THE PROPER ROTATIONAL\r
905                 // SUBROUP\r
906                 // **** IS GENERATED\r
907                 // **** U2 - THE ADDITIONAL IN-PLANE ROTATION WHICH, WHEN COMBINED WITH\r
908                 // **** CONJUGATION, DEFINES THE IMPROPER ROTATION FOR THE CASE\r
909                 // **** REFLN=.TRUE.\r
910 \r
911                 // LOCAL VARIABLES\r
912 \r
913                 double ALPHA, PI, SQRTEPS;\r
914                 // COMPLEX CT,U\r
915                 double CT[] = new double[2];\r
916                 double U[] = new double[2];\r
917                 double cr[] = new double[1];\r
918                 double ci[] = new double[1];\r
919 \r
920                 PI = Math.PI;\r
921                 SQRTEPS = Math.sqrt(EPS);\r
922                 CT[0] = Z2[0] - Z0[0];\r
923                 CT[1] = Z2[1] - Z0[1];\r
924                 double ABSCT = zabs(CT[0], CT[1]);\r
925                 if (ABSCT < SQRTEPS) {\r
926                         IER[0] = 56;\r
927                         return;\r
928                 }\r
929                 U[0] = CT[0] / ABSCT;\r
930                 U[1] = CT[1] / ABSCT;\r
931                 zmlt(U[0], U[1], U[0], U[1], cr, ci);\r
932                 U2[0] = cr[0];\r
933                 U2[1] = ci[0];\r
934 \r
935                 zmlt(Z1[0] - Z0[0], Z1[1] - Z0[1], U[0], -U[1], cr, ci);\r
936                 CT[0] = cr[0];\r
937                 CT[1] = ci[0];\r
938                 ABSCT = zabs(CT[0], CT[1]);\r
939                 if (ABSCT < SQRTEPS) {\r
940                         IER[0] = 57;\r
941                         return;\r
942                 }\r
943                 ALPHA = Math.atan2(CT[1], CT[0]);\r
944                 ALPHA = Math.abs(ALPHA);\r
945 \r
946                 if (REFLN) {\r
947                         ORDRG[0] = (int) Math.round(PI / ALPHA);\r
948                         ORDSG[0] = 2 * ORDRG[0];\r
949                 } else {\r
950                         ORDRG[0] = 2 * (int) Math.round(PI / ALPHA);\r
951                         ORDSG[0] = ORDRG[0];\r
952                 }\r
953 \r
954                 ALPHA = 2.0 * PI / (double) (ORDRG[0]);\r
955                 RTUNI[0] = Math.cos(ALPHA);\r
956                 RTUNI[1] = Math.sin(ALPHA);\r
957 \r
958                 // NORMAL EXIT\r
959 \r
960                 IER[0] = 0;\r
961                 return;\r
962         } // private void SYINF1\r
963 \r
964         // COMPLEX FUNCTION PARFUN(I,T)\r
965         // INTEGER I\r
966         // COMPLEX T\r
967         // \r
968         double[] PARFUN(int I, double T[]) {\r
969 \r
970                 // DUMMY FUNCTION TO AID LINK-LOADING OF PARGEN\r
971 \r
972                 double result[] = new double[] { 1.0, 0.0 };\r
973                 return result;\r
974         } // double[] PARFUN\r
975 \r
976         // COMPLEX FUNCTION DPARFN(I,T)\r
977         // INTEGER I\r
978         // COMPLEX T\r
979         double[] DPARFN(int I, double T[]) {\r
980 \r
981                 // DUMMY FUNCTION TO AID LINK-LOADING OF PARGEN\r
982 \r
983                 double result[] = new double[] { 1.0, 0.0 };\r
984                 return result;\r
985         } // double[] DPARFN\r
986 \r
987         private void WRHEAD(int I, int CHNL, RandomAccessFile raFile) {\r
988 \r
989                 // **** WRITE A HEADING FOR THE MAIN CONFPACK MODULES JAPHYC (I=1),\r
990                 // **** GQPHYC (I=2), JACANP (I=3), GQCANP (I=4), CNDPLT (I=5), THE\r
991                 // **** PARAMETRIC FUNCTION GENERATOR PARGEN (I=6),THE PARAMETRIC\r
992                 // FUNCTION\r
993                 // **** TESTER TSTPLT (I=7) AND THE LEVEL CURVE ROUTINE LEVCUR (I=8). IF\r
994                 // **** CHNL=0 THEN WRITE ON THE STANDARD OUTPUT CHANNEL, OTHERWISE\r
995                 // WRITE\r
996                 // **** ON THE CHANNEL SPECIFIED BY CHNL.\r
997                 //\r
998                 // LOCAL VARIABLES\r
999                 //\r
1000                 String DOTS = ".................................................";\r
1001                 String CPHEAD = ": C O N F P A C K    M O D U L E    ";\r
1002                 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
1003                                 "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
1004                 String TXT = CPHEAD + MOD[I - 1];\r
1005 \r
1006                 if (CHNL == 0 || CHNL == 6) {\r
1007                         System.out.println("\n\n      " + DOTS + "\n      " + TXT + "\n      " + DOTS);\r
1008                 } else {\r
1009                         try {\r
1010                                 raFile.writeBytes("\n\n      //" + DOTS + "\n      //" + TXT + "\n      //" + DOTS + "\n");\r
1011                         } catch (IOException e) {\r
1012                                 MipavUtil.displayError("IOException " + e + " on raFile.writeBytes in WRHEAD");\r
1013                                 System.exit(-1);\r
1014                         }\r
1015                 }\r
1016                 return;\r
1017         } // private void WRHEAD\r
1018 \r
1019         private void WRTAIL(int I, int CHNL, int IER, RandomAccessFile raFile) {\r
1020 \r
1021                 //\r
1022                 // **** WRITE A CLOSING MESSAGE FOR THE MAIN CONFPACK MODULES JAPHYC\r
1023                 // (I=1)\r
1024                 // **** GQPHYC (I=2), JACANP (I=3), GQCANP (I=4), CNDPLT (I=5), THE\r
1025                 // PARA-\r
1026                 // **** METRIC FUNCTION GENERATOR PARGEN (I=6), THE PARAMETRIC FUNCTION\r
1027                 // **** TESTER TSTPLT (I=7) AND THE LEVEL CURVE ROUTINE LEVCUR (I=8). IF\r
1028                 // **** CHNL=0 THEN WRITE ON THE STANDARD OUTPUT CHANNEL, OTHERWISE\r
1029                 // WRITE\r
1030                 // **** ON THE CHANNEL SPECIFIED BY CHNL. THE TEXT OF THE MESSAGE IS\r
1031                 // **** DETERMINED BY THE ERROR NUMBER IER VIA THE SUBROUTINE IERTXT.\r
1032 \r
1033                 // LOCAL VARIABLES\r
1034 \r
1035                 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
1036                                 "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
1037                 String GOOD = "  NORMAL EXIT";\r
1038                 String BAD = "  ABNORMAL EXIT";\r
1039                 String LINE = "__________________________________________________________________&";\r
1040 \r
1041                 String TXT, TXT2;\r
1042                 if (IER == 0) {\r
1043                         TXT = MOD[I - 1] + GOOD;\r
1044                 } else {\r
1045                         TXT = MOD[I - 1] + BAD;\r
1046                 }\r
1047                 TXT2 = IERTXT(IER);\r
1048 \r
1049                 if ((CHNL == 0) || (CHNL == 6)) {\r
1050                         System.out.println("\n\n      " + TXT);\r
1051                         System.out.println("      " + TXT2);\r
1052                         System.out.println(LINE);\r
1053                 } else {\r
1054                         try {\r
1055                                 raFile.writeBytes("\n\n      //" + TXT + "\n");\r
1056                                 raFile.writeBytes("      //" + TXT2 + "\n");\r
1057                                 raFile.writeBytes("//" + LINE + "\n");\r
1058                         } catch (IOException e) {\r
1059                                 MipavUtil.displayError("IOException " + e + " in WRTAIL");\r
1060                                 System.exit(-1);\r
1061                         }\r
1062                 }\r
1063                 return;\r
1064         }\r
1065 \r
1066         private String IERTXT(int IER) {\r
1067 \r
1068                 // **** SUPPLY ERROR MESSAGE TEXT FOR ERROR NUMBER IER\r
1069                 String result = null;\r
1070                 if (IER == 0) {\r
1071                         result = " ";\r
1072                 } else if (IER == 1) {\r
1073                         result = "PARAMETER IBNDS[0] IS TOO SMALL AT START OF JAPHYC";\r
1074                 } else if (IER == 2) {\r
1075                         result = "PARAMETER IBNDS[1] IS TOO SMALL AT START OF JAPHYC";\r
1076                 } else if (IER == 3) {\r
1077                         result = "NQPTS < 1 AT START OF JAPHYC";\r
1078                 } else if (IER == 4) {\r
1079                         result = "FAILURE TO CONVERGE IN EIGSYS; CAN''T SET UP BASIC QUADRATURE RULES";\r
1080                 } else if (IER == 5) {\r
1081                         result = "PARAMETER MNQPT IN IGNLVL MUST BE INCREASED TO AT LEAST NQPTS";\r
1082                 } else if (IER == 6) {\r
1083                         result = "FAILURE TO CONVERGE IN IMTQLH; CAN''T SET UP IGNORE LEVELS";\r
1084                 } else if (IER == 7) {\r
1085                         result = "FAILURE TO CONVERGE IN IMTQLH; CAN''T SET UP COLLOCATION POINTS";\r
1086                 } else if (IER == 8) {\r
1087                         result = "ARGUMENT MNEQN IS TOO SMALL AT START OF JAPHYC";\r
1088                 } else if (IER == 9) {\r
1089                         result = "PARAMETER IBNDS[3] IS TOO SMALL AT START OF JAPHYC";\r
1090                 } else if (IER == 10) {\r
1091                         result = "PARAMETER NMAX IN SUBIN7 MUST BE INCREASED TO AT LEAST 2*NQPTS";\r
1092                 } else if (IER == 11) {\r
1093                         result = "PARAMETER IBNDS[2] IS TOO SMALL AT START OF JAPHYC";\r
1094                 } else if (IER == 12) {\r
1095                         result = "PARAMETER NC IN DEJAC7 AND DELEG7 MUST BE INCREASED";\r
1096                 } else if (IER == 13) {\r
1097                         result = "PARAMETER NR IN DEJAC7 AND DELEG7 MUST BE >= (NQPTS -1)";\r
1098                 } else if (IER == 14) {\r
1099                         result = "A CORNER ANGLE IS TOO SMALL; MAY CAUSE OVERFLOW IN GAMMA FUNCTION";\r
1100                 } else if (IER == 15) {\r
1101                         result = "SINGULAR COLLOCATION MATRIX";\r
1102                 } else if (IER == 16) {\r
1103                         result = "COLLOCATION MATRIX IS EFFECTIVELY SINGULAR";\r
1104                 } else if (IER == 17) {\r
1105                         result = "NUMBER OF SUBARCS EXCEEDS IBNDS[0] DURING REFINEMENT";\r
1106                 } else if (IER == 18) {\r
1107                         result = "NUMBER OF EQUATIONS EXCEEDS MNEQN DURING REFINEMENT";\r
1108                 } else if (IER == 19) {\r
1109                         result = "TOTAL NUMBER OF QUADRATURE PTS EXCEEDS IBNDS[3] DURING REFINEMENT";\r
1110                 } else if (IER == 20) {\r
1111                         result = "NUMBER OF QUADRATURE PANELS EXCEEDS IBNDS[2] DURING REFINEMENT";\r
1112                 } else if (IER == 21) {\r
1113                         result = "FAILURE TO CONVERGE IN IMTQLH; CAN''T SET UP TEST POINTS";\r
1114                 } else if (IER == 22) {\r
1115                         result = "ARGUMENT MQUPH OF GQPHYC MUST BE INCREASED";\r
1116                 } else if (IER == 23) {\r
1117                         result = "PARAMETER MNCOF IN POPQF1 MUST BE >= NQPTS";\r
1118                 } else if (IER == 24) {\r
1119                         result = "NUMBER OF QUADRATURE PANELS EXCEEDS MQIN1 IN GQPHYC";\r
1120                 } else if (IER == 25) {\r
1121                         result = "PARAMETER MNXI IN DEPPJ8 AND DEPPL8 MUST BE INCREASED";\r
1122                 } else if (IER == 26) {\r
1123                         result = "PARAMETER MAXNZ IN DEPPJ9 AND DEPPL9 MUST BE INCREASED";\r
1124                 } else if (IER == 27) {\r
1125                         result = "PARAMETER MXNQD IN PHTCA1 MUST BE INCREASED";\r
1126                 } else if (IER == 28) {\r
1127                         result = "PARAMETER MXCOF IN PHTCA1 MUST BE INCREASED";\r
1128                 } else if (IER == 29) {\r
1129                         result = "PARAMETER MQIN1 IN PHTCA1 MUST BE INCREASED";\r
1130                 } else if (IER == 30) {\r
1131                         result = "PARAMETER MNDG IN JCFIM5 MUST BE INCREASED";\r
1132                 } else if (IER == 31) {\r
1133                         result = "PARAMETER MNQD IN JCFIM5 MUST BE INCREASED";\r
1134                 } else if (IER == 32) {\r
1135                         result = "ARGUMENT IBNDS[1] SUPPLIED TO JACANP MUST BE INCREASED";\r
1136                 } else if (IER == 33) {\r
1137                         result = "ARGUMENT IBNDS[0] SUPPLIED TO JACANP MUST BE INCREASED";\r
1138                 } else if (IER == 34) {\r
1139                         result = "FN HAS SAME SIGN AT INTERVAL ENDS IN BISNEW; CAN''T SOLVE BCF EQN";\r
1140                 } else if (IER == 35) {\r
1141                         result = "DERIVATIVE OF BCF IS ZERO IN BISNEW; CAN''T SOLVE BCF EQN";\r
1142                 } else if (IER == 36) {\r
1143                         result = "ELEMENT OF ARGUMENT ARRAY SVAL IN RHOFN IS +-1; CAN''T CONTINUE";\r
1144                 } else if (IER == 37) {\r
1145                         result = "PARAMETER MXNQD IN CINRAD MUST BE INCREASED";\r
1146                 } else if (IER == 38) {\r
1147                         result = "PARAMETER MXCOF IN CINRAD MUST BE INCREASED";\r
1148                 } else if (IER == 39) {\r
1149                         result = "CENTRE POINT IS PATHOLOGICALLY CLOSE TO BOUNDARY;CAN''T CONTINUE";\r
1150                 } else if (IER == 40) {\r
1151                         result = "PARAMETER MQIN1 IN CINRAD MUST BE INCREASED";\r
1152                 } else if (IER == 41) {\r
1153                         result = "ARGUMENT MQUCA OF GQCANP MUST BE INCREASED";\r
1154                 } else if (IER == 42) {\r
1155                         result = "PARAMETER MNCOF IN POPQG1 MUST BE >= NQPTS";\r
1156                 } else if (IER == 43) {\r
1157                         result = "NUMBER OF QUADRATURE PANELS EXCEEDS MQIN1 IN GQCANP";\r
1158                 } else if (IER == 44) {\r
1159                         result = "PARAMETER MNCOF IN BMPHC1 MUST BE >= NQPTS";\r
1160                 } else if (IER == 45) {\r
1161                         result = "ARGUMENTS IARC, PHYPT OF BMPHYC DON''T DEFINE A BOUNDARY POINT";\r
1162                 } else if (IER == 46) {\r
1163                         result = "PARAMETER MNCOF IN BMCAP1 MUST BE >= NQPTS";\r
1164                 } else if (IER == 47) {\r
1165                         result = "PARAMETER MXNQD IN CATPH4 MUST BE INCREASED";\r
1166                 } else if (IER == 48) {\r
1167                         result = "PARAMETER MNCOF IN CATPH4 MUST BE >= NQPTS";\r
1168                 } else if (IER == 49) {\r
1169                         result = "PARAMETER MQIN1 IN CATPH4 MUST BE INCREASED";\r
1170                 } else if (IER == 50) {\r
1171                         result = "PARAMETER MXCOF IN DIAGN3 MUST BE >= NQPTS";\r
1172                 } else if (IER == 51) {\r
1173                         result = "NON-ANALYTIC ARC DETECTED IN DIAGN3";\r
1174                 } else if (IER == 52) {\r
1175                         result = "PARAMETER MAXSA IN CNDPLT MUST BE INCREASED";\r
1176                 } else if (IER == 53) {\r
1177                         result = "OVERFLOW EXPECTED IN IGNLVL; A CORNER ANGLE IS TOO SMALL";\r
1178                 } else if (IER == 54) {\r
1179                         result = "PARAMETER MXCO IN AXION1 MUST BE INCREASED";\r
1180                 } else if (IER == 55) {\r
1181                         result = "NARCS ISN''T AN INTEGER MULTIPLE OF THE ORDER OF THE SYMMETRY GROUP";\r
1182                 } else if (IER == 56) {\r
1183                         result = "CENTRE OF SYMMETRY IS PATHOLOGICALLY CLOSE TO LAST POINT ON FBS";\r
1184                 } else if (IER == 57) {\r
1185                         result = "CENTRE OF SYMMETRY IS PATHOLOGICALLY CLOSE TO FIRST POINT ON FBS";\r
1186                 } else if (IER == 58) {\r
1187                         result = "NUMBER OF ARCS IS TOO BIG; INCREASE PARAMETER MNARC IN PARGEN";\r
1188                 } else if (IER == 59) {\r
1189                         result = "NUMBER OF ARCS IS TOO BIG; INCREASE PARAMETER MNARC IN TSTPLT";\r
1190                 } else if (IER == 60) {\r
1191                         result = "NON-ANALYTIC ARC (DPARFN=(0.,0.)) DETECTED IN TSTPLT";\r
1192                 } else {\r
1193                         result = "UNRECOGNIZED ERROR NUMBER IN IERTXT ROUTINE !!";\r
1194                 }\r
1195                 return result;\r
1196         }\r
1197 \r
1198         private void WRSYM1(int NARCS, int ORDRG, int ORDSG, double[] RTUNI, double[] U2, double[] CENSY, boolean REFLN,\r
1199                         boolean PARFUN, String REDD, int CHNL, RandomAccessFile raFile) {\r
1200                 // COMPLEX RTUNI,U2,CENSY\r
1201 \r
1202                 // **** TO WRITE THE DIMENSION AND PARAMETER STATEMENTS AND THE CODE TO\r
1203                 // **** TO REDUCE A GIVEN ARC NUMBER TO ITS SYMMETRIC COUNTERPART ON THE\r
1204                 // **** FUNDAMENTAL BOUNDARY SECTION.\r
1205 \r
1206                 // .......................................................................\r
1207                 // AUTHOR: DAVID HOUGH, ETH, ZUERICH\r
1208                 // LAST UPDATE: 4 AUG 1990\r
1209                 // .......................................................................C\r
1210                 // LOCAL VARIABLES\r
1211 \r
1212                 int I;\r
1213                 double R, A;\r
1214                 // COMPLEX ZT\r
1215                 double ZT[] = new double[2];\r
1216                 boolean NEEDC;\r
1217                 // String FMT;\r
1218                 double cr[] = new double[1];\r
1219                 double ci[] = new double[1];\r
1220 \r
1221                 // FMT="(A12,"+REDD+",A1,"+REDD+",A2)";\r
1222 \r
1223                 try {\r
1224                         if (PARFUN) {\r
1225                                 NEEDC = ((CENSY[0] != 0.0) || (CENSY[1] != 0.0));\r
1226                                 if (NEEDC || REFLN) {\r
1227                                         raFile.writeBytes("      PARAMETER (\n");\r
1228                                         if (NEEDC && REFLN) {\r
1229                                                 R = U2[0];\r
1230                                                 A = U2[1];\r
1231                                                 raFile.writeBytes("U2[0] = " + R + ";\n");\r
1232                                                 raFile.writeBytes("U2[1] = " + A + ";\n");\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                                         } // if (NEEDC && REFLN)\r
1238                                         else if (NEEDC && (!REFLN)) {\r
1239                                                 R = CENSY[0];\r
1240                                                 A = CENSY[1];\r
1241                                                 raFile.writeBytes("ZCEN[0] = " + R + ";\n");\r
1242                                                 raFile.writeBytes("ZCEN[1] = " + A + ";)\n");\r
1243                                         } // else if (NEEDC && (!REFLN))\r
1244                                         else {\r
1245                                                 R = U2[0];\r
1246                                                 A = U2[1];\r
1247                                                 raFile.writeBytes("U2[0] = " + R + ";\n");\r
1248                                                 raFile.writeBytes("U2[1] = " + A + ";)\n");\r
1249                                         } // else\r
1250                                         raFile.writeBytes("//\n");\r
1251                                 } // if (NEEDC || REFLN)\r
1252                         } else if (REFLN) {\r
1253                                 R = U2[0];\r
1254                                 A = U2[1];\r
1255                                 raFile.writeBytes("      PARAMETER (\n");\r
1256                                 raFile.writeBytes("U2[0] = " + R + ";\n");\r
1257                                 raFile.writeBytes("U2[1] = " + A + ";)\n");\r
1258                                 raFile.writeBytes("//\n");\r
1259                         }\r
1260 \r
1261                         // FMT="(A7,"+REDD+",A1,"+REDD+",A2)";\r
1262 \r
1263                         if (ORDRG >= 2) {\r
1264                                 raFile.writeBytes("      double WW[][] = new double[" + (ORDRG - 1) + "][2];\n");\r
1265                                 ZT[0] = 1.0;\r
1266                                 ZT[1] = 0.0;\r
1267                                 for (I = 0; I < ORDRG - 2; I++) {\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                                 }\r
1274                                 zmlt(ZT[0], ZT[1], RTUNI[0], RTUNI[1], cr, ci);\r
1275                                 ZT[0] = cr[0];\r
1276                                 ZT[1] = ci[0];\r
1277                                 raFile.writeBytes("      WW[" + I + "][0] = " + ZT[0] + ";\n");\r
1278                                 raFile.writeBytes("      WW[" + I + "][1] = " + ZT[1] + ";\n");\r
1279                                 raFile.writeBytes("//\n");\r
1280                         } // if (ORDRG >= 2)\r
1281 \r
1282                         if (ORDRG > 19) {\r
1283                                 System.out.println("\n");\r
1284                                 System.out.println("             ****WARNING****");\r
1285                                 System.out.println("MORE THAN 19 CONTINUTATION LINES HAVE BEEN WRITTEN");\r
1286                         }\r
1287 \r
1288                         if (REFLN) {\r
1289                                 if (ORDRG > 1) {\r
1290                                         if (NARCS > 1) {\r
1291                                                 I = 2 * NARCS;\r
1292                                                 raFile.writeBytes("      IB = IA%" + I + ";\n");\r
1293                                                 raFile.writeBytes("      if (IB == 0) IB = " + I + ";\n");\r
1294                                                 I = I + 1;\r
1295                                                 raFile.writeBytes("      if (IB > " + NARCS + ") {\n");\r
1296                                                 raFile.writeBytes("          IB = " + I + " - IB;\n");\r
1297                                                 raFile.writeBytes("          TS[0] = -TT[0];\n");\r
1298                                                 raFile.writeBytes("          TS[1] = TT[1]);\n");\r
1299                                                 raFile.writeBytes("      }\n");\r
1300                                                 raFile.writeBytes("      else {\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                                         } // if (NARCS > 1)\r
1305                                         else {\r
1306                                                 raFile.writeBytes("      if ((IA%2) == 0) {\n");\r
1307                                                 raFile.writeBytes("          TS[0] = -TT[0];\n");\r
1308                                                 raFile.writeBytes("          TS[1] = TT[1];\n");\r
1309                                                 raFile.writeBytes("      }\n");\r
1310                                                 raFile.writeBytes("      else {\n");\r
1311                                                 raFile.writeBytes("          TS[0] = TT[0];\n");\r
1312                                                 raFile.writeBytes("          TS[1] = TT[1];\n");\r
1313                                                 raFile.writeBytes("      }\n");\r
1314                                         } // else\r
1315                                 } // if (ORDRG > 1)\r
1316                                 else {\r
1317                                         if (NARCS > 1) {\r
1318                                                 I = 2 * NARCS + 1;\r
1319                                                 raFile.writeBytes("      if (IA > " + NARCS + "){\n");\r
1320                                                 raFile.writeBytes("          IB = " + I + " -IA;\n");\r
1321                                                 raFile.writeBytes("          TS[0] = -TT[0];\n");\r
1322                                                 raFile.writeBytes("          TS[1] = TT[1]);\n");\r
1323                                                 raFile.writeBytes("      }\n");\r
1324                                                 raFile.writeBytes("      else {\n");\r
1325                                                 raFile.writeBytes("          IB = IA;\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                                         } // if (NARCS)\r
1330                                         else {\r
1331                                                 raFile.writeBytes("      if (IA == 2) {\n");\r
1332                                                 raFile.writeBytes("          TS[0] = -TT[0];\n");\r
1333                                                 raFile.writeBytes("          TS[1] = TT[1]);\n");\r
1334                                                 raFile.writeBytes("      }\n");\r
1335                                                 raFile.writeBytes("      else {\n");\r
1336                                                 raFile.writeBytes("          TS[0] = TT[0];\n");\r
1337                                                 raFile.writeBytes("          TS[1] = TT[1];\n");\r
1338                                                 raFile.writeBytes("      }\n");\r
1339                                         } // else\r
1340                                 } // else\r
1341                         } // if (REFLN)\r
1342                         else if (NARCS > 1) {\r
1343                                 raFile.writeBytes("      IB = IA%" + NARCS + ";\n");\r
1344                                 raFile.writeBytes("      if (IB == 0) IB = " + NARCS + ";\n");\r
1345                         } // else if (NARCS > 1)\r
1346 \r
1347                         raFile.writeBytes("//\n");\r
1348                 } // try\r
1349                 catch (IOException e) {\r
1350                         MipavUtil.displayError("IOException " + e + " in WRSYM1");\r
1351                         System.exit(-1);\r
1352                 }\r
1353 \r
1354         }\r
1355 \r
1356         private void WRFUN1(int NARCS, double STAPT[][], int ARCTY[], int PGM[], double RGM[], int PTX[], int NTX[],\r
1357                         String DEFN[], int CHNL, String CHIA, String CHTT, String VAR, String REDD, RandomAccessFile raFile,\r
1358                         boolean writeReturn) {\r
1359                 // COMPLEX STAPT(*)\r
1360                 // CHARACTER DEFN(*)*72,CHIA*2,CHTT*2,VAR*6,REDD*6\r
1361 \r
1362                 // **** TO WRITE THE SOURCE CODE FOR PARFUN IN THE CASE WHERE NO\r
1363                 // **** SYMMETRY IS INVOLVED.\r
1364 \r
1365                 // .......................................................................\r
1366                 // AUTHOR: DAVID HOUGH, ETH, ZUERICH\r
1367                 // LAST UPDATE: 4 AUG 1990\r
1368                 // .......................................................................\r
1369 \r
1370                 // LOCAL VARIABLES\r
1371 \r
1372                 int IA, I, J, K;\r
1373                 // CHARACTER TX1*16,TX2*21,FMT1*11,FMT2*11\r
1374                 String TX1, TX2;\r
1375                 // String FMT1,FMT2;\r
1376                 // EXTERNAL PTFUN1\r
1377                 TX1 = "      if(" + CHIA + " == ";\r
1378                 TX2 = "      else if(" + CHIA + " == ";\r
1379                 // FMT1="(A16,I3,A6)";\r
1380                 // FMT2="(A21,I3,A6)";\r
1381                 double STAPT2[][];\r
1382                 double RGM2[];\r
1383                 String DEFN2[];\r
1384 \r
1385                 try {\r
1386                         for (IA = 1; IA <= NARCS; IA++) {\r
1387                                 I = PGM[IA - 1];\r
1388                                 J = PTX[IA - 1];\r
1389                                 STAPT2 = new double[STAPT.length - IA + 1][2];\r
1390                                 for (K = IA; K <= STAPT.length; K++) {\r
1391                                         STAPT2[K - IA] = STAPT[K - 1];\r
1392                                 }\r
1393                                 if (ARCTY[IA-1] != 1) {\r
1394                                         RGM2 = new double[RGM.length - I + 1];\r
1395                                         for (K = I; K <= RGM.length; K++) {\r
1396                                                 RGM2[K - I] = RGM[K - 1];\r
1397                                         }\r
1398                                 }\r
1399                                 else {\r
1400                                         RGM2 = null;\r
1401                                 }\r
1402                                 if ((ARCTY[IA-1] == 3) || (ARCTY[IA-1] == 4)) {\r
1403                                         DEFN2 = new String[DEFN.length - J + 1];\r
1404                                         for (K = J; K <= DEFN.length; K++) {\r
1405                                                 DEFN2[K - J] = DEFN[K - 1];\r
1406                                         }\r
1407                                 }\r
1408                                 else {\r
1409                                         // DEFN2 goes to TXT in PTFUN1 which is not used for TYPES 1 and 2\r
1410                                         DEFN2 = null;\r
1411                                 }\r
1412                                 if (NARCS == 1) {\r
1413                                         PTFUN1(ARCTY[IA - 1], STAPT2, RGM2, NTX[IA - 1], DEFN2, CHNL, CHTT, VAR, REDD, raFile, writeReturn);\r
1414                                 } else {\r
1415                                         if (IA == 1) {\r
1416                                                 raFile.writeBytes(TX1 + IA + ") {\n");\r
1417                                         } else if (IA == NARCS) {\r
1418                                                 raFile.writeBytes("      else {\n");\r
1419                                         } else {\r
1420                                                 raFile.writeBytes(TX2 + IA + ") {\n");\r
1421                                         }\r
1422                                         PTFUN1(ARCTY[IA - 1], STAPT2, RGM2, NTX[IA - 1], DEFN2, CHNL, CHTT, VAR, REDD, raFile, writeReturn);\r
1423                                         if (IA == NARCS)\r
1424                                                 raFile.writeBytes("      }\n");\r
1425                                 } // else\r
1426                         } // for (IA=1; IA <= NARCS; IA++)\r
1427                 } // try\r
1428                 catch (IOException e) {\r
1429                         MipavUtil.displayError("IOException " + e + " in WRFUN1");\r
1430                         System.exit(-1);\r
1431                 }\r
1432 \r
1433         } // private void WRFUN1\r
1434 \r
1435         private void PTFUN1(int TYPE, double STAPT[][], double RGM[], int NTX, String TXT[], int CHNL, String CHTT,\r
1436                         String VAR, String REDD, RandomAccessFile raFile, boolean writeReturn) {\r
1437         // When TT goes from -1,0 to 1,0 T[0] traces out the original parameterization of the curve\r
1438                 // COMPLEX STAPT(*)\r
1439                 // CHARACTER TXT(*)*72,CHTT*2,VAR*6,REDD*6\r
1440 \r
1441                 // .......................................................................\r
1442                 // AUTHOR: DAVID HOUGH, ETH, ZUERICH\r
1443                 // LAST UPDATE: 8 AUG 1990\r
1444                 // .......................................................................C\r
1445                 // **** LOCAL VARIABLES\r
1446 \r
1447                 int I;\r
1448                 double HA, MD, RAD;\r
1449                 double C1[] = new double[2];\r
1450                 double C2[] = new double[2];\r
1451                 double CENTR[] = new double[2];\r
1452                 String PAD = "          ";\r
1453                 // COMPLEX C1,C2,CENTR\r
1454                 // String TX1, TX1B, TX2;\r
1455                 // String TX2B, CTX1B, FMT1, FMT2, FMT3, FMT4, FMT5;\r
1456                 // CHARACTER TX1*4,TX1B*5,TX2*13,TX2B*14,CTX1B*10,\r
1457                 // +FMT1*25,FMT2*25,FMT3*14,FMT4*25,FMT5*24\r
1458 \r
1459                 // TX1 = "+"+CHTT+"*";\r
1460                 // TX1B = TX1 + "(";\r
1461                 // CTX1B=" " + TX1B;\r
1462                 // TX2=" "+VAR+" = ";\r
1463                 // TX2B=TX2+"(";\r
1464 \r
1465                 // FMT1='(A14,'//REDD//',A1,'//REDD//',A2)'\r
1466                 // FMT2='(A10,'//REDD//',A1,'//REDD//',A1)'\r
1467                 // FMT3='(A6,'//REDD//',A1)'\r
1468                 // FMT4='(A14,'//REDD//',A5,'//REDD//',A3)'\r
1469                 // FMT5='(A8,'//REDD//',A5,'//REDD//',A1)'\r
1470 \r
1471                 try {\r
1472                         if (TYPE == 1) {\r
1473                                 C1[0] = 0.5 * (STAPT[1][0] + STAPT[0][0]);\r
1474                                 C1[1] = 0.5 * (STAPT[1][1] + STAPT[0][1]);\r
1475                                 C2[0] = 0.5 * (STAPT[1][0] - STAPT[0][0]);\r
1476                                 C2[1] = 0.5 * (STAPT[1][1] - STAPT[0][1]);\r
1477                                 raFile.writeBytes("//\n");\r
1478                                 raFile.writeBytes(\r
1479                                                 PAD + VAR + "[0] = " + C1[0] + "+" + CHTT + "[0]*(" + C2[0] + ") - " + CHTT + "[1]*(" + C2[1] + ");\n");\r
1480                                 raFile.writeBytes(\r
1481                                                 PAD + VAR + "[1] = " + C1[1] + "+" + CHTT + "[0]*(" + C2[1] + ") + " + CHTT + "[1]*(" + C2[0] + ");\n");\r
1482                                 raFile.writeBytes("//\n");\r
1483                         } // if (TYPE == 1)\r
1484                         else if (TYPE == 2) {\r
1485                                 CENTR[0] = RGM[0];\r
1486                                 CENTR[1] = RGM[1];\r
1487                                 C1[0] = STAPT[0][0] - CENTR[0];\r
1488                                 C1[1] = STAPT[0][1] - CENTR[1];\r
1489                                 HA = 0.5 * RGM[2];\r
1490                                 MD = Math.atan2(C1[1], C1[0]) + HA;\r
1491                                 RAD = zabs(C1[0], C1[1]);\r
1492                                 raFile.writeBytes("//\n");\r
1493                                 raFile.writeBytes(PAD + VAR + "[0] = " + CENTR[0] + "+" + RAD + " * " + "Math.exp(-" + CHTT + "[1]*(" + HA\r
1494                                                 + "))*" + "Math.cos(" + MD + "+" + CHTT + "[0]*(" + HA + "));\n");\r
1495                                 raFile.writeBytes(PAD + VAR + "[1] = " + CENTR[1] + "+" + RAD + " * " + "Math.exp(-" + CHTT + "[1]*(" + HA\r
1496                                                 + "))*" + "Math.sin(" + MD + "+" + CHTT + "[0]*(" + HA + "));\n");\r
1497                                 raFile.writeBytes("//\n");\r
1498                         } // else if (TYPE == 2)\r
1499                         else if (TYPE == 3) {\r
1500                                 MD = 0.5 * (RGM[1] + RGM[0]);\r
1501                                 HA = 0.5 * (RGM[1] - RGM[0]);\r
1502                                 raFile.writeBytes("//\n");\r
1503                                 raFile.writeBytes(PAD + "T[0] = " + MD + "+" + CHTT + "[0] * (" + HA + ");\n");\r
1504                                 raFile.writeBytes(PAD + "T[1] = " + CHTT + "[1] * (" + HA + ");\n");\r
1505 \r
1506                                 if (TXT[0].toLowerCase().indexOf("ui") == 0) {\r
1507                                     raFile.writeBytes(PAD + VAR + "[0] = 0.0;\n");\r
1508                                 }\r
1509                                 else {\r
1510                                         // NTX = 1 if statements are entered without newlines for\r
1511                                         // multiple lines\r
1512                                         raFile.writeBytes(PAD + VAR + "[0] = ");\r
1513                                         for (I = 1; I <= NTX; I++) {\r
1514                                                 int index = TXT[I - 1].toLowerCase().indexOf("ui");\r
1515                                                 if (index == 0) {\r
1516                                                         raFile.writeBytes(";\n");\r
1517                                                         break;\r
1518                                                 }\r
1519                                                 String realString = null;\r
1520                                                 if (index == -1) {\r
1521                                                         realString = TXT[I-1];\r
1522                                                 }\r
1523                                                 else {\r
1524                                                         realString = TXT[I - 1].substring(0, index);    \r
1525                                                 }\r
1526                                                 if ((I > 1) && (realString != null) && (realString.length() != 0)) {\r
1527                                                         raFile.writeBytes("\n" + PAD);\r
1528                                                 }\r
1529                                                 if ((realString != null) && (realString.length() != 0)) {\r
1530                                                     raFile.writeBytes(realString);\r
1531                                                 }\r
1532                                                 if ((I == NTX) || (index > 0)) {\r
1533                                                         raFile.writeBytes(";\n");\r
1534                                                         break;\r
1535                                                 }\r
1536                                         }\r
1537                                 }\r
1538                                 boolean uifound = false;\r
1539                                 String imagString = null;\r
1540                                 boolean firstImagStringWritten = false;\r
1541                                 for (I = 1; I <= NTX; I++) {\r
1542                                         if (!uifound) {\r
1543                                         int index = TXT[I-1].toLowerCase().indexOf("ui");\r
1544                                             if (index >= 0) {\r
1545                                                 uifound = true;\r
1546                                                 raFile.writeBytes(PAD + VAR + "[1] = ");\r
1547                                                 if (index + 2 < TXT[I-1].length()) {\r
1548                                                         imagString = TXT[I - 1].substring(index + 2);\r
1549                                                             raFile.writeBytes(imagString);\r
1550                                                             firstImagStringWritten = true;\r
1551                                                             if (I == NTX) {\r
1552                                                                 raFile.writeBytes(";\n");\r
1553                                                             }\r
1554                                                 } // if (index + 2 < TXT[I-1].length())\r
1555                                             } // if (index >= 0)\r
1556                                     } // if (!uifound) {\r
1557                                     else {\r
1558                                         imagString = TXT[I-1];\r
1559                                         if (!firstImagStringWritten) {\r
1560                                                 raFile.writeBytes(imagString);\r
1561                                         }\r
1562                                         else if ((imagString != null) && (imagString.length() != 0)) {\r
1563                                             raFile.writeBytes(PAD + imagString);\r
1564                                         }\r
1565                                         firstImagStringWritten = true;\r
1566                                             if (I == NTX) {\r
1567                                                 raFile.writeBytes(";\n");\r
1568                                             }\r
1569                                     }\r
1570                                 } // for (I = 1; I <= NTX; I++)\r
1571                                 if (!uifound) {\r
1572                                     raFile.writeBytes(PAD + VAR + "[1] = 0.0;\n");\r
1573                                 }\r
1574                                 raFile.writeBytes("//\n");\r
1575                         } // else if (TYPE == 3)\r
1576                         else {\r
1577                                 MD = 0.5 * (RGM[1] + RGM[0]);\r
1578                                 HA = 0.5 * (RGM[1] - RGM[0]);\r
1579                                 raFile.writeBytes("//\n");\r
1580                                 raFile.writeBytes(PAD + "T[0] = " + MD + "+" + CHTT + "[0] * (" + HA + ");\n");\r
1581                                 raFile.writeBytes(PAD + "T[1] = " + CHTT + "[1] * (" + HA + ");\n");\r
1582                                 if (TXT[0].toLowerCase().indexOf("ui") == 0) {\r
1583                                     raFile.writeBytes(PAD + "ZRAD[0] = 0.0;\n");\r
1584                                 }\r
1585                                 else {\r
1586                                         // NTX = 1 if statements are entered without newlines for\r
1587                                         // multiple lines\r
1588                                         raFile.writeBytes(PAD + "ZRAD[0] = ");\r
1589                                         for (I = 1; I <= NTX; I++) {\r
1590                                                 int index = TXT[I - 1].toLowerCase().indexOf("ui");\r
1591                                                 if (index == 0) {\r
1592                                                         raFile.writeBytes(";\n");\r
1593                                                         break;\r
1594                                                 }\r
1595                                                 String realString = null;\r
1596                                                 if (index == -1) {\r
1597                                                         realString = TXT[I-1];\r
1598                                                 }\r
1599                                                 else {\r
1600                                                         realString = TXT[I - 1].substring(0, index);    \r
1601                                                 }\r
1602                                                 if ((I > 1) && (realString != null) && (realString.length() != 0)) {\r
1603                                                         raFile.writeBytes("\n" + PAD);\r
1604                                                 }\r
1605                                                 if ((realString != null) && (realString.length() != 0)) {\r
1606                                                     raFile.writeBytes(realString);\r
1607                                                 }\r
1608                                                 if ((I == NTX) || (index > 0)) {\r
1609                                                         raFile.writeBytes(";\n");\r
1610                                                         break;\r
1611                                                 }\r
1612                                         }\r
1613                                 }\r
1614                                 boolean uifound = false;\r
1615                                 String imagString = null;\r
1616                                 boolean firstImagStringWritten = false;\r
1617                                 for (I = 1; I <= NTX; I++) {\r
1618                                         if (!uifound) {\r
1619                                         int index = TXT[I-1].toLowerCase().indexOf("ui");\r
1620                                             if (index >= 0) {\r
1621                                                 uifound = true;\r
1622                                                 raFile.writeBytes(PAD + "ZRAD[1] = ");\r
1623                                                 if (index + 2 < TXT[I-1].length()) {\r
1624                                                         imagString = TXT[I - 1].substring(index + 2);\r
1625                                                             raFile.writeBytes(imagString);\r
1626                                                             firstImagStringWritten = true;\r
1627                                                             if (I == NTX) {\r
1628                                                                 raFile.writeBytes(";\n");\r
1629                                                             }\r
1630                                                 } // if (index + 2 < TXT[I-1].length())\r
1631                                             } // if (index >= 0)\r
1632                                     } // if (!uifound) {\r
1633                                     else {\r
1634                                         imagString = TXT[I-1];\r
1635                                         if (!firstImagStringWritten) {\r
1636                                                 raFile.writeBytes(imagString);\r
1637                                         }\r
1638                                         else if ((imagString != null) && (imagString.length() != 0)) {\r
1639                                             raFile.writeBytes(PAD + imagString);\r
1640                                         }\r
1641                                         firstImagStringWritten = true;\r
1642                                             if (I == NTX) {\r
1643                                                 raFile.writeBytes(";\n");\r
1644                                             }\r
1645                                     }\r
1646                                 } // for (I = 1; I <= NTX; I++)\r
1647                                 if (!uifound) {\r
1648                                     raFile.writeBytes(PAD + "ZRAD[1] = 0.0;\n");\r
1649                                 }\r
1650                                 raFile.writeBytes(PAD + VAR + "[0] = ZRAD[0]*Math.exp(-T[1])*Math.cos(T[0]) - ZRAD[1]*Math.exp(-T[1])*Math.sin(T[0]);\n");\r
1651                                 raFile.writeBytes(PAD + VAR + "[1] = ZRAD[0]*Math.exp(-T[1])*Math.sin(T[0]) + ZRAD[1]*Math.exp(-T[1])*Math.cos(T[0]);\n");\r
1652                                 raFile.writeBytes("//\n");\r
1653                         }\r
1654                         if (writeReturn) {\r
1655                             raFile.writeBytes(PAD + "return " + VAR + ";\n");\r
1656                         }\r
1657                 } // try\r
1658                 catch (IOException e) {\r
1659                         MipavUtil.displayError("IOException " + e + " in PTFUN1");\r
1660                         System.exit(-1);\r
1661                 }\r
1662 \r
1663         } // private void PTFUN1\r
1664 \r
1665         private void WRSYM2(int NARCS, int ORDRG, double CENSY[], boolean REFLN, int CHNL, RandomAccessFile raFile) {\r
1666 \r
1667                 // COMPLEX CENSY\r
1668 \r
1669                 // **** TO WRITE THE CODE TO RECOVER THE BOUNDARY POINT FROM ITS\r
1670                 // SYMMETRIC\r
1671                 // **** COUNTERPART ON THE FUNDAMENTAL BOUNDARY SECTION.\r
1672 \r
1673                 // .......................................................................\r
1674                 // AUTHOR: DAVID HOUGH, ETH, ZUERICH\r
1675                 // LAST UPDATE: 4 AUG 1990\r
1676                 // .......................................................................C\r
1677                 // LOCAL VARIABLES\r
1678 \r
1679                 int I;\r
1680                 boolean NEEDC;\r
1681 \r
1682                 NEEDC = ((CENSY[0] != 0.0) || (CENSY[1] != 0.0));\r
1683                 try {\r
1684                         raFile.writeBytes("//\n");\r
1685 \r
1686                         if (REFLN) {\r
1687                                 if (ORDRG > 1) {\r
1688                                         I = 2 * NARCS;\r
1689                                         if (NARCS > 1) {\r
1690                                                 raFile.writeBytes("      IS = (IA-IB)%" + I + ";\n");\r
1691                                                 raFile.writeBytes("      IR = (IA-IB-IS)/" + I + ";\n");\r
1692                                         } // if (NARCS > 1)\r
1693                                         else {\r
1694                                                 raFile.writeBytes("      IS = (IA-1)%2;\n");\r
1695                                                 raFile.writeBytes("      IR = (IA-1-IS)/2;\n");\r
1696                                         }\r
1697                                         raFile.writeBytes("      if ((IR == 0) && (IS == 0)) {\n");\r
1698                                         raFile.writeBytes("          PARFUNANS[0] = ZETA[0];\n");\r
1699                                         raFile.writeBytes("          PARFUNANS[1] = ZETA[1];\n");\r
1700                                         raFile.writeBytes("      }\n");\r
1701                                         raFile.writeBytes("      else if ((IR > 0) && (IS == 0)) {\n");\r
1702                                         if (NEEDC) {\r
1703                                                 raFile.writeBytes("          PARFUNANS[0] = ZCEN[0] + WW[IR-1][0]*(ZETA[0] - ZCEN[0]) - "\r
1704                                                                 + "WW[IR-1][1]*(ZETA[1] - ZCEN[1]);\n");\r
1705                                                 raFile.writeBytes("          PARFUNANS[1] = ZCEN[1] + WW[IR-1][0]*(ZETA[1] - ZCEN[1]) + "\r
1706                                                                 + "WW[IR-1][1]*(ZETA[0] - ZCEN[0]);\n");\r
1707                                         } // if (NEEDC)\r
1708                                         else {\r
1709                                                 raFile.writeBytes("      PARFUNANS[0] = WW[IR-1][0]*ZETA[0] - WW[IR-1][1]*ZETA[1];\n");\r
1710                                         }\r
1711                                         raFile.writeBytes("      else if ((IR == 0) && (IS > 0)) {\n");\r
1712                                         if (NEEDC) {\r
1713                                                 raFile.writeBytes(\r
1714                                                                 "          PARFUNANS[0] = ZCEN[0] + U2[0]*(ZETA[0]-ZCEN[0]) + " + "U2[1]*(ZETA[1]-ZCEN[1]);\n");\r
1715                                                 raFile.writeBytes(\r
1716                                                                 "          PARFUNANS[1] = ZCEN[1] - U2[0]*(ZETA[1]-ZCEN[1]) + " + "U2[1]*(ZETA[0]-ZCEN[0]);\n");\r
1717                                         } else {\r
1718                                                 raFile.writeBytes("          PARFUNANS[0] = U2[0]*ZETA[0] + U2[1]*ZETA[1];\n");\r
1719                                                 raFile.writeBytes("          PARFUNANS[1] = -U2[0]*ZETA[1] + U2[1]*ZETA[0];\n");\r
1720                                         }\r
1721                                         raFile.writeBytes("      }\n");\r
1722                                         raFile.writeBytes("      else {\n");\r
1723                                         if (NEEDC) {\r
1724                                                 raFile.writeBytes("      double realPart = U2[0]*WW[IR-1][0] - U2[1]*WW[IR-1][1];\n");\r
1725                                                 raFile.writeBytes("      double imagPart = U2[0]*WW[IR-1][1] + U2[1]*WW[IR-1][0];\n");\r
1726                                                 raFile.writeBytes("      PARFUNANS[0] = ZCEN[0] + realPart*(ZETA[0]-ZCEN[0]) + "\r
1727                                                                 + "imagPart*(ZETA[1]-ZCEN[1]);\n");\r
1728                                                 raFile.writeBytes("      PARFUNANS[1] = ZCEN[1] - realPart*(ZETA[1]-ZCEN[1]) + "\r
1729                                                                 + "imagPart*(ZETA[0]-ZCEN[0]);\n");\r
1730                                         } else {\r
1731                                                 raFile.writeBytes("      double realPart = U2[0]*WW[IR-1][0] - U2[1]*WW[IR-1][1];\n");\r
1732                                                 raFile.writeBytes("      double imagPart = U2[0]*WW[IR-1][1] + U2[1]*WW[IR-1][0];\n");\r
1733                                                 raFile.writeBytes("      PARFUNANS[0] = realPart * ZETA[0] + imagPart * ZETA[1];\n");\r
1734                                                 raFile.writeBytes("      PARFUNANS[1] = -realPart * ZETA[1] + imagPart * ZETA[0];\n");\r
1735                                         }\r
1736                                         raFile.writeBytes("}\n");\r
1737                                 } // if (ORDRG > 1)\r
1738                                 else { // ORDRG <= 1\r
1739                                         if (NARCS > 1) {\r
1740                                                 raFile.writeBytes("      IS = IA - IB;\n");\r
1741                                         } else {\r
1742                                                 raFile.writeBytes("      IS = IA - 1;\n");\r
1743                                         }\r
1744                                         raFile.writeBytes("      if (IS == 0) {\n");\r
1745                                         raFile.writeBytes("          PARFUNANS[0] = ZETA[0];\n");\r
1746                                         raFile.writeBytes("          PARFUNANS[1] = ZETA[1];\n");\r
1747                                         raFile.writeBytes("      }\n");\r
1748                                         raFile.writeBytes("      else {\n");\r
1749                                         if (NEEDC) {\r
1750                                                 raFile.writeBytes(\r
1751                                                                 "          PARFUNANS[0] = ZCEN[0] + U2[0]*(ZETA[0]-ZCEN[0]) + " + "U2[1]*(ZETA[1]-ZCEN[1]);\n");\r
1752                                                 raFile.writeBytes(\r
1753                                                                 "          PARFUNANS[1] = ZCEN[1] - U2[0]*(ZETA[1]-ZCEN[1]) + " + "U2[1]*(ZETA[0]-ZCEN[0]);\n");\r
1754                                         } else {\r
1755                                                 raFile.writeBytes("          PARFUNANS[0] = U2[0]*(ZETA[0]-ZCEN[0]) + " + "U2[1]*(ZETA[1]-ZCEN[1]);\n");\r
1756                                                 raFile.writeBytes(\r
1757                                                                 "          PARFUNANS[1] =  -U2[0]*(ZETA[1]-ZCEN[1]) + " + "U2[1]*(ZETA[0]-ZCEN[0]);\n");\r
1758                                         }\r
1759                                         raFile.writeBytes("      }\n");\r
1760                                 } // else ORDRG <= 1\r
1761                         } // if (REFLN)\r
1762                         else { // !REFLN\r
1763                                 if (NARCS > 1) {\r
1764                                         raFile.writeBytes("      IR = (IA - IB)/" + NARCS + ";\n");\r
1765                                 } else {\r
1766                                         raFile.writeBytes("      IR = IA - 1;\n");\r
1767                                 }\r
1768                                 raFile.writeBytes("      if (IR == 0) {\n");\r
1769                                 raFile.writeBytes("          PARFUNANS[0] = ZETA[0];\n");\r
1770                                 raFile.writeBytes("          PARFUNANS[1] = ZETA[1];\n");\r
1771                                 raFile.writeBytes("      }\n");\r
1772                                 raFile.writeBytes("      else {\n");\r
1773                                 if (NEEDC) {\r
1774                                         raFile.writeBytes("          PARFUNANS[0] = ZCEN[0] + WW[IR-1][0]*(ZETA[0] - ZCEN[0]) - "\r
1775                                                         + "WW[IR-1][1]*(ZETA[1] - ZCEN[1]);\n");\r
1776                                         raFile.writeBytes("          PARFUNANS[1] = ZCEN[1] + WW[IR-1][0]*(ZETA[1] - ZCEN[1]) + "\r
1777                                                         + "WW[IR-1][1]*(ZETA[0] - ZCEN[0]);\n");\r
1778                                 } else {\r
1779                                         raFile.writeBytes("          PARFUNANS[0] = WW[IR-1][0]*ZETA[0] - "\r
1780                                                         + "WW[IR-1][1]*ZETA[1];\n");\r
1781                                         raFile.writeBytes("          PARFUNANS[1] = WW[IR-1][0]*ZETA[1] + "\r
1782                                                         + "WW[IR-1][1]*ZETA[0];\n");\r
1783                                 }\r
1784                                 raFile.writeBytes("      }\n");\r
1785                         } // else !REFLN\r
1786                         raFile.writeBytes("      return PARFUNANS;\n");\r
1787                 } // try\r
1788                 catch (IOException e) {\r
1789                         MipavUtil.displayError("IOException " + e + " in WRSYM2");\r
1790                         System.exit(-1);\r
1791                 }\r
1792 \r
1793         } // private void WRSYM2\r
1794 \r
1795         private void WRFUN2(int NARCS, int MNARC, double STAPT[][], int ARCTY[], int PGM[], double RGM[], int PTX[],\r
1796                         int NTX[], String DEFN[], int CHNL, String CHIA, String CHTT, String VAR, boolean NUMDER[], String REDD,\r
1797                         RandomAccessFile raFile, boolean writeReturn) {\r
1798 \r
1799                 // COMPLEX STAPT(*)\r
1800                 // CHARACTER DEFN(*)*72,CHIA*2,CHTT*2,VAR*6,REDD*6\r
1801 \r
1802                 // **** TO WRITE THE SOURCE CODE FOR DPARFN IN THE CASE WHERE NO\r
1803                 // **** SYMMETRY IS INVOLVED.\r
1804 \r
1805                 // .......................................................................\r
1806                 // AUTHOR: DAVID HOUGH, ETH, ZUERICH\r
1807                 // LAST UPDATE: 4 AUG 1990\r
1808                 // .......................................................................\r
1809 \r
1810                 // LOCAL VARIABLES\r
1811 \r
1812                 int IA, I, J1, J2, N1, N2;\r
1813                 String TX1, TX2;\r
1814                 // String FMT1, FMT2;\r
1815                 // CHARACTER TX1*16,TX2*21,FMT1*11,FMT2*11\r
1816                 // EXTERNAL PTFUN2\r
1817                 double STAPT2[][];\r
1818                 double RGM2[];\r
1819                 String DEFN2[];\r
1820                 String DEFN3[];\r
1821                 int K;\r
1822 \r
1823                 TX1 = "      if (" + CHIA + " == ";\r
1824                 TX2 = "      else if (" + CHIA + " == ";\r
1825                 // FMT1="(A16,I3,A6)";\r
1826                 // FMT2="(A21,I3,A6)";\r
1827 \r
1828                 try {\r
1829                         for (IA = 1; IA <= NARCS; IA++) {\r
1830                                 I = PGM[IA - 1];\r
1831                                 J1 = PTX[IA - 1];\r
1832                                 J2 = PTX[IA + MNARC - 1];\r
1833                                 N1 = NTX[IA - 1];\r
1834                                 N2 = NTX[IA + MNARC - 1];\r
1835                                 STAPT2 = new double[STAPT.length - IA + 1][2];\r
1836                                 for (K = IA; K <= STAPT.length; K++) {\r
1837                                         STAPT2[K - IA][0] = STAPT[K - 1][0];\r
1838                                         STAPT2[K - IA][1] = STAPT[K - 1][1];\r
1839                                 }\r
1840                                 if ((ARCTY[IA-1] == 2) || ((!NUMDER[IA-1]) && ((ARCTY[IA-1] == 3) || (ARCTY[IA-1] == 4)))) {\r
1841                                         RGM2 = new double[RGM.length - I + 1];\r
1842                                         for (K = I; K <= RGM.length; K++) {\r
1843                                                 RGM2[K - I] = RGM[K - 1];\r
1844                                         }\r
1845                                 }\r
1846                                 else {\r
1847                                         RGM2 = null;\r
1848                                 }\r
1849                                 if ((!NUMDER[IA-1]) && (ARCTY[IA-1] == 4)) {\r
1850                                         DEFN2 = new String[DEFN.length - J1 + 1];\r
1851                                         for (K = J1; K <= DEFN.length; K++) {\r
1852                                                 DEFN2[K - J1] = DEFN[K - 1];\r
1853                                         }\r
1854                                 }\r
1855                                 else {\r
1856                                         DEFN2 = null;\r
1857                                 }\r
1858                                 if ((!NUMDER[IA-1]) && ((ARCTY[IA-1] == 3) || (ARCTY[IA-1] == 4))) {\r
1859                                         DEFN3 = new String[DEFN.length - J2 + 1];\r
1860                                         for (K = J2; K <= DEFN.length; K++) {\r
1861                                                 DEFN3[K - J2] = DEFN[K - 1];\r
1862                                         }\r
1863                                 }\r
1864                                 else {\r
1865                                         DEFN3 = null;\r
1866                                 }\r
1867                                 if (NARCS == 1) {\r
1868                                         PTFUN2(ARCTY[IA - 1], STAPT2, RGM2, N1, DEFN2, N2, DEFN3, CHNL, CHTT, VAR, " 1", NUMDER[IA - 1],\r
1869                                                         REDD, raFile, writeReturn);\r
1870                                 } else {\r
1871                                         if (IA == 1) {\r
1872                                                 raFile.writeBytes(TX1 + IA + ") {\n");\r
1873                                         } else if (IA == NARCS) {\r
1874                                                 raFile.writeBytes("      else {\n");\r
1875                                         } else {\r
1876                                                 raFile.writeBytes(TX2 + IA + ") {\n");\r
1877                                         }\r
1878                                         PTFUN2(ARCTY[IA - 1], STAPT2, RGM2, N1, DEFN2, N2, DEFN3, CHNL, CHTT, VAR, CHIA, NUMDER[IA - 1],\r
1879                                                         REDD, raFile, writeReturn);\r
1880                                         if (IA == NARCS) {\r
1881                                                 raFile.writeBytes("      }\n");\r
1882                                         }\r
1883                                 } // else\r
1884                         } // for (IA=1; IA <= NARCS; IA++)\r
1885                 } // try\r
1886                 catch (IOException e) {\r
1887                         MipavUtil.displayError("IOException " + e + " in WRFUN2");\r
1888                         System.exit(-1);\r
1889                 }\r
1890 \r
1891         } // private void WRFUN2\r
1892 \r
1893         private void PTFUN2(int TYPE, double STAPT[][], double RGM[], int NTX1, String TXT1[], int NTX2, String TXT2[],\r
1894                         int CHNL, String CHTT, String VAR, String CHIA, boolean NUMDER, String REDD, RandomAccessFile raFile,\r
1895                         boolean writeReturn) {\r
1896                 // COMPLEX STAPT(*)\r
1897                 // CHARACTER TXT1(*)*72,TXT2(*)*72,CHTT*2,VAR*6,CHIA*2,REDD*6\r
1898 \r
1899                 // .......................................................................\r
1900                 // AUTHOR: DAVID HOUGH, ETH, ZUERICH\r
1901                 // LAST UPDATE: 8 AUG 1990\r
1902                 // .......................................................................C\r
1903                 // **** LOCAL VARIABLES\r
1904 \r
1905                 int I;\r
1906                 double HA, MD, RAD, A, R;\r
1907                 double C1[] = new double[2];\r
1908                 double CENTR[] = new double[2];\r
1909                 String PAD = "          ";\r
1910                 // COMPLEX C1,CENTR\r
1911                 // String TX1, TX1B, TX2, TX2B, TX3, FMT1, FMT2, FMT3, FMT4, FMT5;\r
1912                 // CHARACTER TX1*4,TX1B*5,TX2*13,TX2B*14,TX3*39,\r
1913                 // FMT1*25,FMT2*15,FMT3*15,FMT4*25,FMT5*24\r
1914                 // String TX3R, TX3I;\r
1915 \r
1916                 // TX1 = "+"+CHTT+"*";\r
1917                 // TX1B = TX1 + "(";\r
1918                 // TX2 = " "+VAR+" = ";\r
1919                 // TX2B = TX2 + "(";\r
1920                 // TX3R = " "+VAR+"[0] = (ZDER * Math.cos(T) - ZRAD * Math.sin(T))*(";\r
1921                 // TX3I = " "+VAR+"[1] = (ZDER * Math.sin(T) + ZRAD * Math.cos(T))*(";\r
1922                 // TX3=TX2//'(ZDER+UI*ZRAD)*EXP(UI*T)*('\r
1923 \r
1924                 // FMT1='(A14,'//REDD//',A1,'//REDD//',A2)'\r
1925                 // FMT2='(A39,'//REDD//',A1)'\r
1926                 // FMT3='(A13,'//REDD//',A2)'\r
1927                 // FMT4='(A14,'//REDD//',A5,'//REDD//',A3)'\r
1928                 // FMT5='(A8,'//REDD//',A5,'//REDD//',A1)'\r
1929 \r
1930                 try {\r
1931                         if (TYPE == 1) {\r
1932                                 C1[0] = 0.5 * (STAPT[1][0] - STAPT[0][0]);\r
1933                                 C1[1] = 0.5 * (STAPT[1][1] - STAPT[0][1]);\r
1934                                 raFile.writeBytes("//\n");\r
1935                                 R = C1[0];\r
1936                                 A = C1[1];\r
1937                                 raFile.writeBytes(PAD + VAR + "[0] = " + R + ";\n");\r
1938                                 raFile.writeBytes(PAD + VAR + "[1] = " + A + ";\n");\r
1939                                 raFile.writeBytes("//\n");\r
1940                         } // if (TYPE == 1)\r
1941                         else if (TYPE == 2) {\r
1942                                 CENTR[0] = RGM[0];\r
1943                                 CENTR[1] = RGM[1];\r
1944                                 C1[0] = STAPT[0][0] - CENTR[0];\r
1945                                 C1[1] = STAPT[0][1] - CENTR[1];\r
1946                                 HA = 0.5 * RGM[2];\r
1947                                 MD = Math.atan2(C1[1], C1[0]) + HA;\r
1948                                 RAD = zabs(C1[0], C1[1]);\r
1949                                 raFile.writeBytes("//\n");\r
1950                                 raFile.writeBytes(\r
1951                                                 PAD + VAR + "[0] = (-" + RAD + ")*(" + HA + ")*Math.exp((-"+CHTT + "[1])*(" + HA +"))*Math.sin(" + MD + "+" + CHTT + "[0]*(" + HA + "));\n");\r
1952                                 raFile.writeBytes(PAD + VAR + "[1] = (" + RAD + ")*(" + HA + ")*Math.exp((-"+CHTT + "[1])*Math.cos(" + MD + "+" + CHTT + "[0]*(" + HA + "));\n");\r
1953                                 raFile.writeBytes("//\n");\r
1954                         } // else if (TYPE == 2)\r
1955                         else if (NUMDER) {\r
1956                                 // Use numerical derivative if no analytical expression is supplied for TYPE == 3 or TYPE == 4.\r
1957                                 raFile.writeBytes("//\n");\r
1958                                 raFile.writeBytes(PAD + VAR + " = ZDPARF(" + CHIA + "," + CHTT + ");\n");\r
1959                                 raFile.writeBytes("//\n");\r
1960                         } // else if (NUMDER)\r
1961                         else if (TYPE == 3) {\r
1962                                 MD = 0.5 * (RGM[1] + RGM[0]);\r
1963                                 HA = 0.5 * (RGM[1] - RGM[0]);\r
1964                                 raFile.writeBytes("//\n");\r
1965                                 raFile.writeBytes(PAD + "T[0] = " + MD + "+" + CHTT + "[0]*(" + HA + ");\n");\r
1966                                 raFile.writeBytes(PAD + "T[1] = " + CHTT + "[1]*(" + HA + ");\n");\r
1967                                 if (TXT2[0].toLowerCase().indexOf("ui") == 0) {\r
1968                                     raFile.writeBytes(PAD + VAR + "[0] = 0.0;\n");\r
1969                                 }\r
1970                                 else {\r
1971                                         // NTX2 = 1 if statements are entered without newlines for\r
1972                                         // multiple lines\r
1973                                         raFile.writeBytes(PAD + VAR + "[0] = " + HA + "*(");\r
1974                                         for (I = 1; I <= NTX2; I++) {\r
1975                                                 int index = TXT2[I - 1].toLowerCase().indexOf("ui");\r
1976                                                 if (index == 0) {\r
1977                                                         raFile.writeBytes(");\n");\r
1978                                                         break;\r
1979                                                 }\r
1980                                                 String realString = null;\r
1981                                                 if (index == -1) {\r
1982                                                         realString = TXT2[I-1];\r
1983                                                 }\r
1984                                                 else {\r
1985                                                         realString = TXT2[I - 1].substring(0, index);   \r
1986                                                 }\r
1987                                                 if ((I > 1) && (realString != null) && (realString.length() != 0)) {\r
1988                                                         raFile.writeBytes("\n" + PAD);\r
1989                                                 }\r
1990                                                 if ((realString != null) && (realString.length() != 0)) {\r
1991                                                     raFile.writeBytes(realString);\r
1992                                                 }\r
1993                                                 if ((I == NTX2) || (index > 0)) {\r
1994                                                         raFile.writeBytes(";\n");\r
1995                                                         break;\r
1996                                                 }\r
1997                                         }\r
1998                                 }\r
1999                                 boolean uifound = false;\r
2000                                 String imagString = null;\r
2001                                 boolean firstImagStringWritten = false;\r
2002                                 for (I = 1; I <= NTX2; I++) {\r
2003                                         if (!uifound) {\r
2004                                         int index = TXT2[I-1].toLowerCase().indexOf("ui");\r
2005                                             if (index >= 0) {\r
2006                                                 uifound = true;\r
2007                                                 raFile.writeBytes(PAD + VAR + "[1] = " + HA + "*(");\r
2008                                                 if (index + 2 < TXT2[I-1].length()) {\r
2009                                                         imagString = TXT2[I - 1].substring(index + 2);\r
2010                                                             raFile.writeBytes(imagString);\r
2011                                                             firstImagStringWritten = true;\r
2012                                                             if (I == NTX2) {\r
2013                                                                 raFile.writeBytes(");\n");\r
2014                                                             }\r
2015                                                 } // if (index + 2 < TXT2[I-1].length())\r
2016                                             } // if (index >= 0)\r
2017                                     } // if (!uifound) {\r
2018                                     else {\r
2019                                         imagString = TXT2[I-1];\r
2020                                         if (!firstImagStringWritten) {\r
2021                                                 raFile.writeBytes(imagString);\r
2022                                         }\r
2023                                         else if ((imagString != null) && (imagString.length() != 0)) {\r
2024                                             raFile.writeBytes(PAD + imagString);\r
2025                                         }\r
2026                                         firstImagStringWritten = true;\r
2027                                             if (I == NTX2) {\r
2028                                                 raFile.writeBytes(");\n");\r
2029                                             }\r
2030                                     }\r
2031                                 } // for (I = 1; I <= NTX2; I++)\r
2032                                 if (!uifound) {\r
2033                                     raFile.writeBytes(PAD + VAR + "[1] = 0.0;\n");\r
2034                                 }\r
2035                                 raFile.writeBytes("//\n");\r
2036                         } // else if (TYPE == 3)\r
2037                         else {\r
2038                                 MD = 0.5 * (RGM[1] + RGM[0]);\r
2039                                 HA = 0.5 * (RGM[1] - RGM[0]);\r
2040                                 raFile.writeBytes("//\n");\r
2041                                 raFile.writeBytes(PAD + "T[0] = " + MD + "+" + CHTT + "[0]*(" + HA + ");\n");\r
2042                                 raFile.writeBytes(PAD + "T[1] = " + CHTT + "[1]*(" + HA + ");\n");\r
2043                                 if (TXT1[0].toLowerCase().indexOf("ui") == 0) {\r
2044                                     raFile.writeBytes(PAD + "ZRAD[0] = 0.0;\n");\r
2045                                 }\r
2046                                 else {\r
2047                                         // NTX = 1 if statements are entered without newlines for\r
2048                                         // multiple lines\r
2049                                         raFile.writeBytes(PAD + "ZRAD[0] = ");\r
2050                                         for (I = 1; I <= NTX1; I++) {\r
2051                                                 int index = TXT1[I - 1].toLowerCase().indexOf("ui");\r
2052                                                 if (index == 0) {\r
2053                                                         raFile.writeBytes(";\n");\r
2054                                                         break;\r
2055                                                 }\r
2056                                                 String realString = null;\r
2057                                                 if (index == -1) {\r
2058                                                         realString = TXT1[I-1];\r
2059                                                 }\r
2060                                                 else {\r
2061                                                         realString = TXT1[I - 1].substring(0, index);   \r
2062                                                 }\r
2063                                                 if ((I > 1) && (realString != null) && (realString.length() != 0)) {\r
2064                                                         raFile.writeBytes("\n" + PAD);\r
2065                                                 }\r
2066                                                 if ((realString != null) && (realString.length() != 0)) {\r
2067                                                     raFile.writeBytes(realString);\r
2068                                                 }\r
2069                                                 if ((I == NTX1) || (index > 0)) {\r
2070                                                         raFile.writeBytes(";\n");\r
2071                                                         break;\r
2072                                                 }\r
2073                                         }\r
2074                                 }\r
2075                                 boolean uifound = false;\r
2076                                 String imagString = null;\r
2077                                 boolean firstImagStringWritten = false;\r
2078                                 for (I = 1; I <= NTX1; I++) {\r
2079                                         if (!uifound) {\r
2080                                         int index = TXT1[I-1].toLowerCase().indexOf("ui");\r
2081                                             if (index >= 0) {\r
2082                                                 uifound = true;\r
2083                                                 raFile.writeBytes(PAD + "ZRAD[1] = ");\r
2084                                                 if (index + 2 < TXT1[I-1].length()) {\r
2085                                                         imagString = TXT1[I - 1].substring(index + 2);\r
2086                                                             raFile.writeBytes(imagString);\r
2087                                                             firstImagStringWritten = true;\r
2088                                                             if (I == NTX1) {\r
2089                                                                 raFile.writeBytes(";\n");\r
2090                                                             }\r
2091                                                 } // if (index + 2 < TXT1[I-1].length())\r
2092                                             } // if (index >= 0)\r
2093                                     } // if (!uifound) {\r
2094                                     else {\r
2095                                         imagString = TXT1[I-1];\r
2096                                         if (!firstImagStringWritten) {\r
2097                                                 raFile.writeBytes(imagString);\r
2098                                         }\r
2099                                         else if ((imagString != null) && (imagString.length() != 0)) {\r
2100                                             raFile.writeBytes(PAD + imagString);\r
2101                                         }\r
2102                                         firstImagStringWritten = true;\r
2103                                             if (I == NTX1) {\r
2104                                                 raFile.writeBytes(";\n");\r
2105                                             }\r
2106                                     }\r
2107                                 } // for (I = 1; I <= NTX1; I++)\r
2108             &nb