NLSL
nlsl.f90
Go to the documentation of this file.
1 c Version 1.5.1b 11/6/95
2 c----------------------------------------------------------------------
3 c =========================
4 c program NLSL
5 c =========================
6 c
7 c Main program for a nonlinear least-squares fit using an
8 c EPRLL-family slow-motional calculation. The options in running
9 c this program are too numerous to detail here. Read the manual...
10 c or better yet, wait until the movie comes out. DB
11 c
12 c Updated by DC and DEB to include graphical interface by
13 c calls in this program, subroutine GETDAT, and subroutine LFUN.
14 c
15 c
16 c Modules needed: Additional modules needed by NLSINIT:
17 c nlsdim.mod basis.mod
18 c nlsnam.mod iterat.mod
19 c eprprm.mod mspct.mod
20 c expdat.mod tridag.mod
21 c lmcom.mod
22 c parcom.mod
23 c symdef.mod
24 c stdio.mod
25 c
26 c######################################################################
27 c
28  program nlsl
29 c
30  use nlsdim
31  use nlsnam
32  use eprprm
33  use expdat
34  use lmcom
35  use parcom
36  use symdef
37  use stdio
38 c
39  implicit none
40 c
41  integer i,iflg,ioerr,j,lth
42  logical fexist
43  character line*80,token*30,scratch*30,fileID*30,chr1*1
44 c
45  logical getlin
46  external getlin
47 c
48  write (luttyo,1000)
49  write (luttyo,1010)
50 c
51 c ----------------------
52 c Initialize NLS system
53 c ----------------------
54 c
55  call nlsinit
56 c
57 c----------------------------------------------------------------------
58 c Get next command from input stream (skip comments)
59 c----------------------------------------------------------------------
60 c
61 c Check for ^C during command input from indirect files.
62 c If detected, close all files and return to tty mode
63 c
64 c The following line is the start of the main loop
65  25 if (hltcmd.ne.0 .and. nfiles.gt.0) then
66  do 26 i=1,nfiles
67  close(ludisk+i)
68  26 continue
69  nfiles=0
71  call uncatchc( hltcmd )
72  end if
73 c
74  if (getlin(line)) then
75 c
76 c######################################################################
77 c
78  call gettkn(line,token,lth)
79  call touppr(token,lth)
80  if (lth.eq.0 .or. token.eq.'C' .or. token.eq.'/*') go to 25
81 c
82 c----------------------------------------------------------------------
83  if (token.eq.'ASSIGN') then
84  call assgnc(line)
85 c
86 c----------------------------------------------------------------------
87 c AXIAL command
88 c----------------------------------------------------------------------
89  else if (token.eq.'AXIAL') then
90  call convtc(line,axial)
91 c
92 c----------------------------------------------------------------------
93 c BASIS command
94 c----------------------------------------------------------------------
95  else if (token.eq.'BASIS') then
96  call basisc(line)
97 c
98 c----------------------------------------------------------------------
99 c CARTESIAN command
100 c----------------------------------------------------------------------
101  else if (token.eq.'CARTESIAN' .or. token.eq.'CART') then
102  call convtc(line,cartesian)
103 c
104 c----------------------------------------------------------------------
105 c CONFIDENCE command
106 c----------------------------------------------------------------------
107  else if (token.eq.'CONFIDENCE' .or. token .eq. 'CONF') then
108  call confc(line)
109 c
110 c----------------------------------------------------------------------
111 c CONFIDENCE command
112 c----------------------------------------------------------------------
113  else if (token.eq.'CORRELATION' .or. token .eq. 'CORR') then
114  call covrpt(luttyo)
115 c
116 c----------------------------------------------------------------------
117 c DATA command
118 c----------------------------------------------------------------------
119  else if (token.eq.'DATA') then
120  call datac(line)
121 c
122 c----------------------------------------------------------------------
123 c DELETE command
124 c----------------------------------------------------------------------
125  else if (token.eq.'DELETE' .or. token.eq.'DEL' ) then
126  call deletc(line)
127 
128 c
129 c----------------------------------------------------------------------
130 c ECHO command
131 c----------------------------------------------------------------------
132  else if (token.eq.'ECHO') then
133  call gettkn(line,token,lth)
134  if (lth.gt.0) then
135  scratch=token
136  else
137  scratch=' '
138  end if
139  call touppr(scratch,3)
140  if (scratch.eq.'ON') then
141  luecho=luttyo
142  else if (scratch.eq.'OFF') then
143  luecho=0
144  else
145  call ungett(token,lth,line)
146  write(luttyo,1060) line
147  if (luout.ne.luttyo) write (luout,1060) line
148  end if
149 c
150 c----------------------------------------------------------------------
151 c FIT command
152 c----------------------------------------------------------------------
153  else if (token.eq.'FIT') then
154  call fitc(line)
155 c
156 c----------------------------------------------------------------------
157 c FIX command (alias REMOVE)
158 c----------------------------------------------------------------------
159  else if (token.eq.'FIX' .or. token.eq.'REMOVE') then
160  call fixc(line)
161 c
162 c----------------------------------------------------------------------
163 c HELP command
164 c----------------------------------------------------------------------
165  else if (token.eq.'HELP') then
166  call helpc(line)
167 c
168 c----------------------------------------------------------------------
169 c LET command
170 c----------------------------------------------------------------------
171  else if (token.eq.'LET') then
172  call letc(line)
173 c
174 c----------------------------------------------------------------------
175 c LOG command: Set log file identification
176 c----------------------------------------------------------------------
177  else if (token.eq.'LOG') then
178  call gettkn(line,fileid,lth)
179  if (lth.eq.0) then
180 c
181 c *** File name not specified
182  write (luttyo,1020)
183 c
184  else if (fileid.eq.'END' .or. fileid.eq.'end') then
185  if (luout.eq.luttyo) then
186  write (luttyo,1021)
187  else
188  close(lulog)
189  luout=luttyo
190  end if
191 c
192  else
193  call setfil( fileid )
194  open(lulog,file=lgname(:lthfnm),status='unknown',
195  # access='sequential',form='formatted',
196  # iostat=ioerr)
197  if (ioerr.ne.0) then
198  write (luttyo,1022) ioerr,lgname(:lthfnm)
199  else
200  luout=lulog
201  end if
202  end if
203 c
204 c----------------------------------------------------------------------
205 c PARMS command
206 c----------------------------------------------------------------------
207  else if (token.eq.'PARMS') then
208  call parc(line)
209 c
210 c----------------------------------------------------------------------
211 c QUIT command (alias EXIT)
212 c----------------------------------------------------------------------
213  else if (token.eq.'QUIT'.or.token.eq.'EXIT') then
214  goto 9999
215 c
216 c----------------------------------------------------------------------
217 c READ command (alias CALL)
218 c open a new input file and set I/O units appropriately
219 c----------------------------------------------------------------------
220 c
221  else if (token.eq.'READ' .or. token.eq.'CALL') then
222 c
223 c --- get filename
224 c
225  call gettkn(line,fileid,lth)
226 c
227  if (lth.ne.0) then
228 c
229 c --- open input file if possible
230 c
231  if (nfiles.ge.mxfile) then
232  write (luttyo,1050) fileid(:lth),mxfile
233  else
234  nfiles=nfiles+1
236  inquire(file=fileid(:lth),exist=fexist)
237  if (fexist) open(lucmd,file=fileid(:lth),
238  # status='old',access='sequential',
239  # form='formatted',iostat=ioerr)
240 c
241  if ((.not.fexist) .or. ioerr.ne.0) then
242 c
243 c *** open error
244  write (luttyo,1030) fileid(:lth)
245  nfiles=nfiles-1
246  if (nfiles.eq.0) then
247  lucmd=luttyi
248  else
249  lucmd=lucmd-1
250  end if
251 c
252  else
253  files(nfiles)=fileid
254  call catchc( hltcmd )
255  end if
256  end if
257 c
258 c *** File name not specified
259  else
260  write (luttyo,1020)
261  end if
262 c
263 c----------------------------------------------------------------------
264 c RESET command
265 c----------------------------------------------------------------------
266  else if (token.eq.'RESET') then
267  call nlsinit
268 c
269 c----------------------------------------------------------------------
270 c SCALE command
271 c----------------------------------------------------------------------
272  else if (token.eq.'SCALE') then
273  call scalec(line)
274 c
275 c----------------------------------------------------------------------
276 c SEARCH command
277 c----------------------------------------------------------------------
278  else if (token.eq.'SEARCH') then
279  call srchc(line)
280 
281 c----------------------------------------------------------------------
282 c SERIES command
283 c----------------------------------------------------------------------
284  else if (token.eq.'SERIES') then
285  call series(line)
286 c
287 c----------------------------------------------------------------------
288 c SHIFT command
289 c----------------------------------------------------------------------
290  else if (token.eq.'SHIFT') then
291  call shiftc(line)
292 c
293 c----------------------------------------------------------------------
294 c SITES command
295 c----------------------------------------------------------------------
296  else if (token.eq.'SITES') then
297  call sitec(line)
298 c
299 c----------------------------------------------------------------------
300 c SPHERICAL command
301 c----------------------------------------------------------------------
302  else if (token.eq.'SPHERICAL' .or. token.eq.'SPHER') then
303  call convtc(line,spherical)
304 c
305 c----------------------------------------------------------------------
306 c STATUS command
307 c----------------------------------------------------------------------
308  else if (token.eq.'STATUS') then
309  call statc(line)
310 c
311 c----------------------------------------------------------------------
312 c VARY command
313 c----------------------------------------------------------------------
314  else if (token.eq.'VARY') then
315  call varyc(line)
316 c
317 c----------------------------------------------------------------------
318 c WRITE command
319 c----------------------------------------------------------------------
320  else if (token.eq.'WRITE') then
321  call writec( line )
322 c
323 c----------------------------------------------------------------------
324 c Unknown command
325 c----------------------------------------------------------------------
326  else
327  write(luttyo,1040) token(:lth)
328  end if
329 c
330 c----------------------------------------------------------------------
331 c No more lines (getlin returned .false.)
332 c Close current input unit; if there are no open files, stop program
333 c----------------------------------------------------------------------
334 c
335  else
336  if (nfiles.eq.0) then
337  write(luttyo,1000)
338  stop 'end of program NLSL'
339  else
340  close(lucmd)
341  nfiles=nfiles-1
342  if (nfiles.eq.0) then
343  lucmd=luttyi
344  call uncatchc( hltcmd )
345  else
346  lucmd=lucmd-1
347  end if
348  end if
349  end if
350  go to 25
351 c
352 c----------------------------------------------------------------------
353 c Exit program
354 c----------------------------------------------------------------------
355 c
356  9999 continue
357 c
358 c
359 c -----------------------------------
360 c Close all windows before exiting
361 c -----------------------------------
362 c call shutwindows()
363  call shtwndws()
364  stop
365 c
366 c
367 c## format statements ###############################################
368 c
369  1000 format(//,2x,70('#'),//)
370  1010 format(25x,'PROGRAM : NLSL'/20x,'*** Version 1.5.1 beta ***'/
371  #26x,'Mod 05/18/96'/
372  #15x,'Recompiled by Zhichun Liang, 12/13/07'/
373  #25x,'---------------',//)
374  1020 format('*** File name must be specified ***'/)
375  1021 format('*** Log file is not open ***')
376  1022 format('*** Error',i3,' opening file ',a,' ***')
377  1030 format('*** Error opening or reading file ''',a,''' ***'/)
378  1040 format('*** Unknown command : ''',a,''' ***')
379  1050 format('*** Cannot open ''',a,''': more than',i2,
380  # ' read files ***')
381  1060 format(a)
382  end
383 
384 
385 
386 c----------------------------------------------------------------------
387 c =========================
388 c subroutine NLSINIT
389 c =========================
390 c
391 c Initializes the following:
392 c Data arrays
393 c NLS parameter arrays
394 c NLS convergence criteria
395 c----------------------------------------------------------------------
396  subroutine nlsinit
397 c
398  use nlsdim
399  use nlsnam
400  use eprprm
401  use expdat
402  use parcom
403  use mspctr
404  use tridag
405  use basis
406  use lmcom
407  use iterat
408  use stdio
409 c
410  implicit none
411 c
412  integer i,j
413 c
414 c----------------------------------------------------------------------
415 c Initializations
416 c----------------------------------------------------------------------
417  nfiles=0
418  lucmd=luttyi
419  luout=luttyo
420  luecho=luttyo
421  nspc=0
422  ndatot=0
423  nprm=0
424  iser=0
425  nser=1
426  nsite=1
427  nwin=0
428 c
429 c----------------------------------------
430 c Initialize parameter arrays
431 c----------------------------------------
432  do j=1,mxsite
433  do i=1,nvprm
434  fparm(i,j)=0.0d0
435  ixx(i,j)=0
436  end do
437 c
438  do i=1,niprm
439  iparm(i,j)=0
440  end do
441 c
442  do i=1,mxspc
443  sfac(j,i)=1.0d0
444  end do
445 c
446 c----------------------------------------------------------
447 c Initialize pointers to serve as meaningful aliases
448 c for the various parameters stored in lengthy arrays
449 c----------------------------------------------------------
450  call prm_ptr_init
451 c
452 c--------------------------------------------------
453 c Put in defaults for often-forgotten parameters
454 c--------------------------------------------------
455  fparm(icgtol,j)=1.0d-3
456  fparm(ishift,j)=1.0d-3
457 c
458 c------------------------------------------------------------
459 c Define an all-purpose default MTS
460 c (caveat: this is a conservative set, corresponding
461 c to pretty slow motions at X-band!, and long calculation
462 c times!)
463 c------------------------------------------------------------
464  iparm(ilemx,j)=10
465  iparm(ilemx+1,j)=9
466  iparm(ilemx+3,j)=6
467  iparm(ilemx+5,j)=2
468  iparm(ilemx+6,j)=2
469  end do
470 c
471 c-------------------------------------------------------
472 c Initialize tridiagonal matrix and basis index space
473 c-------------------------------------------------------
474  do j=1,mxspc
475  do i=1,mxsite
476  modtd(i,j)=1
477  ltd(i,j)=0
478  basno(i,j)=0
479  end do
480  end do
481  nexttd=1
482  nextbs=1
483  ntd=0
484  nbas=0
485 c
486 c------------------------------------------------------------
487 c Initialize data array parameters
488 c------------------------------------------------------------
489  do i=1,mxspc
490  sbi(i)=0.0d0
491  sdb(i)=0.0d0
492  shft(i)=0.0d0
493  tmpshft(i)=0.0d0
494  sb0(i)=0.0d0
495  spsi(i)=0.0d0
496  sbi(i)=0.0d0
497  iform(i)=0
498  ibase(i)=0
499  npts(i)=0
500  ishft(i)=0
501  ixsp(i)=1
502  idrv(i)=1
503  end do
504  ishglb=0
505 c
506 c----------------------------------------
507 c -- Enable autoscaling for all sites
508 c----------------------------------------
509  do i=1,mxsite
510  iscal(i)=1
511  end do
512  iscglb=1
513 c
514 c------------------------------------------------------
515 c -- Set initial values for NLS convergence criteria
516 c -- First, call the routine to initalize F90 pointers
517 c------------------------------------------------------
518  call lmcom_init
519  xtol=1.0d-4
520  ftol=1.0d-4
521  gtol=1.0d-6
522  factor=1.0d2
523  maxitr=10
524  nshift=8
525  noneg=1
526  srange=0.5d0
527  maxev=100
528  itrace=0
529  lmflag=0
530  iwflag=1
531  confid=0.683
532  ctol=1.0d-3
533 c
534 c--------------------------------------------------
535 c -- Set initial values for line search parameters
536 c--------------------------------------------------
537  pstep=0.05d0
538  ptol=0.01d0
539  pftol=0.1d0
540  pbound=5.0d0
541  mxpitr=100
542 c
543 c--------------------------------------------------
544 c -- Set initial values for data input
545 c--------------------------------------------------
546  inform=0
547  bcmode=0
548  shftflg=1
549  drmode=1
550  normflg=0
551 c
552 c call shutwindows
553  call shtwndws()
554 c call initwindows
555 c
556  return
557  end
integer, parameter nvprm
Definition: nlsdim.f90:57
integer, parameter mxfile
Definition: nlsdim.f90:39
integer, save luout
Definition: stdio.f90:32
integer, save nfiles
Definition: nlsnam.f90:33
integer, save nwin
Definition: expdat.f90:45
subroutine prm_ptr_init
Definition: eprprm.f90:145
double precision, dimension(mxspc), save sbi
Definition: expdat.f90:40
integer, save lucmd
Definition: stdio.f90:32
integer, save lthfnm
Definition: nlsnam.f90:27
subroutine shiftc(line)
Definition: shiftc.f90:34
integer, save drmode
Definition: expdat.f90:45
subroutine srchc(line)
Definition: srchc.f90:29
subroutine basisc(line)
Definition: basisc.f90:19
integer, save noneg
Definition: parcom.f90:62
double precision, save srange
Definition: parcom.f90:56
subroutine varyc(line)
Definition: varyc.f90:40
character *30, dimension(mxfile), save files
Definition: nlsnam.f90:34
integer, save ndatot
Definition: expdat.f90:45
double precision, dimension(mxspc), save sdb
Definition: expdat.f90:40
integer, parameter niprm
Definition: nlsdim.f90:57
subroutine confc(line)
Definition: confc.f90:8
program nlsl
Definition: nlsl.f90:28
integer, save iscglb
Definition: mspctr.f90:32
double precision, pointer, save ftol
Definition: lmcom.f90:29
integer, dimension(mxspc), save ixsp
Definition: expdat.f90:45
integer, save nexttd
Definition: tridag.f90:28
integer, save inform
Definition: expdat.f90:45
void FORTRAN() uncatchc(int *flag)
Definition: catch.c:49
integer, dimension(mxspc), save ishft
Definition: expdat.f90:45
integer, dimension(mxsite, mxspc), save basno
Definition: basis.f90:23
integer, dimension(mxspc), save ibase
Definition: expdat.f90:45
integer, save hltcmd
Definition: stdio.f90:32
subroutine series(line)
Definition: series.f90:20
double precision, dimension(mxspc), save tmpshft
Definition: expdat.f90:40
integer, dimension(mxsite, mxspc), save modtd
Definition: tridag.f90:28
double precision, dimension(mxsite, mxspc), save sfac
Definition: mspctr.f90:33
double precision, save confid
Definition: iterat.f90:15
double precision, dimension(mxspc), save shft
Definition: expdat.f90:40
double precision, save pstep
Definition: parcom.f90:56
Definition: stdio.f90:26
double precision, dimension(mxspc), save spsi
Definition: expdat.f90:40
double precision, dimension(nfprm, mxsite), target, save fparm
Definition: parcom.f90:54
integer, parameter axial
Definition: symdef.f90:14
double precision, save pftol
Definition: parcom.f90:56
double precision, pointer, save gtol
Definition: lmcom.f90:29
subroutine touppr(string, lth)
Definition: strutl2.f90:22
integer, save normflg
Definition: expdat.f90:45
integer, pointer, save maxev
Definition: lmcom.f90:32
Definition: basis.f90:19
integer, parameter cartesian
Definition: symdef.f90:14
integer, save iwflag
Definition: iterat.f90:14
subroutine gettkn(line, token, lth)
Written for free-form input of parameters for slow-motional calculations. Returns a token consisting ...
Definition: strutl1.f90:75
subroutine assgnc(line)
Definition: assgnc.f90:17
subroutine nlsinit
Definition: nlsl.f90:397
integer, parameter mxspc
Definition: nlsdim.f90:39
integer, save bcmode
Definition: expdat.f90:45
subroutine fixc(line)
Definition: fixc.f90:16
integer, save nprm
Definition: parcom.f90:62
integer, save nspc
Definition: expdat.f90:45
integer, save nsite
Definition: parcom.f90:62
integer, dimension(mxsite, mxspc), save ltd
Definition: tridag.f90:28
integer, save nextbs
Definition: basis.f90:23
subroutine lmcom_init
Definition: lmcom.f90:37
integer, save nshift
Definition: parcom.f90:62
character *30, save lgname
Definition: nlsnam.f90:28
integer, dimension(niprm, mxsite), target, save iparm
Definition: parcom.f90:60
integer, dimension(mxsite), save iscal
Definition: mspctr.f90:32
integer, parameter mxsite
Definition: nlsdim.f90:39
subroutine ungett(token, lth, line)
Definition: strutl1.f90:165
subroutine covrpt(lu)
Definition: covrpt.f90:12
integer, save nser
Definition: parcom.f90:62
double factor
Definition: genio.c:44
integer, save lmflag
Definition: lmcom.f90:24
subroutine deletc(line)
Definition: basisc.f90:145
subroutine scalec(line)
Definition: scalec.f90:32
integer, parameter ishift
Definition: eprprm.f90:92
subroutine sitec(line)
Definition: sitec.f90:13
integer, parameter lulog
Definition: stdio.f90:29
subroutine writec(line)
Definition: writec.f90:12
integer, save luecho
Definition: stdio.f90:32
subroutine statc(line)
Definition: statc.f90:20
void FORTRAN() catchc(int *flag)
Definition: catch.c:33
integer, dimension(mxspc), save idrv
Definition: expdat.f90:45
double precision, pointer, save xtol
Definition: lmcom.f90:29
Definition: lmcom.f90:13
integer, save iser
Definition: parcom.f90:62
subroutine fitc(line)
Definition: fitc.f90:22
integer, parameter ludisk
Definition: stdio.f90:29
integer, parameter luttyo
Definition: stdio.f90:29
integer, dimension(mxspc), save iform
Definition: expdat.f90:45
double precision, save ctol
Definition: parcom.f90:56
double precision, save pbound
Definition: parcom.f90:56
integer, parameter ilemx
Definition: eprprm.f90:101
integer, parameter luttyi
Definition: stdio.f90:29
double precision, save ptol
Definition: parcom.f90:56
subroutine datac(line)
Definition: datac.f90:30
subroutine parc(line)
Definition: parc.f90:12
double precision, dimension(mxspc), save sb0
Definition: expdat.f90:40
integer, save mxpitr
Definition: parcom.f90:62
subroutine helpc(line)
Definition: helpc.f90:8
integer, parameter icgtol
Definition: eprprm.f90:92
integer, save shftflg
Definition: expdat.f90:45
integer, dimension(nfprm, mxsite), save ixx
Definition: parcom.f90:62
integer, dimension(mxspc), save npts
Definition: expdat.f90:45
subroutine setfil(fileid)
Definition: setnm.f90:22
integer, pointer, save maxitr
Definition: lmcom.f90:32
integer, parameter spherical
Definition: symdef.f90:14
void FORTRAN() shtwndws()
Definition: pltx.c:875
subroutine convtc(line, iflg)
Definition: convtc.f90:26
integer, save itrace
Definition: stdio.f90:32
integer, save ishglb
Definition: expdat.f90:45
integer, save ntd
Definition: tridag.f90:28
integer, save nbas
Definition: basis.f90:23
subroutine letc(line)
Definition: letc.f90:17
double precision, dimension(mxjcol), save x
Definition: lmcom.f90:17