[Proj] Revised DMS output formatter
Gerald I. Evenden
gerald.evenden at verizon.net
Sun Jun 4 15:24:07 EDT 2006
Because the old DMS output routine was somewhat limited in capability and
was *not* thread proof, a new output format procedure is available that
will replace the old one in future lproj releases.
The prototype is:
int proj_rad2dms(char *field, size_t n, const char *format, double val,
const char *sign)
where:
'field' is a character array to hold the formated string of 'val'
'n' is the size of 'field'
'format' is the C format string
'val' is the double precision radian value to be formated
'sign' is a two character string for suffix sign where 'sign[0]' is
used for positive sign of 'val' and 'sign[1]' is used for
negative 'val'. A %c specification in format designates
that the suffix form is to be used, otherwise normal '-' prefix
sign will be used.
The procedure is thread proof and requires C99 level compiler/libraries.
The following is the output of a test procedure that demonstrates the
usage of 'proj_rad2dms:
classic lproj DMS output format
test format:[%dd%d'%.3f"] sign[]
input: 33 3 7
return: 11: <33d3'7.000">
input: -3 7 45.555555
return: 11: <-3d7'45.556">
input: 0 0 77.3333333
return: 11: <0d1'17.333">
input: 0 0 -22.5
return: 11: <-0d0'22.500">
------------------------
Classic DMS output with sign suffix
test format:[%d°%02d'%07.4f"%c] sign[NS]
input: 33 3 7
return: 16: <33°03'07.0000"N>
input: -3 7 45.555555
return: 15: <3°07'45.5556"S>
input: 0 0 77.3333333
return: 15: <0°01'17.3333"N>
input: 0 0 -22.5
return: 15: <0°00'22.5000"S>
------------------------
DM output with suffix
test format:[%d°%07.4f'%c] sign[EW]
input: 33 3 7
return: 13: <33°03.1167'E>
input: -3 7 45.555555
return: 12: <3°07.7593'W>
input: 0 0 77.3333333
return: 12: <0°01.2889'E>
input: 0 0 -22.5
return: 12: <0°00.3750'W>
------------------------
GRASS style (at least in the old days(?))
test format:[%d:%d:%7.4f] sign[EW]
input: 33 3 7
return: 12: <33:3: 7.0000>
input: -3 7 45.555555
return: 11: <-3:7:45.5556>
input: 0 0 77.3333333
return: 11: <0:1:17.3333>
input: 0 0 -22.5
return: 11: <-0:0:22.5000>
------------------------
simple degree output
test format:[%g] sign[]
input: 33 3 7
return: 7: <33.0519>
input: -3 7 45.555555
return: 8: <-3.12932>
input: 0 0 77.3333333
return: 9: <0.0214815>
input: 0 0 -22.5
return: 8: <-0.00625>
For anyone wanting a copy of the procedure for testing or application
in an existing application, I will be glad to email a tgz file containing:
proj_rad2dms.c, test.c, rad2dms.h, Makefile, and test1 script.
--
Jerry and the low-riders: Daisy Mae and Joshua
"Cogito cogito ergo cogito sum"
Ambrose Bierce, The Devil's Dictionary
More information about the Proj
mailing list