OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
convtc.f
Go to the documentation of this file.
1  subroutine convtc (num,nchar, loc)
2 c
3 c library subroutine
4 c
5 c module name: convtc
6 c
7 c version : 1.0
8 c
9 c programmer : lucy liu and michael peng, stx, august 1990
10 c
11 c purpose: to convert first nchar digits of an integer into a character
12 c or a string. (note: nchar doesn't include the sign if num
13 c is negative)
14 c
15 c calling sequence: convtc (num,nchar, loc)
16 c
17 c subroutines called: none
18 c
19 c intrinsic functions used: char, ichar, iabs
20 c
21 c common blocks used: none
22 c
23 c arguments and local variables:
24 c
25 c name type i/o descriptions
26 c --------- ---- --- ----------------------------------------------
27 c num i*4 i integer number for conversion
28 c nchar i*4 i number of chars to be converted
29 c loc c*x o char variable or array (string)
30 c istart i*4 start position of integral char string:
31 c 1 for positive integer; 2 for negative integer
32 c irem i*4 absolute value or remainder by 10
33 c itemp i*4 temporary buffer
34 c***********************************************************************
35 c
36 c --- arguments
37 c
38  integer num, nchar
39  character loc(1)
40 c
41 c --- local variables
42 c
43  integer istart, irem, itemp
44 c
45  irem = iabs(num )
46  istart = 1
47 c
48 c --- keep the sign if the integer is negative
49 c
50  if (num.lt.0) then
51  nchar = nchar + 1
52  loc(1) = '-'
53  istart = istart + 1
54  endif
55 c
56 c --- convert digit by digit starting with the least significant digit
57 c
58  do 100 i = nchar, istart, -1
59  itemp = irem / 10
60  loc(i) = char(irem - itemp * 10 + ichar('0'))
61  irem = itemp
62  100 continue
63 c
64 c --- put an asterisk at the first position if the actual number of
65 c --- digits in the integer is found greater than nchar
66 c
67  if (irem.ne.0) loc(1) = '*'
68 c
69  return
70  end
71 c***********************************************************************
subroutine convtc(num, nchar, loc)
Definition: ocn.f:156