Changeset 18424
- Timestamp:
- Jul 3, 2008, 10:26:51 PM (18 years ago)
- Location:
- branches/eam_branch_20080421/Ohana
- Files:
-
- 6 added
- 82 edited
-
configure (modified) (4 diffs)
-
configure.tcsh (modified) (2 diffs)
-
src/addstar/include/addstar.h (modified) (1 diff)
-
src/addstar/src/args.c (modified) (1 diff)
-
src/addstar/src/args_client.c (modified) (1 diff)
-
src/addstar/src/args_load2mass.c (modified) (1 diff)
-
src/addstar/src/args_sedstar.c (modified) (1 diff)
-
src/addstar/src/args_server.c (modified) (1 diff)
-
src/addstar/src/find_matches_refstars.c (modified) (5 diffs)
-
src/kapa2/include/structures.h (modified) (1 diff)
-
src/kapa2/src/DrawFrame.c (modified) (2 diffs)
-
src/kapa2/src/InterpretKeys.c (modified) (1 diff)
-
src/kapa2/src/LoadFrame.c (modified) (2 diffs)
-
src/kapa2/src/Remap16.c (modified) (3 diffs)
-
src/kapa2/src/Remap24.c (modified) (4 diffs)
-
src/kapa2/src/Remap32.c (modified) (3 diffs)
-
src/kapa2/src/Remap8.c (modified) (4 diffs)
-
src/libfits/extern/ricecomp.c (modified) (30 diffs)
-
src/libfits/extern/ricecomp.h (modified) (1 diff)
-
src/libfits/header/F_copy_H.c (modified) (1 diff)
-
src/libfits/include/gfitsio.h (modified) (1 diff)
-
src/libfits/matrix/F_compress_M.c (modified) (12 diffs)
-
src/libfits/matrix/F_copy_M.c (modified) (1 diff)
-
src/libfits/matrix/F_create_M.c (modified) (1 diff)
-
src/libfits/matrix/F_uncompress_data.c (modified) (2 diffs)
-
src/libfits/table/F_table_varlength.c (modified) (2 diffs)
-
src/libkapa/src/IOfuncs.c (modified) (5 diffs)
-
src/libkapa/src/KapaWindow.c (modified) (1 diff)
-
src/libohana/src/IOBufferOps.c (modified) (1 diff)
-
src/libohana/src/findexec.c (modified) (1 diff)
-
src/opihi/cmd.astro/coord_systems.c (modified) (2 diffs)
-
src/opihi/cmd.astro/coords.c (modified) (1 diff)
-
src/opihi/cmd.basic/Makefile (modified) (1 diff)
-
src/opihi/cmd.basic/basename.c (added)
-
src/opihi/cmd.basic/init.c (modified) (2 diffs)
-
src/opihi/cmd.data/Makefile (modified) (1 diff)
-
src/opihi/cmd.data/box.c (modified) (1 diff)
-
src/opihi/cmd.data/dbselect.c (modified) (3 diffs)
-
src/opihi/cmd.data/histogram.c (modified) (1 diff)
-
src/opihi/cmd.data/init.c (modified) (2 diffs)
-
src/opihi/cmd.data/queuesubstr.c (added)
-
src/opihi/cmd.data/rd.c (modified) (2 diffs)
-
src/opihi/cmd.data/spline_construct.c (modified) (1 diff)
-
src/opihi/cmd.data/wd.c (modified) (1 diff)
-
src/opihi/dvo/ImageOps.c (modified) (1 diff)
-
src/opihi/dvo/dbExtractMeasures.c (modified) (1 diff)
-
src/opihi/include/pcontrol.h (modified) (6 diffs)
-
src/opihi/lib.data/fft.c (modified) (1 diff)
-
src/opihi/lib.data/open_kapa.c (modified) (1 diff)
-
src/opihi/lib.shell/BufferOps.c (modified) (1 diff)
-
src/opihi/lib.shell/evaluate_stack.c (modified) (1 diff)
-
src/opihi/lib.shell/multicommand.c (modified) (3 diffs)
-
src/opihi/lib.shell/stack_math.c (modified) (11 diffs)
-
src/opihi/pantasks/ControllerOps.c (modified) (5 diffs)
-
src/opihi/pantasks/JobOps.c (modified) (3 diffs)
-
src/opihi/pantasks/LocalJob.c (modified) (1 diff)
-
src/opihi/pantasks/Makefile (modified) (1 diff)
-
src/opihi/pantasks/controller.c (modified) (2 diffs)
-
src/opihi/pantasks/controller_jobstack.c (modified) (1 diff)
-
src/opihi/pantasks/controller_output.c (modified) (2 diffs)
-
src/opihi/pantasks/controller_verbose.c (added)
-
src/opihi/pantasks/ipptool2book.c (modified) (2 diffs)
-
src/opihi/pclient/pclient.c.in (modified) (2 diffs)
-
src/opihi/pcontrol/CheckBusyJob.c (modified) (5 diffs)
-
src/opihi/pcontrol/CheckDoneHost.c (modified) (5 diffs)
-
src/opihi/pcontrol/CheckHost.c (modified) (2 diffs)
-
src/opihi/pcontrol/CheckIdleHost.c (modified) (1 diff)
-
src/opihi/pcontrol/CheckRespHost.c (added)
-
src/opihi/pcontrol/CheckSystem.c (modified) (4 diffs)
-
src/opihi/pcontrol/HostOps.c (modified) (9 diffs)
-
src/opihi/pcontrol/IDops.c (modified) (2 diffs)
-
src/opihi/pcontrol/JobID.c (modified) (1 diff)
-
src/opihi/pcontrol/JobOps.c (modified) (10 diffs)
-
src/opihi/pcontrol/KillJob.c (modified) (2 diffs)
-
src/opihi/pcontrol/Makefile (modified) (3 diffs)
-
src/opihi/pcontrol/PclientCommand.c (modified) (3 diffs)
-
src/opihi/pcontrol/ResetJob.c (modified) (2 diffs)
-
src/opihi/pcontrol/StartJob.c (modified) (5 diffs)
-
src/opihi/pcontrol/StopHosts.c (modified) (2 diffs)
-
src/opihi/pcontrol/check.c (modified) (4 diffs)
-
src/opihi/pcontrol/delete.c (modified) (1 diff)
-
src/opihi/pcontrol/host.c (modified) (3 diffs)
-
src/opihi/pcontrol/notes.txt (added)
-
src/opihi/pcontrol/pcontrol.c.in (modified) (1 diff)
-
src/opihi/pcontrol/rconnect.c (modified) (2 diffs)
-
src/opihi/pcontrol/status.c (modified) (3 diffs)
-
src/opihi/pcontrol/stdout.c (modified) (4 diffs)
-
src/opihi/test/strings.pro (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080421/Ohana/configure
r12842 r18424 2 2 3 3 # strip out CC, CFLAGS, CPPFLAGS, LDFLAGS and set env vars 4 while (( $# > 0 )); do 4 while ( test $# -gt 0 ); do 5 5 6 skip=0 6 7 7 8 # strip out CC, set as env variable 8 9 echo $1 | grep "^CC=" > /dev/null 9 if ( ( $? == 0 )) ; then10 if ( test $? -eq 0 ) ; then 10 11 val=`echo $1 | sed "s|^CC=||"` 11 12 export CC=$val … … 14 15 # strip out CFLAGS, set as env variable 15 16 echo $1 | grep "^CFLAGS=" > /dev/null 16 if ( ( $? == 0 )) ; then17 if ( test $? -eq 0 ) ; then 17 18 val=`echo $1 | sed "s|^CFLAGS=||"` 18 19 export CFLAGS=$val … … 21 22 # strip out CPPFLAGS, set as env variable 22 23 echo $1 | grep "^CPPFLAGS=" > /dev/null 23 if ( ( $? == 0 )) ; then24 if ( test $? -eq 0 ) ; then 24 25 val=`echo $1 | sed "s|^CPPFLAGS=||"` 25 26 export CPPFLAGS=$val … … 28 29 # strip out LDFLAGS, set as env variable 29 30 echo $1 | grep "^LDFLAGS=" > /dev/null 30 if ( ( $? == 0 )) ; then31 if ( test $? -eq 0 ) ; then 31 32 val=`echo $1 | sed "s|^LDFLAGS=||"` 32 33 export LDFLAGS=$val 33 34 skip=1 34 35 fi 35 if ( ( $skip == 0 )) ; then36 if ( test $skip -eq 0 ) ; then 36 37 args="$args $1" 37 38 fi -
branches/eam_branch_20080421/Ohana/configure.tcsh
r16968 r18424 350 350 foreach f ( ncurses curses termcap ) 351 351 foreach g ( $libpath $libdir $syslibpath ) 352 # echo "trying $g" 352 353 set name = $g/lib$f.a 354 # echo "trying $name" 353 355 if (-e $name[1]) goto got_curses; 354 356 set name = $g/lib$f.$dlltype 357 # echo "trying $name" 358 if (-e $name[1]) goto got_curses; 359 end 360 # try versioned libraries such as .so.N 361 foreach g ( $libpath $libdir $syslibpath ) 362 # echo "trying $g" 363 set name = $g/lib$f.$dlltype.* 364 # echo "$#name : $name[1]" 365 if ($#name < 2) continue 366 # echo "trying $name[1]" 355 367 if (-e $name[1]) goto got_curses; 356 368 end … … 359 371 echo "missing a valid curses library" 360 372 echo "missing: $faillibs" 361 echo "please find one of them and install them in $lib "373 echo "please find one of them and install them in $libpath" 362 374 exit 1 363 375 -
branches/eam_branch_20080421/Ohana/src/addstar/include/addstar.h
r16983 r18424 129 129 SkyRegion UserPatch; // used by MODE CAT 130 130 char *SELECT_2MASS_QUALITY; // used only by get2mass_as 131 int NREFSTAR_GROUP; 131 132 132 133 /*** addstar prototypes ***/ -
branches/eam_branch_20080421/Ohana/src/addstar/src/args.c
r16992 r18424 6 6 int i, N; 7 7 int QUALITY_AIRMASS; 8 9 // a global used by find_matches_refstars.c (value is 1 except for load2mass) 10 NREFSTAR_GROUP = 1; 8 11 9 12 /* check for help request */ -
branches/eam_branch_20080421/Ohana/src/addstar/src/args_client.c
r16992 r18424 11 11 help (); 12 12 } 13 14 // a global used by find_matches_refstars.c (value is 1 except for load2mass) 15 NREFSTAR_GROUP = 1; 13 16 14 17 /*** check for command line options ***/ -
branches/eam_branch_20080421/Ohana/src/addstar/src/args_load2mass.c
r16938 r18424 11 11 help (); 12 12 } 13 14 // a global used by find_matches_refstars.c (value is 1 except for load2mass) 15 NREFSTAR_GROUP = 3; 13 16 14 17 /*** check for command line options ***/ -
branches/eam_branch_20080421/Ohana/src/addstar/src/args_sedstar.c
r7696 r18424 11 11 help (); 12 12 } 13 14 // a global used by find_matches_refstars.c (value is 1 except for load2mass) 15 NREFSTAR_GROUP = 1; 13 16 14 17 /*** check for command line options ***/ -
branches/eam_branch_20080421/Ohana/src/addstar/src/args_server.c
r7691 r18424 11 11 help (); 12 12 } 13 14 // a global used by find_matches_refstars.c (value is 1 except for load2mass) 15 NREFSTAR_GROUP = 1; 13 16 14 17 /* restrict to a portion of the sky? (REFCAT only) */ -
branches/eam_branch_20080421/Ohana/src/addstar/src/find_matches_refstars.c
r17469 r18424 14 14 Coords tcoords; 15 15 int Nsecfilt; 16 17 if ((NREFSTAR_GROUP != 1) && (NREFSTAR_GROUP != 3)) { 18 fprintf (stderr, "ERROR: NREFSTAR_GROUP NOT SET!\n"); 19 exit (1); 20 } 16 21 17 22 /* photcode data -- should not have to modify secfilt / average */ … … 98 103 99 104 /** find matched stars **/ 105 // XXX could use NREFSTAR_GROUP to do this match more quicky 100 106 for (i = j = 0; (i < Nstars) && (j < Nave); ) { 101 107 … … 225 231 the reference up-to-date with known stars only */ 226 232 227 for (i = 0; (i < Nstars) && !options.only_match; i+ +) {233 for (i = 0; (i < Nstars) && !options.only_match; i+=NREFSTAR_GROUP) { 228 234 N = N1[i]; 229 235 if (stars[N][0].found >= 0) continue; … … 232 238 catalog[0].average[Nave].D = stars[N][0].D; 233 239 catalog[0].average[Nave].Xp = 0; 234 catalog[0].average[Nave].Nmeasure = 1;240 catalog[0].average[Nave].Nmeasure = NREFSTAR_GROUP; 235 241 catalog[0].average[Nave].Nmissing = 0; 236 242 catalog[0].average[Nave].measureOffset = Nmeas; … … 268 274 } 269 275 270 catalog[0].measure[Nmeas].dR = 0.0; 271 catalog[0].measure[Nmeas].dD = 0.0; 272 catalog[0].measure[Nmeas].M = stars[N][0].M; 273 catalog[0].measure[Nmeas].dM = stars[N][0].dM; 274 catalog[0].measure[Nmeas].Mcal = 0; 275 catalog[0].measure[Nmeas].t = (stars[N][0].t == 0) ? TIMEREF : stars[N][0].t; /** careful : time_t vs e_time **/ 276 catalog[0].measure[Nmeas].averef = Nave; 277 catalog[0].measure[Nmeas].photcode = stars[N][0].code; 278 catalog[0].measure[Nmeas].dophot = 0; 279 catalog[0].measure[Nmeas].dbFlags = 0; 280 catalog[0].measure[Nmeas].dt = 0xffff; 281 282 catalog[0].measure[Nmeas].photFlags = stars[N][0].flags; // XXX make sure these are zero'ed as needed 283 catalog[0].measure[Nmeas].qPSF = 0; 284 catalog[0].measure[Nmeas].psfChisq = 0; 285 catalog[0].measure[Nmeas].crNsigma = 0; 286 catalog[0].measure[Nmeas].extNsigma = 0; 287 catalog[0].measure[Nmeas].Sky = 0; 288 catalog[0].measure[Nmeas].dSky = 0; 289 290 catalog[0].measure[Nmeas].stargal = 0; // XXX not yet set 291 292 catalog[0].measure[Nmeas].detID = 0; 293 catalog[0].measure[Nmeas].imageID = 0; 294 295 catalog[0].measure[Nmeas].dXccd = 0; 296 catalog[0].measure[Nmeas].dYccd = 0; 297 298 catalog[0].measure[Nmeas].Xccd = stars[N][0].X; // XXX make sure these are zero'ed as needed 299 catalog[0].measure[Nmeas].Yccd = stars[N][0].Y; // XXX make sure these are zero'ed as needed 300 301 catalog[0].measure[Nmeas].airmass = 0; 302 catalog[0].measure[Nmeas].Map = NAN; 303 catalog[0].measure[Nmeas].FWx = stars[N][0].fx; // XXX make sure these are zero'ed as needed 304 catalog[0].measure[Nmeas].FWy = stars[N][0].fy; // XXX make sure these are zero'ed as needed 305 catalog[0].measure[Nmeas].theta = stars[N][0].df; // XXX make sure these are zero'ed as needed 306 307 catalog[0].measure[Nmeas].Xccd = 0.0; 308 catalog[0].measure[Nmeas].Yccd = 0.0; 309 310 stars[N][0].found = Nmeas; 311 next[last] = Nmeas; 312 next[Nmeas] = -1; 313 last = Nmeas; 314 Nmeas ++; 315 if (Nmeas == NMEAS) { 316 NMEAS = Nmeas + 1000; 317 REALLOCATE (next, int, NMEAS); 318 REALLOCATE (catalog[0].measure, Measure, NMEAS); 319 } 276 for (j = 0; j < NREFSTAR_GROUP; j++) { 277 N = N1[i + j]; 278 catalog[0].measure[Nmeas].dR = 0.0; 279 catalog[0].measure[Nmeas].dD = 0.0; 280 catalog[0].measure[Nmeas].M = stars[N][0].M; 281 catalog[0].measure[Nmeas].dM = stars[N][0].dM; 282 catalog[0].measure[Nmeas].Mcal = 0; 283 catalog[0].measure[Nmeas].t = (stars[N][0].t == 0) ? TIMEREF : stars[N][0].t; /** careful : time_t vs e_time **/ 284 catalog[0].measure[Nmeas].averef = Nave; 285 catalog[0].measure[Nmeas].photcode = stars[N][0].code; 286 catalog[0].measure[Nmeas].dophot = 0; 287 catalog[0].measure[Nmeas].dbFlags = 0; 288 catalog[0].measure[Nmeas].dt = 0xffff; 289 290 catalog[0].measure[Nmeas].photFlags = stars[N][0].flags; // XXX make sure these are zero'ed as needed 291 catalog[0].measure[Nmeas].qPSF = 0; 292 catalog[0].measure[Nmeas].psfChisq = 0; 293 catalog[0].measure[Nmeas].crNsigma = 0; 294 catalog[0].measure[Nmeas].extNsigma = 0; 295 catalog[0].measure[Nmeas].Sky = 0; 296 catalog[0].measure[Nmeas].dSky = 0; 297 298 catalog[0].measure[Nmeas].stargal = 0; // XXX not yet set 299 300 catalog[0].measure[Nmeas].detID = 0; 301 catalog[0].measure[Nmeas].imageID = 0; 302 303 catalog[0].measure[Nmeas].dXccd = 0; 304 catalog[0].measure[Nmeas].dYccd = 0; 305 306 catalog[0].measure[Nmeas].Xccd = stars[N][0].X; // XXX make sure these are zero'ed as needed 307 catalog[0].measure[Nmeas].Yccd = stars[N][0].Y; // XXX make sure these are zero'ed as needed 308 309 catalog[0].measure[Nmeas].airmass = 0; 310 catalog[0].measure[Nmeas].Map = NAN; 311 catalog[0].measure[Nmeas].FWx = stars[N][0].fx; // XXX make sure these are zero'ed as needed 312 catalog[0].measure[Nmeas].FWy = stars[N][0].fy; // XXX make sure these are zero'ed as needed 313 catalog[0].measure[Nmeas].theta = stars[N][0].df; // XXX make sure these are zero'ed as needed 314 315 catalog[0].measure[Nmeas].Xccd = 0.0; 316 catalog[0].measure[Nmeas].Yccd = 0.0; 317 318 stars[N][0].found = Nmeas; 319 next[last] = Nmeas; 320 next[Nmeas] = -1; 321 last = Nmeas; 322 Nmeas ++; 323 if (Nmeas == NMEAS) { 324 NMEAS = Nmeas + 1000; 325 REALLOCATE (next, int, NMEAS); 326 REALLOCATE (catalog[0].measure, Measure, NMEAS); 327 } 328 } 329 320 330 Nave ++; 321 331 if (Nave == NAVE) { -
branches/eam_branch_20080421/Ohana/src/kapa2/include/structures.h
r16810 r18424 138 138 char isaxis, areticks, islabel, islog; 139 139 double fx, dfx, fy, dfy; /* axis location on graphic */ 140 double lweight; 141 int color; 140 142 } Axis; 141 143 -
branches/eam_branch_20080421/Ohana/src/kapa2/src/DrawFrame.c
r17469 r18424 8 8 9 9 int i, fx, fy, dfx, dfy, P, IsLabel, IsMajor; 10 double range, major, minor, first, next ;10 double range, major, minor, first, next, lweight; 11 11 12 12 graphic = GetGraphic(); 13 14 // XXX why is this called for every redraw?15 DrawRotTextInit (graphic->display, graphic->window, graphic->gc, graphic->fore, graphic->back);16 13 17 14 /* each axis is drawn independently, but ticks and labels are placed according to … … 23 20 dfy = graph[0].axis[i].dfy; 24 21 P = hypot ((double)graph[0].axis[(i+1)%2].dfx, (double)graph[0].axis[(i+1)%2].dfy); 22 23 lweight = MAX (0, MIN (10, graph[0].axis[i].lweight)); 24 XSetLineAttributes (graphic->display, graphic->gc, lweight, LineSolid, CapNotLast, JoinMiter); 25 XSetForeground (graphic->display, graphic->gc, graphic->color[graph[0].axis[i].color]); 26 DrawRotTextInit (graphic->display, graphic->window, graphic->gc, graphic->color[graph[0].axis[i].color], graphic->back); 25 27 26 28 if (graph[0].axis[i].isaxis) { -
branches/eam_branch_20080421/Ohana/src/kapa2/src/InterpretKeys.c
r16256 r18424 152 152 153 153 case XK_KP_Add: 154 image[0].image[0].zero += 0.1*image[0].image[0].range; 154 if (modstate & ControlMask) { 155 image[0].image[0].zero -= 0.05*image[0].image[0].range; 156 image[0].image[0].range *= 1.1; 157 } else { 158 image[0].image[0].zero += 0.1*image[0].image[0].range; 159 } 160 SetColorScale (graphic, image); 161 Remap (graphic, image); 155 162 Reorient (graphic, image, image[0].picture.X, image[0].picture.Y, 0); 156 163 break; 157 164 case XK_KP_Subtract: 158 image[0].image[0].zero -= 0.1*image[0].image[0].range; 165 if (modstate & ControlMask) { 166 image[0].image[0].zero += 0.05*image[0].image[0].range; 167 image[0].image[0].range *= 0.90; 168 } else { 169 image[0].image[0].zero -= 0.1*image[0].image[0].range; 170 } 171 SetColorScale (graphic, image); 172 Remap (graphic, image); 159 173 Reorient (graphic, image, image[0].picture.X, image[0].picture.Y, 0); 160 174 break; -
branches/eam_branch_20080421/Ohana/src/kapa2/src/LoadFrame.c
r14590 r18424 3 3 int LoadFrame (int sock) { 4 4 5 int i ;5 int i, color; 6 6 char Axis[16], Labels[16], Ticks[16]; 7 double lweight; 7 8 Section *section; 8 9 KapaGraphWidget *graph; … … 24 25 graph[0].axis[2].max = graph[0].axis[0].max; 25 26 27 KiiScanMessage (sock, "%lf %d", &lweight, &color); 28 26 29 KiiScanMessage (sock, "%s %s %s", Axis, Labels, Ticks); 27 30 28 31 for (i = 0; i < 4; i++) { 32 graph[0].axis[i].lweight = lweight; 33 graph[0].axis[i].color = color; 34 29 35 switch (Axis[i]) { 30 36 case '0': -
branches/eam_branch_20080421/Ohana/src/kapa2/src/Remap16.c
r16391 r18424 86 86 87 87 /**** fill in area to the left of the picture ****/ 88 for (jj = 0; (i_start > 0) && (jj < expand_out) ; jj++) {88 for (jj = 0; (i_start > 0) && (jj < expand_out) && (j + jj < dy); jj++) { 89 89 out_pix2 = out_pix + jj*dx; 90 90 for (i = 0; i < i_start; i++, out_pix2++) { … … 104 104 pixvalue = pixel[*in_pix2]; 105 105 out_pix2 = out_pix; 106 for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {106 for (jj = 0; (jj < expand_out) && (j + jj < dy); jj++, out_pix2+=(dx-expand_out)) { 107 107 for (ii = 0; ii < expand_out; ii++, out_pix2++) { 108 108 *out_pix2 = pixvalue; … … 114 114 115 115 /**** fill in area to the right of the picture ****/ 116 for (jj = 0; jj < expand_out; jj++) {116 for (jj = 0; (jj < expand_out) && (j + jj < dy); jj++) { 117 117 out_pix2 = out_pix + jj*dx; 118 118 for (i = i_end; i < dx; i++, out_pix2++) { -
branches/eam_branch_20080421/Ohana/src/kapa2/src/Remap24.c
r16256 r18424 84 84 85 85 /**** fill in area to the left of the picture ****/ 86 for (jj = 0; (i_start > 0) && (jj < expand_out) ; jj++) {86 for (jj = 0; (i_start > 0) && (jj < expand_out) && (j + jj < dy); jj++) { 87 87 out_pix2 = out_pix + jj*(3*dx + extra); 88 88 for (i = 0; i < i_start; i++, out_pix2+=3) { … … 108 108 pixvalue3 = pixel3[*in_pix2]; 109 109 out_pix2 = out_pix; 110 for (jj = 0; jj < expand_out; jj++, out_pix2+=3*(dx-expand_out)+extra) {110 for (jj = 0; (jj < expand_out) && (j + jj < dy); jj++, out_pix2+=3*(dx-expand_out)+extra) { 111 111 for (ii = 0; ii < expand_out; ii++, out_pix2+=3) { 112 112 out_pix2[0] = pixvalue1; … … 120 120 121 121 /**** fill in area to the right of the picture ****/ 122 for (jj = 0; jj < expand_out; jj++) { 122 for (jj = 0; (jj < expand_out) && (j + jj < dy); jj++) { 123 // for (jj = 0; jj < expand_out; jj++) { 123 124 out_pix2 = out_pix + jj*(3*dx+extra); 124 125 for (i = i_end; i < dx; i++, out_pix2+=3) { … … 142 143 143 144 picture[0].pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 144 picture[0].data, picture[0].dx, picture[0].dy, 32, 0);145 picture[0].data, picture[0].dx, picture[0].dy, 32, 0); 145 146 146 147 free (pixel1); -
branches/eam_branch_20080421/Ohana/src/kapa2/src/Remap32.c
r17121 r18424 100 100 101 101 /**** fill in area to the left of the picture ****/ 102 for (jj = 0; (i_start > 0) && (jj < expand_out) ; jj++) {102 for (jj = 0; (i_start > 0) && (jj < expand_out) && (j + jj < dy); jj++) { 103 103 out_pix2 = out_pix + jj*dx; 104 104 for (i = 0; i < i_start; i++, out_pix2++) { … … 118 118 pixvalue = pixel[*in_pix2]; 119 119 out_pix2 = out_pix; 120 for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {120 for (jj = 0; (jj < expand_out) && (j + jj < dy); jj++, out_pix2+=(dx-expand_out)) { 121 121 for (ii = 0; ii < expand_out; ii++, out_pix2++) { 122 122 *out_pix2 = pixvalue; … … 133 133 134 134 /**** fill in area to the right of the picture ****/ 135 for (jj = 0; jj < expand_out; jj++) {135 for (jj = 0; (jj < expand_out) && (j + jj < dy); jj++) { 136 136 out_pix2 = out_pix + jj*dx; 137 137 for (i = i_end; i < dx; i++, out_pix2++) { -
branches/eam_branch_20080421/Ohana/src/kapa2/src/Remap8.c
r16256 r18424 69 69 70 70 /**** fill in area to the left of the picture ****/ 71 for (jj = 0; (i_start > 0) && (jj < expand_out) ; jj++) {71 for (jj = 0; (i_start > 0) && (jj < expand_out) && (j + jj < dy); jj++) { 72 72 out_pix2 = out_pix + jj*dx; 73 73 for (i = 0; i < i_start; i++, out_pix2++) { … … 87 87 pixvalue = pixel[*in_pix2]; 88 88 out_pix2 = out_pix; 89 for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {89 for (jj = 0; (jj < expand_out) & (j + jj < dy); jj++, out_pix2+=(dx-expand_out)) { 90 90 for (ii = 0; ii < expand_out; ii++, out_pix2++) { 91 91 *out_pix2 = pixvalue; … … 97 97 98 98 /**** fill in area to the right of the picture ****/ 99 for (jj = 0; jj < expand_out; jj++) {99 for (jj = 0; (jj < expand_out) && (j + jj < dy); jj++) { 100 100 out_pix2 = out_pix + jj*dx; 101 101 for (i = i_end; i < dx; i++, out_pix2++) { … … 115 115 } 116 116 picture[0].pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 117 picture[0].data, picture[0].dx, picture[0].dy, 8, 0);117 picture[0].data, picture[0].dx, picture[0].dy, 8, 0); 118 118 free (pixel); 119 119 } -
branches/eam_branch_20080421/Ohana/src/libfits/extern/ricecomp.c
r15487 r18424 1 2 // 2008.06.22 EAM : This code was taken from CFITSIO and included in Ohana for rice 3 // decompression. In order to include this .c file (or future upgrades), we include our own 4 // version of ricecomp.h (not the one available in the CFITSIO tree) and include it instead of 5 // fitsio2.h. This file defines our own version of ffpmsg. 6 1 7 /* 2 8 The following code was written by Richard White at STScI and made … … 23 29 #include <stdlib.h> 24 30 #include <string.h> 25 #include "ricecomp.h" /* originally included in rcomp.c file (WDP) */ 31 32 typedef unsigned char Buffer_t; 33 34 typedef struct { 35 int bitbuffer; /* bit buffer */ 36 int bits_to_go; /* bits to go in buffer */ 37 Buffer_t *start; /* start of buffer */ 38 Buffer_t *current; /* current position in buffer */ 39 Buffer_t *end; /* end of buffer */ 40 } Buffer; 41 42 #define putcbuf(c,mf) ((*(mf->current)++ = c), 0) 43 26 44 // #include "fitsio2.h" 27 45 # include "ricecomp.h" 28 46 29 47 static void start_outputing_bits(Buffer *buffer); … … 32 50 33 51 /* this routine used to be called 'rcomp' (WDP) */ 52 /*---------------------------------------------------------------------------*/ 34 53 35 54 int fits_rcomp(int a[], /* input array */ … … 55 74 */ 56 75 bsize = 4; 57 /* nblock = 32; */ 76 77 /* nblock = 32; now an input parameter*/ 58 78 /* 59 79 * From bsize derive: … … 62 82 * BBITS = bits/pixel for direct coding 63 83 */ 84 85 /* 64 86 switch (bsize) { 65 87 case 1: … … 76 98 break; 77 99 default: 78 f printf (stderr,"rdecomp: bsize must be 1, 2, or 4 bytes");100 ffpmsg("rdecomp: bsize must be 1, 2, or 4 bytes"); 79 101 return(-1); 80 102 } 103 */ 104 105 /* move out of switch block, to tweak performance */ 106 fsbits = 5; 107 fsmax = 25; 81 108 bbits = 1<<fsbits; 82 109 … … 93 120 diff = (unsigned int *) malloc(nblock*sizeof(unsigned int)); 94 121 if (diff == (unsigned int *) NULL) { 95 f printf (stderr,"fits_rcomp: insufficient memory");122 ffpmsg("fits_rcomp: insufficient memory"); 96 123 return(-1); 97 124 } … … 103 130 /* write out first int value to the first 4 bytes of the buffer */ 104 131 if (output_nbits(buffer, a[0], 32) == EOF) { 105 f printf (stderr,"rice_encode: end of buffer");132 ffpmsg("rice_encode: end of buffer"); 106 133 free(diff); 107 134 return(-1); … … 133 160 lastpix = nextpix; 134 161 } 162 135 163 /* 136 164 * compute number of bits to split from sum … … 140 168 psum = ((unsigned int) dpsum ) >> 1; 141 169 for (fs = 0; psum>0; fs++) psum >>= 1; 170 142 171 /* 143 172 * write the codes … … 149 178 */ 150 179 if (output_nbits(buffer, fsmax+1, fsbits) == EOF) { 151 f printf (stderr,"rice_encode: end of buffer");180 ffpmsg("rice_encode: end of buffer"); 152 181 free(diff); 153 182 return(-1); … … 155 184 for (j=0; j<thisblock; j++) { 156 185 if (output_nbits(buffer, diff[j], bbits) == EOF) { 157 f printf (stderr,"rice_encode: end of buffer");186 ffpmsg("rice_encode: end of buffer"); 158 187 free(diff); 159 188 return(-1); … … 167 196 */ 168 197 if (output_nbits(buffer, 0, fsbits) == EOF) { 169 f printf (stderr,"rice_encode: end of buffer");198 ffpmsg("rice_encode: end of buffer"); 170 199 free(diff); 171 200 return(-1); … … 174 203 /* normal case: not either very high or very low entropy */ 175 204 if (output_nbits(buffer, fs+1, fsbits) == EOF) { 176 f printf (stderr,"rice_encode: end of buffer");205 ffpmsg("rice_encode: end of buffer"); 177 206 free(diff); 178 207 return(-1); … … 196 225 } else { 197 226 lbitbuffer <<= lbits_to_go; 198 if (putcbuf(lbitbuffer & 0xff,buffer) == EOF) { 199 fprintf (stderr, "rice_encode: end of buffer"); 200 free(diff); 201 return(-1); 202 } 227 putcbuf(lbitbuffer & 0xff,buffer); 228 203 229 for (top -= lbits_to_go; top>=8; top -= 8) { 204 if (putcbuf(0, buffer) == EOF) { 205 fprintf (stderr, "rice_encode: end of buffer"); 206 free(diff); 207 return(-1); 208 } 230 putcbuf(0, buffer); 209 231 } 210 232 lbitbuffer = 1; … … 222 244 lbits_to_go -= fs; 223 245 while (lbits_to_go <= 0) { 224 if (putcbuf((lbitbuffer>>(-lbits_to_go)) & 0xff,buffer)==EOF) { 225 fprintf (stderr, "rice_encode: end of buffer"); 226 free(diff); 227 return(-1); 228 } 246 putcbuf((lbitbuffer>>(-lbits_to_go)) & 0xff,buffer); 229 247 lbits_to_go += 8; 230 248 } 231 249 } 250 } 251 252 /* check if overflowed output buffer */ 253 if (buffer->current > buffer->end) { 254 ffpmsg("rice_encode: end of buffer"); 255 free(diff); 256 return(-1); 257 } 258 buffer->bitbuffer = lbitbuffer; 259 buffer->bits_to_go = lbits_to_go; 260 } 261 } 262 done_outputing_bits(buffer); 263 free(diff); 264 /* 265 * return number of bytes used 266 */ 267 return(buffer->current - buffer->start); 268 } 269 /*---------------------------------------------------------------------------*/ 270 271 int fits_rcomp_short( 272 short a[], /* input array */ 273 int nx, /* number of input pixels */ 274 unsigned char *c, /* output buffer */ 275 int clen, /* max length of output */ 276 int nblock) /* coding block size */ 277 { 278 Buffer bufmem, *buffer = &bufmem; 279 int bsize, i, j, thisblock; 280 281 /* 282 NOTE: in principle, the following 2 variable could be declared as 'short' 283 but in fact the code runs faster (on 32-bit Linux at least) as 'int' 284 */ 285 int lastpix, nextpix; 286 /* int pdiff; */ 287 short pdiff; 288 int v, fs, fsmask, top, fsmax, fsbits, bbits; 289 int lbitbuffer, lbits_to_go; 290 /* unsigned int psum; */ 291 unsigned short psum; 292 double pixelsum, dpsum; 293 unsigned int *diff; 294 295 /* 296 * Original size of each pixel (bsize, bytes) and coding block 297 * size (nblock, pixels) 298 * Could make bsize a parameter to allow more efficient 299 * compression of short & byte images. 300 */ 301 bsize = 2; 302 303 /* nblock = 32; now an input parameter */ 304 /* 305 * From bsize derive: 306 * FSBITS = # bits required to store FS 307 * FSMAX = maximum value for FS 308 * BBITS = bits/pixel for direct coding 309 */ 310 311 /* 312 switch (bsize) { 313 case 1: 314 fsbits = 3; 315 fsmax = 6; 316 break; 317 case 2: 318 fsbits = 4; 319 fsmax = 14; 320 break; 321 case 4: 322 fsbits = 5; 323 fsmax = 25; 324 break; 325 default: 326 ffpmsg("rdecomp: bsize must be 1, 2, or 4 bytes"); 327 return(-1); 328 } 329 */ 330 331 /* move these out of switch block to further tweak performance */ 332 fsbits = 4; 333 fsmax = 14; 334 bbits = 1<<fsbits; 335 336 /* 337 * Set up buffer pointers 338 */ 339 buffer->start = c; 340 buffer->current = c; 341 buffer->end = c+clen; 342 buffer->bits_to_go = 8; 343 /* 344 * array for differences mapped to non-negative values 345 */ 346 diff = (unsigned int *) malloc(nblock*sizeof(unsigned int)); 347 if (diff == (unsigned int *) NULL) { 348 ffpmsg("fits_rcomp: insufficient memory"); 349 return(-1); 350 } 351 /* 352 * Code in blocks of nblock pixels 353 */ 354 start_outputing_bits(buffer); 355 356 /* write out first short value to the first 2 bytes of the buffer */ 357 if (output_nbits(buffer, a[0], 16) == EOF) { 358 ffpmsg("rice_encode: end of buffer"); 359 free(diff); 360 return(-1); 361 } 362 363 lastpix = a[0]; /* the first difference will always be zero */ 364 365 thisblock = nblock; 366 for (i=0; i<nx; i += nblock) { 367 /* last block may be shorter */ 368 if (nx-i < nblock) thisblock = nx-i; 369 /* 370 * Compute differences of adjacent pixels and map them to unsigned values. 371 * Note that this may overflow the integer variables -- that's 372 * OK, because we can recover when decompressing. If we were 373 * compressing shorts or bytes, would want to do this arithmetic 374 * with short/byte working variables (though diff will still be 375 * passed as an int.) 376 * 377 * compute sum of mapped pixel values at same time 378 * use double precision for sum to allow 32-bit integer inputs 379 */ 380 pixelsum = 0.0; 381 for (j=0; j<thisblock; j++) { 382 nextpix = a[i+j]; 383 pdiff = nextpix - lastpix; 384 diff[j] = (unsigned int) ((pdiff<0) ? ~(pdiff<<1) : (pdiff<<1)); 385 pixelsum += diff[j]; 386 lastpix = nextpix; 387 } 388 /* 389 * compute number of bits to split from sum 390 */ 391 dpsum = (pixelsum - (thisblock/2) - 1)/thisblock; 392 if (dpsum < 0) dpsum = 0.0; 393 /* psum = ((unsigned int) dpsum ) >> 1; */ 394 psum = ((unsigned short) dpsum ) >> 1; 395 for (fs = 0; psum>0; fs++) psum >>= 1; 396 397 /* 398 * write the codes 399 * fsbits ID bits used to indicate split level 400 */ 401 if (fs >= fsmax) { 402 /* Special high entropy case when FS >= fsmax 403 * Just write pixel difference values directly, no Rice coding at all. 404 */ 405 if (output_nbits(buffer, fsmax+1, fsbits) == EOF) { 406 ffpmsg("rice_encode: end of buffer"); 407 free(diff); 408 return(-1); 409 } 410 for (j=0; j<thisblock; j++) { 411 if (output_nbits(buffer, diff[j], bbits) == EOF) { 412 ffpmsg("rice_encode: end of buffer"); 413 free(diff); 414 return(-1); 415 } 416 } 417 } else if (fs == 0 && pixelsum == 0) { 418 /* 419 * special low entropy case when FS = 0 and pixelsum=0 (all 420 * pixels in block are zero.) 421 * Output a 0 and return 422 */ 423 if (output_nbits(buffer, 0, fsbits) == EOF) { 424 ffpmsg("rice_encode: end of buffer"); 425 free(diff); 426 return(-1); 427 } 428 } else { 429 /* normal case: not either very high or very low entropy */ 430 if (output_nbits(buffer, fs+1, fsbits) == EOF) { 431 ffpmsg("rice_encode: end of buffer"); 432 free(diff); 433 return(-1); 434 } 435 fsmask = (1<<fs) - 1; 436 /* 437 * local copies of bit buffer to improve optimization 438 */ 439 lbitbuffer = buffer->bitbuffer; 440 lbits_to_go = buffer->bits_to_go; 441 for (j=0; j<thisblock; j++) { 442 v = diff[j]; 443 top = v >> fs; 444 /* 445 * top is coded by top zeros + 1 446 */ 447 if (lbits_to_go >= top+1) { 448 lbitbuffer <<= top+1; 449 lbitbuffer |= 1; 450 lbits_to_go -= top+1; 451 } else { 452 lbitbuffer <<= lbits_to_go; 453 putcbuf(lbitbuffer & 0xff,buffer); 454 for (top -= lbits_to_go; top>=8; top -= 8) { 455 putcbuf(0, buffer); 456 } 457 lbitbuffer = 1; 458 lbits_to_go = 7-top; 459 } 460 /* 461 * bottom FS bits are written without coding 462 * code is output_nbits, moved into this routine to reduce overheads 463 * This code potentially breaks if FS>24, so I am limiting 464 * FS to 24 by choice of FSMAX above. 465 */ 466 if (fs > 0) { 467 lbitbuffer <<= fs; 468 lbitbuffer |= v & fsmask; 469 lbits_to_go -= fs; 470 while (lbits_to_go <= 0) { 471 putcbuf((lbitbuffer>>(-lbits_to_go)) & 0xff,buffer); 472 lbits_to_go += 8; 473 } 474 } 475 } 476 /* check if overflowed output buffer */ 477 if (buffer->current > buffer->end) { 478 ffpmsg("rice_encode: end of buffer"); 479 free(diff); 480 return(-1); 481 } 482 buffer->bitbuffer = lbitbuffer; 483 buffer->bits_to_go = lbits_to_go; 484 } 485 } 486 done_outputing_bits(buffer); 487 free(diff); 488 /* 489 * return number of bytes used 490 */ 491 return(buffer->current - buffer->start); 492 } 493 /*---------------------------------------------------------------------------*/ 494 495 int fits_rcomp_byte( 496 signed char a[], /* input array */ 497 int nx, /* number of input pixels */ 498 unsigned char *c, /* output buffer */ 499 int clen, /* max length of output */ 500 int nblock) /* coding block size */ 501 { 502 Buffer bufmem, *buffer = &bufmem; 503 int bsize, i, j, thisblock; 504 505 /* 506 NOTE: in principle, the following 2 variable could be declared as 'short' 507 but in fact the code runs faster (on 32-bit Linux at least) as 'int' 508 */ 509 int lastpix, nextpix; 510 /* int pdiff; */ 511 signed char pdiff; 512 int v, fs, fsmask, top, fsmax, fsbits, bbits; 513 int lbitbuffer, lbits_to_go; 514 /* unsigned int psum; */ 515 unsigned char psum; 516 double pixelsum, dpsum; 517 unsigned int *diff; 518 519 /* 520 * Original size of each pixel (bsize, bytes) and coding block 521 * size (nblock, pixels) 522 * Could make bsize a parameter to allow more efficient 523 * compression of short & byte images. 524 */ 525 bsize = 1; 526 527 /* nblock = 32; now an input parameter */ 528 /* 529 * From bsize derive: 530 * FSBITS = # bits required to store FS 531 * FSMAX = maximum value for FS 532 * BBITS = bits/pixel for direct coding 533 */ 534 535 /* 536 switch (bsize) { 537 case 1: 538 fsbits = 3; 539 fsmax = 6; 540 break; 541 case 2: 542 fsbits = 4; 543 fsmax = 14; 544 break; 545 case 4: 546 fsbits = 5; 547 fsmax = 25; 548 break; 549 default: 550 ffpmsg("rdecomp: bsize must be 1, 2, or 4 bytes"); 551 return(-1); 552 } 553 */ 554 555 /* move these out of switch block to further tweak performance */ 556 fsbits = 3; 557 fsmax = 6; 558 bbits = 1<<fsbits; 559 560 /* 561 * Set up buffer pointers 562 */ 563 buffer->start = c; 564 buffer->current = c; 565 buffer->end = c+clen; 566 buffer->bits_to_go = 8; 567 /* 568 * array for differences mapped to non-negative values 569 */ 570 diff = (unsigned int *) malloc(nblock*sizeof(unsigned int)); 571 if (diff == (unsigned int *) NULL) { 572 ffpmsg("fits_rcomp: insufficient memory"); 573 return(-1); 574 } 575 /* 576 * Code in blocks of nblock pixels 577 */ 578 start_outputing_bits(buffer); 579 580 /* write out first byte value to the first byte of the buffer */ 581 if (output_nbits(buffer, a[0], 8) == EOF) { 582 ffpmsg("rice_encode: end of buffer"); 583 free(diff); 584 return(-1); 585 } 586 587 lastpix = a[0]; /* the first difference will always be zero */ 588 589 thisblock = nblock; 590 for (i=0; i<nx; i += nblock) { 591 /* last block may be shorter */ 592 if (nx-i < nblock) thisblock = nx-i; 593 /* 594 * Compute differences of adjacent pixels and map them to unsigned values. 595 * Note that this may overflow the integer variables -- that's 596 * OK, because we can recover when decompressing. If we were 597 * compressing shorts or bytes, would want to do this arithmetic 598 * with short/byte working variables (though diff will still be 599 * passed as an int.) 600 * 601 * compute sum of mapped pixel values at same time 602 * use double precision for sum to allow 32-bit integer inputs 603 */ 604 pixelsum = 0.0; 605 for (j=0; j<thisblock; j++) { 606 nextpix = a[i+j]; 607 pdiff = nextpix - lastpix; 608 diff[j] = (unsigned int) ((pdiff<0) ? ~(pdiff<<1) : (pdiff<<1)); 609 pixelsum += diff[j]; 610 lastpix = nextpix; 611 } 612 /* 613 * compute number of bits to split from sum 614 */ 615 dpsum = (pixelsum - (thisblock/2) - 1)/thisblock; 616 if (dpsum < 0) dpsum = 0.0; 617 /* psum = ((unsigned int) dpsum ) >> 1; */ 618 psum = ((unsigned char) dpsum ) >> 1; 619 for (fs = 0; psum>0; fs++) psum >>= 1; 620 621 /* 622 * write the codes 623 * fsbits ID bits used to indicate split level 624 */ 625 if (fs >= fsmax) { 626 /* Special high entropy case when FS >= fsmax 627 * Just write pixel difference values directly, no Rice coding at all. 628 */ 629 if (output_nbits(buffer, fsmax+1, fsbits) == EOF) { 630 ffpmsg("rice_encode: end of buffer"); 631 free(diff); 632 return(-1); 633 } 634 for (j=0; j<thisblock; j++) { 635 if (output_nbits(buffer, diff[j], bbits) == EOF) { 636 ffpmsg("rice_encode: end of buffer"); 637 free(diff); 638 return(-1); 639 } 640 } 641 } else if (fs == 0 && pixelsum == 0) { 642 /* 643 * special low entropy case when FS = 0 and pixelsum=0 (all 644 * pixels in block are zero.) 645 * Output a 0 and return 646 */ 647 if (output_nbits(buffer, 0, fsbits) == EOF) { 648 ffpmsg("rice_encode: end of buffer"); 649 free(diff); 650 return(-1); 651 } 652 } else { 653 /* normal case: not either very high or very low entropy */ 654 if (output_nbits(buffer, fs+1, fsbits) == EOF) { 655 ffpmsg("rice_encode: end of buffer"); 656 free(diff); 657 return(-1); 658 } 659 fsmask = (1<<fs) - 1; 660 /* 661 * local copies of bit buffer to improve optimization 662 */ 663 lbitbuffer = buffer->bitbuffer; 664 lbits_to_go = buffer->bits_to_go; 665 for (j=0; j<thisblock; j++) { 666 v = diff[j]; 667 top = v >> fs; 668 /* 669 * top is coded by top zeros + 1 670 */ 671 if (lbits_to_go >= top+1) { 672 lbitbuffer <<= top+1; 673 lbitbuffer |= 1; 674 lbits_to_go -= top+1; 675 } else { 676 lbitbuffer <<= lbits_to_go; 677 putcbuf(lbitbuffer & 0xff,buffer); 678 for (top -= lbits_to_go; top>=8; top -= 8) { 679 putcbuf(0, buffer); 680 } 681 lbitbuffer = 1; 682 lbits_to_go = 7-top; 683 } 684 /* 685 * bottom FS bits are written without coding 686 * code is output_nbits, moved into this routine to reduce overheads 687 * This code potentially breaks if FS>24, so I am limiting 688 * FS to 24 by choice of FSMAX above. 689 */ 690 if (fs > 0) { 691 lbitbuffer <<= fs; 692 lbitbuffer |= v & fsmask; 693 lbits_to_go -= fs; 694 while (lbits_to_go <= 0) { 695 putcbuf((lbitbuffer>>(-lbits_to_go)) & 0xff,buffer); 696 lbits_to_go += 8; 697 } 698 } 699 } 700 /* check if overflowed output buffer */ 701 if (buffer->current > buffer->end) { 702 ffpmsg("rice_encode: end of buffer"); 703 free(diff); 704 return(-1); 232 705 } 233 706 buffer->bitbuffer = lbitbuffer; … … 270 743 int lbitbuffer; 271 744 int lbits_to_go; 745 /* AND mask for the right-most n bits */ 746 static unsigned int mask[33] = 747 {0, 748 0x1, 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff, 749 0x1ff, 0x3ff, 0x7ff, 0xfff, 0x1fff, 0x3fff, 0x7fff, 0xffff, 750 0x1ffff, 0x3ffff, 0x7ffff, 0xfffff, 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff, 751 0x1ffffff, 0x3ffffff, 0x7ffffff, 0xfffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff}; 272 752 273 753 /* … … 282 762 */ 283 763 lbitbuffer <<= lbits_to_go; 284 lbitbuffer |= (bits>>(n-lbits_to_go)) & ((1<<lbits_to_go)-1); 285 if (putcbuf(lbitbuffer & 0xff,buffer) == EOF) return(EOF); 764 /* lbitbuffer |= (bits>>(n-lbits_to_go)) & ((1<<lbits_to_go)-1); */ 765 lbitbuffer |= (bits>>(n-lbits_to_go)) & *(mask+lbits_to_go); 766 putcbuf(lbitbuffer & 0xff,buffer); 286 767 n -= lbits_to_go; 287 768 lbits_to_go = 8; 288 769 } 289 770 lbitbuffer <<= n; 290 lbitbuffer |= ( bits & ((1<<n)-1) ); 771 /* lbitbuffer |= ( bits & ((1<<n)-1) ); */ 772 lbitbuffer |= ( bits & *(mask+n) ); 291 773 lbits_to_go -= n; 292 774 while (lbits_to_go <= 0) { … … 294 776 * bitbuffer full, put out top 8 bits 295 777 */ 296 if (putcbuf((lbitbuffer>>(-lbits_to_go)) & 0xff,buffer) == EOF) 297 return(EOF); 778 putcbuf((lbitbuffer>>(-lbits_to_go)) & 0xff,buffer); 298 779 lbits_to_go += 8; 299 780 } … … 302 783 return(0); 303 784 } 304 305 785 /*---------------------------------------------------------------------------*/ 306 786 /* Flush out the last bits */ … … 309 789 { 310 790 if(buffer->bits_to_go < 8) { 311 if (putcbuf(buffer->bitbuffer<<buffer->bits_to_go,buffer) == EOF) 791 putcbuf(buffer->bitbuffer<<buffer->bits_to_go,buffer); 792 793 /* if (putcbuf(buffer->bitbuffer<<buffer->bits_to_go,buffer) == EOF) 312 794 return(EOF); 795 */ 313 796 } 314 797 return(0); … … 334 817 */ 335 818 819 /*---------------------------------------------------------------------------*/ 336 820 /* this routine used to be called 'rdecomp' (WDP) */ 337 821 … … 356 840 */ 357 841 bsize = 4; 358 /* nblock = 32; */ 842 843 /* nblock = 32; now an input parameter */ 359 844 /* 360 845 * From bsize derive: … … 363 848 * BBITS = bits/pixel for direct coding 364 849 */ 850 851 /* 365 852 switch (bsize) { 366 853 case 1: … … 377 864 break; 378 865 default: 379 f printf (stderr,"rdecomp: bsize must be 1, 2, or 4 bytes");866 ffpmsg("rdecomp: bsize must be 1, 2, or 4 bytes"); 380 867 return 1; 381 868 } 869 */ 870 871 /* move out of switch block, to tweak performance */ 872 fsbits = 5; 873 fsmax = 25; 874 382 875 bbits = 1<<fsbits; 383 876 384 // XXX EAM : sensible code would put this in an init function,385 // with a provided cleanup function. this is just generating386 // the number of 1 bits for any 8bit value387 877 if (nonzero_count == (int *) NULL) { 388 878 /* … … 394 884 nonzero_count = (int *) malloc(256*sizeof(int)); 395 885 if (nonzero_count == (int *) NULL) { 396 f printf (stderr,"rdecomp: insufficient memory");886 ffpmsg("rdecomp: insufficient memory"); 397 887 return 1; 398 888 } … … 411 901 /* first 4 bytes of input buffer contain the value of the first */ 412 902 /* 4 byte integer value, without any encoding */ 413 414 // XXX EAM : wow! this is just doing { lastpix = *(int *)c; } without a cast (encoded value is big-endian)415 903 416 904 lastpix = 0; … … 437 925 } 438 926 fs = (b >> nbits) - 1; 927 439 928 b &= (1<<nbits)-1; 440 929 /* loop over the next block */ … … 494 983 diff = (nzero<<fs) | (b>>nbits); 495 984 b &= (1<<nbits)-1; 985 496 986 /* undo mapping and differencing */ 497 987 if ((diff & 1) == 0) { … … 505 995 } 506 996 if (c > cend) { 507 f printf (stderr,"decompression error: hit end of compressed byte stream");997 ffpmsg("decompression error: hit end of compressed byte stream"); 508 998 return 1; 509 999 } 510 1000 } 511 1001 if (c < cend) { 512 f printf (stderr,"decompression warning: unused bytes at end of compressed buffer");1002 ffpmsg("decompression warning: unused bytes at end of compressed buffer"); 513 1003 } 514 1004 return 0; 515 1005 } 1006 /*---------------------------------------------------------------------------*/ 1007 /* this routine used to be called 'rdecomp' (WDP) */ 1008 1009 int fits_rdecomp_short (unsigned char *c, /* input buffer */ 1010 int clen, /* length of input */ 1011 unsigned short array[], /* output array */ 1012 int nx, /* number of output pixels */ 1013 int nblock) /* coding block size */ 1014 { 1015 int i, imax; 1016 int bsize, k; 1017 int nbits, nzero, fs; 1018 unsigned char *cend, bytevalue; 1019 unsigned int b, diff, lastpix; 1020 int fsmax, fsbits, bbits; 1021 static int *nonzero_count = (int *)NULL; 1022 1023 /* 1024 * Original size of each pixel (bsize, bytes) and coding block 1025 * size (nblock, pixels) 1026 * Could make bsize a parameter to allow more efficient 1027 * compression of short & byte images. 1028 */ 1029 1030 bsize = 2; 1031 1032 /* nblock = 32; now an input parameter */ 1033 /* 1034 * From bsize derive: 1035 * FSBITS = # bits required to store FS 1036 * FSMAX = maximum value for FS 1037 * BBITS = bits/pixel for direct coding 1038 */ 1039 1040 /* 1041 switch (bsize) { 1042 case 1: 1043 fsbits = 3; 1044 fsmax = 6; 1045 break; 1046 case 2: 1047 fsbits = 4; 1048 fsmax = 14; 1049 break; 1050 case 4: 1051 fsbits = 5; 1052 fsmax = 25; 1053 break; 1054 default: 1055 ffpmsg("rdecomp: bsize must be 1, 2, or 4 bytes"); 1056 return 1; 1057 } 1058 */ 1059 1060 /* move out of switch block, to tweak performance */ 1061 fsbits = 4; 1062 fsmax = 14; 1063 1064 bbits = 1<<fsbits; 1065 1066 if (nonzero_count == (int *) NULL) { 1067 /* 1068 * nonzero_count is lookup table giving number of bits 1069 * in 8-bit values not including leading zeros 1070 */ 1071 1072 /* NOTE!!! This memory never gets freed */ 1073 nonzero_count = (int *) malloc(256*sizeof(int)); 1074 if (nonzero_count == (int *) NULL) { 1075 ffpmsg("rdecomp: insufficient memory"); 1076 return 1; 1077 } 1078 nzero = 8; 1079 k = 128; 1080 for (i=255; i>=0; ) { 1081 for ( ; i>=k; i--) nonzero_count[i] = nzero; 1082 k = k/2; 1083 nzero--; 1084 } 1085 } 1086 /* 1087 * Decode in blocks of nblock pixels 1088 */ 1089 1090 /* first 2 bytes of input buffer contain the value of the first */ 1091 /* 2 byte integer value, without any encoding */ 1092 1093 lastpix = 0; 1094 bytevalue = c[0]; 1095 lastpix = lastpix | (bytevalue<<8); 1096 bytevalue = c[1]; 1097 lastpix = lastpix | bytevalue; 1098 1099 c += 2; 1100 cend = c + clen - 2; 1101 1102 b = *c++; /* bit buffer */ 1103 nbits = 8; /* number of bits remaining in b */ 1104 for (i = 0; i<nx; ) { 1105 /* get the FS value from first fsbits */ 1106 nbits -= fsbits; 1107 while (nbits < 0) { 1108 b = (b<<8) | (*c++); 1109 nbits += 8; 1110 } 1111 fs = (b >> nbits) - 1; 1112 1113 b &= (1<<nbits)-1; 1114 /* loop over the next block */ 1115 imax = i + nblock; 1116 if (imax > nx) imax = nx; 1117 if (fs<0) { 1118 /* low-entropy case, all zero differences */ 1119 for ( ; i<imax; i++) array[i] = lastpix; 1120 } else if (fs==fsmax) { 1121 /* high-entropy case, directly coded pixel values */ 1122 for ( ; i<imax; i++) { 1123 k = bbits - nbits; 1124 diff = b<<k; 1125 for (k -= 8; k >= 0; k -= 8) { 1126 b = *c++; 1127 diff |= b<<k; 1128 } 1129 if (nbits>0) { 1130 b = *c++; 1131 diff |= b>>(-k); 1132 b &= (1<<nbits)-1; 1133 } else { 1134 b = 0; 1135 } 1136 1137 /* 1138 * undo mapping and differencing 1139 * Note that some of these operations will overflow the 1140 * unsigned int arithmetic -- that's OK, it all works 1141 * out to give the right answers in the output file. 1142 */ 1143 if ((diff & 1) == 0) { 1144 diff = diff>>1; 1145 } else { 1146 diff = ~(diff>>1); 1147 } 1148 array[i] = diff+lastpix; 1149 lastpix = array[i]; 1150 } 1151 } else { 1152 /* normal case, Rice coding */ 1153 for ( ; i<imax; i++) { 1154 /* count number of leading zeros */ 1155 while (b == 0) { 1156 nbits += 8; 1157 b = *c++; 1158 } 1159 nzero = nbits - nonzero_count[b]; 1160 nbits -= nzero+1; 1161 /* flip the leading one-bit */ 1162 b ^= 1<<nbits; 1163 /* get the FS trailing bits */ 1164 nbits -= fs; 1165 while (nbits < 0) { 1166 b = (b<<8) | (*c++); 1167 nbits += 8; 1168 } 1169 diff = (nzero<<fs) | (b>>nbits); 1170 b &= (1<<nbits)-1; 1171 1172 /* undo mapping and differencing */ 1173 if ((diff & 1) == 0) { 1174 diff = diff>>1; 1175 } else { 1176 diff = ~(diff>>1); 1177 } 1178 array[i] = diff+lastpix; 1179 lastpix = array[i]; 1180 } 1181 } 1182 if (c > cend) { 1183 ffpmsg("decompression error: hit end of compressed byte stream"); 1184 return 1; 1185 } 1186 } 1187 if (c < cend) { 1188 ffpmsg("decompression warning: unused bytes at end of compressed buffer"); 1189 } 1190 return 0; 1191 } 1192 /*---------------------------------------------------------------------------*/ 1193 /* this routine used to be called 'rdecomp' (WDP) */ 1194 1195 int fits_rdecomp_byte (unsigned char *c, /* input buffer */ 1196 int clen, /* length of input */ 1197 unsigned char array[], /* output array */ 1198 int nx, /* number of output pixels */ 1199 int nblock) /* coding block size */ 1200 { 1201 int i, imax; 1202 int bsize, k; 1203 int nbits, nzero, fs; 1204 unsigned char *cend; 1205 unsigned int b, diff, lastpix; 1206 int fsmax, fsbits, bbits; 1207 static int *nonzero_count = (int *)NULL; 1208 1209 /* 1210 * Original size of each pixel (bsize, bytes) and coding block 1211 * size (nblock, pixels) 1212 * Could make bsize a parameter to allow more efficient 1213 * compression of short & byte images. 1214 */ 1215 1216 bsize = 1; 1217 1218 /* nblock = 32; now an input parameter */ 1219 /* 1220 * From bsize derive: 1221 * FSBITS = # bits required to store FS 1222 * FSMAX = maximum value for FS 1223 * BBITS = bits/pixel for direct coding 1224 */ 1225 1226 /* 1227 switch (bsize) { 1228 case 1: 1229 fsbits = 3; 1230 fsmax = 6; 1231 break; 1232 case 2: 1233 fsbits = 4; 1234 fsmax = 14; 1235 break; 1236 case 4: 1237 fsbits = 5; 1238 fsmax = 25; 1239 break; 1240 default: 1241 ffpmsg("rdecomp: bsize must be 1, 2, or 4 bytes"); 1242 return 1; 1243 } 1244 */ 1245 1246 /* move out of switch block, to tweak performance */ 1247 fsbits = 3; 1248 fsmax = 6; 1249 1250 bbits = 1<<fsbits; 1251 1252 if (nonzero_count == (int *) NULL) { 1253 /* 1254 * nonzero_count is lookup table giving number of bits 1255 * in 8-bit values not including leading zeros 1256 */ 1257 1258 /* NOTE!!! This memory never gets freed */ 1259 nonzero_count = (int *) malloc(256*sizeof(int)); 1260 if (nonzero_count == (int *) NULL) { 1261 ffpmsg("rdecomp: insufficient memory"); 1262 return 1; 1263 } 1264 nzero = 8; 1265 k = 128; 1266 for (i=255; i>=0; ) { 1267 for ( ; i>=k; i--) nonzero_count[i] = nzero; 1268 k = k/2; 1269 nzero--; 1270 } 1271 } 1272 /* 1273 * Decode in blocks of nblock pixels 1274 */ 1275 1276 /* first byte of input buffer contain the value of the first */ 1277 /* byte integer value, without any encoding */ 1278 1279 lastpix = c[0]; 1280 c += 1; 1281 cend = c + clen - 1; 1282 1283 b = *c++; /* bit buffer */ 1284 nbits = 8; /* number of bits remaining in b */ 1285 for (i = 0; i<nx; ) { 1286 /* get the FS value from first fsbits */ 1287 nbits -= fsbits; 1288 while (nbits < 0) { 1289 b = (b<<8) | (*c++); 1290 nbits += 8; 1291 } 1292 fs = (b >> nbits) - 1; 1293 1294 b &= (1<<nbits)-1; 1295 /* loop over the next block */ 1296 imax = i + nblock; 1297 if (imax > nx) imax = nx; 1298 if (fs<0) { 1299 /* low-entropy case, all zero differences */ 1300 for ( ; i<imax; i++) array[i] = lastpix; 1301 } else if (fs==fsmax) { 1302 /* high-entropy case, directly coded pixel values */ 1303 for ( ; i<imax; i++) { 1304 k = bbits - nbits; 1305 diff = b<<k; 1306 for (k -= 8; k >= 0; k -= 8) { 1307 b = *c++; 1308 diff |= b<<k; 1309 } 1310 if (nbits>0) { 1311 b = *c++; 1312 diff |= b>>(-k); 1313 b &= (1<<nbits)-1; 1314 } else { 1315 b = 0; 1316 } 1317 1318 /* 1319 * undo mapping and differencing 1320 * Note that some of these operations will overflow the 1321 * unsigned int arithmetic -- that's OK, it all works 1322 * out to give the right answers in the output file. 1323 */ 1324 if ((diff & 1) == 0) { 1325 diff = diff>>1; 1326 } else { 1327 diff = ~(diff>>1); 1328 } 1329 array[i] = diff+lastpix; 1330 lastpix = array[i]; 1331 } 1332 } else { 1333 /* normal case, Rice coding */ 1334 for ( ; i<imax; i++) { 1335 /* count number of leading zeros */ 1336 while (b == 0) { 1337 nbits += 8; 1338 b = *c++; 1339 } 1340 nzero = nbits - nonzero_count[b]; 1341 nbits -= nzero+1; 1342 /* flip the leading one-bit */ 1343 b ^= 1<<nbits; 1344 /* get the FS trailing bits */ 1345 nbits -= fs; 1346 while (nbits < 0) { 1347 b = (b<<8) | (*c++); 1348 nbits += 8; 1349 } 1350 diff = (nzero<<fs) | (b>>nbits); 1351 b &= (1<<nbits)-1; 1352 1353 /* undo mapping and differencing */ 1354 if ((diff & 1) == 0) { 1355 diff = diff>>1; 1356 } else { 1357 diff = ~(diff>>1); 1358 } 1359 array[i] = diff+lastpix; 1360 lastpix = array[i]; 1361 } 1362 } 1363 if (c > cend) { 1364 ffpmsg("decompression error: hit end of compressed byte stream"); 1365 return 1; 1366 } 1367 } 1368 if (c < cend) { 1369 ffpmsg("decompression warning: unused bytes at end of compressed buffer"); 1370 } 1371 return 0; 1372 } -
branches/eam_branch_20080421/Ohana/src/libfits/extern/ricecomp.h
r15487 r18424 1 /* @(#) buffer.h 1.1 98/07/21 12:34:27 */2 /* buffer.h: structure for compression to buffer rather than to a file, including3 * bit I/O buffer4 *5 * R. White, 19 June 19986 */7 1 8 2 9 typedef unsigned char Buffer_t; 3 // 2008.06.22 EAM : This code was taken from CFITSIO and included in Ohana for rice 4 // decompression. In order to include this .c file (or future upgrades), we include our own 5 // version of ricecomp.h (not the one available in the CFITSIO tree) and include it instead of 6 // fitsio2.h. This file defines our own version of ffpmsg. 10 7 11 typedef struct { 12 int bitbuffer; /* bit buffer */ 13 int bits_to_go; /* bits to go in buffer */ 14 Buffer_t *start; /* start of buffer */ 15 Buffer_t *current; /* current position in buffer */ 16 Buffer_t *end; /* end of buffer */ 17 } Buffer; 18 19 #define buffree(mf) (free(mf->start), free(mf)) 20 #define bufused(mf) (mf->current - mf->start) 21 #define bufreset(mf) (mf->current = mf->start) 22 23 /* 24 * getcbuf, putcbuf macros for character IO to buffer 25 * putcbuf returns EOF on end of buffer, else returns 0 26 */ 27 #define getcbuf(mf) ((mf->current >= mf->end) ? EOF : *(mf->current)++) 28 #define putcbuf(c,mf) \ 29 ((mf->current >= mf->end) ? \ 30 EOF :\ 31 ((*(mf->current)++ = c), 0)) 32 33 /* 34 * bufalloc sets up buffer of length n 35 */ 36 37 /* not needed by CFITSIO 38 39 static Buffer *bufalloc(int n) 40 { 41 Buffer *mf; 42 43 mf = (Buffer *) malloc(sizeof(Buffer)); 44 if (mf == (Buffer *)NULL) return((Buffer *)NULL); 45 46 mf->start = (Buffer_t *) malloc(n*sizeof(Buffer_t)); 47 if (mf->start == (Buffer_t *)NULL) { 48 free(mf); 49 return((Buffer *)NULL); 50 } 51 mf->bits_to_go = 8; 52 mf->end = mf->start + n; 53 mf->current = mf->start; 54 return(mf); 55 } 56 */ 57 58 /* 59 * bufrealloc extends buffer (or truncates it) by 60 * reallocating memory 61 */ 62 63 /* not needed by CFITSIO 64 static int bufrealloc(Buffer *mf, int n) 65 { 66 int len; 67 68 len = mf->current - mf->start; 69 70 * silently throw away data if buffer is already longer than n * 71 if (len>n) len = n; 72 if (len<0) len = 0; 73 74 mf->start = (Buffer_t *) realloc(mf->start, n*sizeof(Buffer_t)); 75 if (mf->start == (Buffer_t *)NULL) return(0); 76 77 mf->end = mf->start + n; 78 mf->current = mf->start + len; 79 return(n); 80 } 81 */ 82 83 /* 84 * bufdump dumps contents of buffer to outfile and resets 85 * it to be empty. Returns number of bytes written. 86 * 87 * Note we don't write out the bit buffer -- you must call 88 * done_outputing_bits() first to ensure that the bit buffer 89 * is written out. I do it this way to allow incremental 90 * buffer dumps while bit IO is still going on. 91 */ 92 93 /* not needed by CFITSIO 94 95 static int bufdump(FILE *outfile, Buffer *buffer) 96 { 97 int ndump; 98 99 ndump = bufused(buffer); 100 if (fwrite(buffer->start, 1, ndump, outfile) != ndump) { 101 fprintf(stderr, "bufdump: error in write\n"); 102 exit(1); 103 } 104 bufreset(buffer); 105 return(ndump); 106 } 107 */ 8 #define ffpmsg(MSG) fprintf(stderr, "%s\n", MSG) -
branches/eam_branch_20080421/Ohana/src/libfits/header/F_copy_H.c
r15487 r18424 23 23 out[0].bscale = in[0].bscale; 24 24 25 if (out[0].buffer != NULL) free (out[0].buffer); 25 26 ALLOCATE (out[0].buffer, char, out[0].size); 26 27 -
branches/eam_branch_20080421/Ohana/src/libfits/include/gfitsio.h
r16995 r18424 161 161 int gfits_extension_is_compressed PROTO((Header *header)); 162 162 int gfits_tile_size PROTO((Matrix *matrix, int *otile, int *ztile)); 163 int gfits_uncompressed_data_pixsize PROTO((char *cmptype, int out_bitpix ));163 int gfits_uncompressed_data_pixsize PROTO((char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions)); 164 164 int gfits_vartable_heap_pixsize PROTO((char format)); 165 165 -
branches/eam_branch_20080421/Ohana/src/libfits/matrix/F_compress_M.c
r16970 r18424 18 18 return (FALSE); } 19 19 20 # define MOD_KEYWORD(NAME,ZNAME,TYPE,IN,OUT) { \ 21 gfits_scan (header, ZNAME, TYPE, 1, IN); \ 22 gfits_delete (header, ZNAME, 1); \ 23 gfits_print (header, NAME, TYPE, 1, OUT); } 20 # define MOD_KEYWORD(ZNAME,NAME,TYPE,IN,OUT) { \ 21 if (gfits_scan (header, ZNAME, TYPE, 1, IN)) { \ 22 gfits_modify (header, NAME, TYPE, 1, OUT); \ 23 } \ 24 gfits_delete (header, ZNAME, 1); } 24 25 25 26 # define MOD_KEYWORD_REQUIRED(ZNAME,NAME,TYPE,IN,OUT) { \ 26 27 if (!gfits_scan (header, ZNAME, TYPE, 1, IN)) ESCAPE; \ 27 28 gfits_delete (header, ZNAME, 1); \ 28 gfits_ print(header, NAME, TYPE, 1, OUT); }29 gfits_modify (header, NAME, TYPE, 1, OUT); } 29 30 30 31 int gfits_uncompress_image (Header *header, Matrix *matrix, FTable *ftable) { … … 55 56 // copy original header to output header 56 57 gfits_copy_header (ftable->header, header); 58 59 // delete ZIMAGE from output header 60 gfits_delete (header, "ZIMAGE", 1); 57 61 58 62 // extract compression-specific keywords, update header as needed. … … 79 83 } 80 84 } else { 85 gfits_delete (header, "ZTILE1", 1); 81 86 for (i = 1; i < header->Naxes; i++) { 82 87 snprintf (key, 10, "ZTILE%d", i + 1); … … 143 148 gfits_delete (header, "ZTENSION", 1); 144 149 gfits_modify_extended (header, exttype, "Image extension"); 145 // XXX validate that exttype == 'IMAGE'? 146 147 MOD_KEYWORD ("ZPCOUNT", "PCOUNT", "%d", &header->pcount, header->pcount); 148 MOD_KEYWORD ("ZGCOUNT", "GCOUNT", "%d", &header->gcount, header->gcount); 149 } 150 151 MOD_KEYWORD ("ZHECKSUM", "ZHECKSUM", "%s", checksum, checksum); 150 151 // we may have an uncompressed PCOUNT / GCOUNT value, otherwise set to 0,1 152 if (gfits_scan (header, "ZPCOUNT", "%d", 1, &header->pcount)) { 153 gfits_delete (header, "ZPCOUNT", 1); 154 gfits_modify (header, "PCOUNT", "%d", 1, header->pcount); 155 } else { 156 header->pcount = 0; 157 gfits_modify (header, "PCOUNT", "%d", 1, header->pcount); 158 } 159 if (gfits_scan (header, "ZGCOUNT", "%d", 1, &header->gcount)) { 160 gfits_delete (header, "ZGCOUNT", 1); 161 gfits_modify (header, "GCOUNT", "%d", 1, header->gcount); 162 } else { 163 header->pcount = 1; 164 gfits_modify (header, "GCOUNT", "%d", 1, header->gcount); 165 } 166 } else { 167 header->pcount = 0; 168 header->gcount = 1; 169 gfits_modify (header, "PCOUNT", "%d", 1, header->pcount); 170 gfits_modify (header, "GCOUNT", "%d", 1, header->gcount); 171 } 172 173 MOD_KEYWORD ("ZHECKSUM", "CHECKSUM", "%s", checksum, checksum); 152 174 MOD_KEYWORD ("ZDATASUM", "DATASUM", "%s", datasum, datasum); 153 175 … … 167 189 168 190 if (!gfits_varlength_column_define (ftable, &zdef, zcol)) ESCAPE; 191 gfits_delete (header, "TFIELDS", 1); 192 snprintf (key, 10, "TTYPE%d", zcol); 193 gfits_delete (header, key, 1); 194 snprintf (key, 10, "TFORM%d", zcol); 195 gfits_delete (header, key, 1); 169 196 170 197 // create the output image … … 200 227 201 228 // size of a pixel in the output from the decompression routine 202 odata_pixsize = gfits_uncompressed_data_pixsize (cmptype, header[0].bitpix );229 odata_pixsize = gfits_uncompressed_data_pixsize (cmptype, header[0].bitpix, optname, optvalue, Noptions); 203 230 ALLOCATE (out, char, odata_pixsize*max_tile_size); 204 231 … … 385 412 386 413 case 2: 387 for (i = 0; i < Nzdata; i+=2) {414 for (i = 0; i < 2*Nzdata; i+=2) { 388 415 tmp = zdata[i]; 389 416 zdata[i] = zdata[i+1]; … … 393 420 394 421 case 4: 395 for (i = 0; i < Nzdata; i+=4) {422 for (i = 0; i < 4*Nzdata; i+=4) { 396 423 tmp = zdata[i+1]; 397 424 zdata[i+1] = zdata[i+2]; … … 404 431 405 432 case 8: 406 for (i = 0; i < Nzdata; i+=8) {433 for (i = 0; i < 8*Nzdata; i+=8) { 407 434 tmp = zdata[i+0]; 408 435 zdata[i+0] = zdata[i+7]; … … 426 453 int gfits_extension_is_compressed (Header *header) { 427 454 428 int has_extname, has_zimage, zimage; 429 char extname[80]; 430 455 int has_extension, has_extname, has_zimage, zimage; 456 char extname[80], extension[80]; 457 458 has_extension = gfits_scan (header, "XTENSION", "%s", 1, extension); 431 459 has_extname = gfits_scan (header, "EXTNAME", "%s", 1, extname); 432 460 has_zimage = gfits_scan (header, "ZIMAGE", "%t", 1, &zimage); 433 461 462 if (has_extension && !strcmp (extension, "IMAGE")) return (FALSE); 434 463 if (has_zimage && zimage) return (TRUE); 435 464 if (has_extname) { … … 453 482 } 454 483 455 int gfits_uncompressed_data_pixsize (char *cmptype, int out_bitpix) { 484 int gfits_uncompressed_data_pixsize (char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions) { 485 486 int i, Nbyte; 456 487 457 488 if (!strcasecmp(cmptype, "GZIP_1")) { … … 459 490 } 460 491 if (!strcasecmp(cmptype, "RICE_1")) { 492 493 // if BYTEPIX option is specified, use that for Nbyte 494 for (i = 0; i < Noptions; i++) { 495 if (!strcmp(optname[i], "BYTEPIX")) { 496 Nbyte = atoi (optvalue[i]); 497 return (Nbyte); 498 } 499 } 500 461 501 return (4); 462 502 } 463 503 if (!strcasecmp(cmptype, "PLIO_1")) { 464 return ( 1);504 return (4); 465 505 } 466 506 if (!strcasecmp(cmptype, "HCOMPRESS_1")) { -
branches/eam_branch_20080421/Ohana/src/libfits/matrix/F_copy_M.c
r7054 r18424 16 16 matrix2[0].Naxis[i] = matrix1[0].Naxis[i]; 17 17 18 if (matrix2[0].buffer != NULL) free (matrix2[0].buffer); 18 19 ALLOCATE (matrix2[0].buffer, char, matrix2[0].size); 19 20 -
branches/eam_branch_20080421/Ohana/src/libfits/matrix/F_create_M.c
r15487 r18424 27 27 } 28 28 29 // XXX free buffer if non-null: need to double check for existing frees -
branches/eam_branch_20080421/Ohana/src/libfits/matrix/F_uncompress_data.c
r15657 r18424 6 6 int fits_rcomp(int a[], int nx, unsigned char *c, int clen, int nblock); 7 7 int fits_rdecomp (unsigned char *c, int clen, unsigned int array[], int nx, int nblock); 8 int fits_rdecomp_short (unsigned char *c, int clen, unsigned short array[], int nx, int nblock); 9 int fits_rdecomp_byte (unsigned char *c, int clen, unsigned char array[], int nx, int nblock); 8 10 9 11 /* functions defined in fits_hcompress.c */ … … 60 62 // fprintf (stderr, "%d comp bytes; %d uncomp 'pixels', totals: %d %d\n", Nzdata, Npix, Ninsum, Noutsum); 61 63 62 // rice decompression from the CFITSIO source tree : we need to tell it the expected number of pixels 63 // is also REQUIRES 4byte output, which is fairly stupid. 64 if (fits_rdecomp ((unsigned char *) zdata, Nzdata, (unsigned int *) outdata, Npix, blocksize)) { 65 fprintf (stderr, "error in rice decompression\n"); 66 return (FALSE); 64 switch (out_pixsize) { 65 case 4: 66 // rice decompression from the CFITSIO source tree : we need to tell it the expected number of pixels 67 // is also REQUIRES 4byte output, which is fairly stupid. 68 if (fits_rdecomp ((unsigned char *) zdata, Nzdata, (unsigned int *) outdata, Npix, blocksize)) { 69 fprintf (stderr, "error in rice decompression\n"); 70 return (FALSE); 71 } 72 return (TRUE); 73 74 case 2: 75 if (fits_rdecomp_short ((unsigned char *) zdata, Nzdata, (unsigned short *) outdata, Npix, blocksize)) { 76 fprintf (stderr, "error in rice decompression\n"); 77 return (FALSE); 78 } 79 return (TRUE); 80 81 case 1: 82 if (fits_rdecomp_byte ((unsigned char *) zdata, Nzdata, (unsigned char *) outdata, Npix, blocksize)) { 83 fprintf (stderr, "error in rice decompression\n"); 84 return (FALSE); 85 } 86 return (TRUE); 87 88 default: 89 fprintf (stderr, "invalid output pixel size %d\n", out_pixsize); 90 return (FALSE); 67 91 } 68 return (TRUE);92 69 93 } 70 94 -
branches/eam_branch_20080421/Ohana/src/libfits/table/F_table_varlength.c
r15487 r18424 70 70 void *gfits_varlength_column_pointer (FTable *ftable, VarLengthColumn *column, int row, int *length) { 71 71 72 void *result; 72 73 int offset, Nx, *ptr; 73 74 … … 92 93 offset = ptr[1]; 93 94 94 switch (column->format) { 95 case 'X': 96 case 'L': 97 case 'A': 98 case 'B': { 99 char *result; 100 result = (char *) ftable->buffer + column->heap_start + offset; 101 return result; 102 } 103 case 'I': { 104 short *result; 105 result = (short *) ftable->buffer + column->heap_start + offset; 106 return result; 107 } 108 case 'J': { 109 int *result; 110 result = (int *) ftable->buffer + column->heap_start + offset; 111 return result; 112 } 113 case 'E': 114 case 'C': { 115 float *result; 116 result = (float *) ftable->buffer + column->heap_start + offset; 117 return result; 118 } 119 case 'D': 120 case 'M': { 121 double *result; 122 result = (double *) ftable->buffer + column->heap_start + offset; 123 return result; 124 } 125 case 'P': 126 default: 127 abort(); 128 } 129 abort(); 95 result = (void *) (ftable->buffer + column->heap_start + offset); 96 return result; 130 97 } 131 -
branches/eam_branch_20080421/Ohana/src/libkapa/src/IOfuncs.c
r16466 r18424 1 1 # include <kapa_internal.h> 2 # define DEBUG 0 2 3 3 4 /** these function expect to operate with a BLOCKing socket **/ … … 63 64 status = read (device, buffer, 16); 64 65 buffer[16] = 0; 65 if (status != 16) fprintf (stderr, "dropped message length\n"); 66 if (status != 16) { 67 fprintf (stderr, "dropped message length\n"); 68 } 69 if (DEBUG) fprintf (stderr, "recv buffer: %s\n", buffer); 66 70 67 71 /* find the message length, allocate space */ … … 71 75 /* read Nbytes from the device */ 72 76 status = read (device, message, Nbytes); 73 if (status != Nbytes) fprintf (stderr, "Kii/Kapa comm error\n"); 77 if (status != Nbytes) { 78 fprintf (stderr, "Kii/Kapa comm error\n"); 79 } 74 80 message[status] = 0; 75 81 /* make the string easy to parse */ 76 82 77 //fprintf (stderr, "recv: %s\n", message);83 if (DEBUG) fprintf (stderr, "recv: %s\n", message); 78 84 79 85 /* scan the incoming message */ … … 112 118 write (device, string, length); 113 119 114 //fprintf (stderr, "send: %s\n", string);120 if (DEBUG) fprintf (stderr, "send: %s\n", string); 115 121 116 122 free (string); … … 129 135 /* read Nbytes from the device */ 130 136 status = read (device, message, length); 137 if (DEBUG) fprintf (stderr, "recv message: %s\n", message); 131 138 132 139 if (status != length) { -
branches/eam_branch_20080421/Ohana/src/libkapa/src/KapaWindow.c
r14401 r18424 23 23 KiiSendMessage (fd, "%12.6g %12.6g %12.6g %12.6g", 24 24 graphdata[0].xmin, graphdata[0].xmax, graphdata[0].ymin, graphdata[0].ymax); 25 26 KiiSendMessage (fd, "%lf %d", graphdata[0].lweight, graphdata[0].color); 25 27 26 28 KiiSendMessage (fd, "%s %s %s", graphdata[0].axis, graphdata[0].labels, graphdata[0].ticks); -
branches/eam_branch_20080421/Ohana/src/libohana/src/IOBufferOps.c
r16060 r18424 57 57 switch (errno) { 58 58 case EAGAIN: 59 case EI O:60 /** no data available in pipe**/59 case EINTR: 60 /** data not available in pipe or read interrupted : just try again **/ 61 61 return (-1); 62 62 default: 63 /** error reading from pipe**/63 /** serious error (buffer overflow, invalid fd, etc **/ 64 64 perror ("ReadtoIOBuffer read error"); 65 65 return (-2); -
branches/eam_branch_20080421/Ohana/src/libohana/src/findexec.c
r16212 r18424 213 213 214 214 ALLOCATE (file, char, strlen(name) + 1); 215 strcpy (file, name); 216 c = strrchr ( file, '/');215 216 c = strrchr (name, '/'); 217 217 if (c == (char *) NULL) { 218 218 strcpy (file, name); -
branches/eam_branch_20080421/Ohana/src/opihi/cmd.astro/coord_systems.c
r17469 r18424 59 59 abort(); 60 60 } 61 break; 61 62 case COORD_GALACTIC: 62 63 switch (output) { … … 77 78 abort(); 78 79 } 80 break; 79 81 default: 80 82 abort(); -
branches/eam_branch_20080421/Ohana/src/opihi/cmd.astro/coords.c
r12524 r18424 104 104 gprint (GP_ERR, "USAGE: coords [buffer] (-c R D) | (-p X Y)\n"); 105 105 gprint (GP_ERR, "only one of -p or -c can be used\n"); 106 gprint (GP_ERR, " -p : from pixels to ra/dec\n"); 107 gprint (GP_ERR, " -c : from ra/dec to pixels\n"); 106 108 escape: 107 109 if (MOSAIC != NULL) free (MOSAIC); -
branches/eam_branch_20080421/Ohana/src/opihi/cmd.basic/Makefile
r16211 r18424 22 22 $(SRC)/config.$(ARCH).o \ 23 23 $(SRC)/continue.$(ARCH).o \ 24 $(SRC)/basename.$(ARCH).o \ 24 25 $(SRC)/dirname.$(ARCH).o \ 25 26 $(SRC)/date.$(ARCH).o \ -
branches/eam_branch_20080421/Ohana/src/opihi/cmd.basic/init.c
r16426 r18424 1 1 # include "basic.h" 2 2 3 int basename_opihi PROTO((int, char **)); 3 4 int config PROTO((int, char **)); 4 5 int exec_sleep PROTO((int, char **)); … … 47 48 {1, "cd", cd, "change directory"}, 48 49 {1, "date", date, "get current date"}, 50 {1, "basename", basename_opihi, "built-in basename function"}, 49 51 {1, "dirname", dirname_opihi, "built-in dirname function"}, 50 52 {1, "echo", echo, "type this line *"}, -
branches/eam_branch_20080421/Ohana/src/opihi/cmd.data/Makefile
r17123 r18424 89 89 $(SRC)/queuepop.$(ARCH).o \ 90 90 $(SRC)/queueprint.$(ARCH).o \ 91 $(SRC)/queuesubstr.$(ARCH).o \ 91 92 $(SRC)/queueinit.$(ARCH).o \ 92 93 $(SRC)/radial.$(ARCH).o \ -
branches/eam_branch_20080421/Ohana/src/opihi/cmd.data/box.c
r13479 r18424 15 15 if (!GetGraph (&graphmode, &kapa, name)) return (FALSE); 16 16 FREE (name); 17 18 graphmode.lweight = 1; 19 if ((N = get_argument (argc, argv, "-lw"))) { 20 remove_argument (N, &argc, argv); 21 graphmode.lweight = atof(argv[N]); 22 remove_argument (N, &argc, argv); 23 } 24 25 graphmode.color = KapaColorByName ("black"); 26 if ((N = get_argument (argc, argv, "-c"))) { 27 remove_argument (N, &argc, argv); 28 graphmode.color = KapaColorByName (argv[N]); 29 if (graphmode.color == -1) return (FALSE); 30 remove_argument (N, &argc, argv); 31 } 17 32 18 33 strcpy (graphmode.ticks, "2222"); -
branches/eam_branch_20080421/Ohana/src/opihi/cmd.data/dbselect.c
r13615 r18424 5 5 int dbselect (int argc, char **argv) { 6 6 7 time_t seconds; 7 8 int i, j, Nbytes, Ncols, Nrows; 8 9 char *query; … … 80 81 } 81 82 for (i = 0; i < Ncols; i++) { 82 vec[i][0].elements[j] = atof (row[i]); 83 if (row[i]) { 84 switch (fields[i].type) { 85 case FIELD_TYPE_TINY: 86 case FIELD_TYPE_SHORT: 87 case FIELD_TYPE_LONG: 88 case FIELD_TYPE_INT24: 89 case FIELD_TYPE_LONGLONG: 90 case FIELD_TYPE_DECIMAL: 91 case FIELD_TYPE_FLOAT: 92 case FIELD_TYPE_DOUBLE: 93 vec[i][0].elements[j] = atof (row[i]); 94 break; 95 case FIELD_TYPE_TIME: 96 case FIELD_TYPE_DATE: 97 case FIELD_TYPE_DATETIME: 98 seconds = ohana_date_to_sec (row[i]); 99 vec[i][0].elements[j] = ohana_sec_to_mjd (seconds); 100 break; 101 default: 102 vec[i][0].elements[j] = NAN; 103 } 104 } else { 105 vec[i][0].elements[j] = NAN; 106 } 83 107 } 84 108 } 85 86 109 free (query); 87 110 free (vec); … … 89 112 return (TRUE); 90 113 } 91 92 114 # else 93 115 -
branches/eam_branch_20080421/Ohana/src/opihi/cmd.data/histogram.c
r15514 r18424 34 34 REALLOCATE (yvec[0].elements, float, yvec[0].Nelements); 35 35 bzero (yvec[0].elements, sizeof(float)*yvec[0].Nelements); 36 if (Nbins < 1) { 37 return (TRUE); 38 } 36 39 37 40 V = xvec[0].elements; -
branches/eam_branch_20080421/Ohana/src/opihi/cmd.data/init.c
r17123 r18424 74 74 int queueprint PROTO((int, char **)); 75 75 int queuepush PROTO((int, char **)); 76 int queuesubstr PROTO((int, char **)); 76 77 int queuesize PROTO((int, char **)); 77 78 int rd PROTO((int, char **)); … … 196 197 {1, "queuelist", queuelist, "list defined queues"}, 197 198 {1, "queueload", queueload, "load queue from command"}, 199 {1, "queuesubstr", queuesubstr, "bulk replace strings in queue"}, 198 200 {1, "queuesize", queuesize, "show queue size"}, 199 201 {1, "rd", rd, "load fits image"}, -
branches/eam_branch_20080421/Ohana/src/opihi/cmd.data/rd.c
r15661 r18424 182 182 Header theader; 183 183 ftable.header = &theader; 184 ftable.header[0].buffer = NULL; 184 185 gfits_copy_header (&buf[0].header, ftable.header); 185 186 status = gfits_fread_ftable_data (f, &ftable); // this just reads the bytes (not even a SWAP) 186 187 status = gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable); 188 // uncompressing the image leaves the format as an extension 189 gfits_extended_to_primary (&buf[0].header, TRUE, "Standard FITS"); 187 190 gfits_free_table (&ftable); 188 191 // XXX this currently does not work for a cube (we get a cube back, not a specific plane) … … 190 193 sprintf (region, "-1 -1 -1 -1 %d %d", (plane - 1), plane); 191 194 status = gfits_fread_matrix_segment (f, &buf[0].matrix, &buf[0].header, region); 192 fclose (f);193 }195 } 196 fclose (f); 194 197 195 198 if (!status) { -
branches/eam_branch_20080421/Ohana/src/opihi/cmd.data/spline_construct.c
r16119 r18424 16 16 if ((out = SelectBuffer (argv[2], ANYBUFFER, TRUE)) == NULL) return (FALSE); 17 17 18 // XXX move this to gfits_create_matrix 18 19 free (out[0].matrix.buffer); 19 free (out[0].header.buffer);20 20 if ((in[0].file[0] != '*') && (in[0].file[0] != '(')) { 21 21 sprintf (out[0].file, "*%s", in[0].file); -
branches/eam_branch_20080421/Ohana/src/opihi/cmd.data/wd.c
r15487 r18424 81 81 memcpy (temp_header.buffer, buf[0].header.buffer, temp_header.size); 82 82 83 if (temp_header.Naxes) gfits_convert_format (&temp_header, &temp_matrix, outBitpix, outScale, outZero, outUnsign); 83 if (temp_header.Naxes) { 84 gfits_convert_format (&temp_header, &temp_matrix, outBitpix, outScale, outZero, outUnsign); 85 } else { 86 gfits_modify (&temp_header, "BITPIX", "%d", 1, outBitpix); 87 gfits_modify (&temp_header, "BSCALE", "%lf", 1, outScale); 88 gfits_modify (&temp_header, "BZERO", "%lf", 1, outZero); 89 gfits_modify (&temp_header, "UNSIGN", "%t", 1, outUnsign); 90 } 84 91 85 92 if (Extend) { -
branches/eam_branch_20080421/Ohana/src/opihi/dvo/ImageOps.c
r14590 r18424 50 50 if (selection->useDisplay) { 51 51 if (!FindMosaicForImage (image, Nimage, i)) continue; 52 // first check if region center is in image 53 status = RD_to_XY (&X, &Y, Rmid, graph.coords.crval2, &image[i].coords); 54 if (status && (X >= 0) && (X < image[i].NX) && (Y >= 0) && (Y < image[i].NY)) goto in_region; 55 52 56 /* project this image to screen display coords */ 53 57 x[0] = 0; y[0] = 0; -
branches/eam_branch_20080421/Ohana/src/opihi/dvo/dbExtractMeasures.c
r17469 r18424 291 291 break; 292 292 case MEAS_FWHM: /* OK */ 293 value = 0.01*(measure[0].FWx + measure[0].FWy) ;293 value = 0.01*(measure[0].FWx + measure[0].FWy) / 2.0; 294 294 break; 295 295 case MEAS_FWHM_MAJ: /* OK */ -
branches/eam_branch_20080421/Ohana/src/opihi/include/pcontrol.h
r17469 r18424 8 8 /** job status values **/ 9 9 typedef enum { 10 PCONTROL_JOB_ALLJOBS, 10 11 PCONTROL_JOB_PENDING, 11 12 PCONTROL_JOB_BUSY, 13 PCONTROL_JOB_RESP, 12 14 PCONTROL_JOB_HUNG, 13 15 PCONTROL_JOB_DONE, … … 26 28 /** host status values **/ 27 29 typedef enum { 30 PCONTROL_HOST_ALLHOSTS, 28 31 PCONTROL_HOST_IDLE, 29 32 PCONTROL_HOST_BUSY, 33 PCONTROL_HOST_RESP, 30 34 PCONTROL_HOST_DOWN, 31 35 PCONTROL_HOST_DONE, 32 36 PCONTROL_HOST_OFF, 33 37 } HostStat; 38 39 /** host response options **/ 40 typedef enum { 41 PCONTROL_RESP_NONE, 42 PCONTROL_RESP_START_JOB, 43 PCONTROL_RESP_CHECK_BUSY_JOB, 44 PCONTROL_RESP_CHECK_DONE_HOST, 45 PCONTROL_RESP_CHECK_HOST, 46 PCONTROL_RESP_KILL_JOB, 47 PCONTROL_RESP_STOP_HOST, 48 } HostResp; 34 49 35 50 typedef enum { … … 97 112 Ptime nexttry; 98 113 IDtype HostID; 114 IOBuffer comms_buffer; 115 char *response; 116 HostResp response_state; 99 117 struct Job *job; 100 118 } Host; … … 156 174 157 175 /*** own files ***/ 176 int StartJob (Job *job, Host *host); 177 int StartJobResponse (Host *host); 178 158 179 int CheckHost (Host *host); 180 int CheckHostResponse (Host *host); 181 182 int CheckDoneHost (Host *host); 183 int CheckDoneHostResponse (Host *host); 184 185 int CheckBusyJob (Job *job, Host *host); 186 int CheckBusyJobResponse (Host *host); 187 188 int KillJob (Job *job, Host *host); 189 int KillJobResponse (Host *host); 190 159 191 int StartHost (Host *host); 160 192 int CheckIdleHost (Host *host); 161 int CheckDoneHost (Host *host);162 int CheckBusyJob (Job *job, Host *host);163 193 int CheckDoneJob (Job *job, Host *host); 164 int KillJob (Job *job, Host *host);165 int StartJob (Job *job, Host *host);166 int ResetJob (Job *job);167 194 int GetJobOutput (char *command, Host *host, IOBuffer *buffer, int Nbytes); 168 int PclientCommand (Host *host, char *command, char *response, IOBuffer *buffer);169 195 int rconnect (char *command, char *hostname, char *shell, int *stdio); 196 197 int PclientCommand (Host *host, char *command, char *response, HostResp response_state); 198 int PclientResponse (Host *host, char *response, IOBuffer *buffer); 199 200 int CheckRespHosts (float MaxDelay); 201 int CheckRespHost (Host *host); 170 202 171 203 /*** misc files ***/ … … 178 210 IDtype NextHostID (); 179 211 void PrintID (gpDest dest, IDtype ID); 212 IDtype GetID (char *IDword); 180 213 181 214 /*** CheckPoint.c ***/ … … 203 236 int DownHosts (); 204 237 int StopHost (Host *host); 238 int StopHostResponse (Host *host); 205 239 int HarvestHost (int pid); 206 240 -
branches/eam_branch_20080421/Ohana/src/opihi/lib.data/fft.c
r16107 r18424 127 127 Nminor *= Nsize[iDim]; 128 128 } 129 free (Nbit); 129 130 free (tmpX); 130 131 free (tmpY); -
branches/eam_branch_20080421/Ohana/src/opihi/lib.data/open_kapa.c
r16435 r18424 108 108 109 109 if (!strncmp (kapa_exec, "unix://", 7)) { 110 fd = KapaOpenNamedSocket (&kapa_exec[7], "psphot");110 fd = KapaOpenNamedSocket (&kapa_exec[7], kapa_name); 111 111 } else { 112 112 fd = KapaOpen (kapa_exec, kapa_name); -
branches/eam_branch_20080421/Ohana/src/opihi/lib.shell/BufferOps.c
r16886 r18424 122 122 123 123 int CopyBuffer (Buffer *out, Buffer *in) { 124 free (out[0].matrix.buffer);125 free (out[0].header.buffer);126 124 out[0].bitpix = in[0].bitpix; 127 125 out[0].unsign = in[0].unsign; -
branches/eam_branch_20080421/Ohana/src/opihi/lib.shell/evaluate_stack.c
r16890 r18424 13 13 14 14 int i, j, Nvar, Nout, status; 15 char line[512]; 15 char line[512]; // this is only used to report an error 16 16 StackVar tmp_stack; 17 17 Nout = Nvar = 0; -
branches/eam_branch_20080421/Ohana/src/opihi/lib.shell/multicommand.c
r16903 r18424 93 93 94 94 // receive the command exit status 95 if (ExpectMessage (server, 2.0, &message)) {95 if (ExpectMessage (server, 10.0, &message)) { 96 96 switch (errno) { 97 97 case EPIPE: … … 108 108 109 109 // receive the resulting stderr 110 if (ExpectMessage (server, 2.0, &message)) {110 if (ExpectMessage (server, 10.0, &message)) { 111 111 switch (errno) { 112 112 case EPIPE: … … 123 123 124 124 // receive the resulting stdout 125 if (ExpectMessage (server, 2.0, &message)) {125 if (ExpectMessage (server, 10.0, &message)) { 126 126 switch (errno) { 127 127 case EPIPE: -
branches/eam_branch_20080421/Ohana/src/opihi/lib.shell/stack_math.c
r17470 r18424 10 10 int i, Nx; 11 11 float *out, *M1, *M2; 12 char line[512]; 12 char line[512]; // this is only used to report an error 13 13 14 14 Nx = V1[0].vector[0].Nelements; … … 83 83 switch (op[0]) { 84 84 case '+': 85 VV_FUN 86 85 VV_FUNC 87 86 88 87 if ((M1->type == OPIHI_FLOAT) && (M2->type == OPIHI_FLOAT)) { … … 222 221 int i, Nx; 223 222 float *out, *M1, *M2; 224 char line[512]; 223 char line[512]; // this is only used to report an error 225 224 226 225 Nx = V2[0].vector[0].Nelements; … … 340 339 int i, Nx; 341 340 float *out, *M1, *M2; 342 char line[512]; 341 char line[512]; // this is only used to report an error 343 342 344 343 Nx = V1[0].vector[0].Nelements; … … 459 458 int i, j, Nx, Ny; 460 459 float *out, *M1, *M2; 461 char line[512]; 460 char line[512]; // this is only used to report an error 462 461 463 462 Nx = V1[0].buffer[0].matrix.Naxis[0]; … … 629 628 int i, j, Nx, Ny; 630 629 float *out, *M1, *M2; 631 char line[512]; 630 char line[512]; // this is only used to report an error 632 631 633 632 Nx = V2[0].buffer[0].matrix.Naxis[0]; … … 815 814 int i, Nx, Ny; 816 815 float *out, *M1, *M2; 817 char line[512]; 816 char line[512]; // this is only used to report an error 818 817 819 818 Nx = V1[0].buffer[0].matrix.Naxis[0]; … … 947 946 int i, Nx, Ny; 948 947 float *out, *M1, *M2; 949 char line[512]; 948 char line[512]; // this is only used to report an error 950 949 951 950 Nx = V1[0].buffer[0].matrix.Naxis[0]; … … 1066 1065 int i, Nx, Ny; 1067 1066 float *out, *M1, *M2; 1068 char line[512]; 1067 char line[512]; // this is only used to report an error 1069 1068 1070 1069 Nx = V2[0].buffer[0].matrix.Naxis[0]; … … 1183 1182 1184 1183 float *M1, *M2, *out; 1185 char line[512]; 1184 char line[512]; // this is only used to report an error 1186 1185 1187 1186 M1 = V1[0].ptr; … … 1267 1266 1268 1267 int value; 1269 char line[512]; 1268 char line[512]; // this is only used to report an error 1270 1269 1271 1270 /* only 'N' and 'E' are allowed for WW_binary operations. anything else is either a -
branches/eam_branch_20080421/Ohana/src/opihi/pantasks/ControllerOps.c
r13581 r18424 1 1 # include "pantasks.h" 2 2 /* adding a new host can delay controller up to a second or so */ 3 # define CONTROLLER_TIMEOUT 10004 # define CONNECT_TIMEOUT 3003 # define CONTROLLER_TIMEOUT 5000 4 # define CONNECT_TIMEOUT 1000 5 5 6 6 /* local static variables to hold the connection to the controller */ … … 88 88 /** parse status message **/ 89 89 p = memstr (buffer.buffer, "STATUS", buffer.Nbuffer); 90 if (p == NULL) goto escape; 90 91 sscanf (p, "%*s %s", status_string); 91 92 p = memstr (buffer.buffer, "EXITST", buffer.Nbuffer); 93 if (p == NULL) goto escape; 92 94 sscanf (p, "%*s %d", &job[0].exit_status); 93 95 p = memstr (buffer.buffer, "STDOUT", buffer.Nbuffer); 96 if (p == NULL) goto escape; 94 97 sscanf (p, "%*s %d", &job[0].stdout_size); 95 98 p = memstr (buffer.buffer, "STDERR", buffer.Nbuffer); 99 if (p == NULL) goto escape; 96 100 sscanf (p, "%*s %d", &job[0].stderr_size); 97 101 p = memstr (buffer.buffer, "DTIME", buffer.Nbuffer); 102 if (p == NULL) goto escape; 98 103 sscanf (p, "%*s %lf", &job[0].dtime); 99 104 p = memstr (buffer.buffer, "HOSTNAME", buffer.Nbuffer); 105 if (p == NULL) goto escape; 100 106 sscanf (p, "%*s %s", string); 101 107 job[0].realhost = strcreate (string); … … 109 115 if (!strcmp(status_string, "EXIT")) outstate = JOB_EXIT; 110 116 if (!strcmp(status_string, "CRASH")) outstate = JOB_CRASH; 111 if (outstate == -1) { 112 gprint (GP_ERR, "programming error?\n"); 113 exit (1); 114 } 117 if (outstate == -1) goto escape; 118 115 119 job[0].state = outstate; 116 120 return (TRUE); 121 122 escape: 123 gprint (GP_ERR, "garbage in pcontrol reponse\n"); 124 FreeIOBuffer (&buffer); 125 return (FALSE); 117 126 } 118 127 … … 297 306 status = ReadtoIOBuffer (&buffer, stdout_fd[0]); 298 307 p = memstr (buffer.buffer, "CONNECTED", buffer.Nbuffer); 299 usleep ( 10000); // wait for controller to start up308 usleep (50000); // wait for controller to start up 300 309 } 301 310 if (status == 0) goto pipe_error; … … 436 445 } 437 446 447 int FlushControllerOutput () { 448 449 FlushIOBuffer (&stdout_buffer); 450 FlushIOBuffer (&stderr_buffer); 451 452 return (TRUE); 453 } 438 454 439 455 int KillControllerJob (Job *job) { -
branches/eam_branch_20080421/Ohana/src/opihi/pantasks/JobOps.c
r16451 r18424 16 16 } 17 17 18 /* free all jobs, only used on shutdown */ 18 19 void FreeJobs () { 19 20 int i; … … 159 160 if (task[0].stderr_dump != NULL) job[0].stderr_dump = strcreate (task[0].stderr_dump); 160 161 162 job[0].stdout_fd = -1; 163 job[0].stderr_fd = -1; 164 161 165 jobs[Njobs] = job; 162 166 Njobs ++; … … 185 189 } 186 190 free (job[0].optv); 191 192 if (job[0].stdout_fd >= 0) close (job[0].stdout_fd); 193 if (job[0].stderr_fd >= 0) close (job[0].stderr_fd); 187 194 188 195 if (job[0].stdout_dump != NULL) free (job[0].stdout_dump); -
branches/eam_branch_20080421/Ohana/src/opihi/pantasks/LocalJob.c
r15875 r18424 21 21 close (job[0].stdout_fd); 22 22 close (job[0].stderr_fd); 23 job[0].stdout_fd = -1; // prevent FreeJob from trying to close again 24 job[0].stderr_fd = -1; // prevent FreeJob from trying to close again 23 25 } else { 24 26 /* read stdout buffer */ -
branches/eam_branch_20080421/Ohana/src/opihi/pantasks/Makefile
r16903 r18424 79 79 $(SRC)/controller_status.$(ARCH).o \ 80 80 $(SRC)/controller_jobstack.$(ARCH).o \ 81 $(SRC)/controller_verbose.$(ARCH).o \ 81 82 $(SRC)/controller_run.$(ARCH).o \ 82 83 $(SRC)/controller_output.$(ARCH).o \ -
branches/eam_branch_20080421/Ohana/src/opihi/pantasks/controller.c
r16463 r18424 5 5 int controller_status PROTO((int, char **)); 6 6 int controller_jobstack PROTO((int, char **)); 7 int controller_verbose PROTO((int, char **)); 7 8 int controller_run PROTO((int, char **)); 8 9 int controller_stop PROTO((int, char **)); … … 19 20 {1, "status", controller_status, "check controller status"}, 20 21 {1, "jobstack", controller_jobstack, "check controller status"}, 22 {1, "verbose", controller_verbose, "set controller verbosity"}, 21 23 {1, "output", controller_output, "print controller output"}, 22 24 {1, "pulse", controller_pulse, "set controller pulse"}, -
branches/eam_branch_20080421/Ohana/src/opihi/pantasks/controller_jobstack.c
r14590 r18424 21 21 22 22 // XXX this has an error? test this out... 23 sprintf (command, "jobstack %s", argv[ 2]);23 sprintf (command, "jobstack %s", argv[1]); 24 24 InitIOBuffer (&buffer, 0x100); 25 25 -
branches/eam_branch_20080421/Ohana/src/opihi/pantasks/controller_output.c
r7917 r18424 3 3 int controller_output (int argc, char **argv) { 4 4 5 if ( argc != 1) {6 gprint (GP_ERR, "USAGE: controller status\n");5 if ((argc != 1) || ((argc == 2) && (strcmp(argv[1], "flush")))) { 6 gprint (GP_ERR, "USAGE: controller output\n"); 7 7 return (FALSE); 8 8 } … … 10 10 CheckControllerOutput (); 11 11 PrintControllerOutput (); 12 13 if (argc == 2) { 14 FlushControllerOutput (); 15 } 16 12 17 return (TRUE); 13 18 } -
branches/eam_branch_20080421/Ohana/src/opihi/pantasks/ipptool2book.c
r16810 r18424 11 11 int i, N, onPage, found, Unique, Nkeys, NKEYS; 12 12 char *line, *tmpword, *tmpvalue; 13 char pagename[512], *bookName, **keys, *p, *q; 13 char pagename[512]; // XXX this should be made dynamic, though it is an unlikey problem 14 char *bookName, **keys, *p, *q; 14 15 char **setWordList; 15 16 char **setWordValue; … … 102 103 tmpword = nextword (line); 103 104 104 if ( strcmp(tmpword, "MULTI")) {105 if (!tmpword || strcmp(tmpword, "MULTI")) { 105 106 gprint (GP_ERR, "ERROR: missing metadata output name on first line\n"); 106 107 free (bookName); -
branches/eam_branch_20080421/Ohana/src/opihi/pclient/pclient.c.in
r16455 r18424 23 23 rl_attempted_completion_function = command_completer; 24 24 rl_event_hook = CheckChild; 25 rl_set_keyboard_input_timeout ( 1000);25 rl_set_keyboard_input_timeout (20000); 26 26 /* 1 ms seems to be the minimum valid number */ 27 27 … … 63 63 FreeBasic (); 64 64 FreePclient (); 65 gprint (GP_LOG, "Goodbye\n"); 65 66 return; 66 67 } -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/CheckBusyJob.c
r16456 r18424 4 4 int CheckBusyJob (Job *job, Host *host) { 5 5 6 int status; 7 int outstate; 8 char *p; 9 char string[64]; 10 IOBuffer buffer; 6 int status; 11 7 12 8 /* we are checking a job which is currently busy. it has been pulled from the … … 16 12 ASSERT (job, "job not set"); 17 13 ASSERT (host, "host not set"); 18 19 14 ASSERT (host == (Host *) job[0].host, "invalid host"); 20 15 ASSERT (job == (Job *) host[0].job, "invalid job"); 21 16 22 InitIOBuffer (&buffer, 0x100); 23 24 status = PclientCommand (host, "status", PCLIENT_PROMPT, &buffer); 17 status = PclientCommand (host, "status", PCLIENT_PROMPT, PCONTROL_RESP_CHECK_BUSY_JOB); 25 18 26 19 /* check on success of pclient command */ 27 20 switch (status) { 28 21 case PCLIENT_DOWN: 29 HarvestHost (host[0].pid); 22 // free the realhost name 23 if (job[0].realhost) free (job[0].realhost); 24 job[0].realhost = NULL; 25 30 26 // unlink host & job 27 if (VerboseMode()) gprint (GP_ERR, "host %s is down\n", host[0].hostname); 31 28 job[0].host = NULL; 32 29 host[0].job = NULL; 33 if (job[0].realhost) free (job[0].realhost); 34 job[0].realhost = NULL; 30 HarvestHost (host[0].pid); 35 31 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 36 32 PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM); 37 FreeIOBuffer (&buffer);38 33 return (FALSE); 39 40 case PCLIENT_HUNG:41 // don't do anything drastic, just keep trying42 if (DEBUG || VerboseMode()) gprint (GP_ERR, "client is busy, not responding");43 PutHost (host, PCONTROL_HOST_BUSY, STACK_BOTTOM);44 PutJob (job, PCONTROL_JOB_BUSY, STACK_BOTTOM);45 FreeIOBuffer (&buffer);46 return (TRUE);47 34 48 35 case PCLIENT_GOOD: 49 36 if (DEBUG || VerboseMode()) gprint (GP_ERR, "message received (CheckBusyJob)"); 50 break; 37 PutHost (host, PCONTROL_HOST_RESP, STACK_BOTTOM); 38 PutJob (job, PCONTROL_JOB_RESP, STACK_BOTTOM); 39 return (TRUE); 51 40 52 41 default: 53 42 ABORT ("unknown status for pclient command"); 54 43 } 44 } 45 46 int CheckBusyJobResponse (Host *host) { 47 48 int outstate; 49 char *p; 50 char string[64]; 51 IOBuffer *buffer; 52 Job *job; 53 54 /* job must have assigned host */ 55 ASSERT (host, "missing host"); 56 ASSERT (host[0].job, "missing job"); 57 buffer = &host[0].comms_buffer; 58 job = (Job *) host[0].job; 55 59 56 60 /** host is up, need to parse message **/ 57 p = memstr (buffer.buffer, "STATUS", buffer.Nbuffer); 58 // this condition means the message is garbage. toss it and try again 61 p = memstr (buffer[0].buffer, "STATUS", buffer[0].Nbuffer); 59 62 if (p == NULL) { 60 PutHost (host, PCONTROL_HOST_BUSY, STACK_BOTTOM);61 PutJob (job, PCONTROL_JOB_BUSY, STACK_BOTTOM);62 FreeIOBuffer (&buffer);63 return (FALSE);63 if (DEBUG || VerboseMode()) gprint (GP_ERR, "missing STATUS in response; try again\n"); 64 PutHost (host, PCONTROL_HOST_BUSY, STACK_BOTTOM); 65 PutJob (job, PCONTROL_JOB_BUSY, STACK_BOTTOM); 66 return (TRUE); 64 67 } 65 68 … … 71 74 PutHost (host, PCONTROL_HOST_BUSY, STACK_BOTTOM); 72 75 PutJob (job, PCONTROL_JOB_BUSY, STACK_BOTTOM); 73 FreeIOBuffer (&buffer);74 76 return (TRUE); 75 77 } … … 79 81 if (!strcmp(string, "EXIT")) outstate = PCONTROL_JOB_EXIT; 80 82 if (!strcmp(string, "CRASH")) outstate = PCONTROL_JOB_CRASH; 81 ASSERT (outstate != PCONTROL_JOB_BUSY, " should not reach here (CheckJob)");83 ASSERT (outstate != PCONTROL_JOB_BUSY, "invalid status response (CheckBusyJobResponse)"); 82 84 83 85 /* parse the exit status and sizes of output buffers */ 84 p = memstr (buffer .buffer, "EXITST", buffer.Nbuffer);86 p = memstr (buffer[0].buffer, "EXITST", buffer[0].Nbuffer); 85 87 sscanf (p, "%*s %d", &job[0].exit_status); 86 p = memstr (buffer .buffer, "STDOUT", buffer.Nbuffer);88 p = memstr (buffer[0].buffer, "STDOUT", buffer[0].Nbuffer); 87 89 sscanf (p, "%*s %d", &job[0].stdout_size); 88 p = memstr (buffer .buffer, "STDERR", buffer.Nbuffer);90 p = memstr (buffer[0].buffer, "STDERR", buffer[0].Nbuffer); 89 91 sscanf (p, "%*s %d", &job[0].stderr_size); 90 92 … … 98 100 PutHost (host, PCONTROL_HOST_BUSY, STACK_BOTTOM); 99 101 PutJobSetState (job, PCONTROL_JOB_DONE, STACK_BOTTOM, outstate); 100 gettimeofday (&job[0].stop, (void *)NULL);102 gettimeofday (&job[0].stop, NULL); 101 103 job[0].dtime = DTIME(job[0].stop, job[0].start); 102 FreeIOBuffer (&buffer);103 104 return (TRUE); 104 105 } -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/CheckDoneHost.c
r10668 r18424 5 5 6 6 int status; 7 char *p;8 IOBuffer buffer;9 7 10 8 ASSERT (host, "host not set"); 11 9 12 InitIOBuffer (&buffer, 0x100); 13 14 status = PclientCommand (host, "reset", PCLIENT_PROMPT, &buffer); 10 status = PclientCommand (host, "reset", PCLIENT_PROMPT, PCONTROL_RESP_CHECK_DONE_HOST); 15 11 16 12 /* check on success of pclient command */ … … 18 14 case PCLIENT_DOWN: 19 15 if (DEBUG || VerboseMode()) gprint (GP_ERR, "host %s is down\n", host[0].hostname); 20 /* DONE host does not have an incomplete job */21 16 HarvestHost (host[0].pid); 22 17 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 23 FreeIOBuffer (&buffer);24 18 return (FALSE); 19 /* DONE host does not have an incomplete job */ 25 20 // XXX do we need to close the connection? 26 21 27 case PCLIENT_HUNG:28 // don't do anything drastic, just try again later29 PutHost (host, PCONTROL_HOST_DONE, STACK_BOTTOM);30 if (DEBUG || VerboseMode()) gprint (GP_ERR, "host %s is not responding\n", host[0].hostname);31 FreeIOBuffer (&buffer);32 return (FALSE);33 34 22 case PCLIENT_GOOD: 35 if (VerboseMode()) gprint (GP_ERR, "message received (CheckDoneHost)\n"); 36 break; 23 if (VerboseMode()) gprint (GP_ERR, "checking done host %s\n", host[0].hostname); 24 PutHost (host, PCONTROL_HOST_RESP, STACK_BOTTOM); 25 return (TRUE); 37 26 38 27 default: 39 28 ABORT ("unknown status for pclient command"); 40 29 } 30 ABORT ("should not reach here (CheckDoneHost)"); 31 } 32 33 int CheckDoneHostResponse (Host *host) { 34 35 int status; 36 char *p; 37 IOBuffer *buffer; 38 39 /* job must have assigned host */ 40 ASSERT (host, "missing host"); 41 buffer = &host[0].comms_buffer; 41 42 42 43 /** successful command, examine result **/ 43 p = memstr (buffer.buffer, "STATUS", buffer.Nbuffer); 44 ASSERT (p != NULL, "missing STATUS in pclient message (CheckDoneHost)"); 44 p = memstr (buffer[0].buffer, "STATUS", buffer[0].Nbuffer); 45 if (p == NULL) { 46 if (DEBUG || VerboseMode()) gprint (GP_ERR, "missing STATUS in response; try again\n"); 47 PutHost (host, PCONTROL_HOST_DONE, STACK_BOTTOM); 48 return (FALSE); 49 } 45 50 46 51 sscanf (p, "%*s %d", &status); … … 52 57 if (DEBUG || VerboseMode()) gprint (GP_ERR, "reset failed\n"); 53 58 PutHost (host, PCONTROL_HOST_DONE, STACK_BOTTOM); 54 FreeIOBuffer (&buffer);55 59 return (FALSE); 56 60 … … 59 63 if (DEBUG || VerboseMode()) gprint (GP_ERR, "successful reset\n"); 60 64 PutHost (host, PCONTROL_HOST_IDLE, STACK_BOTTOM); 61 FreeIOBuffer (&buffer);62 65 return (FALSE); 63 66 … … 67 70 ABORT ("should not reach here (CheckDoneHost)"); 68 71 } 69 70 /** probably need to flush the buffer before the command **/71 /** need to add timeout check here **/ -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/CheckHost.c
r10652 r18424 1 1 # include "pcontrol.h" 2 2 3 // if the host has a job, we skip it (down or crash state will be caught elsewhere) 4 // in fact, just touch the IDLE hosts, not the BUSY hosts? 3 5 int CheckHost (Host *host) { 4 6 5 7 int status; 6 IOBuffer buffer;7 8 8 9 ASSERT (host, "host not set"); … … 14 15 host[0].markoff = FALSE; 15 16 StopHost (host); 16 OffHost (host);17 17 return (TRUE); 18 18 } 19 19 20 InitIOBuffer (&buffer, 0x100); 20 // the argument to echo (OK) is the expected response below in CheckHostResponse 21 status = PclientCommand (host, "echo OK", PCLIENT_PROMPT, PCONTROL_RESP_CHECK_HOST); 21 22 22 status = PclientCommand (host, "echo OK", PCLIENT_PROMPT, &buffer);23 23 switch (status) { 24 case 0:24 case PCLIENT_DOWN: 25 25 if (VerboseMode()) gprint (GP_ERR, "host %s is down\n", host[0].hostname); 26 26 HarvestHost (host[0].pid); 27 27 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 28 FreeIOBuffer (&buffer);29 28 return (FALSE); 30 29 31 case -1: 32 if (VerboseMode()) gprint (GP_ERR, "host %s is not responding\n", host[0].hostname); 33 /*** do we mark this in some way (HUNG) ? ***/ 34 PutHost (host, host[0].stack, STACK_BOTTOM); 35 FreeIOBuffer (&buffer); 36 return (FALSE); 30 case PCLIENT_GOOD: 31 PutHost (host, PCONTROL_HOST_RESP, STACK_BOTTOM); 32 return (TRUE); 37 33 38 34 default: 39 PutHost (host, host[0].stack, STACK_BOTTOM); 40 FreeIOBuffer (&buffer); 41 return (TRUE); 35 ABORT ("unknown status for pclient command"); 42 36 } 43 ABORT ("should not reach here (Check Host)");37 ABORT ("should not reach here (CheckHost)"); 44 38 } 45 39 46 // if the host has a job, we skip it (down or crash state will be caught elsewhere) 47 // in fact, just touch the IDLE hosts, not the BUSY hosts? 40 int CheckHostResponse (Host *host) { 41 42 IOBuffer *buffer; 43 44 /* we only check IDLE hosts without jobs */ 45 ASSERT (host, "missing host"); 46 buffer = &host[0].comms_buffer; 47 48 // XXX check on the value of the response? (OK) 49 50 PutHost (host, PCONTROL_HOST_IDLE, STACK_BOTTOM); 51 return (TRUE); 52 } -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/CheckIdleHost.c
r10667 r18424 14 14 host[0].markoff = FALSE; 15 15 StopHost (host); 16 OffHost (host);17 16 return (TRUE); 18 17 } -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/CheckSystem.c
r16589 r18424 99 99 100 100 if (RunLevel != PCONTROL_RUN_NONE) { 101 Nhostchecks += CheckRespHosts(0.020); /* check for incoming messages */ 102 TestCheckPoint (); 101 103 Nhostchecks += CheckDoneHosts(0.020); /* reset the host */ 102 104 TestCheckPoint (); … … 258 260 } 259 261 262 int CheckRespHosts (float MaxDelay) { 263 264 struct timeval start, stop; 265 int i, Nobject; 266 Stack *hoststack; 267 Stack *jobstack; 268 Host *host; 269 Job *job; 270 float dtime; 271 272 /* Loop through objects on the stack, no more than once. see note above */ 273 hoststack = GetHostStack (PCONTROL_HOST_RESP); 274 jobstack = GetJobStack (PCONTROL_JOB_RESP); 275 Nobject = hoststack[0].Nobject; 276 277 /* always allow at least one test */ 278 gettimeofday (&start, (void *) NULL); 279 dtime = 0.0; 280 for (i = 0; (i < Nobject) && (dtime < MaxDelay); i++) { 281 LockStack (jobstack); 282 host = PullStackByLocation (hoststack, STACK_TOP); 283 if (host == NULL) { 284 UnlockStack (jobstack); 285 break; 286 } 287 288 // if the host has a job, we need to pull the job from its stack 289 job = (Job *) host[0].job; 290 if (job != NULL) { 291 RemoveStackByID (jobstack, job[0].JobID); 292 } 293 UnlockStack (jobstack); 294 295 CheckRespHost (host); 296 gettimeofday (&stop, (void *) NULL); 297 dtime = DTIME (stop, start); 298 } 299 if (DEBUG) gprint (GP_ERR, "checked %d hosts\n", i); 300 return (i); 301 } 302 260 303 int CheckDoneHosts (float MaxDelay) { 261 304 … … 303 346 if (host == NULL) break; 304 347 if (host[0].markoff) { 348 // DOWN -> OFF 305 349 host[0].markoff = FALSE; 306 350 OffHost (host); … … 311 355 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 312 356 } else { 357 // DOWN -> IDLE (maybe) 358 // this is a race condition with "host retry", but the only 359 // consequence is that both StartHost and reset set the times to 0.0 313 360 StartHost (host); 314 361 } -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/HostOps.c
r16472 r18424 1 1 # include "pcontrol.h" 2 2 3 Stack *HostPool_Idle; 4 Stack *HostPool_Busy; 5 Stack *HostPool_Done; 6 Stack *HostPool_Down; 7 Stack *HostPool_Off; 3 Stack *HostPool_AllHosts; // virtual pool for user status queries 4 5 Stack *HostPool_Idle; // these hosts are waiting for something to do 6 Stack *HostPool_Busy; // these hosts are working 7 Stack *HostPool_Resp; // these hosts are trying to respond 8 Stack *HostPool_Done; // these hosts have finished a job 9 Stack *HostPool_Down; // these hosts are not responding 10 Stack *HostPool_Off; // these hosts are off 8 11 9 12 void InitHostStacks () { 13 HostPool_AllHosts = InitStack (); 14 10 15 HostPool_Idle = InitStack (); 11 16 HostPool_Busy = InitStack (); 17 HostPool_Resp = InitStack (); 12 18 HostPool_Done = InitStack (); 13 19 HostPool_Down = InitStack (); … … 26 32 FreeHostStack (HostPool_Idle); 27 33 FreeHostStack (HostPool_Busy); 34 FreeHostStack (HostPool_Resp); 28 35 FreeHostStack (HostPool_Done); 29 36 FreeHostStack (HostPool_Down); 30 37 FreeHostStack (HostPool_Off ); 38 39 // AllHosts is a virtual stack : all hosts are references 40 FreeStack (HostPool_AllHosts); 31 41 } 32 42 33 43 char *GetHostStackName (int StackID) { 34 44 switch (StackID) { 45 case PCONTROL_HOST_ALLHOSTS: return ("ALLHOSTS"); 35 46 case PCONTROL_HOST_IDLE: return ("IDLE"); 36 47 case PCONTROL_HOST_DOWN: return ("DOWN"); 48 case PCONTROL_HOST_RESP: return ("RESP"); 37 49 case PCONTROL_HOST_DONE: return ("DONE"); 38 50 case PCONTROL_HOST_BUSY: return ("BUSY"); … … 46 58 Stack *GetHostStack (int StackID) { 47 59 switch (StackID) { 60 case PCONTROL_HOST_ALLHOSTS: return (HostPool_AllHosts); 48 61 case PCONTROL_HOST_IDLE: return (HostPool_Idle); 49 62 case PCONTROL_HOST_DOWN: return (HostPool_Down); 63 case PCONTROL_HOST_RESP: return (HostPool_Resp); 50 64 case PCONTROL_HOST_DONE: return (HostPool_Done); 51 65 case PCONTROL_HOST_BUSY: return (HostPool_Busy); … … 58 72 59 73 Stack *GetHostStackByName (char *name) { 74 if (!strcasecmp (name, "all")) return (HostPool_AllHosts); 60 75 if (!strcasecmp (name, "idle")) return (HostPool_Idle); 61 76 if (!strcasecmp (name, "down")) return (HostPool_Down); 77 if (!strcasecmp (name, "resp")) return (HostPool_Resp); 62 78 if (!strcasecmp (name, "done")) return (HostPool_Done); 63 79 if (!strcasecmp (name, "busy")) return (HostPool_Busy); … … 71 87 int stat; 72 88 Stack *stack; 89 90 // fprintf (stderr, "move host %s to %s\n", host[0].hostname, GetHostStackName(StackID)); 73 91 74 92 stack = GetHostStack (StackID); … … 94 112 if (host != NULL) return (host); 95 113 114 *StackID = PCONTROL_HOST_RESP; 115 host = PullHostFromStackByID (*StackID, HostID); 116 if (host != NULL) return (host); 117 96 118 *StackID = PCONTROL_HOST_DONE; 97 119 host = PullHostFromStackByID (*StackID, HostID); … … 120 142 121 143 *StackID = PCONTROL_HOST_DOWN; 144 host = PullHostFromStackByName (*StackID, name); 145 if (host != NULL) return (host); 146 147 *StackID = PCONTROL_HOST_RESP; 122 148 host = PullHostFromStackByName (*StackID, name); 123 149 if (host != NULL) return (host); … … 180 206 host[0].nexttry.tv_usec = 0; 181 207 208 InitIOBuffer (&host[0].comms_buffer, 0x100); 209 host[0].response_state = PCONTROL_RESP_NONE; 210 host[0].response = NULL; 211 182 212 host[0].markoff = FALSE; 183 213 host[0].job = NULL; 214 215 PutHost (host, PCONTROL_HOST_ALLHOSTS, STACK_BOTTOM); 184 216 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 185 217 return (host[0].HostID); … … 187 219 188 220 void DelHost (Host *host) { 221 222 Host *copy; 223 224 copy = PullStackByID (HostPool_AllHosts, host[0].HostID); 225 ASSERT (copy == host, "programming error: ALLHOSTS entry does not match"); 226 227 FreeIOBuffer (&host[0].comms_buffer); 189 228 FREE (host[0].hostname); 190 229 FREE (host[0].job); -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/IDops.c
r8296 r18424 1 1 # include "pcontrol.h" 2 2 3 static IDtype CurrentJobID = 0;4 static IDtype CurrentHostID = 0;3 static IDtype CurrentJobID = 1; 4 static IDtype CurrentHostID = 1; 5 5 6 /* for now, no persistence : we could use the date/time to seed the upper byte(s) if needed */ 6 /* for now, no persistence between sessions : we could use the date/time to seed the upper 7 * byte(s) if needed */ 7 8 void InitIDs () { 8 CurrentJobID = 0;9 CurrentHostID = 0;9 CurrentJobID = 1; 10 CurrentHostID = 1; 10 11 } 11 12 … … 41 42 } 42 43 44 IDtype GetID (char *IDword) { 45 46 int Nargs; 47 IDtype ID; 48 unsigned int word0, word1, word2, word3; 49 char *endptr; 50 51 Nargs = sscanf (IDword, "%x.%x.%x.%x", &word3, &word2, &word1, &word0); 52 if (Nargs == 4) { 53 IDtype tmp; 54 ID = 0; 55 ID |= (word0 << 0); 56 ID |= (word1 << 16); 57 tmp = word2; 58 ID |= (tmp << 32); 59 tmp = word3; 60 ID |= (tmp << 48); 61 return ID; 62 } 63 64 ID = strtoll (IDword, &endptr, 10); 65 if (*endptr == 0) { 66 return ID; 67 } 68 69 return 0; 70 } -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/JobID.c
r7917 r18424 40 40 } 41 41 42 IDtype GetID (char *IDword) { 43 44 int Nargs; 45 IDtype ID; 46 unsigned short int word0, word1, word2, word3; 47 48 Nargs = sscanf (IDword, "%x.%x.%x.%x", &word0, &word1, &word2, &word3); 49 if (Nargs == 4) { 50 ID = 0; 51 ID |= (word0 << 0); 52 ID |= (word1 << 16); 53 ID |= (word2 << 32); 54 ID |= (word3 << 48); 55 return ID; 56 } 57 58 ID = strtoll (IDword, &endptr, 10); 59 if (*endptr == 0) { 60 return ID; 61 } 62 63 return 0; 64 } -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/JobOps.c
r16472 r18424 1 1 # include "pcontrol.h" 2 3 Stack *JobPool_AllJobs; // virtual pool for user status queries 2 4 3 5 Stack *JobPool_Pending; 4 6 Stack *JobPool_Busy; 7 Stack *JobPool_Resp; 5 8 Stack *JobPool_Done; 6 9 Stack *JobPool_Kill; … … 9 12 10 13 void InitJobStacks () { 14 JobPool_AllJobs = InitStack (); 15 11 16 JobPool_Pending = InitStack (); 12 17 JobPool_Busy = InitStack (); 18 JobPool_Resp = InitStack (); 13 19 JobPool_Done = InitStack (); 14 20 JobPool_Kill = InitStack (); … … 28 34 FreeJobStack (JobPool_Pending); 29 35 FreeJobStack (JobPool_Busy ); 36 FreeJobStack (JobPool_Resp ); 30 37 FreeJobStack (JobPool_Done ); 31 38 FreeJobStack (JobPool_Kill ); 32 39 FreeJobStack (JobPool_Exit ); 33 40 FreeJobStack (JobPool_Crash ); 41 42 // AllJobs is a virtual stack : all jobs are references 43 FreeStack (JobPool_AllJobs); 34 44 } 35 45 36 46 char *GetJobStackName (int StackID) { 37 47 switch (StackID) { 48 case PCONTROL_JOB_ALLJOBS: return ("ALLJOBS"); 49 38 50 case PCONTROL_JOB_PENDING: return ("PENDING"); 39 51 case PCONTROL_JOB_BUSY: return ("BUSY"); 52 case PCONTROL_JOB_RESP: return ("RESP"); 40 53 case PCONTROL_JOB_DONE: return ("DONE"); 41 54 case PCONTROL_JOB_KILL: return ("KILL"); … … 50 63 Stack *GetJobStack (int StackID) { 51 64 switch (StackID) { 65 case PCONTROL_JOB_ALLJOBS: return (JobPool_AllJobs); 66 52 67 case PCONTROL_JOB_PENDING: return (JobPool_Pending); 53 68 case PCONTROL_JOB_BUSY: return (JobPool_Busy); 69 case PCONTROL_JOB_RESP: return (JobPool_Resp); 54 70 case PCONTROL_JOB_DONE: return (JobPool_Done); 55 71 case PCONTROL_JOB_KILL: return (JobPool_Kill); … … 64 80 Stack *GetJobStackByName (char *name) { 65 81 82 if (!strcasecmp (name, "all")) return (JobPool_AllJobs); 83 66 84 if (!strcasecmp (name, "pending")) return (JobPool_Pending); 67 85 if (!strcasecmp (name, "busy")) return (JobPool_Busy); 86 if (!strcasecmp (name, "resp")) return (JobPool_Resp); 68 87 if (!strcasecmp (name, "done")) return (JobPool_Done); 69 88 if (!strcasecmp (name, "exit")) return (JobPool_Exit); … … 77 96 int stat; 78 97 Stack *stack; 98 99 // fprintf (stderr, "move job %s to %s\n", job[0].argv[0], GetJobStackName(StackID)); 79 100 80 101 stack = GetJobStack (StackID); … … 118 139 if (job != NULL) return (job); 119 140 141 *StackID = PCONTROL_JOB_RESP; 142 job = PullJobFromStackByID (*StackID, JobID); 143 if (job != NULL) return (job); 144 120 145 *StackID = PCONTROL_JOB_EXIT; 121 146 job = PullJobFromStackByID (*StackID, JobID); … … 160 185 job[0].argv = argv; 161 186 job[0].hostname = hostname; 187 job[0].realhost = NULL; 188 189 job[0].exit_status = 0; 190 job[0].Reset = FALSE; 191 job[0].stdout_size = 0; 192 job[0].stderr_size = 0; 193 162 194 job[0].mode = mode; 163 job[0].host = NULL; 164 job[0].JobID = NextJobID(); 165 job[0].Reset = FALSE; 166 job[0].realhost = NULL; 195 196 job[0].state = 0; 197 job[0].stack = 0; 167 198 168 199 /* do this step on start? */ … … 170 201 InitIOBuffer (&job[0].stderr_buff, 0x1000); 171 202 203 job[0].dtime = 0.0; 204 job[0].pid = 0; 205 206 job[0].JobID = NextJobID(); 207 job[0].host = NULL; 208 172 209 JobID = job[0].JobID; 210 211 // Put a copy of all created jobs on the ALLJOBS stack 212 // This is a virtual stack: do not free the job from this stack 213 PutJob (job, PCONTROL_JOB_ALLJOBS, STACK_BOTTOM); 173 214 PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM); 215 174 216 if (VerboseMode()) gprint (GP_ERR, "added new job\n"); 175 217 return (JobID); … … 179 221 180 222 int i; 223 224 Job *copy; 225 226 copy = PullStackByID (JobPool_AllJobs, job[0].JobID); 227 ASSERT (copy == job, "programming error: ALLJOBS entry does not match"); 181 228 182 229 FREE (job[0].hostname); -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/KillJob.c
r10661 r18424 3 3 int KillJob (Job *job, Host *host) { 4 4 5 IOBuffer buffer;6 5 int status; 7 char *p;8 6 9 7 ASSERT (host != NULL, "host missing"); 10 8 ASSERT (job != NULL, "job missing"); 11 12 9 ASSERT (host == (Host *) job[0].host, "invalid host"); 13 10 ASSERT (job == (Job *) host[0].job, "invalid job"); 14 11 15 InitIOBuffer (&buffer, 0x100); 16 17 status = PclientCommand (host, "reset", PCLIENT_PROMPT, &buffer); 12 status = PclientCommand (host, "reset", PCLIENT_PROMPT, PCONTROL_RESP_KILL_JOB); 18 13 19 14 /* check on success of pclient command */ 20 15 switch (status) { 21 16 case PCLIENT_DOWN: 22 HarvestHost (host[0].pid);23 17 // unlink host & job 18 if (VerboseMode()) gprint (GP_ERR, "host %s is down\n", host[0].hostname); 24 19 job[0].host = NULL; 25 20 host[0].job = NULL; 21 HarvestHost (host[0].pid); 26 22 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 27 23 PutJob (job, PCONTROL_JOB_CRASH, STACK_BOTTOM); 28 FreeIOBuffer (&buffer);29 24 return (FALSE); 30 25 31 case PCLIENT_ HUNG:32 // don't do anything drastic, just keep trying33 // XXX move to which stack??34 gprint (GP_ERR, "client is busy, not responding (KillJob)");35 FreeIOBuffer (&buffer);26 case PCLIENT_GOOD: 27 if (VerboseMode()) gprint (GP_ERR, "kill job on host %s\n", host[0].hostname); 28 FlushIOBuffer (&host[0].comms_buffer); 29 PutHost (host, PCONTROL_HOST_RESP, STACK_BOTTOM); 30 PutJob (job, PCONTROL_JOB_RESP, STACK_BOTTOM); 36 31 return (TRUE); 37 38 case PCLIENT_GOOD:39 if (VerboseMode()) gprint (GP_ERR, "message received (KillJob)\n");40 break;41 32 42 33 default: 43 34 ABORT ("unknown status for pclient command"); 44 35 } 36 } 45 37 46 /** host is up, need to parse message **/ 47 p = memstr (buffer.buffer, "STATUS", buffer.Nbuffer); 48 ASSERT (p != NULL, "missing STATUS in pclient message"); 49 if (VerboseMode()) gprint (GP_ERR, "client message: %s\n", buffer.buffer); 38 int KillJobResponse (Host *host) { 39 40 int status; 41 char *p; 42 IOBuffer *buffer; 43 Job *job; 44 45 ASSERT (host != NULL, "host missing"); 46 ASSERT (host[0].job, "missing job"); 47 buffer = &host[0].comms_buffer; 48 job = (Job *) host[0].job; 49 50 /** check on response to pclient command **/ 51 p = memstr (buffer[0].buffer, "STATUS", buffer[0].Nbuffer); 52 if (p == NULL) { 53 if (VerboseMode()) gprint (GP_ERR, "missing STATUS in response; try again\n"); 54 PutHost (host, PCONTROL_HOST_BUSY, STACK_BOTTOM); 55 PutJob (job, PCONTROL_JOB_KILL, STACK_BOTTOM); 56 return (FALSE); 57 } 58 if (VerboseMode()) gprint (GP_ERR, "client message: %s\n", buffer[0].buffer); 50 59 51 60 sscanf (p, "%*s %d", &status); 52 FreeIOBuffer (&buffer);53 61 gprint (GP_ERR, "client status: %d\n", status); 54 62 … … 62 70 return (FALSE); 63 71 case 1: 64 gprint (GP_ERR, "kill ingjob %s on %s\n", job[0].argv[0], host[0].hostname);72 gprint (GP_ERR, "killed job %s on %s\n", job[0].argv[0], host[0].hostname); 65 73 // unlink host & job 66 74 job[0].host = NULL; -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/Makefile
r12842 r18424 13 13 LIBS1 = -lkapa -lFITS -lohana 14 14 LIBS2 = -lbasiccmd -lshell -ldata 15 FULL_CFLAGS = $(BASE_CFLAGS) 15 FULL_CFLAGS = $(BASE_CFLAGS) -Wall -Werror 16 16 FULL_CPPFLAGS = $(BASE_CPPFLAGS) 17 17 FULL_LDFLAGS = $(LIBS1) $(LIBS2) $(BASE_LDFLAGS) … … 27 27 $(SRC)/CheckBusyJob.$(ARCH).o \ 28 28 $(SRC)/CheckDoneHost.$(ARCH).o \ 29 $(SRC)/CheckRespHost.$(ARCH).o \ 29 30 $(SRC)/CheckDoneJob.$(ARCH).o \ 30 31 $(SRC)/CheckHost.$(ARCH).o \ … … 38 39 $(SRC)/StackOps.$(ARCH).o \ 39 40 $(SRC)/PclientCommand.$(ARCH).o \ 40 $(SRC)/ResetJob.$(ARCH).o \41 41 $(SRC)/StartHost.$(ARCH).o \ 42 42 $(SRC)/StopHosts.$(ARCH).o \ -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/PclientCommand.c
r16590 r18424 1 1 # include "pcontrol.h" 2 # define PCLIENT_TIMEOUT 50002 # define PCLIENT_TIMEOUT 100 3 3 4 int PclientCommand (Host *host, char *command, char *response, IOBuffer *buffer) { 4 // send a command and check for errors; ignore output 5 int PclientCommand (Host *host, char *command, char *response, HostResp response_state) { 5 6 6 int i;7 7 int status; 8 char *line;9 struct timespec request, remain;10 8 11 9 ASSERT (host != NULL, "host missing"); 12 ASSERT (buffer != NULL, "buffer missing");13 10 ASSERT (command != NULL, "command missing"); 14 ASSERT (response != NULL, "response missing");15 16 /* avoid blocking on read, test every 100 usec, up to 50 msec */17 request.tv_sec = 0;18 request.tv_nsec = 100000;19 11 20 12 // flush the stdout and stderr buffers here 21 ReadtoIOBuffer (buffer, host[0].stdout_fd); 22 FlushIOBuffer (buffer); 23 ReadtoIOBuffer (buffer, host[0].stderr_fd); 24 FlushIOBuffer (buffer); 13 // recycle comms_buffer to minimize page thrashing 14 ReadtoIOBuffer (&host[0].comms_buffer, host[0].stdout_fd); 15 FlushIOBuffer (&host[0].comms_buffer); 16 ReadtoIOBuffer (&host[0].comms_buffer, host[0].stderr_fd); 17 FlushIOBuffer (&host[0].comms_buffer); 25 18 26 19 /* send command to client (adding on \n) */ … … 33 26 } 34 27 28 // prepare host to accept response 29 host[0].response_state = response_state; 30 host[0].response = response; 31 FlushIOBuffer (&host[0].comms_buffer); 32 33 // fprintf (stderr, "command: %s\n", command); 34 35 return (PCLIENT_GOOD); 36 } 37 38 // check for response; message must end with specified string. 39 // accumulate the response in the buffer 40 int PclientResponse (Host *host, char *response, IOBuffer *buffer) { 41 42 int i; 43 int status; 44 char *line; 45 struct timespec request, remain; 46 47 ASSERT (response != NULL, "response missing"); 48 ASSERT (buffer != NULL, "buffer missing"); 49 50 /* avoid blocking very long on read, test every 100 usec, up to 0.1 sec */ 51 request.tv_sec = 0; 52 request.tv_nsec = 100000; 53 35 54 /* watch for response - wait up to 1 second */ 36 55 line = NULL; 37 56 status = -1; 57 58 // how long does each cycle really take? 38 59 for (i = 0; (i < PCLIENT_TIMEOUT) && (status != 0) && (line == NULL); i++) { 39 60 status = ReadtoIOBuffer (buffer, host[0].stdout_fd); … … 45 66 return (PCLIENT_DOWN); 46 67 } 68 if (line == NULL) return (PCLIENT_HUNG); 47 69 if (status == -1) return (PCLIENT_HUNG); 48 /* gprint (GP_ERR, "buffer.buffer: %s\n", buffer[0].buffer); */ 70 71 // fprintf (stderr, "response: %s\n", buffer[0].buffer); 72 49 73 return (PCLIENT_GOOD); 50 74 } 51 75 52 76 /* memstr returns a view, not an allocated string : don't free */ 77 /* ReadtoIOBuffer returns : 78 0 - pipe closed 79 -1 - no more data in pipe, data not ready 80 -2 - serious error reading from pipe 81 >0 - data read from pipe 82 */ -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/ResetJob.c
r16472 r18424 1 1 # include "pcontrol.h" 2 3 // XXX deprecated 2 4 3 5 int ResetJob (Job *job) { 4 6 5 7 int status; 6 IOBuffer buffer;7 8 Host *host; 8 9 … … 13 14 ASSERT (job != NULL, "host missing"); 14 15 15 InitIOBuffer (&buffer, 0x100);16 17 16 /* we have tried to reset the job; may not get status */ 18 17 job[0].Reset = TRUE; 19 18 20 status = PclientCommand (host, "reset" , PCLIENT_PROMPT, &buffer);19 status = PclientCommand (host, "reset"); 21 20 22 21 /* check on success of pclient command */ 23 22 switch (status) { 24 23 case PCLIENT_DOWN: 25 /*** different behavior for ANYHOST, WANTHOST, NEEDHOST? ***/ 26 gprint (GP_ERR, "host %s is down\n", host[0].hostname); 24 if (VerboseMode()) gprint (GP_ERR, "host %s is down\n", host[0].hostname); 27 25 HarvestHost (host[0].pid); 28 26 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 29 FreeIOBuffer (&buffer);30 return (FALSE);31 32 case PCLIENT_HUNG:33 /*** should we consider a HUNG host DOWN? ***/34 gprint (GP_ERR, "host %s is not responding (ResetJob)\n", host[0].hostname);35 FreeIOBuffer (&buffer);36 27 return (FALSE); 37 28 38 29 case PCLIENT_GOOD: 39 gprint (GP_ERR, "message received (ResetJob)\n"); 40 FreeIOBuffer (&buffer); 30 host[0].response_state = PCONTROL_RESP_RESET_JOB; 31 host[0].response = PCLIENT_PROMPT; 32 FlushIOBuffer (&host[0].comms_buffer, 0x100); 33 PutHost (host, PCONTROL_HOST_RESP, STACK_BOTTOM); 41 34 return (TRUE); 42 35 43 36 default: 44 gprint (GP_ERR, "unknown status for pclient command: programming error\n"); 45 pcontrol_exit (55); 37 ABORT ("unknown status for pclient command"); 46 38 } 39 ABORT ("should not reach here (ResetJob)"); 40 } 47 41 48 gprint (GP_ERR, "programming error in ResetJob (should not reach here)\n"); 49 FreeIOBuffer (&buffer); 50 pcontrol_exit (56); 51 return (FALSE); 42 int ResetJobResponse (Host *host) { 43 44 int status; 45 IOBuffer *buffer; 46 47 /* job must have assigned host */ 48 ASSERT (host, "missing host"); 49 ASSERT (host[0].job, "missing job"); 50 buffer = host[0].comms_buffer; 51 52 gprint (GP_ERR, "message received (ResetJob)\n"); 53 return (TRUE); 52 54 } 53 55 -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/StartJob.c
r11388 r18424 1 1 # include "pcontrol.h" 2 2 3 // job and host are bound together (why pass in both?) 3 4 int StartJob (Job *job, Host *host) { 4 5 5 6 int i, Nline, status; 6 char *line, *p; 7 IOBuffer buffer; 8 9 InitIOBuffer (&buffer, 0x100); 7 char *line; 10 8 11 9 /* job must have assigned host */ … … 28 26 } 29 27 30 status = PclientCommand (host, line, PCLIENT_PROMPT, &buffer);28 status = PclientCommand (host, line, PCLIENT_PROMPT, PCONTROL_RESP_START_JOB); 31 29 free (line); 32 30 … … 34 32 switch (status) { 35 33 case PCLIENT_DOWN: 34 // unlink host & job 36 35 if (VerboseMode()) gprint (GP_ERR, "host %s is down\n", host[0].hostname); 37 goto failure;38 39 case PCLIENT_HUNG:40 // we need the job start to return a valid Job ID,41 // give up on jobs which don't get started.42 // XXX we are sensitive here to the time it takes pclient43 // to fork the job. if this is slow, the client may appear to hang.44 gprint (GP_ERR, "host %s is not responding (StartJob)\n", host[0].hostname);45 if (VerboseMode()) gprint (GP_ERR, "host %s is not responding\n", host[0].hostname);46 47 // unlink host & job48 36 job[0].host = NULL; 49 37 host[0].job = NULL; 50 if (job[0].realhost) free (job[0].realhost); 51 job[0].realhost = NULL; 52 PutHost (host, PCONTROL_HOST_DONE, STACK_BOTTOM); 38 HarvestHost (host[0].pid); 39 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 53 40 PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM); 54 FreeIOBuffer (&buffer);55 41 return (FALSE); 56 42 57 43 case PCLIENT_GOOD: 58 if (VerboseMode()) gprint (GP_ERR, "message received (StartJob)\n"); 59 break; 44 job[0].realhost = strcreate (host[0].hostname); 45 job[0].pid = -1; 46 gettimeofday (&job[0].start, (void *) NULL); 47 48 if (VerboseMode()) gprint (GP_ERR, "started job on host %s\n", host[0].hostname); 49 PutHost (host, PCONTROL_HOST_RESP, STACK_BOTTOM); 50 PutJob (job, PCONTROL_JOB_RESP, STACK_BOTTOM); 51 return (TRUE); 60 52 61 53 default: 62 54 ABORT ("unknown status for pclient command"); 63 55 } 56 } 57 58 // message has been received from the host, interpret results 59 int StartJobResponse (Host *host) { 60 61 int status; 62 char *p; 63 IOBuffer *buffer; 64 Job *job; 65 66 /* job must have assigned host */ 67 ASSERT (host, "missing host"); 68 ASSERT (host[0].job, "missing job"); 69 buffer = &host[0].comms_buffer; 70 job = (Job *) host[0].job; 64 71 65 72 /* check on result of pclient command */ 66 p = memstr (buffer.buffer, "STATUS", buffer.Nbuffer); 67 ASSERT (p != NULL, "missing STATUS in pclient message"); 73 p = memstr (buffer[0].buffer, "STATUS", buffer[0].Nbuffer); 74 if (p == NULL) { 75 // failed to get a valid response. kill the job and try again, 76 // or accept a running process without a PID? 77 if (VerboseMode()) gprint (GP_ERR, "failed to get a valid PID, trying to continue without\n"); 78 PutHost (host, PCONTROL_HOST_BUSY, STACK_BOTTOM); 79 PutJob (job, PCONTROL_JOB_BUSY, STACK_BOTTOM); 80 gettimeofday (&job[0].start, NULL); 81 return (TRUE); 82 } 68 83 69 84 sscanf (p, "%*s %d", &status); … … 71 86 case -1: 72 87 if (VerboseMode()) gprint (GP_ERR, "error in pclient child\n"); 73 goto failure; 88 // unlink host & job 89 job[0].host = NULL; 90 host[0].job = NULL; 91 HarvestHost (host[0].pid); 92 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM); 93 PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM); 94 return (FALSE); 74 95 75 96 case -2: … … 80 101 81 102 default: 82 job[0].realhost = strcreate (host[0].hostname);103 if (VerboseMode()) gprint (GP_ERR, "message received (StartJobResponse)\n"); 83 104 job[0].pid = status; 84 105 PutHost (host, PCONTROL_HOST_BUSY, STACK_BOTTOM); 85 106 PutJob (job, PCONTROL_JOB_BUSY, STACK_BOTTOM); 86 FreeIOBuffer (&buffer); 87 gettimeofday (&job[0].start, (void *) NULL); 107 gettimeofday (&job[0].start, NULL); 88 108 return (TRUE); 89 109 } 110 90 111 /* we should never reach here */ 91 112 ABORT ("should not reach here (StartJob)"); 92 93 failure:94 // unlink host & job95 job[0].host = NULL;96 host[0].job = NULL;97 HarvestHost (host[0].pid);98 PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM);99 PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM);100 FreeIOBuffer (&buffer);101 return (FALSE);102 113 } -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/StopHosts.c
r16472 r18424 72 72 73 73 int status; 74 IOBuffer buffer;75 74 76 InitIOBuffer (&buffer, 0x100); 77 status = PclientCommand (host, "exit", "Goodbye", &buffer); 78 FreeIOBuffer (&buffer); 75 status = PclientCommand (host, "exit", "Goodbye", PCONTROL_RESP_STOP_HOST); 79 76 80 77 /* check on success of pclient command */ 81 78 switch (status) { 82 79 case PCLIENT_DOWN: 83 break; 84 85 case PCLIENT_HUNG: 86 gprint (GP_ERR, "host %s is not responding\n", host[0].hostname); 80 // XXX this is the desired result in any case, so ignore it 87 81 break; 88 82 89 83 case PCLIENT_GOOD: 90 break; 84 if (VerboseMode()) gprint (GP_ERR, "stop host %s\n", host[0].hostname); 85 FlushIOBuffer (&host[0].comms_buffer); 86 PutHost (host, PCONTROL_HOST_RESP, STACK_BOTTOM); 87 return (TRUE); 91 88 92 89 default: 93 gprint (GP_ERR, "unknown status for pclient command: programming error\n"); 94 pcontrol_exit (57); 90 ABORT ("unknown status for pclient command"); 95 91 } 92 ABORT ("should not reach here"); 93 } 94 95 int StopHostResponse (Host *host) { 96 97 OffHost (host); 96 98 HarvestHost (host[0].pid); 97 99 return (TRUE); … … 103 105 int i, result, waitstatus; 104 106 105 gprint (GP_ERR, "harvesting within thread %d\n", pthread_self());106 gprint (GP_ERR, "child process %d is down, wait for exit status\n", pid);107 if (VerboseMode()) gprint (GP_ERR, "harvesting within thread %p\n", pthread_self()); 108 if (VerboseMode()) gprint (GP_ERR, "child process %d is down, wait for exit status\n", pid); 107 109 108 110 // Loop a few times waiting for child to exit -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/check.c
r11388 r18424 3 3 int check (int argc, char **argv) { 4 4 5 Job *job; 6 Host *host; 7 int JobID, HostID, StackID; 5 int JobID, HostID; 6 7 Stack *stack = NULL; 8 Job *job = NULL; 9 Host *host = NULL; 8 10 9 11 if (argc != 3) { … … 14 16 15 17 if (!strcasecmp (argv[1], "JOB")) { 16 JobID = atoi (argv[2]); 18 JobID = GetID (argv[2]); 19 if (!JobID) { 20 gprint (GP_ERR, "invalid job id %s\n", argv[2]); 21 return (FALSE); 22 } 17 23 18 SetCheckPoint (); // ensure the JOB is on one of the stacks19 job = Pull JobByID (JobID, &StackID);24 stack = GetJobStack (PCONTROL_JOB_ALLJOBS); 25 job = PullStackByID (stack, JobID); 20 26 if (job == NULL) { 21 27 gprint (GP_LOG, "job not found\n"); 22 ClearCheckPoint ();23 28 return (FALSE); 24 29 } 25 gprint (GP_LOG, "STATUS %s\n", GetJobStackName(StackID)); 30 31 gprint (GP_LOG, "STATUS %s\n", GetJobStackName(job[0].stack)); 26 32 gprint (GP_LOG, "EXITST %d\n", job[0].exit_status); 27 33 gprint (GP_LOG, "STDOUT %d\n", job[0].stdout_size); … … 33 39 gprint (GP_LOG, "HOSTNAME NONE\n"); 34 40 } 35 PutJob (job, StackID, STACK_BOTTOM); 36 ClearCheckPoint (); 41 PushStack (stack, STACK_BOTTOM, job, job[0].JobID, job[0].argv[0]); 37 42 return (TRUE); 38 43 } … … 41 46 HostID = atoi (argv[2]); 42 47 43 SetCheckPoint (); // ensure the HOST is on one of the stacks44 host = Pull HostByID (HostID, &StackID);48 stack = GetHostStack (PCONTROL_HOST_ALLHOSTS); 49 host = PullStackByID (stack, HostID); 45 50 if (host == NULL) { 46 51 gprint (GP_LOG, "host not found\n"); 47 ClearCheckPoint ();48 52 return (FALSE); 49 53 } 50 gprint (GP_LOG, "host %s\n", GetHostStackName(StackID)); 51 PutHost (host, StackID, STACK_BOTTOM); 52 ClearCheckPoint (); 54 gprint (GP_LOG, "host %s\n", GetHostStackName(host[0].stack)); 55 PushStack (stack, STACK_BOTTOM, host, host[0].HostID, host[0].hostname); 53 56 return (TRUE); 54 57 } -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/delete.c
r8296 r18424 10 10 return (FALSE); 11 11 } 12 JobID = atoi (argv[1]); 12 JobID = GetID (argv[1]); 13 if (!JobID) { 14 gprint (GP_ERR, "invalid job id %s\n", argv[1]); 15 return (FALSE); 16 } 17 13 18 /* use a string interp to convert JobIDs to ints ? */ 14 19 -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/host.c
r10652 r18424 1 1 # include "pcontrol.h" 2 2 3 // we use CheckPoints in this function to prevent objects in flight from being missing.4 3 int host (int argc, char **argv) { 5 4 6 int StackID;7 5 IDtype HostID; 8 6 Host *host; 7 Stack *AllHosts; 9 8 10 9 if (argc != 3) goto usage; 10 11 AllHosts = GetHostStack (PCONTROL_HOST_ALLHOSTS); 11 12 12 13 if (!strcasecmp (argv[1], "ADD")) { … … 15 16 return (TRUE); 16 17 } 18 19 // this one is safe from in-flight entries: no one else pulls from OFF 17 20 if (!strcasecmp (argv[1], "ON")) { 18 21 host = PullHostFromStackByName (PCONTROL_HOST_OFF, argv[2]); … … 25 28 return (TRUE); 26 29 } 30 31 // this is a race condition with "CheckDownHosts", but the only 32 // consequence is that both StartHost and reset set the times to 0.0 27 33 if (!strcasecmp (argv[1], "RETRY")) { 28 34 // no need to use a check point [thief: CheckDownHost (DOWN->IDLE)] 29 host = PullHostFromStackByName (PCONTROL_HOST_ DOWN, argv[2]);35 host = PullHostFromStackByName (PCONTROL_HOST_ALLHOSTS, argv[2]); 30 36 if (!host) { 37 gprint (GP_LOG, "host %s not found\n", argv[2]); 38 return (FALSE); 39 } 40 if (host[0].stack != PCONTROL_HOST_DOWN) { 31 41 gprint (GP_LOG, "host %s is not DOWN\n", argv[2]); 32 42 return (FALSE); 33 43 } 34 /* reset time, place back on DOWNstack */44 /* reset time, place back on ALLHOSTS stack */ 35 45 host[0].nexttry.tv_sec = 0; 36 46 host[0].nexttry.tv_usec = 0; 37 47 host[0].lasttry.tv_sec = 0; 38 48 host[0].lasttry.tv_usec = 0; 39 Pu tHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM);49 PushStack (AllHosts, STACK_BOTTOM, host, host[0].HostID, host[0].hostname); 40 50 return (TRUE); 41 51 } 52 42 53 if (!strcasecmp (argv[1], "CHECK")) { 43 SetCheckPoint (); // ensure the host is on one of the stacks 44 host = PullHostByName (argv[2], &StackID); 54 host = PullHostFromStackByName (PCONTROL_HOST_ALLHOSTS, argv[2]); 45 55 if (host == NULL) { 46 56 gprint (GP_LOG, "host %s not found\n", argv[2]); 47 ClearCheckPoint ();48 57 return (FALSE); 49 58 } 50 PutHost (host, StackID, STACK_BOTTOM); 51 ClearCheckPoint (); 52 53 gprint (GP_LOG, "host %s is %s\n", argv[2], GetHostStackName (StackID)); 59 gprint (GP_LOG, "host %s is %s\n", argv[2], GetHostStackName (host[0].stack)); 60 PushStack (AllHosts, STACK_BOTTOM, host, host[0].HostID, host[0].hostname); 54 61 return (TRUE); 55 62 } 63 56 64 if (!strcasecmp (argv[1], "OFF")) { 57 SetCheckPoint (); // ensure we can find the specified host 58 host = PullHostByName (argv[2], &StackID); 65 host = PullHostFromStackByName (PCONTROL_HOST_ALLHOSTS, argv[2]); 59 66 if (host == NULL) { 60 67 gprint (GP_LOG, "host %s not found\n", argv[2]); 61 ClearCheckPoint ();62 68 return (FALSE); 63 69 } 64 70 host[0].markoff = TRUE; 65 PutHost (host, StackID, STACK_BOTTOM); 66 ClearCheckPoint (); 71 PushStack (AllHosts, STACK_BOTTOM, host, host[0].HostID, host[0].hostname); 67 72 return (TRUE); 68 73 } 69 74 75 // this one is safe from in-flight entries: no one else pulls from OFF 70 76 if (!strcasecmp (argv[1], "DELETE")) { 71 // a check point is not required: no possible thief72 77 host = PullHostFromStackByName (PCONTROL_HOST_OFF, argv[2]); 73 78 if (!host) { -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/pcontrol.c.in
r16473 r18424 68 68 /* add program-dependent exit functions here */ 69 69 void cleanup () { 70 // stop checking on the jobs 71 SetRunLevel (PCONTROL_RUN_HOSTS); 70 72 DownHosts (); 71 73 ConfigFree (); -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/rconnect.c
r16472 r18424 2 2 3 3 /* connection can take a while, allow up to 2 sec */ 4 # define CONNECT_TIMEOUT 500 4 # define CONNECT_TIMEOUT 5000 5 5 6 6 /* connect to host, start the shell: ssh hostname pclient -> command hostname shell … … 106 106 107 107 connect_error: 108 if (VerboseMode()) gprint (GP_ERR, "error while connecting \n");108 if (VerboseMode()) gprint (GP_ERR, "error while connecting, status: %d, ncycles: %d\n", status, i); 109 109 110 110 /* avoid blocking on waitpid, test every 100 usec, up to 50 msec */ -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/status.c
r12471 r18424 6 6 int status (int argc, char **argv) { 7 7 8 SetCheckPoint (); 9 PrintJobStack (PCONTROL_JOB_PENDING); 10 PrintJobStack (PCONTROL_JOB_BUSY); 11 PrintJobStack (PCONTROL_JOB_DONE); 12 PrintJobStack (PCONTROL_JOB_KILL); 13 PrintJobStack (PCONTROL_JOB_EXIT); 14 PrintJobStack (PCONTROL_JOB_CRASH); 8 PrintJobStack (PCONTROL_JOB_ALLJOBS); 9 PrintHostStack (PCONTROL_HOST_ALLHOSTS); 15 10 16 PrintHostStack (PCONTROL_HOST_OFF);17 PrintHostStack (PCONTROL_HOST_DOWN);18 PrintHostStack (PCONTROL_HOST_IDLE);19 PrintHostStack (PCONTROL_HOST_BUSY);20 PrintHostStack (PCONTROL_HOST_DONE);21 ClearCheckPoint ();22 11 return (TRUE); 23 12 } … … 39 28 job = stack[0].object[i]; 40 29 ASSERT (job != NULL, "programming error"); 41 gprint (GP_LOG, "%d %s %d ", i, job[0].hostname, job[0].argc); 30 if (job[0].realhost == NULL) { 31 gprint (GP_LOG, "%3d %9s ", i, job[0].hostname); 32 } else { 33 gprint (GP_LOG, "%3d %9s ", i, job[0].realhost); 34 } 35 gprint (GP_LOG, "%7s ", GetJobStackName (job[0].state)); 42 36 for (j = 0; j < job[0].argc; j++) { 43 37 gprint (GP_LOG, "%s ", job[0].argv[j]); … … 66 60 host = stack[0].object[i]; 67 61 gprint (GP_LOG, "%d %s ", i, host[0].hostname); 62 gprint (GP_LOG, "%5s ", GetHostStackName (host[0].stack)); 68 63 PrintID (GP_LOG, host[0].HostID); 69 64 gprint (GP_LOG, "\n"); -
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/stdout.c
r12840 r18424 1 1 # include "pcontrol.h" 2 2 3 // XXX unify by testing for value of argv[0] 3 4 int stdout_pc (int argc, char **argv) { 4 5 5 int JobID, StackID;6 int N, JobID, StackID; 6 7 Job *job; 7 8 IOBuffer *buffer; 9 char *varName; 10 11 varName = NULL; 12 if ((N = get_argument (argc, argv, "-var"))) { 13 remove_argument (N, &argc, argv); 14 varName = strcreate (argv[N]); 15 remove_argument (N, &argc, argv); 16 } 8 17 9 18 if (argc != 2) { 10 gprint (GP_ERR, "USAGE: stdout (JobID) \n");19 gprint (GP_ERR, "USAGE: stdout (JobID) [-var name]\n"); 11 20 gprint (GP_LOG, "STATUS %d\n", -1); 12 21 return (FALSE); … … 25 34 26 35 gprint (GP_ERR, "job not found in EXIT or CRASH\n"); 27 gprint (GP_LOG, "STATUS %d\n", -2); 36 if (varName == NULL) { 37 gprint (GP_LOG, "STATUS %d\n", -2); 38 } else { 39 set_str_variable (varName, "NULL"); 40 free (varName); 41 } 28 42 return (FALSE); 29 43 30 44 found_stdout: 31 45 buffer = &job[0].stdout_buff; 32 fwrite (buffer[0].buffer, 1, buffer[0].Nbuffer, stdout); 33 gprint (GP_LOG, "STATUS %d\n", 0); 46 if (varName == NULL) { 47 fwrite (buffer[0].buffer, 1, buffer[0].Nbuffer, stdout); 48 gprint (GP_LOG, "STATUS %d\n", 0); 49 } else { 50 // XXX this can drop '0' values 51 set_str_variable (varName, buffer[0].buffer); 52 free (varName); 53 } 34 54 PutJob (job, StackID, STACK_BOTTOM); 35 55 return (TRUE); … … 38 58 int stderr_pc (int argc, char **argv) { 39 59 40 int JobID, StackID;60 int N, JobID, StackID; 41 61 Job *job; 42 62 IOBuffer *buffer; 63 char *varName; 64 65 varName = NULL; 66 if ((N = get_argument (argc, argv, "-var"))) { 67 remove_argument (N, &argc, argv); 68 varName = strcreate (argv[N]); 69 remove_argument (N, &argc, argv); 70 } 43 71 44 72 if (argc != 2) { 45 gprint (GP_ERR, "USAGE: stderr (JobID) \n");73 gprint (GP_ERR, "USAGE: stderr (JobID) [-var name]\n"); 46 74 gprint (GP_LOG, "STATUS %d\n", -1); 47 75 return (FALSE); … … 60 88 61 89 gprint (GP_ERR, "job not found in EXIT or CRASH\n"); 62 gprint (GP_LOG, "STATUS %d\n", -2); 90 if (varName == NULL) { 91 gprint (GP_LOG, "STATUS %d\n", -2); 92 } else { 93 set_str_variable (varName, "NULL"); 94 free (varName); 95 } 63 96 return (FALSE); 64 97 65 98 found_stderr: 66 99 buffer = &job[0].stderr_buff; 67 fwrite (buffer[0].buffer, 1, buffer[0].Nbuffer, stdout); 68 gprint (GP_LOG, "STATUS %d\n", 0); 100 if (varName == NULL) { 101 fwrite (buffer[0].buffer, 1, buffer[0].Nbuffer, stdout); 102 gprint (GP_LOG, "STATUS %d\n", 0); 103 } else { 104 // XXX this can drop '0' values 105 set_str_variable (varName, buffer[0].buffer); 106 free (varName); 107 } 69 108 PutJob (job, StackID, STACK_BOTTOM); 70 109 return (TRUE);
Note:
See TracChangeset
for help on using the changeset viewer.
