|
| 1 | +/* |
| 2 | +*+ |
| 3 | +* Name: |
| 4 | +* hdsIsOpen |
| 5 | +
|
| 6 | +* Purpose: |
| 7 | +* Check if a container file is already open in HDS V5. |
| 8 | +
|
| 9 | +* Language: |
| 10 | +* Starlink ANSI C |
| 11 | +
|
| 12 | +* Type of Module: |
| 13 | +* Library routine |
| 14 | +
|
| 15 | +* Invocation: |
| 16 | +* int hdsIsOpen( const char *file_str, int *isopen, int * status ); |
| 17 | +
|
| 18 | +* Arguments: |
| 19 | +* file = const char * (Given) |
| 20 | +* Container file name. Use DAT__FLEXT (".h5sdf") if no suffix specified. |
| 21 | +* isopen = int * (Returned) |
| 22 | +* Pointer to a flag that is returned non-zero if the supplied |
| 23 | +* container file is already open within HDS V5. |
| 24 | +* status = int* (Given and Returned) |
| 25 | +* Pointer to global status. |
| 26 | +
|
| 27 | +* Description: |
| 28 | +* Checks if the supplied container file is already open within HDS V5. |
| 29 | +
|
| 30 | +* Returned Value: |
| 31 | +* int = inherited status on exit. This is for compatibility with the |
| 32 | +* original HDS API. |
| 33 | +
|
| 34 | +* Authors: |
| 35 | +* DSB: David S Berry (EAO): |
| 36 | +* {enter_new_authors_here} |
| 37 | +
|
| 38 | +* Notes: |
| 39 | +* - A file extension of DAT__FLEXT (".h5sdf") is the default. |
| 40 | +
|
| 41 | +* History: |
| 42 | +* 2020-10-15 (DSB): |
| 43 | +* Initial version |
| 44 | +* {enter_further_changes_here} |
| 45 | +
|
| 46 | +* Copyright: |
| 47 | +* Copyright (C) 2020 East Asian Observatory. |
| 48 | +* All Rights Reserved. |
| 49 | +
|
| 50 | +* Licence: |
| 51 | +* Redistribution and use in source and binary forms, with or |
| 52 | +* without modification, are permitted provided that the following |
| 53 | +* conditions are met: |
| 54 | +* |
| 55 | +* - Redistributions of source code must retain the above copyright |
| 56 | +* notice, this list of conditions and the following disclaimer. |
| 57 | +* |
| 58 | +* - Redistributions in binary form must reproduce the above |
| 59 | +* copyright notice, this list of conditions and the following |
| 60 | +* disclaimer in the documentation and/or other materials |
| 61 | +* provided with the distribution. |
| 62 | +* |
| 63 | +* - Neither the name of the {organization} nor the names of its |
| 64 | +* contributors may be used to endorse or promote products |
| 65 | +* derived from this software without specific prior written |
| 66 | +* permission. |
| 67 | +* |
| 68 | +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
| 69 | +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| 70 | +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 71 | +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 72 | +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| 73 | +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 74 | +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 75 | +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 76 | +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 77 | +* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 78 | +* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 79 | +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 80 | +* THE POSSIBILITY OF SUCH DAMAGE. |
| 81 | +
|
| 82 | +* Bugs: |
| 83 | +* {note_any_bugs_here} |
| 84 | +*- |
| 85 | +*/ |
| 86 | + |
| 87 | +#include <stdlib.h> |
| 88 | +#include <string.h> |
| 89 | +#include <unistd.h> |
| 90 | + |
| 91 | +#include "hds1.h" |
| 92 | +#include "dat1.h" |
| 93 | +#include "ems.h" |
| 94 | +#include "dat_err.h" |
| 95 | +#include "hds.h" |
| 96 | +#include "sae_par.h" |
| 97 | + |
| 98 | +#include "star/one.h" |
| 99 | + |
| 100 | +#include "hdf5.h" |
| 101 | + |
| 102 | +int hdsIsOpen(const char *file_str, int *isopen, int *status) { |
| 103 | + |
| 104 | + char *fname = NULL; |
| 105 | + |
| 106 | + /* Returns the inherited status for compatibility reasons */ |
| 107 | + if (*status != SAI__OK) return *status; |
| 108 | + |
| 109 | + /* Configure the HDF5 library for our needs as this routine could be called |
| 110 | + before any others. */ |
| 111 | + dat1InitHDF5(); |
| 112 | + |
| 113 | + /* Create buffer for file name so that we include the file extension */ |
| 114 | + fname = dau1CheckFileName( file_str, status ); |
| 115 | + |
| 116 | + /* Check to see if the file is currently open. */ |
| 117 | + *isopen = hds1IsOpen( fname, status ); |
| 118 | + |
| 119 | + /* Free allocated resource */ |
| 120 | + CLEANUP: |
| 121 | + if (fname) MEM_FREE(fname); |
| 122 | + |
| 123 | + return *status; |
| 124 | +} |
| 125 | + |
| 126 | + |
0 commit comments