1 /* ----------------------------- MNI Header -----------------------------------
2 @NAME       : gcomserver.h
3 @DESCRIPTION: Header file that includes things needed for gcomserver.
4 @METHOD     :
5 @GLOBALS    :
6 @CREATED    : November 23, 1993 (Peter Neelin)
7 @MODIFIED   :
8  * $Log: gcomserver.h,v $
9  * Revision 6.7  2001-04-21 13:29:57  neelin
10  * Added support for PROJECT_CAPTURE project type.
11  *
12  * Revision 6.6  2001/04/09 23:02:48  neelin
13  * Modified copyright notice, removing permission statement since copying,
14  * etc. is probably not permitted by our non-disclosure agreement with
15  * Philips.
16  *
17  * Revision 6.5  2000/06/14 18:24:08  neelin
18  * Added UseSafeOrientations keyword to project files to allow forcing of
19  * direction cosines to standard (safe) ones, and modified convert_to_dicom
20  * so that this is no longer the default behaviour.
21  *
22  * Revision 6.4  2000/02/21 23:48:14  neelin
23  * More changes to improve dicom conformance for MNH PACS system.
24  * Allow UID prefix to be defined in project file. Define SOP instance UID in
25  * addition to study and series instance UIDs and frame-of-reference UID and
26  * make sure that these are all the constant for the same image data.
27  * Set series number from acquisition number.
28  * Set study description from part of comment field.
29  *
30  * Revision 6.3  2000/01/31 13:57:38  neelin
31  * Added keyword to project file to allow definition of the local AEtitle.
32  * A simple syntax allows insertion of the host name into the AEtitle.
33  *
34  * Revision 6.2  1999/10/29 17:52:03  neelin
35  * Fixed Log keyword
36  *
37  * Revision 6.1  1997/09/12 23:13:28  neelin
38  * Added ability to convert gyrocom images to dicom images.
39  *
40  * Revision 6.0  1997/09/12  13:23:50  neelin
41  * Release of minc version 0.6
42  *
43  * Revision 5.1  1997/09/11  13:09:40  neelin
44  * Added more complicated syntax for project files so that different things
45  * can be done to the data. The old syntax is still supported.
46  *
47  * Revision 5.0  1997/08/21  13:24:50  neelin
48  * Release of minc version 0.5
49  *
50  * Revision 4.0  1997/05/07  20:01:07  neelin
51  * Release of minc version 0.4
52  *
53  * Revision 3.0  1995/05/15  19:31:44  neelin
54  * Release of minc version 0.3
55  *
56  * Revision 2.1  1995/02/14  18:12:26  neelin
57  * Added project names and defaults files (using volume name).
58  * Added process id to log file name.
59  * Moved temporary files to subdirectory.
60  *
61  * Revision 2.0  1994/09/28  10:35:25  neelin
62  * Release of minc version 0.2
63  *
64  * Revision 1.9  94/09/28  10:34:56  neelin
65  * Pre-release
66  *
67  * Revision 1.8  94/05/24  15:09:57  neelin
68  * Break up multiple echoes or time frames into separate files for 2 echoes
69  * or 2 frames (put in 1 file for more).
70  * Changed units of repetition time, echo time, etc to seconds.
71  * Save echo times in dimension variable when appropriate.
72  * Changed to file names to end in _mri.mnc.
73  *
74  * Revision 1.7  94/04/07  11:03:37  neelin
75  * Changed error handling to be more explicit about errors.
76  * When the server terminates due to an error, a message is printed to /dev/log.
77  * Changed handling of file cleanup.
78  *
79  * Revision 1.6  94/01/14  11:37:40  neelin
80  * Fixed handling of multiple reconstructions and image types. Add spiinfo variable with extra info (including window min/max). Changed output
81  * file name to include reconstruction number and image type number.
82  *
83  * Revision 1.5  94/01/11  12:38:42  neelin
84  * Modified handling of output directory and user id.
85  * Defaults are current dir and no chown.
86  * Read from file /usr/local/lib/gcomserver.<hostname>
87  *
88  * Revision 1.4  93/12/10  15:35:46  neelin
89  * Improved file name generation from patient name. No buffering on stderr.
90  * Added spi group list to minc header.
91  * Optionally read a defaults file to get output minc directory and owner.
92  *
93  * Revision 1.3  93/11/30  14:42:41  neelin
94  * Copies to minc format.
95  *
96  * Revision 1.2  93/11/25  13:27:25  neelin
97  * Working version.
98  *
99  * Revision 1.1  93/11/23  14:13:43  neelin
100  * Initial revision
101  *
102 @COPYRIGHT  :
103               Copyright 1993 Peter Neelin, McConnell Brain Imaging Centre,
104               Montreal Neurological Institute, McGill University.
105 ---------------------------------------------------------------------------- */
106 
107 #include <stdlib.h>
108 #include <stdio.h>
109 #include <unistd.h>
110 #include <string.h>
111 #include <ctype.h>
112 #include <memory.h>
113 #include <limits.h>
114 #ifdef FLT_DIG
115 #  undef FLT_DIG
116 #endif
117 #ifdef DBL_DIG
118 #  undef DBL_DIG
119 #endif
120 #ifdef DBL_MIN
121 #  undef DBL_MIN
122 #endif
123 #ifdef DBL_MAX
124 #  undef DBL_MAX
125 #endif
126 #include <float.h>
127 #include <minc_def.h>
128 #include <time_stamp.h>
129 #include <acr_nema.h>
130 #include <spi_element_defs.h>
131 
132 #ifndef TRUE
133 #  define TRUE 1
134 #endif
135 #ifndef FALSE
136 #  define FALSE 0
137 #endif
138 
139 /* Define logging constants */
140 #define NO_LOGGING   0
141 #define LOW_LOGGING  1
142 #define HIGH_LOGGING 2
143 
144 /* File containing defaults for gcomserver */
145 #define OUTPUT_DEFAULT_FILE_DIR "/usr/local/lib"
146 #define OUTPUT_DEFAULT_FILE_PREFIX "gcomserver."
147 #define OUTPUT_DEFAULT_FILE_SUFFIX "default"
148 
149 /* String lengths */
150 #define SHORT_LINE 64
151 #define LONG_LINE 512
152 #define MAX_AE_LEN 16
153 
154 /* System log file (set to NULL for no logging of error) */
155 #define SYSTEM_LOG "/dev/log"
156 
157 /* Type for carrying around object information */
158 typedef struct {
159    int study_id;
160    int acq_id;
161    int rec_num;
162    int image_type;
163    int num_echoes;
164    int echo_number;
165    int num_dyn_scans;
166    int dyn_scan_number;
167 } Data_Object_Info;
168 
169 /* Type for project file information */
170 typedef struct {
171 
172    /* Type of information stored in project file */
173    enum {PROJECT_DIRECTORY, PROJECT_DICOM, PROJECT_CAPTURE,
174          PROJECT_UNKNOWN} type;
175 
176    /* Information associated with project */
177    union {
178 
179       /* Information for storing data in directories */
180       struct {
181          char file_prefix[LONG_LINE];
182          int output_uid;
183          int output_gid;
184          char command_line[LONG_LINE];
185       } directory;
186 
187       /* Information for converting data to dicom */
188       struct {
189          char hostname[SHORT_LINE];
190          char port[SHORT_LINE];
191          char AEtitle[SHORT_LINE];
192          char LocalAEtitle[SHORT_LINE];
193          char UIDprefix[SHORT_LINE];
194          int use_safe_orientations;
195          Acr_File *afpin;
196          Acr_File *afpout;
197       } dicom;
198 
199    } info;
200 
201 } Project_File_Info;
202 
203 /* Define macro for array size */
204 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))
205 
206 #include <gyro_to_minc.h>
207 #include <gcom_prototypes.h>
208