OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
make_queue.c
Go to the documentation of this file.
1 #include "L1A_prototype.h"
2 #include "PGS_MODIS_35005.h"
3 #include "FP_failed_pkt_queue.h"
4 
5 
6 FP_QUEUE_t make_queue (void)
7 
8 /*
9 !C************************************************************************
10 
11 !Description: Creates a new linked list FIFO queue.
12 
13 !Input Parameters:
14  None
15 
16 !Output Parameters:
17  None
18 
19 Return Values:
20  FP_QUEUE_t Q ** The newly created FIFO queue **
21  MODIS_E_MALLOC_FAILED (PGS_MODIS_35005.t)
22 
23 Externally Defined:
24  FP_QUEUE_t (FP_failed_pkt_queue.h)
25 
26 Called By:
27  level1a
28 
29 Routines Called:
30  log_fmt_msg
31 
32 !Revision History:
33  Revision 1.1 1997/09/03 10:55
34  Tom Johnson/GSC (johnson@ltpmail.gsfc.nasa.gov)
35  Incorporate walkthrough comments
36 
37  Revision 1.0 1997/07/14 15:58 EDT
38  David Catozzi/SAIC/GSC (cato@ltpmail.gsfc.nasa.gov)
39  Original design.
40 
41 !Team-unique Header:
42  This software is developed by the MODIS Science
43  Data Support Team (SDST) for the National Aeronautics
44  and Space Administration (NASA), Goddard Space Flight
45  Center (GSFC), under contract NAS5-32373.
46 
47 !References and Credits:
48  None
49 
50 !Design Notes:
51  None
52 
53 !END************************************************************************
54 */
55 
56 {
57 
58  /**************************************************************************/
59  /* Declare and Initialize Local Variables */
60  /* */
61  /**************************************************************************/
62 
63  FP_QUEUE_t Q;
64 
65  char *routine = "make_queue";
66 
67  /**************************************************************************/
68 
69  /**************************************************************************/
70  /* */
71  /* set routine to "make_queue" (done during declaration) */
72  /* */
73  /**************************************************************************/
74 
75 
76  /**************************************************************************/
77  /* */
78  /* dynamically allocate memory for the queue (Q) */
79  /* IF ( Q equals NULL ) */
80  /* THEN */
81  /* CALL log_fmt_msg to report the memory allocation error */
82  /* INPUTS: Status, routine, msg */
83  /* OUTPUTS: None */
84  /* RETURN: None */
85  /* */
86  /**************************************************************************/
87 
88  Q = (struct queue_record *) malloc( sizeof (struct queue_record) );
89  if (Q == NULL)
91  "unable to allocate memory for the failed packets queue");
92 
93 
94  /**************************************************************************/
95  /* */
96  /* ELSE */
97  /* dynamically allocate memory for the queue (Q.head) */
98  /* IF ( Q.head equals NULL ) */
99  /* THEN */
100  /* set Status to MODIS_E_MALLOC_FAILED */
101  /* CALL log_fmt_msg to report the memory allocation error */
102  /* INPUTS: Status, routine, msg */
103  /* OUTPUTS: None */
104  /* RETURN: None */
105  /* set Q to NULL */
106  /* */
107  /**************************************************************************/
108 
109  else
110  {
111  Q->head = (node_ptr) malloc( sizeof (struct node) );
112 
113  if ( Q->head == NULL)
114  {
116  "unable to allocate memory for the failed packet queue's head");
117  Q = NULL;
118  }
119 
120 
121  /***********************************************************************/
122  /* */
123  /* ELSE */
124  /* dynamically allocate memory for the queue (Q.tail) */
125  /* IF ( Q.head.next equals NULL ) */
126  /* THEN */
127  /* set Status to MODIS_E_MALLOC_FAILED */
128  /* CALL log_fmt_msg to report the memory allocation error */
129  /* INPUTS: Status, routine, msg */
130  /* OUTPUTS: None */
131  /* RETURN: None */
132  /* set Q to NULL */
133  /* */
134  /***********************************************************************/
135 
136  else
137  {
138  Q->head->next = (node_ptr) malloc( sizeof (struct node));
139  if (Q->head->next == NULL)
140  {
142  "unable to allocate memory for the failed packet queue's tail");
143  Q = NULL;
144  }
145 
146 
147  /********************************************************************/
148  /* */
149  /* ELSE */
150  /* set Q.tail to Q.head.next */
151  /* set Q.tail.prev to Q.head */
152  /* */
153  /********************************************************************/
154 
155  else
156  {
157  Q->tail = Q->head->next;
158  Q->tail->prev = Q->head;
159 
160 
161  /**************************************************************************/
162  /* */
163  /* ENDIF */
164  /* ENDIF */
165  /* ENDIF */
166  /* */
167  /* return Q */
168  /* */
169  /**************************************************************************/
170 
171  }
172  }
173  }
174 
175  return (Q);
176 }
#define NULL
Definition: decode_rs.h:63
#define MODIS_E_MALLOC_FAILED
FP_QUEUE_t make_queue(void)
Definition: make_queue.c:6
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6