Debian Codegraph @

libsrc/st/scdb.c

raw
1 /*===========================================================================
2 Copyright (C) 1995-2009 European Southern Observatory (ESO)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with this program; if not, write to the Free
16 Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
17 MA 02139, USA.
18
19 Correspondence concerning ESO-MIDAS should be addressed as follows:
20 Internet e-mail: [email protected]
21 Postal address: European Southern Observatory
22 Data Management Division
23 Karl-Schwarzschild-Strasse 2
24 D 85748 Garching bei Muenchen
25 GERMANY
26 ===========================================================================*/
27
28 /*+++++++++++++++++++++++++++ SC interface module SCDD +++++++++++++++++++++++
29 .LANGUAGE C
30 .IDENTIFICATION Module SCDD
31 .AUTHOR K. Banse ESO - Garching
32 .KEYWORDS standard interfaces, descriptors
33 .ENVIRONMENT VMS and UNIX
34 .COMMENTS holds wdscdirec, SCDWRi, SCDHWi (i=C,D,S,H,I,R,L)
35
36 .VERSION [1.00] 920211: pull out from scd.c
37
38 090323 last modif
39
40 ----------------------------------------------------------------------------*/
41
42 #include <stdlib.h>
43 #include <fileexts.h>
44
45 #include <stdlib.h>
46 #include <stdio.h>
47
48
49
50 #define DMULT DD_SIZE/II_SIZE
51 #define SMULT SS_SIZE/II_SIZE
52
53
54 static char dtype[4], help[72], realdescr[52];
55
56 static int newlen, first, bytelem, dblock, dindx, dunit, dsclen;
57
58 static struct FCB_STRUCT *fcbp;
59
60 static struct FCT_STRUCT *fctpntr;
61
62
63 /*
64
65 */
66
67 int wdscdirec(jmno,descr,noelm,felem,nval)
68
69 /*++++++++++++++++++++++++++++++++++++++++++++++++++
70 .PURPOSE
71 handle lower level descr directory stuff common to all descr tytpes
72 .ALGORITHM
73 .RETURNS
74 return status ( 0 = o.k. )
75 --------------------------------------------------*/
76
77 int *jmno; /* IN : no. of data frame */
78 char *descr; /* IN : descriptor name */
79 int noelm; /* IN : CHAR*noelm */
80 int felem; /* IN : first element to write */
81 int nval; /* IN : no. of data values to write */
82
83 {
84 int imno, status, noelem;
85 int old_direc();
86
87 char thelp[72];
88
89
90
91 imno = *jmno;
92 if ( (imno < 0) || (imno >= FCT.MAXENT) || (nval <= 0) || (noelm < 1) )
93 return ERR_INPINV;
94
95 fctpntr = FCT.ENTRIES + imno;
96 if (fctpntr->PROT == 2) /* file is write protected... */
97 return ERR_FILPRO;
98
99 if (fctpntr->LINK[0] >= 2) /* we write into father frame */
100 {
101 imno = fctpntr->LINK[1];
102 fctpntr = FCT.ENTRIES + imno;
103 *jmno = imno;
104 }
105 first = felem;
106
107 dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */
108
109 /*
110 if ((strcmp(realdescr,"HYPOTHETICAL_DESCRIPTOR_NAME_0060") == 0)
111 || (strcmp(realdescr,"HYPOTHETICAL_DESCRIPTOR_NAME_0061") == 0))
112 {
113 printf("ojo!\n");
114 }
115 */
116
117 fcbp = fctpntr->FZP;
118
119 if (dtype[0] == 'H') /* update help text */
120 { /* use global help string */
121 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
122 &noelem,&dunit,&dblock,&dindx,help);
123 newlen = 0; /* avoid "old" help text writing... */
124 fctpntr->KAUX[2] = 1; /* set descriptor-modified flag */
125 return status;
126 }
127 else
128 {
129 thelp[0] = '\0';
130 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
131 &noelem,&dunit,&dblock,&dindx,thelp);
132 }
133
134 dunit = 0; /* not used yet */
135
136 if (status == ERR_DSCNPR)
137 { /* if not found, add new descriptor */
138 bytelem = noelm;
139 if (felem < 1) first = 1;
140 noelem = nval + first - 1;
141 status = MID_YDSCDIR(imno,'A',realdescr,dtype,&bytelem,
142 &noelem,&dunit,&dblock,&dindx,help); /* add descr */
143 }
144
145
146 else
147 {
148 if (dtype[0] == 'I')
149 {
150 if (status == ERR_NORMAL)
151 {
152 if (felem < 1) first = noelem + 1; /* append to the end */
153 newlen = nval + first - 1;
154
155 if (newlen > noelem)
156 status = MID_YDSCDIR(imno,'E',realdescr,dtype,&bytelem,
157 &newlen,&dunit,&dblock,&dindx,thelp);
158 }
159 }
160
161 else if (dtype[0] == 'S')
162 {
163 if (status == ERR_NORMAL)
164 {
165 if (felem < 1) first = noelem + 1; /* append to the end */
166 newlen = nval + first - 1;
167
168 if (newlen > noelem)
169 status = MID_YDSCDIR(imno,'E',realdescr,dtype,&bytelem,
170 &newlen,&dunit,&dblock,&dindx,thelp);
171 }
172 }
173
174 else if (dtype[0] == 'D') /* dtype is always updated ... */
175 {
176 if (status == ERR_DSCTYP)
177 { /* try again with correct type */
178 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
179 &noelem,&dunit,&dblock,&dindx,thelp);
180 if (status != ERR_NORMAL) return status;
181 dunit = 0;
182 }
183
184 if (status == ERR_NORMAL)
185 {
186 if (felem < 1) first = noelem + 1; /* append to the end */
187 newlen = nval + first - 1;
188
189 if (newlen > noelem)
190 status = MID_YDSCDIR(imno,'E',realdescr,dtype,&bytelem,
191 &newlen,&dunit,&dblock,&dindx,thelp);
192 }
193 }
194
195 else if (dtype[0] == 'R') /* dtype is always updated ... */
196 {
197 if (status == ERR_DSCTYP)
198 { /* try again with correct type */
199 status = MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
200 &noelem,&dunit,&dblock,&dindx,thelp);
201 if (status != ERR_NORMAL) return status;
202 dunit = 0;
203 }
204
205 if (status == ERR_NORMAL)
206 {
207 if (felem < 1) first = noelem + 1; /* append to the end */
208 newlen = nval + first - 1;
209
210 if (newlen > noelem)
211 status = MID_YDSCDIR(imno,'E',realdescr,dtype,&bytelem,
212 &newlen,&dunit,&dblock,&dindx,thelp);
213 }
214 }
215
216 else if (dtype[0] == 'C')
217 {
218 if (status == ERR_NORMAL)
219 {
220 if (noelm != bytelem)
221 return ERR_DSCBAD; /* bytes per element must match! */
222
223 if (felem < 1) first = noelem + 1; /* append to the end */
224 newlen = nval + first - 1;
225
226 if (newlen > noelem)
227 status = MID_YDSCDIR(imno,'E',realdescr,dtype,&bytelem,
228 &newlen,&dunit,&dblock,&dindx,thelp);
229 }
230 }
231
232 else /* remains (new) type 'L' */
233 {
234 if (status == ERR_NORMAL)
235 {
236 if (felem < 1) first = noelem + 1; /* append to the end */
237 newlen = nval + first - 1;
238
239 if (newlen > noelem)
240 status = MID_YDSCDIR(imno,'E',realdescr,dtype,&bytelem,
241 &newlen,&dunit,&dblock,&dindx,thelp);
242 }
243 }
244 }
245
246
247 fctpntr->KAUX[2] = 1; /* set descriptor-modified flag */
248
249 return status;
250 }
251 /*
252
253 */
254
255 int wrhelp(imno,descr,htext)
256 int imno;
257 char *descr, *htext;
258
259 {
260 int noelem, hlen;
261
262
263
264 hlen = 0;
265 if (htext != (char *) 0) hlen = (int) strlen(htext);
266 if (hlen == 0) return ERR_NORMAL; /* not an error */
267
268
269 /* no need, to check `imno' - we only get here if `imno' o.k. ...*/
270
271 fctpntr = FCT.ENTRIES + imno;
272 if (fctpntr->LINK[0] >= 2) /* we write into father frame */
273 {
274 imno = fctpntr->LINK[1];
275 fctpntr = FCT.ENTRIES + imno;
276 }
277
278
279 fcbp = fctpntr->FZP;
280 if (fcbp->DSCFLAG != 'Y') return (ERR_INPINV);
281
282 if (hlen > 71)
283 { /* global char.string has 72 chars */
284 (void) strncpy(help,htext,71);
285 help[71] = '\0';
286 }
287 else
288 (void) strcpy(help,htext);
289
290 dtype[0] = 'H';
291 dsclen = DSCNAM_COPY(realdescr,descr); /* build uppercase name */
292
293 (void) MID_YDSCDIR(imno,'F',realdescr,dtype,&bytelem,
294 &noelem,&dunit,&dblock,&dindx,help);
295
296 fctpntr->KAUX[2] = 1; /* set descriptor-modified flag */
297 return (ERR_NORMAL);
298 }
299 /*
300
301 */
302
303 int SCDHWC(imno,descr,noelm,values,felem,nval,unit,htext)
304
305 int imno /* IN : no. of data frame */;
306 char *descr /* IN : descriptor name (max. 48 char.) */;
307 int noelm /* IN : CHAR*noelm */;
308 char *values /* IN : buffer with descriptor data */;
309 int felem /* IN : position of 1st descriptor value to be accessed */;
310 int nval /* IN : no. of data values to write */;
311 int *unit /* IN : unit-pointer */;
312 char *htext /* IN : help text */;
313
314 {
315 int status;
316
317
318 status = SCDWRC(imno,descr,noelm,values,felem,nval,unit);
319
320 if (status == ERR_NORMAL) (void) wrhelp(imno,descr,htext);
321 return status;
322 }
323
324
325
326 int SCDWRC(imno,descr,noelm,values,felem,nval,unit)
327
328 /*++++++++++++++++++++++++++++++++++++++++++++++++++
329 .PURPOSE
330 Write a descriptor and its data
331 .ALGORITHM
332 A new descriptor is written at the end of the existing
333 descriptor area or exisitng descriptor data is modified
334 and extended, if necessary.
335 .RETURNS
336 return status ( 0 = o.k. )
337 .REMARKS
338 if 'felem' = -1, descriptor values are appended to existing ones
339 --------------------------------------------------*/
340
341 int imno /* IN : no. of data frame */;
342 char *descr /* IN : descriptor name (max. 48 char.) */;
343 int noelm /* IN : CHAR*noelm */;
344 char *values /* IN : buffer with descriptor data */;
345 int felem /* IN : position of 1st descriptor value to be accessed */;
346 int nval /* IN : no. of data values to write */;
347 int *unit /* IN : unit-pointer */;
348
349 {
350 int kk, status, nlen;
351 register int nr;
352 static int xlen = 0;
353
354 static char *xpntr = (char *) 0;
355
356
357
358 dtype[0] = 'C';
359 help[0] = '\0';
360 status = wdscdirec(&imno,descr,noelm,felem,nval);
361
362 if (status == ERR_NORMAL)
363 {
364 nlen = nval * bytelem; /* char array -> flat string */
365 first = (first-1)*bytelem + 1;
366
367 for (nr=0; nr<nlen; nr++)
368 {
369 if (values[nr] == '\0') /* we don't have enough data */
370 {
371 kk = nr;
372 if (xlen < nlen) /* need to allocate more */
373 {
374 if (xpntr != (char *) 0) free(xpntr);
375
376 xpntr = malloc((size_t)nlen);
377 if (xpntr == (char *) 0)
378 {
379 xpntr = values;
380 nlen = kk; /* all what we can do ... */
381 }
382 xlen = nlen;
383 }
384
385 /* first copy data, then pad wth blanks */
386
387 (void) memcpy(xpntr,values,(size_t)kk); /* copy */
388 (void) memset(xpntr+kk,32,(size_t)(nlen-kk)); /* and pad */
389
390 (void) MID_WDSCRC(fctpntr->IOCHAN,dblock,dindx,xpntr,0,first,nlen);
391 return ERR_NORMAL;
392 }
393 }
394
395 (void) MID_WDSCRC(fctpntr->IOCHAN,dblock,dindx,values,0,first,nlen);
396 }
397
398 else
399 MID_E2(5,imno,descr,status,1);
400
401
402 return (status);
403 }
404 /*
405
406 */
407
408 int SCDHWD(imno,descr,values,felem,nval,unit,htext)
409
410 int imno /* IN : no. of data frame */;
411 char *descr /* IN : descriptor name (max. 48 char.) */;
412 double *values /* IN : buffer with descriptor data */;
413 int felem /* IN : position of 1st descriptor value to be accessed */;
414 int nval /* IN : no. of data values to write */;
415 int *unit /* IN : unit-pointer */;
416 char *htext /* IN : help text */;
417
418 {
419 int status;
420
421
422 status = SCDWRD(imno,descr,values,felem,nval,unit);
423
424 if (status == ERR_NORMAL) (void) wrhelp(imno,descr,htext);
425 return status;
426 }
427
428
429
430 int SCDWRD(imno,descr,values,felem,nval,unit)
431
432 /*++++++++++++++++++++++++++++++++++++++++++++++++++
433 .PURPOSE
434 Write a descriptor and its data
435 .ALGORITHM
436 A new descriptor is written at the end of the existing
437 descriptor area or existing descriptor data is modified
438 and extended, if necessary.
439 .RETURNS
440 return status ( 0 = o.k. )
441 .REMARKS
442 if 'felem' = -1, descriptor values are appended to existing ones
443 --------------------------------------------------*/
444
445 int imno /* IN : no. of data frame */;
446 char *descr /* IN : descriptor name (max. 48 char.) */;
447 double *values /* IN : buffer with descriptor data */;
448 int felem /* IN : position of 1st descriptor value to be accessed */;
449 int nval /* IN : no. of data values to write */;
450 int *unit /* IN : unit-pointer */;
451
452 {
453 int n, status, *ipntr;
454
455
456
457 dtype[0] = 'D';
458 help[0] = '\0';
459 status = wdscdirec(&imno,descr,DD_SIZE,felem,nval);
460
461
462 if (status == ERR_NORMAL)
463 {
464 if (dtype[0] == 'R') /* write double data to real descr */
465 {
466 float *rvals;
467 char tmp[80], *mypntr;
468
469 n = RR_SIZE * nval;
470 mypntr = malloc((size_t) n);
471 if (mypntr == (char *) 0)
472 {
473 status = ERR_MEMOUT;
474 goto end_of_it;
475 }
476 rvals = (float *)mypntr;
477
478 for (n=0; n<nval; n++) /* double -> float data */
479 *rvals++ = (float) values[n];
480 rvals = (float *)mypntr; /* set back to start */
481 (void) MID_WDSCRR(fctpntr->IOCHAN,dblock,dindx,rvals,0,first,nval);
482 (void) free (mypntr);
483
484 (void) sprintf(tmp,"SCDWRD with descr: %s",descr);
485 status = ERR_LOSPRC; /* send a warning */
486 MID_ERROR("MID",tmp,status,1);
487 }
488
489 else
490 { /* use MID_WDSCRI to write double precision descr... */
491 newlen = DMULT * nval;
492 first = (DMULT * first) - 1;
493 ipntr = (int *) values;
494 (void) MID_WDSCRI(fctpntr->IOCHAN,dblock,dindx,ipntr,0,first,newlen);
495 }
496
497 return ERR_NORMAL;
498 }
499
500
501 end_of_it:
502 MID_E2(5,imno,descr,status,1);
503 return (status);
504 }
505 /*
506
507 */
508
509 int SCDHWS(imno,descr,values,felem,nval,unit,htext)
510
511 int imno /* IN : no. of data frame */;
512 char *descr /* IN : descriptor name (max. 48 char.) */;
513 size_t *values /* IN : buffer with descriptor data */;
514 int felem /* IN : position of 1st descriptor value to be accessed */;
515 int nval /* IN : no. of data values to write */;
516 int *unit /* IN : unit-pointer */;
517 char *htext /* IN : help text */;
518
519 {
520 int status;
521
522
523 status = SCDWRS(imno,descr,values,felem,nval,unit);
524
525 if (status == ERR_NORMAL) (void) wrhelp(imno,descr,htext);
526 return status;
527 }
528
529
530
531 int SCDWRS(imno,descr,values,felem,nval,unit)
532
533 /*++++++++++++++++++++++++++++++++++++++++++++++++++
534 .PURPOSE
535 Write a descriptor and its data
536 .ALGORITHM
537 A new descriptor is written at the end of the existing
538 descriptor area or existing descriptor data is modified
539 and extended, if necessary.
540 .RETURNS
541 return status ( 0 = o.k. )
542 .REMARKS
543 if 'felem' = -1, descriptor values are appended to existing ones
544 --------------------------------------------------*/
545
546 int imno /* IN : no. of data frame */;
547 char *descr /* IN : descriptor name (max. 48 char.) */;
548 size_t *values /* IN : buffer with descriptor data */;
549 int felem /* IN : position of 1st descriptor value to be accessed */;
550 int nval /* IN : no. of data values to write */;
551 int *unit /* IN : unit-pointer */;
552
553 {
554 int status, *ipntr;
555
556
557
558 dtype[0] = 'S';
559 help[0] = '\0';
560 status = wdscdirec(&imno,descr,SS_SIZE,felem,nval);
561
562
563 if (status == ERR_NORMAL)
564 { /* use MID_WDSCRI to write size_t descr... */
565 newlen = SMULT * nval;
566 first = (SMULT * first) - 1;
567 ipntr = (int *) values;
568 (void) MID_WDSCRI(fctpntr->IOCHAN,dblock,dindx,ipntr,0,first,newlen);
569
570 return ERR_NORMAL;
571 }
572
573
574 MID_E2(5,imno,descr,status,1);
575 return (status);
576 }
577 /*
578
579 */
580
581 int SCDHWL(imno,descr,values,felem,nval,unit,htext)
582
583 int imno /* IN : no. of data frame */;
584 char *descr /* IN : descriptor name (max. 48 char.) */;
585 int *values /* IN : buffer with (logical) descriptor data */;
586 int felem /* IN : position of 1st descriptor value to be accessed */;
587 int nval /* IN : no. of data values to write */;
588 int *unit /* IN : unit-pointer */;
589 char *htext /* IN : help text */;
590
591 {
592 int status;
593
594
595 status = SCDWRL(imno,descr,values,felem,nval,unit);
596
597 if (status == ERR_NORMAL) (void) wrhelp(imno,descr,htext);
598 return status;
599 }
600
601
602
603 int SCDWRL(imno,descr,values,felem,nval,unit)
604
605 /*++++++++++++++++++++++++++++++++++++++++++++++++++
606 .PURPOSE
607 Write a descriptor and its data
608 .ALGORITHM
609 A new descriptor is written at the end of the existing
610 descriptor area or exisitng descriptor data is modified
611 and extended, if necessary.
612 .RETURNS
613 return status ( 0 = o.k. )
614 .REMARKS
615 if 'felem' = -1, descriptor values are appended to existing ones
616 --------------------------------------------------*/
617
618 int imno /* IN : no. of data frame */;
619 char *descr /* IN : descriptor name (max. 48 char.) */;
620 int *values /* IN : buffer with (logical) descriptor data */;
621 int felem /* IN : position of 1st descriptor value to be accessed */;
622 int nval /* IN : no. of data values to write */;
623 int *unit /* IN : unit-pointer */;
624
625 {
626 int status;
627
628
629
630 dtype[0] = 'L';
631 help[0] = '\0';
632 status = wdscdirec(&imno,descr,II_SIZE,felem,nval);
633
634 if (status == ERR_NORMAL)
635 (void) MID_WDSCRI(fctpntr->IOCHAN,dblock,dindx,values,0,first,nval);
636 else
637 MID_E2(5,imno,descr,status,1);
638
639 return (status);
640 }
641 /*
642
643 */
644
645 int SCDHWI(imno,descr,values,felem,nval,unit,htext)
646
647 int imno /* IN : no. of data frame */;
648 char *descr /* IN : descriptor name (max. 48 char.) */;
649 int *values /* IN : buffer with descriptor data */;
650 int felem /* IN : position of 1st descriptor value to be accessed */;
651 int nval /* IN : no. of data values to write */;
652 int *unit /* IN : unit-pointer */;
653 char *htext /* IN : help text */;
654
655 {
656 int status;
657
658
659 status = SCDWRI(imno,descr,values,felem,nval,unit);
660
661 if (status == ERR_NORMAL) (void) wrhelp(imno,descr,htext);
662 return status;
663 }
664
665
666
667 int SCDWRI(imno,descr,values,felem,nval,unit)
668
669 /*++++++++++++++++++++++++++++++++++++++++++++++++++
670 .PURPOSE
671 Write a descriptor and its data
672 .ALGORITHM
673 A new descriptor is written at the end of the existing
674 descriptor area or exisitng descriptor data is modified
675 and extended, if necessary.
676 .RETURNS
677 return status ( 0 = o.k. )
678 .REMARKS
679 if 'felem' = -1, descriptor values are appended to existing ones
680 --------------------------------------------------*/
681
682 int imno /* IN : no. of data frame */;
683 char *descr /* IN : descriptor name (max. 48 char.) */;
684 int *values /* IN : buffer with descriptor data */;
685 int felem /* IN : position of 1st descriptor value to be accessed */;
686 int nval /* IN : no. of data values to write */;
687 int *unit /* IN : unit-pointer */;
688
689 {
690 int status;
691
692
693
694
695 dtype[0] = 'I';
696 help[0] = '\0';
697 status = wdscdirec(&imno,descr,II_SIZE,felem,nval);
698
699
700 if (status == ERR_NORMAL)
701 {
702 (void) MID_WDSCRI(fctpntr->IOCHAN,dblock,dindx,values,0,first,nval);
703
704 if (realdescr[0] == 'N')
705 { /* NAXIS, NPIX also -> FCB */
706 int *npix;
707
708 if (strcmp(realdescr,"NAXIS") == 0)
709 fcbp->DATAINFO[0] = *values; /* keep FCB info in sync */
710 else if (strcmp(realdescr,"NPIX") == 0)
711 {
712 if (first < 4)
713 {
714 npix = values;
715 fcbp->DATAINFO[first++] = *npix++;
716 if ( ((--nval) > 0) && (first < 4) )
717 {
718 fcbp->DATAINFO[first++] = *npix++;
719 if ( ((--nval) > 0) && (first < 4) )
720 fcbp->DATAINFO[first] = *npix;
721 }
722 }
723 }
724 }
725 return ERR_NORMAL;
726 }
727
728 MID_E2(5,imno,descr,status,1);
729 return (status);
730 }
731 /*
732
733 */
734
735 int SCDHWR(imno,descr,values,felem,nval,unit,htext)
736
737 int imno /* IN : no. of data frame */;
738 char *descr /* IN : descriptor name (max. 48 char.) */;
739 float *values /* IN : buffer with descriptor data */;
740 int felem /* IN : position of 1st descriptor value to be accessed */;
741 int nval /* IN : no. of data values to write */;
742 int *unit /* IN : unit-pointer */;
743 char *htext /* IN : help text */;
744
745 {
746 int status;
747
748
749 status = SCDWRR(imno,descr,values,felem,nval,unit);
750
751 if (status == ERR_NORMAL) (void) wrhelp(imno,descr,htext);
752 return status;
753 }
754
755
756
757 int SCDWRR(imno,descr,values,felem,nval,unit)
758
759 /*++++++++++++++++++++++++++++++++++++++++++++++++++
760 .PURPOSE
761 Write a descriptor and its data
762 .ALGORITHM
763 A new descriptor is written at the end of the existing
764 descriptor area or exisitng descriptor data is modified
765 and extended, if necessary.
766 .RETURNS
767 return status ( 0 = o.k. )
768 .REMARKS
769 if 'felem' = -1, descriptor values are appended to existing ones
770 --------------------------------------------------*/
771
772 int imno /* IN : no. of data frame */;
773 char *descr /* IN : descriptor name (max. 48 char.) */;
774 float *values /* IN : buffer with descriptor data */;
775 int felem /* IN : position of 1st descriptor value to be accessed */;
776 int nval /* IN : no. of data values to write */;
777 int *unit /* IN : unit-pointer */;
778
779 {
780 int status;
781
782
783
784
785 dtype[0] = 'R';
786 help[0] = '\0';
787 status = wdscdirec(&imno,descr,RR_SIZE,felem,nval);
788
789
790 if (status == ERR_NORMAL)
791 {
792 if (dtype[0] == 'D') /* write real data to double descr */
793 {
794 double *dvals;
795 int *ipntr, n;
796 char *mypntr;
797
798 n = DD_SIZE * nval;
799 mypntr = malloc((size_t) n);
800 if (mypntr == (char *) 0)
801 {
802 status = ERR_MEMOUT;
803 goto end_of_it;
804 }
805 dvals = (double *)mypntr;
806 for (n=0; n<nval; n++) /* float -> double data */
807 *dvals++ = (double) values[n];
808 ipntr = (int *) mypntr; /* set to start of double data */
809
810 n = DD_SIZE/II_SIZE;
811 newlen = n * nval;
812 first = (n * first) - 1;
813 (void) MID_WDSCRI(fctpntr->IOCHAN,dblock,dindx,ipntr,0,first,newlen);
814 (void) free (mypntr);
815 }
816
817 else
818 (void) MID_WDSCRR(fctpntr->IOCHAN,dblock,dindx,values,0,first,nval);
819
820 return ERR_NORMAL;
821 }
822
823 end_of_it:
824 MID_E2(5,imno,descr,status,1);
825 return (status);
826 }
827 /*
828
829 */
830
831 int SCDWRH(imno,descr,values,felem,nval)
832
833 /*++++++++++++++++++++++++++++++++++++++++++++++++++
834 .PURPOSE
835 Write a HELP descriptor and its data
836 .ALGORITHM
837 A new descriptor is written at the end of the existing
838 descriptor area or existing descriptor data is modified
839 and extended, if necessary.
840 .RETURNS
841 return status ( 0 = o.k. )
842 .REMARKS
843 if 'felem' = -1, descriptor values are appended to existing ones
844 --------------------------------------------------*/
845
846 int imno /* IN : no. of data frame */;
847 char *descr /* IN : descriptor name (max. 48 char.) */;
848 char *values /* IN : buffer with descriptor data */;
849 int felem /* IN : position of 1st descriptor value to be accessed */;
850 int nval /* IN : no. of data values to write */;
851
852 {
853 int status;
854
855
856
857
858 dtype[0] = 'H';
859
860 if (nval > 71) nval = 71; /* global char.string has 72 chars */
861 (void) memcpy(help,values,(size_t)nval);
862 help[nval] = '\0';
863
864 status = wdscdirec(&imno,descr,1,felem,nval);
865
866 if (status == ERR_NORMAL)
867 {
868 if (newlen > 0) /* use static newlen */
869 (void) MID_WDSCRC(fctpntr->IOCHAN,dblock,dindx,values,0,first,newlen);
870 }
871 else
872 MID_E2(5,imno,descr,status,1);
873
874 return (status);
875 }
876