1 /* 2 3 -Procedure zzadrpin_c (GF, progress report initialization adapter ) 4 5 -Abstract 6 7 Provide an f2c-style interface allowing f2c'd Fortran code to call a 8 CSPICE-style GF progress reporting initialization function. 9 10 -Disclaimer 11 12 THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE 13 CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. 14 GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE 15 ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE 16 PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" 17 TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY 18 WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A 19 PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC 20 SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE 21 SOFTWARE AND RELATED MATERIALS, HOWEVER USED. 22 23 IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA 24 BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT 25 LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, 26 INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, 27 REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE 28 REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. 29 30 RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF 31 THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY 32 CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE 33 ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. 34 35 -Required_Reading 36 37 None. 38 39 -Keywords 40 41 UTILITY 42 43 */ 44 45 #include "SpiceUsr.h" 46 #include "SpiceZfc.h" 47 #include "SpiceZmc.h" 48 #include "SpiceZst.h" 49 #include "SpiceZad.h" 50 #undef zzadrepi_c 51 zzadrepi_c(doublereal * cnfine,char * begmss,char * endmss,ftnlen begmssLen,ftnlen endmssLen)52 int zzadrepi_c ( doublereal * cnfine, 53 char * begmss, 54 char * endmss, 55 ftnlen begmssLen, 56 ftnlen endmssLen ) 57 58 59 /* 60 61 -Brief_I/O 62 63 VARIABLE I/O DESCRIPTION 64 -------- --- -------------------------------------------------- 65 cnfine I Confinement window. 66 begmss I Beginning of the text portion of the output message. 67 endmss I End of the text portion of the output message. 68 69 -Detailed_Input 70 71 cnfine is an array of type double containing a SPICE window. 72 This is the confinement window associated with some 73 GF root finding activity. It is used to determine how 74 much total time is being searched in order to find 75 the events of interest. 76 77 78 begmss is the beginning of the output message reported by 79 the routine gfrpwk_. This output message has the form 80 81 begmss ' xx.xx% ' endmss 82 83 `begmss' is a Fortran-style string. 84 85 86 endmss is the last portion of the output message reported by 87 the routine gfrpwk_. 88 89 `endmss' is a Fortran-style string. 90 91 92 begmssLen is the length of the string `begmss'. The total 93 length of `begmss' must be less than 40 characters. 94 95 endmssLen is the length of the string `endmss'. The total 96 length of `endmss' must be less than 40 characters. 97 98 99 -Detailed_Output 100 101 None. 102 103 -Parameters 104 105 None. 106 107 -Exceptions 108 109 1) A run-time error will result if this routine is called before 110 a valid pointer to a CSPICE-style GF progress reporting 111 initialization function has been stored via a call to zzadsave_c. 112 113 The argument list of the stored function must match that of 114 gfrepi_c. 115 116 -Files 117 118 None. 119 120 -Particulars 121 122 This routine is meant to be passed to f2c'd Fortran GF code that 123 requires a progress reporting initialization function input argument. 124 The argument list of this routine matches that of the f2c'd routine 125 126 gfrepi_ 127 128 This routine calls the CSPICE-style progress reporting 129 initialization function passed into a CSPICE wrapper for an 130 intermediate-level GF function. A pointer to this progress reporting 131 initialization function must be stored via a call to zzadsave_c 132 before this routine is called. 133 134 The argument list of the function referenced by the saved pointer 135 must match that of 136 137 gfrepi_c 138 139 -Examples 140 141 None. 142 143 -Restrictions 144 145 None. 146 147 -Literature_References 148 149 None. 150 151 -Author_and_Institution 152 153 N.J. Bachman (JPL) 154 W.L. Taber (JPL) 155 I.M. Underwood (JPL) 156 L.S. Elson (JPL) 157 E.D. Wright (JPL) 158 159 -Version 160 161 -CSPICE Version 1.0.0, 29-MAR-2008 (NJB) 162 163 -Index_Entries 164 165 provide status of a job in progress 166 167 -& 168 */ 169 170 { /* Begin zzadrepi_c */ 171 172 173 174 /* 175 Local variables 176 */ 177 SpiceCell cnfineCell; 178 179 SpiceChar * prefstr; 180 SpiceChar * suffstr; 181 182 SpiceInt nBytes; 183 184 /* 185 Function pointer for CSPICE-style progress reporting 186 initialization function: 187 */ 188 void ( * fPtr ) ( ConstSpiceCell *, 189 ConstSpiceChar *, 190 ConstSpiceChar * ); 191 192 /* 193 Participate in error tracing. 194 */ 195 if ( return_c() ) 196 { 197 return ( 0 ); 198 } 199 chkin_c ( "zzadrepi_c" ); 200 201 202 /* 203 In order to call the saved, passed-in progress report 204 initialization function, we'll have to prepare 205 some of the input arguments. We need C-style strings, 206 and we need a confinement cell rather than an array. 207 208 Set up the cell first. 209 */ 210 cnfineCell.dtype = SPICE_DP; 211 cnfineCell.length = 0; 212 cnfineCell.size = sized_(cnfine); 213 cnfineCell.card = cardd_(cnfine); 214 cnfineCell.isSet = SPICEFALSE; 215 cnfineCell.adjust = SPICEFALSE; 216 cnfineCell.init = SPICETRUE; 217 cnfineCell.base = cnfine; 218 cnfineCell.data = (SpiceDouble *)cnfine + SPICE_CELL_CTRLSZ; 219 220 /* 221 Allocate memory to hold C-style versions of the input strings. 222 223 First create a C-style prefix string. 224 */ 225 nBytes = (begmssLen+1) * sizeof(char); 226 227 prefstr = (SpiceChar *) malloc( nBytes ); 228 229 if ( !prefstr ) 230 { 231 setmsg_c ( "Could not allocate # bytes for progress report " 232 "prefix string." ); 233 errint_c ( "#", nBytes ); 234 sigerr_c ( "SPICE(MALLOCFAILURE)" ); 235 chkout_c ( "zzadrepi_c" ); 236 237 /* 238 Return status of "0" because we don't want to invoke any f2c 239 error handling mechanism that may exist. 240 */ 241 return ( 0 ); 242 } 243 244 strncpy ( prefstr, begmss, begmssLen ); 245 prefstr[begmssLen] = NULLCHAR; 246 247 248 /* 249 Create a C-style suffix string. 250 */ 251 nBytes = (endmssLen+1) * sizeof(char); 252 253 suffstr = (SpiceChar *) malloc( nBytes ); 254 255 if ( !suffstr ) 256 { 257 /* 258 Free the dynamically allocated prefix string before doing 259 anything else. 260 */ 261 free ( prefstr ); 262 263 264 setmsg_c ( "Could not allocate # bytes for progress report " 265 "suffix string." ); 266 errint_c ( "#", nBytes ); 267 sigerr_c ( "SPICE(MALLOCFAILURE)" ); 268 chkout_c ( "zzadrepi_c" ); 269 270 return ( 0 ); 271 } 272 273 strncpy ( suffstr, endmss, endmssLen ); 274 suffstr[endmssLen] = NULLCHAR; 275 276 /* 277 Retrieve the stored pointer for the passed-in function; cast 278 the pointer from (void *) to that of a function whose argument 279 list matches that of gfrepi_c. 280 */ 281 282 fPtr = ( void (*) ( ConstSpiceCell *, 283 ConstSpiceChar *, 284 ConstSpiceChar * ) ) zzadget_c ( UDREPI ); 285 /* 286 At this point we have the inputs required by the saved 287 GF progress report initialization function. 288 */ 289 290 ( *fPtr ) ( (ConstSpiceCell *) &cnfineCell, 291 (ConstSpiceChar *) prefstr, 292 (ConstSpiceChar *) suffstr ); 293 294 /* 295 Free the dynamically allocated strings. 296 */ 297 free ( prefstr ); 298 free ( suffstr ); 299 300 301 chkout_c ( "zzadrepi_c" ); 302 303 return ( 0 ); 304 305 } /* End zzadrepi_c */ 306