1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright by The HDF Group.                                               *
3 * Copyright by the Board of Trustees of the University of Illinois.         *
4 * All rights reserved.                                                      *
5 *                                                                           *
6 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7 * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /* This files contains C stubs for H5D Fortran APIs */
15 
16 #include "H5IMcc.h"
17 #include "H5LTf90proto.h"
18 #include "H5Eprivate.h"
19 
20 /*-------------------------------------------------------------------------
21 * Function: h5immake_image_8bit_c
22 *
23 * Purpose: Call H5IMmake_image_8bit
24 *
25 * Return: Success: 0, Failure: -1
26 *
27 * Programmer: pvn@ncsa.uiuc.edu
28 *
29 * Date: October 05, 2004
30 *
31 * Comments:
32 *
33 * Modifications:
34 *
35 *
36 *-------------------------------------------------------------------------
37 */
38 
39 int_f
h5immake_image_8bit_c(hid_t_f * loc_id,size_t_f * namelen,_fcd name,hsize_t_f * width,hsize_t_f * height,int_f * buf)40 h5immake_image_8bit_c (hid_t_f *loc_id,
41                         size_t_f *namelen,
42                         _fcd name,
43                         hsize_t_f *width,
44                         hsize_t_f *height,
45                         int_f *buf)
46 {
47     int     ret_value = -1;
48     herr_t  ret;
49     hid_t   c_loc_id;
50     char    *c_name = NULL;
51     hsize_t w = (hsize_t)*width;
52     hsize_t h = (hsize_t)*height;
53 
54     /*
55     * convert FORTRAN name to C name
56     */
57     c_name = (char *)HD5f2cstring(name, (size_t)*namelen);
58     if (c_name == NULL)
59         goto done;
60 
61     /*
62     * call H5IMmake_image_8bitf function.
63     */
64     c_loc_id = (hid_t)*loc_id;
65     ret = H5IMmake_image_8bitf(c_loc_id,c_name,w,h,buf);
66 
67     if (ret < 0)
68         goto done;
69 
70     ret_value = 0;
71 
72 done:
73     if(c_name!=NULL)
74         HDfree(c_name);
75 
76     return ret_value;
77 
78 
79 }
80 
81 /*-------------------------------------------------------------------------
82 * Function: h5imread_image_c
83 *
84 * Purpose: Call H5IMread_image
85 *
86 * Return: Success: 0, Failure: -1
87 *
88 * Programmer: pvn@ncsa.uiuc.edu
89 *
90 * Date: October 05, 2004
91 *
92 * Comments:
93 *
94 * Modifications:
95 *
96 *
97 *-------------------------------------------------------------------------
98 */
99 
100 int_f
h5imread_image_c(hid_t_f * loc_id,size_t_f * namelen,_fcd name,int_f * buf)101 h5imread_image_c (hid_t_f *loc_id,
102                    size_t_f *namelen,
103                    _fcd name,
104                    int_f *buf)
105 {
106     int     ret_value = -1;
107     herr_t  ret;
108     char    *c_name = NULL;
109 
110     /*
111     * convert FORTRAN name to C name
112     */
113     c_name = (char *)HD5f2cstring(name, (size_t)*namelen);
114     if (c_name == NULL)
115         goto done;
116 
117     /*
118     * call H5IMread_image function.
119     */
120     ret = H5IMread_imagef((hid_t)*loc_id,c_name,buf);
121 
122     if (ret < 0)
123         goto done;
124 
125     ret_value = 0;
126 
127 done:
128     if(c_name!=NULL)
129         HDfree(c_name);
130 
131     return ret_value;
132 }
133 
134 /*-------------------------------------------------------------------------
135 * Function: h5immake_image_24bit_c
136 *
137 * Purpose: Call H5IMmake_image_24bit
138 *
139 * Return: Success: 0, Failure: -1
140 *
141 * Programmer: pvn@ncsa.uiuc.edu
142 *
143 * Date: October 05, 2004
144 *
145 * Comments:
146 *
147 * Modifications:
148 *
149 *
150 *-------------------------------------------------------------------------
151 */
152 
153 int_f
h5immake_image_24bit_c(hid_t_f * loc_id,size_t_f * namelen,_fcd name,size_t_f * ilen,_fcd il,hsize_t_f * width,hsize_t_f * height,void * buf)154 h5immake_image_24bit_c (hid_t_f *loc_id,
155                          size_t_f *namelen,
156                          _fcd name,
157                          size_t_f *ilen,
158                          _fcd il,
159                          hsize_t_f *width,
160                          hsize_t_f *height,
161                          void *buf)
162 {
163     int     ret_value = -1;
164     herr_t  ret;
165     hid_t   c_loc_id;
166     char    *c_name = NULL;
167     char    *c_il = NULL;
168     hsize_t w = (hsize_t)*width;
169     hsize_t h = (hsize_t)*height;
170 
171     /*
172     * convert FORTRAN name to C name
173     */
174     c_name = (char *)HD5f2cstring(name, (size_t)*namelen);
175     if (c_name == NULL)
176         goto done;
177 
178     c_il = (char *)HD5f2cstring(il, (size_t)*ilen);
179     if (c_il == NULL)
180         goto done;
181 
182     /*
183     * call H5IMmake_image_24bitf function.
184     */
185     c_loc_id = (hid_t)*loc_id;
186 
187     ret = H5IMmake_image_24bitf(c_loc_id,c_name,w,h,c_il,(int_f *)buf);
188 
189     if (ret < 0)
190         goto done;
191 
192     ret_value = 0;
193 
194 done:
195     if(c_name!=NULL)
196         HDfree(c_name);
197     if(c_il!=NULL)
198         HDfree(c_il);
199 
200     return ret_value;
201 }
202 
203 /*-------------------------------------------------------------------------
204 * Function: h5imget_image_info_c
205 *
206 * Purpose: Call H5IMget_image_info
207 *
208 * Return: Success: 0, Failure: -1
209 *
210 * Programmer: pvn@ncsa.uiuc.edu
211 *
212 * Date: October 05, 2004
213 *
214 * Comments:
215 *
216 * Modifications:
217 *
218 *
219 *-------------------------------------------------------------------------
220 */
221 
222 int_f
h5imget_image_info_c(hid_t_f * loc_id,size_t_f * namelen,_fcd name,hsize_t_f * width,hsize_t_f * height,hsize_t_f * planes,hsize_t_f * npals,size_t_f * ilen,_fcd interlace)223 h5imget_image_info_c(hid_t_f *loc_id,
224                       size_t_f *namelen,
225                       _fcd name,
226                       hsize_t_f *width,
227                       hsize_t_f *height,
228                       hsize_t_f *planes,
229                       hsize_t_f *npals,
230                       size_t_f *ilen,
231                       _fcd interlace)
232 {
233     int          ret_value = -1;
234     herr_t       ret;
235     hid_t        c_loc_id;
236     char         *c_name = NULL;
237     hsize_t      c_width;
238     hsize_t      c_height;
239     hsize_t      c_planes;
240     hssize_t     c_npals;
241     char         *c_buf=NULL;           /* buffer to hold C string */
242 
243     /*
244     * convert FORTRAN name to C name
245     */
246     c_name = (char *)HD5f2cstring(name, (size_t)*namelen);
247     if (c_name == NULL)
248         goto done;
249 
250     /*
251     * allocate buffer to hold name of an attribute
252     */
253     if ((c_buf = (char *)HDmalloc((size_t)*ilen +1)) == NULL)
254         goto done;
255 
256     /*
257     * call H5IMget_image_info function.
258     */
259     c_loc_id = (hid_t)*loc_id;
260 
261     ret = H5IMget_image_info(c_loc_id,c_name,&c_width,&c_height,&c_planes,c_buf,&c_npals);
262 
263     if (ret < 0)
264         goto done;
265 
266     *width  = (hsize_t_f) c_width;
267     *height = (hsize_t_f) c_height;
268     *planes = (hsize_t_f) c_planes;
269     *npals  = (hsize_t_f) c_npals;
270 
271     /*
272     * convert C name to FORTRAN and place it in the given buffer
273     */
274     HD5packFstring(c_buf, _fcdtocp(interlace), (size_t)*ilen);
275 
276     ret_value = 0;
277 
278 done:
279     if(c_name!=NULL)
280         HDfree(c_name);
281     if(c_buf!=NULL)
282         HDfree(c_buf);
283 
284     return ret_value;
285 }
286 
287 
288 /*-------------------------------------------------------------------------
289 * Function: h5imis_image_c
290 *
291 * Purpose: Call H5IMis_image
292 *
293 * Return: Success: 0, Failure: -1
294 *
295 * Programmer: pvn@ncsa.uiuc.edu
296 *
297 * Date: October 06, 2004
298 *
299 * Comments:
300 *
301 * Modifications:
302 *
303 *
304 *-------------------------------------------------------------------------
305 */
306 
307 int_f
h5imis_image_c(hid_t_f * loc_id,size_t_f * namelen,_fcd name)308 h5imis_image_c(hid_t_f *loc_id,
309                 size_t_f *namelen,
310                 _fcd name)
311 {
312     hid_t   c_loc_id;
313     char    *c_name = NULL;
314     herr_t  ret;
315 
316     /*
317     * convert FORTRAN name to C name
318     */
319     c_name = (char *)HD5f2cstring(name, (size_t)*namelen);
320     if (c_name == NULL) return -1;
321 
322     /*
323     * call H5LTget_dataset_ndims function.
324     */
325     c_loc_id = (hid_t)*loc_id;
326 
327     ret = H5IMis_image(c_loc_id, c_name);
328 
329     if(c_name!=NULL)
330         HDfree(c_name);
331 
332     return ret;
333 
334 }
335 
336 
337 /*-------------------------------------------------------------------------
338 * Function: h5immake_palette_c
339 *
340 * Purpose: Call H5IMmake_palette
341 *
342 * Return: Success: 0, Failure: -1
343 *
344 * Programmer: pvn@ncsa.uiuc.edu
345 *
346 * Date: October 06, 2004
347 *
348 * Comments:
349 *
350 * Modifications:
351 *
352 *
353 *-------------------------------------------------------------------------
354 */
355 
356 int_f
h5immake_palette_c(hid_t_f * loc_id,size_t_f * namelen,_fcd name,hsize_t_f * dims,void * buf)357 h5immake_palette_c (hid_t_f *loc_id,
358                      size_t_f *namelen,
359                      _fcd name,
360                      hsize_t_f *dims,
361                      void *buf)
362 {
363     char    *c_name = NULL;
364     hsize_t c_dims[H5S_MAX_RANK];
365     int     i;
366     int     rank=2;
367     int_f   ret_value = 0;
368 
369     /*
370     * convert FORTRAN name to C name
371     */
372     if(NULL == (c_name = (char *)HD5f2cstring(name, (size_t)*namelen)))
373         HGOTO_DONE(FAIL)
374 
375     for(i = 0; i < rank ; i++)
376       c_dims[i] =  (hsize_t)dims[i];
377 
378     /*
379     * call H5IMmake_palette function.
380     */
381     if(H5IMmake_palettef((hid_t)*loc_id, c_name, c_dims, (int_f *)buf) < 0)
382         HGOTO_DONE(FAIL)
383 
384 done:
385     if(c_name)
386         HDfree(c_name);
387 
388     return ret_value;
389 }
390 
391 
392 /*-------------------------------------------------------------------------
393 * Function: h5imlink_palette_c
394 *
395 * Purpose: Call H5IMlink_palette
396 *
397 * Return: Success: 0, Failure: -1
398 *
399 * Programmer: pvn@ncsa.uiuc.edu
400 *
401 * Date: October 06, 2004
402 *
403 * Comments:
404 *
405 * Modifications:
406 *
407 *
408 *-------------------------------------------------------------------------
409 */
410 
411 int_f
h5imlink_palette_c(hid_t_f * loc_id,size_t_f * namelen,_fcd name,size_t_f * ilen,_fcd pal_name)412 h5imlink_palette_c (hid_t_f *loc_id,
413                      size_t_f *namelen,
414                      _fcd name,
415                      size_t_f *ilen,
416                      _fcd pal_name)
417 {
418     int     ret_value = -1;
419     herr_t  ret;
420     hid_t   c_loc_id;
421     char    *c_name = NULL;
422     char    *c_namepal = NULL;
423 
424     /*
425     * convert FORTRAN name to C name
426     */
427     c_name = (char *)HD5f2cstring(name, (size_t)*namelen);
428     if (c_name == NULL)
429         goto done;
430 
431     c_namepal = (char *)HD5f2cstring(pal_name, (size_t)*ilen);
432     if (c_namepal == NULL)
433         goto done;
434 
435     /*
436     * call H5IMlink_palette function.
437     */
438     c_loc_id = (hid_t)*loc_id;
439 
440     ret = H5IMlink_palette(c_loc_id,c_name,c_namepal);
441 
442     if (ret < 0)
443         goto done;
444 
445     ret_value = 0;
446 
447 done:
448     if(c_name!=NULL)
449         HDfree(c_name);
450     if(c_namepal!=NULL)
451         HDfree(c_namepal);
452 
453     return ret_value;
454 }
455 
456 
457 /*-------------------------------------------------------------------------
458 * Function: h5imunlink_palette_c
459 *
460 * Purpose: Call H5IMunlink_palette
461 *
462 * Return: Success: 0, Failure: -1
463 *
464 * Programmer: pvn@ncsa.uiuc.edu
465 *
466 * Date: October 06, 2004
467 *
468 * Comments:
469 *
470 * Modifications:
471 *
472 *
473 *-------------------------------------------------------------------------
474 */
475 
476 int_f
h5imunlink_palette_c(hid_t_f * loc_id,size_t_f * namelen,_fcd name,size_t_f * ilen,_fcd pal_name)477 h5imunlink_palette_c (hid_t_f *loc_id,
478                        size_t_f *namelen,
479                        _fcd name,
480                        size_t_f *ilen,
481                        _fcd pal_name)
482 {
483     int     ret_value = -1;
484     herr_t  ret;
485     hid_t   c_loc_id;
486     char    *c_name = NULL;
487     char    *c_namepal = NULL;
488 
489     /*
490     * convert FORTRAN name to C name
491     */
492     c_name = (char *)HD5f2cstring(name, (size_t)*namelen);
493     if (c_name == NULL)
494         goto done;
495 
496     c_namepal = (char *)HD5f2cstring(pal_name, (size_t)*ilen);
497     if (c_namepal == NULL)
498         goto done;
499 
500     /*
501     * call H5IMunlink_palette function.
502     */
503     c_loc_id = (hid_t)*loc_id;
504 
505     ret = H5IMunlink_palette(c_loc_id,c_name,c_namepal);
506 
507     if (ret < 0)
508         goto done;
509 
510     ret_value = 0;
511 
512 done:
513     if(c_name!=NULL)
514         HDfree(c_name);
515     if(c_namepal!=NULL)
516         HDfree(c_namepal);
517 
518     return ret_value;
519 }
520 
521 
522 
523 /*-------------------------------------------------------------------------
524 * Function: h5imget_npalettes_c
525 *
526 * Purpose: Call H5IMget_npalettes
527 *
528 * Return: Success: 0, Failure: -1
529 *
530 * Programmer: pvn@ncsa.uiuc.edu
531 *
532 * Date: October 06 2004
533 *
534 * Comments:
535 *
536 * Modifications:
537 *
538 *
539 *-------------------------------------------------------------------------
540 */
541 
542 int_f
h5imget_npalettes_c(hid_t_f * loc_id,size_t_f * namelen,_fcd name,hsize_t_f * npals)543 h5imget_npalettes_c(hid_t_f *loc_id,
544                      size_t_f *namelen,
545                      _fcd name,
546                      hsize_t_f *npals)
547 {
548     int          ret_value = -1;
549     herr_t       ret;
550     hid_t        c_loc_id;
551     char         *c_name = NULL;
552     hssize_t     c_npals;
553 
554     /*
555     * convert FORTRAN name to C name
556     */
557     c_name = (char *)HD5f2cstring(name, (size_t)*namelen);
558     if (c_name == NULL)
559         goto done;
560 
561     /*
562     * call H5IMget_image_info function.
563     */
564     c_loc_id = (hid_t)*loc_id;
565 
566     ret = H5IMget_npalettes(c_loc_id,c_name,&c_npals);
567 
568     *npals  = (hsize_t_f) c_npals;
569 
570     if (ret < 0)
571         goto done;
572 
573     ret_value = 0;
574 
575 done:
576     if(c_name!=NULL)
577         HDfree(c_name);
578 
579     return ret_value;
580 }
581 
582 
583 
584 /*-------------------------------------------------------------------------
585 * Function: h5imget_palette_info_c
586 *
587 * Purpose: Call H5IMget_palette_info
588 *
589 * Return: Success: 0, Failure: -1
590 *
591 * Programmer: pvn@ncsa.uiuc.edu
592 *
593 * Date: October 06 2004
594 *
595 * Comments:
596 *
597 * Modifications:
598 *
599 *
600 *-------------------------------------------------------------------------
601 */
602 
603 
604 int_f
h5imget_palette_info_c(hid_t_f * loc_id,size_t_f * namelen,_fcd name,int_f * pal_number,hsize_t_f * dims)605 h5imget_palette_info_c(hid_t_f *loc_id,
606                         size_t_f *namelen,
607                         _fcd name,
608                         int_f *pal_number,
609                         hsize_t_f *dims)
610 {
611     int          ret_value = -1;
612     herr_t       ret;
613     hid_t        c_loc_id;
614     char         *c_name = NULL;
615     hsize_t      c_dims[2];
616     int          i;
617 
618     /*
619     * convert FORTRAN name to C name
620     */
621     c_name = (char *)HD5f2cstring(name, (size_t)*namelen);
622     if (c_name == NULL)
623         goto done;
624 
625     /*
626     * call H5IMget_image_info function.
627     */
628     c_loc_id = (hid_t)*loc_id;
629 
630     ret = H5IMget_palette_info(c_loc_id,c_name,*pal_number,c_dims);
631 
632     if (ret < 0)
633         goto done;
634 
635     for (i = 0; i < 2 ; i++)
636     {
637         dims[i] = (hsize_t_f) c_dims[i];
638     }
639 
640     ret_value = 0;
641 
642 
643 done:
644     if(c_name!=NULL)
645         HDfree(c_name);
646 
647     return ret_value;
648 }
649 
650 
651 /*-------------------------------------------------------------------------
652 * Function: h5imget_palette_c
653 *
654 * Purpose: Call H5IMget_palette
655 *
656 * Return: Success: 0, Failure: -1
657 *
658 * Programmer: pvn@ncsa.uiuc.edu
659 *
660 * Date: October 06 2004
661 *
662 * Comments:
663 *
664 * Modifications:
665 *
666 *
667 *-------------------------------------------------------------------------
668 */
669 
670 
671 int_f
h5imget_palette_c(hid_t_f * loc_id,size_t_f * namelen,_fcd name,int_f * pal_number,void * buf)672 h5imget_palette_c(hid_t_f *loc_id,
673                    size_t_f *namelen,
674                    _fcd name,
675                    int_f *pal_number,
676                    void *buf)
677 {
678     int          ret_value = -1;
679     herr_t       ret;
680     hid_t        c_loc_id;
681     char         *c_name = NULL;
682 
683     /*
684     * convert FORTRAN name to C name
685     */
686     c_name = (char *)HD5f2cstring(name, (size_t)*namelen);
687     if (c_name == NULL)
688          goto done;
689 
690     /*
691     * call H5IMget_image_info function.
692     */
693     c_loc_id = (hid_t)*loc_id;
694 
695     ret = H5IMget_palettef(c_loc_id,c_name,*pal_number,(int_f *)buf);
696 
697     if (ret < 0)
698          goto done;
699 
700     ret_value = 0;
701 
702 done:
703     if(c_name!=NULL)
704         HDfree(c_name);
705 
706     return ret_value;
707 }
708 
709 
710 /*-------------------------------------------------------------------------
711 * Function: h5imis_palette_c
712 *
713 * Purpose: Call H5IMis_palette
714 *
715 * Return: true, false, fail
716 *
717 * Programmer: pvn@ncsa.uiuc.edu
718 *
719 * Date: October 06, 2004
720 *
721 * Comments:
722 *
723 * Modifications:
724 *
725 *
726 *-------------------------------------------------------------------------
727 */
728 
729 int_f
h5imis_palette_c(hid_t_f * loc_id,size_t_f * namelen,_fcd name)730 h5imis_palette_c(hid_t_f *loc_id,
731                   size_t_f *namelen,
732                   _fcd name)
733 {
734     hid_t   c_loc_id;
735     char    *c_name;
736     herr_t  ret;
737 
738     /*
739     * convert FORTRAN name to C name
740     */
741     c_name = (char *)HD5f2cstring(name, (size_t)*namelen);
742     if (c_name == NULL) return -1;
743 
744     /*
745     * call H5IMis_palette function.
746     */
747     c_loc_id = (hid_t)*loc_id;
748 
749     ret = H5IMis_palette(c_loc_id, c_name);
750 
751     if(c_name!=NULL)
752         HDfree(c_name);
753 
754     return ret;
755 
756 }
757