| 1 |
package nom.tam.fits.header; |
| 2 |
|
| 3 |
/* |
| 4 |
* #%L |
| 5 |
* nom.tam FITS library |
| 6 |
* %% |
| 7 |
* Copyright (C) 1996 - 2024 nom-tam-fits |
| 8 |
* %% |
| 9 |
* This is free and unencumbered software released into the public domain. |
| 10 |
* |
| 11 |
* Anyone is free to copy, modify, publish, use, compile, sell, or |
| 12 |
* distribute this software, either in source code form or as a compiled |
| 13 |
* binary, for any purpose, commercial or non-commercial, and by any |
| 14 |
* means. |
| 15 |
* |
| 16 |
* In jurisdictions that recognize copyright laws, the author or authors |
| 17 |
* of this software dedicate any and all copyright interest in the |
| 18 |
* software to the public domain. We make this dedication for the benefit |
| 19 |
* of the public at large and to the detriment of our heirs and |
| 20 |
* successors. We intend this dedication to be an overt act of |
| 21 |
* relinquishment in perpetuity of all present and future rights to this |
| 22 |
* software under copyright law. |
| 23 |
* |
| 24 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 25 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 26 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 27 |
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 28 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 29 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 30 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 31 |
* #L% |
| 32 |
*/ |
| 33 |
|
| 34 |
import nom.tam.fits.header.IFitsHeader.HDU; |
| 35 |
import nom.tam.fits.header.IFitsHeader.SOURCE; |
| 36 |
import nom.tam.fits.header.IFitsHeader.VALUE; |
| 37 |
|
| 38 |
/** |
| 39 |
* generic key interface, create an IFitsHeader from a key. |
| 40 |
* |
| 41 |
* @author ritchie |
| 42 |
* @deprecated This class duplicates functionality that is available in |
| 43 |
* {@link FitsKey}, {@link Standard}, ans/or {@link IFitsHeader}. |
| 44 |
*/ |
| 45 |
public final class GenericKey { |
| 46 |
|
| 47 |
private static final int NUMBER_BASE = 10; |
| 48 |
|
| 49 |
/** |
| 50 |
* Creates a generic FITS header key that may be used in any HDU, with any |
| 51 |
* type of value, and does not have a standard comment. |
| 52 |
* |
| 53 |
* @param key |
| 54 |
* the string to create the key for |
| 55 |
* @return the IFitsHeader implementation for the key. |
| 56 |
* @deprecated Use {@link FitsKey#FitsKey(String, VALUE, String)} instead. |
| 57 |
*/ |
| 58 |
public static IFitsHeader create(String key) { |
| 59 |
IFitsHeader result = lookup(key); |
| 60 |
if (result == null) { |
| 61 |
result = new FitsKey(key, SOURCE.UNKNOWN, HDU.ANY, VALUE.ANY, ""); |
| 62 |
} |
| 63 |
return result; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* @deprecated (<i>for internal use</i>) Creates a array of generic FITS |
| 68 |
* header keys. The resulting keys have no HDU assignment or |
| 69 |
* value type restrictions, not default comments. As such they |
| 70 |
* may be used for accessing existing keys by the specified |
| 71 |
* names, more so than for adding new values. |
| 72 |
* @param keys |
| 73 |
* the array of string keys |
| 74 |
* @return the equivalent array of super-generic standarddized keys. |
| 75 |
*/ |
| 76 |
public static IFitsHeader[] create(String[] keys) { |
| 77 |
IFitsHeader[] result = new IFitsHeader[keys.length]; |
| 78 |
for (int index = 0; index < result.length; index++) { |
| 79 |
result[index] = create(keys[index]); |
| 80 |
} |
| 81 |
return result; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Returns the number value that appear at the trailing end of a FITS |
| 86 |
* keyword. For example for <code>NAXIS2</code> it will return 2, while for |
| 87 |
* <code>TFORM17</code> it will return 17. If there keyword does not end |
| 88 |
* with a number, 0 is returned (FITS keywords are always numbered from 1 |
| 89 |
* and up). |
| 90 |
* |
| 91 |
* @param key |
| 92 |
* The FITS keyword from which to extract the trailing number. |
| 93 |
* @return the number contained at the end of the keyword or else 0 if the |
| 94 |
* keyword does not end with a number. |
| 95 |
* @deprecated Use {@link IFitsHeader#extractIndices(String)} instead. |
| 96 |
*/ |
| 97 |
public static int getN(String key) { |
| 98 |
int index = key.length() - 1; |
| 99 |
int n = 0; |
| 100 |
int numberBase = 1; |
| 101 |
|
| 102 |
// Skip coordinate alternative marker letter at end... |
| 103 |
if (Character.isAlphabetic(key.charAt(index))) { |
| 104 |
index--; |
| 105 |
} |
| 106 |
|
| 107 |
while (index >= 0 && Character.isDigit(key.charAt(index))) { |
| 108 |
n = n + (key.charAt(index) - '0') * numberBase; |
| 109 |
numberBase *= NUMBER_BASE; |
| 110 |
index--; |
| 111 |
} |
| 112 |
return n; |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Lookup a string key in the standard key sets, resolving indexes and |
| 117 |
* coordinate alternatives as appropriate for the set of standard FITS |
| 118 |
* keywords. Same as {@link Standard#match(String)}, which is preferred. |
| 119 |
* |
| 120 |
* @param key |
| 121 |
* the fits key to search. |
| 122 |
* @return the found fits key or null |
| 123 |
* @deprecated Use {@link Standard#match(String)} instead. |
| 124 |
*/ |
| 125 |
public static IFitsHeader lookup(String key) { |
| 126 |
return Standard.match(key); |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* utility class do not instantiate it. |
| 131 |
*/ |
| 132 |
private GenericKey() { |
| 133 |
} |
| 134 |
} |