TPCCLIB
Loading...
Searching...
No Matches
dcmvr.c
Go to the documentation of this file.
1
4/*****************************************************************************/
5#include "tpcclibConfig.h"
6/*****************************************************************************/
7#include <stdio.h>
8#include <stdlib.h>
9#include <math.h>
10#include <time.h>
11#include <string.h>
12/*****************************************************************************/
13#include "tpcextensions.h"
14/*****************************************************************************/
15#include "tpcdcm.h"
16/*****************************************************************************/
17
18/*****************************************************************************/
21typedef struct DCM_VR {
23 dcmvr vr;
25 char name[8];
27 unsigned char res;
29 short int es;
31 size_t s;
33 char descr[64];
34} DCM_VR;
35
41static DCM_VR dcm_vr[]={
42 {DCM_VR_AE, "AE", 0, 0, 16, "application entity"},
43 {DCM_VR_AS, "AS", 0, 0, 4, "age string"},
44 {DCM_VR_AT, "AT", 0, 0, 4, "attribute tag"},
45 {DCM_VR_CS, "CS", 0, 0, 16, "code string"},
46 {DCM_VR_DA, "DA", 0, 0, 8, "date"},
47 {DCM_VR_DS, "DS", 0, 0, 16, "decimal string"}, // actual files may contain longer strings too
48 {DCM_VR_DT, "DT", 0, 0, 26, "date and time"},
49 {DCM_VR_FL, "FL", 0, 1, 4, "floating point single precision"},
50 {DCM_VR_FD, "FD", 0, 1, 8, "floating point double precision"},
51 {DCM_VR_IS, "IS", 0, 0, 12, "integer string"},
52 {DCM_VR_LO, "LO", 0, 0, 64, "long string"},
53 {DCM_VR_LT, "LT", 0, 0, 10240, "long text"},
54 {DCM_VR_OB, "OB", 2, 0, 0, "other byte (8-bit) stream"}, // even bytes
55 {DCM_VR_OD, "OD", 2, 1, 0, "other double (64-bit) stream"},
56 {DCM_VR_OF, "OF", 2, 1, 0, "other float (32-bit) stream"},
57 {DCM_VR_OL, "OL", 2, 1, 0, "other long (32-bit) stream"},
58 {DCM_VR_OW, "OW", 2, 1, 0, "other word (16-bit) stream"},
59 {DCM_VR_PN, "PN", 0, 0, 64, "person name"},
60 {DCM_VR_SH, "SH", 0, 0, 16, "short string"},
61 {DCM_VR_SL, "SL", 0, 1, 4, "signed long (32-bit integer)"},
62 {DCM_VR_SQ, "SQ", 2, 0, 0, "sequence of elements (used for nested data)"},
63 {DCM_VR_SS, "SS", 0, 1, 2, "signed short (16-bit integer)"},
64 {DCM_VR_ST, "ST", 0, 0, 1024, "short text"},
65 {DCM_VR_TM, "TM", 0, 0, 14, "time"},
66 {DCM_VR_UC, "UC", 2, 0, 0, "unlimited characters"},
67 {DCM_VR_UI, "UI", 0, 0, 64, "UID"},
68 {DCM_VR_UL, "UL", 0, 1, 4, "unsigned long (32-bit integer)"},
69 {DCM_VR_UN, "UN", 2, 0, 0, "unknown, any valid length of another VR"},
70 {DCM_VR_UR, "UR", 2, 0, 64, "URI or URL string"},
71 {DCM_VR_US, "US", 0, 1, 2, "unsigned short (16-bit integer)"},
72 {DCM_VR_UT, "UT", 2, 0, 0, "unlimited text"},
73 // This MUST be kept as the last element
74 {DCM_VR_INVALID, "INVALID", 0, 0, 0, "invalid value representation"}
75};
77/*****************************************************************************/
78
79/*****************************************************************************/
85unsigned char dcmVRReserved(
87 dcmvr id
88) {
89 unsigned short int i=0;
90 while(dcm_vr[i].vr!=DCM_VR_INVALID) {
91 if(id==dcm_vr[i].vr) return(dcm_vr[i].res);
92 i++;
93 }
94 return(2);
95}
96/*****************************************************************************/
97
98/*****************************************************************************/
106 const char *s
107) {
108 if(s==NULL) return(DCM_VR_INVALID);
109 char buf[3]; buf[0]=s[0]; buf[1]=s[1]; buf[2]=(char)0;
110
111 /* Identify the VR */
112 unsigned short int i=0;
113 while(dcm_vr[i].vr!=DCM_VR_INVALID) {
114 if(strncmp(dcm_vr[i].name, buf, 2)==0) return(dcm_vr[i].vr);
115 i++;
116 }
117 return(DCM_VR_INVALID);
118}
119/*****************************************************************************/
120
121/*****************************************************************************/
128 dcmvr id
129) {
130 unsigned short int i=0;
131 while(dcm_vr[i].vr!=DCM_VR_INVALID) {
132 if(id==dcm_vr[i].vr) return(dcm_vr[i].name);
133 i++;
134 }
135 return(dcm_vr[DCM_VR_INVALID].name);
136}
137/*****************************************************************************/
138
139/*****************************************************************************/
146 dcmvr id
147) {
148 unsigned short int i=0;
149 while(dcm_vr[i].vr!=DCM_VR_INVALID) {
150 if(id==dcm_vr[i].vr) return(dcm_vr[i].s);
151 i++;
152 }
153 return(dcm_vr[DCM_VR_INVALID].s);
154}
155/*****************************************************************************/
156
157/*****************************************************************************/
164 dcmvr id
165) {
166 unsigned short int i=0;
167 while(dcm_vr[i].vr!=DCM_VR_INVALID) {
168 if(id==dcm_vr[i].vr) return(dcm_vr[i].descr);
169 i++;
170 }
171 return(dcm_vr[DCM_VR_INVALID].descr);
172}
173/*****************************************************************************/
174
175/*****************************************************************************/
181 const char *orig,
184 char *intl
185) {
186 if(orig==NULL || intl==NULL) return(NULL);
187 if(strnlen(orig, 10)<8) return(NULL);
188 if(isdigit(orig[4])) { // modern format YYYYMMDD
189 sprintf(intl, "%4.4s-%2.2s-%2.2s", orig, orig+4, orig+6);
190 } else { // old format YYYY.MM.DD
191 sprintf(intl, "%4.4s-%2.2s-%2.2s", orig, orig+5, orig+8);
192 }
193 if(strDateValid(intl)) {intl[0]=(char)0; return(NULL);}
194 return(intl);
195}
196/*****************************************************************************/
197
198/*****************************************************************************/
204 const char *orig,
207 char *intl
208) {
209 if(orig==NULL || intl==NULL) return(NULL);
210 if(strnlen(orig, 14)<6) return(NULL);
211 if(isdigit(orig[2])) { // modern format hhmmss.fract
212 sprintf(intl, "%2.2s:%2.2s:%2.2s", orig, orig+2, orig+4);
213 } else { // old format hh.mm.ss
214 sprintf(intl, "%2.2s:%2.2s:%2.2s", orig, orig+3, orig+6);
215 }
216 if(strTimeValid(intl)) {intl[0]=(char)0; return(NULL);}
217 return(intl);
218}
219/*****************************************************************************/
220
221/*****************************************************************************/
228 const char *orig,
231 char *intl
232) {
233 if(orig==NULL || intl==NULL) return(NULL);
234 if(strnlen(orig, 26)<14) return(NULL);
235 sprintf(intl, "%4.4s-%2.2s-%2.2s %2.2s:%2.2s:%2.2s",
236 orig, orig+4, orig+6, orig+8, orig+10, orig+12);
237 if(strDateTimeValid(intl, NULL)) {intl[0]=(char)0; return(NULL);}
238 return(intl);
239}
240/*****************************************************************************/
241
242/*****************************************************************************/
int strDateValid(const char *str)
Definition datetime.c:155
int strTimeValid(const char *str)
Definition datetime.c:284
int strDateTimeValid(const char *str, char *intdate)
Definition datetime.c:308
unsigned char dcmVRReserved(dcmvr id)
Definition dcmvr.c:85
size_t dcmVRVLength(dcmvr id)
Definition dcmvr.c:144
dcmvr dcmVRId(const char *s)
Definition dcmvr.c:103
char * dcmDT2intl(const char *orig, char *intl)
Definition dcmvr.c:225
char * dcmDA2intl(const char *orig, char *intl)
Definition dcmvr.c:179
char * dcmTM2intl(const char *orig, char *intl)
Definition dcmvr.c:202
char * dcmVRName(dcmvr id)
Definition dcmvr.c:126
char * dcmVRDescr(dcmvr id)
Definition dcmvr.c:162
size_t strnlen(const char *s, size_t n)
Definition stringext.c:566
Header file for libtpcdcm.
dcmvr
Definition tpcdcm.h:91
@ DCM_VR_INVALID
Invalid DICOM value representation.
Definition tpcdcm.h:123
@ DCM_VR_DT
DICOM date time, max 26 bytes.
Definition tpcdcm.h:98
@ DCM_VR_UI
DICOM unique identifier (UID), max 64 bytes.
Definition tpcdcm.h:117
@ DCM_VR_FD
DICOM floating point double precision, 8 bytes fixed.
Definition tpcdcm.h:100
@ DCM_VR_UC
DICOM unlimited characters.
Definition tpcdcm.h:116
@ DCM_VR_PN
DICOM person name, max 64 chars per component group.
Definition tpcdcm.h:109
@ DCM_VR_CS
DICOM code (control) string, max 16 bytes.
Definition tpcdcm.h:95
@ DCM_VR_SS
DICOM signed short (16-bit integer), 2 bytes fixed.
Definition tpcdcm.h:113
@ DCM_VR_SH
DICOM short string, max 16 chars.
Definition tpcdcm.h:110
@ DCM_VR_OF
DICOM other float (32-bit) stream, endian sensitive.
Definition tpcdcm.h:106
@ DCM_VR_UT
DICOM unlimited text, character string.
Definition tpcdcm.h:122
@ DCM_VR_US
DICOM unsigned short (16-bit) integer, 2 bytes fixed.
Definition tpcdcm.h:121
@ DCM_VR_TM
DICOM time HHMMSS.FFFFFF, max 14 bytes.
Definition tpcdcm.h:115
@ DCM_VR_OB
DICOM other byte string, even bytes, endian insensitive.
Definition tpcdcm.h:104
@ DCM_VR_AS
DICOM age string, 4 bytes fixed.
Definition tpcdcm.h:93
@ DCM_VR_ST
DICOM short text, max 1024 chars.
Definition tpcdcm.h:114
@ DCM_VR_AT
DICOM attribute tag, 4 bytes fixed.
Definition tpcdcm.h:94
@ DCM_VR_LT
DICOM long text, max 10240 chars.
Definition tpcdcm.h:103
@ DCM_VR_DA
DICOM date in format YYYYMMDD, 8 bytes fixed.
Definition tpcdcm.h:96
@ DCM_VR_UL
DICOM unsigned long (32-bit) integer, 4 bytes fixed.
Definition tpcdcm.h:118
@ DCM_VR_UN
DICOM unknown, any valid length of another VR.
Definition tpcdcm.h:119
@ DCM_VR_DS
DICOM decimal string, max 16 bytes.
Definition tpcdcm.h:97
@ DCM_VR_OW
DICOM other word (16-bit) stream, even bytes, endian sensitive.
Definition tpcdcm.h:108
@ DCM_VR_IS
DICOM integer string, max 12 bytes.
Definition tpcdcm.h:101
@ DCM_VR_AE
DICOM application entity, max 16 bytes.
Definition tpcdcm.h:92
@ DCM_VR_UR
DICOM URI or URL, string of characters.
Definition tpcdcm.h:120
@ DCM_VR_LO
DICOM long string, max 64 chars.
Definition tpcdcm.h:102
@ DCM_VR_SQ
DICOM sequence of zero or more elements (used for nested data).
Definition tpcdcm.h:112
@ DCM_VR_FL
DICOM floating point single precision, 4 bytes fixed.
Definition tpcdcm.h:99
@ DCM_VR_SL
DICOM signed long (32-bit integer), 4 bytes fixed.
Definition tpcdcm.h:111
@ DCM_VR_OL
DICOM other long (32-bit) stream, endian sensitive.
Definition tpcdcm.h:107
@ DCM_VR_OD
DICOM other double (64-bit) stream, endian sensitive.
Definition tpcdcm.h:105
Header file for library libtpcextensions.