-
Notifications
You must be signed in to change notification settings - Fork 3
/
xyz_to_pdb.f90
1140 lines (1004 loc) · 25 KB
/
xyz_to_pdb.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
program main
!*****************************************************************************80
!
!! MAIN is the main program for XYZ_TO_PDB.
!
! Discussion:
!
! XYZ_TO_PDB writes the data from an XYZ file as spatial coordinates
! of ATOM records in a PDB file.
!
! The program may be invoked with both files specified on the command
! line.
!
! xyz_to_pdb file.xyz file.pdb
!
! If either or both files are missing, the program will ask for them.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 19 January 2006
!
! Author:
!
! John Burkardt
!
implicit none
integer ( kind = 4 ) iarg
integer ( kind = 4 ) iargc
integer ( kind = 4 ) ios
integer ( kind = 4 ) numarg
character ( len = 80 ) pdb_file_name
integer ( kind = 4 ) pdb_file_unit
character ( len = 40 ) string
integer ( kind = 4 ) xyz_file_line_num
character ( len = 80 ) xyz_file_name
integer ( kind = 4 ) xyz_file_unit
integer ( kind = 4 ) xyz_num
call timestamp ( )
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'XYZ_TO_PDB'
write ( *, '(a)' ) ' FORTRAN90 version'
write ( *, '(a)' ) ' Read XYZ data from a file.'
write ( *, '(a)' ) ' Rewrite it as atomic coordinates in'
write ( *, '(a)' ) ' ATOM records of a PDB file.'
write ( *, '(a)' ) ' '
!
! Get the number of command line arguments.
!
numarg = iargc ( )
if ( 1 <= numarg ) then
iarg = 1
call getarg ( iarg, xyz_file_name )
else
write ( *, '(a)' ) ' Enter the XYZ file name:'
read ( *, '(a)', iostat = ios ) xyz_file_name
if ( ios /= 0 ) then
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'XYZ_TO_PDB - Fatal error!'
write ( *, '(a)' ) ' Could not read the XYZ file name.'
stop
end if
end if
if ( 2 <= numarg ) then
iarg = 2
call getarg ( iarg, pdb_file_name )
else
write ( *, '(a)' ) ' Enter the PDB file name:'
read ( *, '(a)', iostat = ios ) pdb_file_name
if ( ios /= 0 ) then
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'XYZ_TO_PDB - Fatal error!'
write ( *, '(a)' ) ' Could not read the PDB file name.'
stop
end if
end if
write ( *, '(a)') 'Reading XYZ file "' // trim ( xyz_file_name ) // '".'
!
! Open the XYZ file.
!
call get_unit ( xyz_file_unit )
open ( unit = xyz_file_unit, file = xyz_file_name, status = 'old', &
iostat = ios )
if ( ios /= 0 ) then
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'XYZ_TO_PDB - Fatal error!'
write ( *, '(a)' ) ' Could not open the XYZ file.'
stop
end if
!
! Open the PDB file.
!
call get_unit ( pdb_file_unit )
open ( unit = pdb_file_unit, file = pdb_file_name, status = 'replace', &
iostat = ios )
if ( ios /= 0 ) then
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'XYZ_TO_PDB - Fatal error!'
write ( *, '(a)' ) ' Could not open the PDB file.'
stop
end if
call timestring ( string )
!
! TITLE section.
!
write ( pdb_file_unit, '(a)' ) &
'HEADER MUSCLE PROTEIN 02-JUN-93 1MYS'
write ( pdb_file_unit, '(a)' ) 'TITLE XYZ data.'
write ( pdb_file_unit, '(a)' ) &
'CAVEAT 1MYS Artificial data. Only the ATOM XYZ is important.'
write ( pdb_file_unit, '(a)' ) 'COMPND MOL_ID: 1'
write ( pdb_file_unit, '(a)' ) 'SOURCE MOL_ID: 1;'
write ( pdb_file_unit, '(a)' ) 'KEYWDS NONE'
write ( pdb_file_unit, '(a)' ) 'EXPDTA X-RAY DIFFRACTION'
write ( pdb_file_unit, '(a)' ) 'AUTHOR JOHN BURKARDT'
write ( pdb_file_unit, '(a)' ) 'REVDAT 09-JAN-06'
!
! REMARKS section.
!
write ( pdb_file_unit, '(a)' ) 'REMARK 1'
write ( pdb_file_unit, '(a)' ) 'REMARK 1 REFERENCE 1'
write ( pdb_file_unit, '(a)' ) 'REMARK 2'
write ( pdb_file_unit, '(a)' ) 'REMARK 2 RESOLUTION. NOT APPLICABLE'
write ( pdb_file_unit, '(a)' ) 'REMARK 3'
write ( pdb_file_unit, '(a)' ) 'REMARK 3 REFINEMENT.'
write ( pdb_file_unit, '(a)' ) &
'REMARK 4 XXXX COMPLIES WITH FORMAT V. 2.1, 25-OCT-1996'
write ( pdb_file_unit, '(a)' ) 'REMARK 5'
write ( pdb_file_unit, '(a)' ) 'REMARK 5 WARNING.'
write ( pdb_file_unit, '(a)' ) 'REMARK 6'
write ( pdb_file_unit, '(a)' ) 'REMARK 6 ' // trim ( pdb_file_name )
write ( pdb_file_unit, '(a)' ) 'REMARK 6'
write ( pdb_file_unit, '(a)' ) 'REMARK 6 Created by XYZ_TO_PDB on'
write ( pdb_file_unit, '(a)' ) 'REMARK 6 ' // trim ( string )
write ( pdb_file_unit, '(a)' ) 'REMARK 6'
!
! PRIMARY STRUCTURE section.
!
! HETEROGEN section.
!
! SECONDARY STRUCTURE section.
!
! CONNECTIVITY ANNOTATION section.
!
! MISCELLANEOUS FEATURES section.
!
! CRYSTALLOGRAPHIC section.
!
write ( pdb_file_unit, '(a)' ) &
'CRYST1 1.0 1.0 1.0 90 90 90 P 1 1'
!
! COORDINATE TRANSFORMATION section.
!
write ( pdb_file_unit, '(a)' ) &
'ORIGX1 1.000000 0.000000 0.000000 0.00000'
write ( pdb_file_unit, '(a)' ) &
'ORIGX2 0.000000 1.000000 0.000000 0.00000'
write ( pdb_file_unit, '(a)' ) &
'ORIGX3 0.000000 0.000000 1.000000 0.00000'
write ( pdb_file_unit, '(a)' ) &
'SCALE1 1.000000 0.000000 0.000000 0.00000'
write ( pdb_file_unit, '(a)' ) &
'SCALE2 0.000000 1.000000 0.000000 0.00000'
write ( pdb_file_unit, '(a)' ) &
'SCALE3 0.000000 0.000000 1.000000 0.00000'
!
! ATOMIC COORDINATE DATA section.
!
write ( pdb_file_unit, '(a)' ) 'MODEL 1'
!
! Transfer the XYZ coordinate data to the PDB file as ATOM records.
!
call xyz_to_pdb_atom ( xyz_file_unit, pdb_file_unit, xyz_file_line_num, &
xyz_num )
write ( pdb_file_unit, '(a)' ) 'ENMDL'
!
! CHEMICAL CONNECTIVITY section.
!
! BOOKKEEPING section.
!
write ( pdb_file_unit, '(a,i5,a)' ) &
'MASTER 15 0 0 0 0 0 0 6', &
xyz_num, ' 1 0 0'
write ( pdb_file_unit, '(a)' ) 'END'
write ( *, '(a)' ) ' '
write ( *, '(2x,i8,a)' ) xyz_file_line_num, ' lines read from XYZ file.'
write ( *, '(2x,i8,a)' ) xyz_num, ' coordinate records found in XYZ file.'
!
! Close the XYZ file.
!
close ( unit = xyz_file_unit )
!
! Close the PDB file.
!
close ( unit = pdb_file_unit )
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'XYZ_TO_PDB'
write ( *, '(a)' ) ' Normal end of execution.'
write ( *, '(a)' ) ' '
call timestamp ( )
stop
end
subroutine ch_cap ( c )
!*****************************************************************************80
!
!! CH_CAP capitalizes a single character.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 19 July 1998
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input/output, character C, the character to capitalize.
!
implicit none
character c
integer ( kind = 4 ) itemp
itemp = ichar ( c )
if ( 97 <= itemp .and. itemp <= 122 ) then
c = char ( itemp - 32 )
end if
return
end
function ch_eqi ( c1, c2 )
!*****************************************************************************80
!
!! CH_EQI is a case insensitive comparison of two characters for equality.
!
! Example:
!
! CH_EQI ( 'A', 'a' ) is .TRUE.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 28 July 2000
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, character C1, C2, the characters to compare.
!
! Output, logical CH_EQI, the result of the comparison.
!
implicit none
logical ch_eqi
character c1
character c1_cap
character c2
character c2_cap
c1_cap = c1
c2_cap = c2
call ch_cap ( c1_cap )
call ch_cap ( c2_cap )
if ( c1_cap == c2_cap ) then
ch_eqi = .true.
else
ch_eqi = .false.
end if
return
end
subroutine ch_to_digit ( c, digit )
!*****************************************************************************80
!
!! CH_TO_DIGIT returns the integer value of a base 10 digit.
!
! Example:
!
! C DIGIT
! --- -----
! '0' 0
! '1' 1
! ... ...
! '9' 9
! ' ' 0
! 'X' -1
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 04 August 1999
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, character C, the decimal digit, '0' through '9' or blank
! are legal.
!
! Output, integer ( kind = 4 ) DIGIT, the corresponding integer value. If C was
! 'illegal', then DIGIT is -1.
!
implicit none
character c
integer ( kind = 4 ) digit
if ( lge ( c, '0' ) .and. lle ( c, '9' ) ) then
digit = ichar ( c ) - 48
else if ( c == ' ' ) then
digit = 0
else
digit = -1
end if
return
end
subroutine get_unit ( iunit )
!*****************************************************************************80
!
!! GET_UNIT returns a free FORTRAN unit number.
!
! Discussion:
!
! A "free" FORTRAN unit number is an integer between 1 and 99 which
! is not currently associated with an I/O device. A free FORTRAN unit
! number is needed in order to open a file with the OPEN command.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 02 March 1999
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Output, integer ( kind = 4 ) IUNIT.
! If IUNIT = 0, then no free FORTRAN unit could be found, although
! all 99 units were checked (except for units 5 and 6).
! Otherwise, IUNIT is an integer between 1 and 99, representing a
! free FORTRAN unit. Note that GET_UNIT assumes that units 5 and 6
! are special, and will never return those values.
!
implicit none
integer ( kind = 4 ) i
integer ( kind = 4 ) ios
integer ( kind = 4 ) iunit
logical lopen
iunit = 0
do i = 1, 99
if ( i /= 5 .and. i /= 6 ) then
inquire ( unit = i, opened = lopen, iostat = ios )
if ( ios == 0 ) then
if ( .not. lopen ) then
iunit = i
return
end if
end if
end if
end do
return
end
function s_eqi ( strng1, strng2 )
!*****************************************************************************80
!
!! S_EQI is a case insensitive comparison of two strings for equality.
!
! Example:
!
! S_EQI ( 'Anjana', 'ANJANA' ) is .TRUE.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 14 April 1999
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, character ( len = * ) STRNG1, STRNG2, the strings to compare.
!
! Output, logical S_EQI, the result of the comparison.
!
implicit none
integer ( kind = 4 ) i
integer ( kind = 4 ) len1
integer ( kind = 4 ) len2
integer ( kind = 4 ) lenc
logical s_eqi
character s1
character s2
character ( len = * ) strng1
character ( len = * ) strng2
len1 = len ( strng1 )
len2 = len ( strng2 )
lenc = min ( len1, len2 )
s_eqi = .false.
do i = 1, lenc
s1 = strng1(i:i)
s2 = strng2(i:i)
call ch_cap ( s1 )
call ch_cap ( s2 )
if ( s1 /= s2 ) then
return
end if
end do
do i = lenc + 1, len1
if ( strng1(i:i) /= ' ' ) then
return
end if
end do
do i = lenc + 1, len2
if ( strng2(i:i) /= ' ' ) then
return
end if
end do
s_eqi = .true.
return
end
subroutine s_to_r8 ( s, dval, ierror, length )
!*****************************************************************************80
!
!! S_TO_R8 reads an R8 from a string.
!
! Discussion:
!
! The routine will read as many characters as possible until it reaches
! the end of the string, or encounters a character which cannot be
! part of the number.
!
! Legal input is:
!
! 1 blanks,
! 2 '+' or '-' sign,
! 2.5 blanks
! 3 integer part,
! 4 decimal point,
! 5 fraction part,
! 6 'E' or 'e' or 'D' or 'd', exponent marker,
! 7 exponent sign,
! 8 exponent integer part,
! 9 exponent decimal point,
! 10 exponent fraction part,
! 11 blanks,
! 12 final comma or semicolon,
!
! with most quantities optional.
!
! Example:
!
! S DVAL
!
! '1' 1.0
! ' 1 ' 1.0
! '1A' 1.0
! '12,34,56' 12.0
! ' 34 7' 34.0
! '-1E2ABCD' -100.0
! '-1X2ABCD' -1.0
! ' 2E-1' 0.2
! '23.45' 23.45
! '-4.2E+2' -420.0
! '17d2' 1700.0
! '-14e-2' -0.14
! 'e2' 100.0
! '-12.73e-9.23' -12.73 * 10.0**(-9.23)
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 07 September 2004
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, character ( len = * ) S, the string containing the
! data to be read. Reading will begin at position 1 and
! terminate at the end of the string, or when no more
! characters can be read to form a legal real. Blanks,
! commas, or other nonnumeric data will, in particular,
! cause the conversion to halt.
!
! Output, real ( kind = 8 ) DVAL, the value read from the string.
!
! Output, integer IERROR, error flag.
! 0, no errors occurred.
! 1, 2, 6 or 7, the input number was garbled. The
! value of IERROR is the last type of input successfully
! read. For instance, 1 means initial blanks, 2 means
! a plus or minus sign, and so on.
!
! Output, integer LENGTH, the number of characters read
! to form the number, including any terminating
! characters such as a trailing comma or blanks.
!
implicit none
logical ch_eqi
character c
real ( kind = 8 ) dval
integer ( kind = 4 ) ierror
integer ( kind = 4 ) ihave
integer ( kind = 4 ) isgn
integer ( kind = 4 ) iterm
integer ( kind = 4 ) jbot
integer ( kind = 4 ) jsgn
integer ( kind = 4 ) jtop
integer ( kind = 4 ) length
integer ( kind = 4 ) nchar
integer ( kind = 4 ) ndig
real ( kind = 8 ) rbot
real ( kind = 8 ) rexp
real ( kind = 8 ) rtop
character ( len = * ) s
nchar = len_trim ( s )
ierror = 0
dval = 0.0D+00
length = -1
isgn = 1
rtop = 0
rbot = 1
jsgn = 1
jtop = 0
jbot = 1
ihave = 1
iterm = 0
do
length = length + 1
if ( nchar < length+1 ) then
exit
end if
c = s(length+1:length+1)
!
! Blank character.
!
if ( c == ' ' ) then
if ( ihave == 2 ) then
else if ( ihave == 6 .or. ihave == 7 ) then
iterm = 1
else if ( 1 < ihave ) then
ihave = 11
end if
!
! Comma.
!
else if ( c == ',' .or. c == ';' ) then
if ( ihave /= 1 ) then
iterm = 1
ihave = 12
length = length + 1
end if
!
! Minus sign.
!
else if ( c == '-' ) then
if ( ihave == 1 ) then
ihave = 2
isgn = -1
else if ( ihave == 6 ) then
ihave = 7
jsgn = -1
else
iterm = 1
end if
!
! Plus sign.
!
else if ( c == '+' ) then
if ( ihave == 1 ) then
ihave = 2
else if ( ihave == 6 ) then
ihave = 7
else
iterm = 1
end if
!
! Decimal point.
!
else if ( c == '.' ) then
if ( ihave < 4 ) then
ihave = 4
else if ( 6 <= ihave .and. ihave <= 8 ) then
ihave = 9
else
iterm = 1
end if
!
! Scientific notation exponent marker.
!
else if ( ch_eqi ( c, 'E' ) .or. ch_eqi ( c, 'D' ) ) then
if ( ihave < 6 ) then
ihave = 6
else
iterm = 1
end if
!
! Digit.
!
else if ( ihave < 11 .and. lle ( '0', c ) .and. lle ( c, '9' ) ) then
if ( ihave <= 2 ) then
ihave = 3
else if ( ihave == 4 ) then
ihave = 5
else if ( ihave == 6 .or. ihave == 7 ) then
ihave = 8
else if ( ihave == 9 ) then
ihave = 10
end if
call ch_to_digit ( c, ndig )
if ( ihave == 3 ) then
rtop = 10.0D+00 * rtop + real ( ndig, kind = 8 )
else if ( ihave == 5 ) then
rtop = 10.0D+00 * rtop + real ( ndig, kind = 8 )
rbot = 10.0D+00 * rbot
else if ( ihave == 8 ) then
jtop = 10 * jtop + ndig
else if ( ihave == 10 ) then
jtop = 10 * jtop + ndig
jbot = 10 * jbot
end if
!
! Anything else is regarded as a terminator.
!
else
iterm = 1
end if
!
! If we haven't seen a terminator, and we haven't examined the
! entire string, go get the next character.
!
if ( iterm == 1 ) then
exit
end if
end do
!
! If we haven't seen a terminator, and we have examined the
! entire string, then we're done, and LENGTH is equal to NCHAR.
!
if ( iterm /= 1 .and. length+1 == nchar ) then
length = nchar
end if
!
! Number seems to have terminated. Have we got a legal number?
! Not if we terminated in states 1, 2, 6 or 7!
!
if ( ihave == 1 .or. ihave == 2 .or. ihave == 6 .or. ihave == 7 ) then
ierror = ihave
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'S_TO_R8 - Serious error!'
write ( *, '(a)' ) ' Illegal or nonnumeric input:'
write ( *, '(a)' ) ' ' // trim ( s )
return
end if
!
! Number seems OK. Form it.
!
if ( jtop == 0 ) then
rexp = 1.0D+00
else
if ( jbot == 1 ) then
rexp = 10.0D+00 ** ( jsgn * jtop )
else
rexp = 10.0D+00 ** ( real ( jsgn * jtop, kind = 8 ) &
/ real ( jbot, kind = 8 ) )
end if
end if
dval = real ( isgn, kind = 8 ) * rexp * rtop / rbot
return
end
subroutine s_to_r8vec ( s, n, rvec, ierror )
!*****************************************************************************80
!
!! S_TO_R8VEC reads an R8VEC from a string.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 07 September 2004
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, character ( len = * ) S, the string to be read.
!
! Input, integer ( kind = 4 ) N, the number of values expected.
!
! Output, real ( kind = 8 ) RVEC(N), the values read from the string.
!
! Output, integer ( kind = 4 ) IERROR, error flag.
! 0, no errors occurred.
! -K, could not read data for entries -K through N.
!
implicit none
integer ( kind = 4 ) n
integer ( kind = 4 ) i
integer ( kind = 4 ) ierror
integer ( kind = 4 ) ilo
integer ( kind = 4 ) lchar
real ( kind = 8 ) rvec(n)
character ( len = * ) s
i = 0
ierror = 0
ilo = 1
do while ( i < n )
i = i + 1
call s_to_r8 ( s(ilo:), rvec(i), ierror, lchar )
if ( ierror /= 0 ) then
ierror = -i
exit
end if
ilo = ilo + lchar
end do
return
end
subroutine timestamp ( )
!*****************************************************************************80
!
!! TIMESTAMP prints the current YMDHMS date as a time stamp.
!
! Example:
!
! May 31 2001 9:45:54.872 AM
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 31 May 2001
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! None
!
implicit none
character ( len = 8 ) ampm
integer ( kind = 4 ) d
character ( len = 8 ) date
integer ( kind = 4 ) h
integer ( kind = 4 ) m
integer ( kind = 4 ) mm
character ( len = 9 ), parameter, dimension(12) :: month = (/ &
'January ', 'February ', 'March ', 'April ', &
'May ', 'June ', 'July ', 'August ', &
'September', 'October ', 'November ', 'December ' /)
integer ( kind = 4 ) n
integer ( kind = 4 ) s
character ( len = 10 ) time
integer ( kind = 4 ) values(8)
integer ( kind = 4 ) y
character ( len = 5 ) zone
call date_and_time ( date, time, zone, values )
y = values(1)
m = values(2)
d = values(3)
h = values(5)
n = values(6)
s = values(7)
mm = values(8)
if ( h < 12 ) then
ampm = 'AM'
else if ( h == 12 ) then
if ( n == 0 .and. s == 0 ) then
ampm = 'Noon'
else
ampm = 'PM'
end if
else
h = h - 12
if ( h < 12 ) then
ampm = 'PM'
else if ( h == 12 ) then
if ( n == 0 .and. s == 0 ) then
ampm = 'Midnight'
else
ampm = 'AM'
end if
end if
end if
write ( *, '(a,1x,i2,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) &
trim ( month(m) ), d, y, h, ':', n, ':', s, '.', mm, trim ( ampm )
return
end
subroutine timestring ( string )
!*****************************************************************************80
!
!! TIMESTRING writes the current YMDHMS date into a string.
!
! Example:
!
! STRING = '31 May 2001 9:45:54.872 AM'
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 06 August 2005
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Output, character ( len = * ) STRING, contains the date information.
! A character length of 40 should always be sufficient.
!
implicit none
character ( len = 8 ) ampm
integer ( kind = 4 ) d
integer ( kind = 4 ) h
integer ( kind = 4 ) m
integer ( kind = 4 ) mm
character ( len = 9 ), parameter, dimension(12) :: month = (/ &
'January ', 'February ', 'March ', 'April ', &
'May ', 'June ', 'July ', 'August ', &
'September', 'October ', 'November ', 'December ' /)
integer ( kind = 4 ) n
integer ( kind = 4 ) s
character ( len = * ) string
integer ( kind = 4 ) values(8)
integer ( kind = 4 ) y
call date_and_time ( values = values )
y = values(1)
m = values(2)
d = values(3)
h = values(5)
n = values(6)
s = values(7)
mm = values(8)
if ( h < 12 ) then
ampm = 'AM'
else if ( h == 12 ) then
if ( n == 0 .and. s == 0 ) then
ampm = 'Noon'
else
ampm = 'PM'
end if
else
h = h - 12
if ( h < 12 ) then
ampm = 'PM'
else if ( h == 12 ) then