- Timestamp:
- Apr 16, 2020, 1:54:47 PM (6 years ago)
- Location:
- trunk/Ohana/src
- Files:
-
- 52 deleted
- 132 edited
- 4 copied
-
addstar/Makefile (modified) (5 diffs)
-
addstar/doc/mapping_UKIDSS_unWISE_DVO.pdf (deleted)
-
addstar/include/ukirt_uhs.h (deleted)
-
addstar/src/ReadImageHeader.c (modified) (1 diff)
-
addstar/src/args_loadukirt_uhs.c (deleted)
-
addstar/src/find_matches_ukirt_uhs.c (deleted)
-
addstar/src/loadukirt_uhs.c (deleted)
-
addstar/src/loadukirt_uhs_catalog.c (deleted)
-
addstar/src/loadukirt_uhs_make_subset.c (deleted)
-
addstar/src/loadukirt_uhs_readstars.c (deleted)
-
addstar/src/loadukirt_uhs_readstars_ugcs.c (deleted)
-
addstar/src/loadukirt_uhs_readstars_ugps.c (deleted)
-
addstar/src/loadukirt_uhs_readstars_uhs.c (deleted)
-
addstar/src/loadukirt_uhs_readstars_ulas.c (deleted)
-
addstar/src/loadukirt_uhs_table.c (deleted)
-
dvomerge/include/dvomerge.h (modified) (1 diff)
-
dvomerge/src/args.c (modified) (2 diffs)
-
dvomerge/src/dvomergeUpdate_catalogs.c (modified) (1 diff)
-
dvomerge/src/merge_catalogs_old.c (modified) (5 diffs)
-
kapa2/Makefile (modified) (4 diffs)
-
kapa2/doc/base85.c (deleted)
-
kapa2/doc/outline.txt (deleted)
-
kapa2/include/prototypes.h (modified) (6 diffs)
-
kapa2/include/structures.h (modified) (3 diffs)
-
kapa2/samples (deleted)
-
kapa2/src/CheckPipe.c (modified) (2 diffs)
-
kapa2/src/DrawObjects.c (modified) (6 diffs)
-
kapa2/src/Image.c (modified) (4 diffs)
-
kapa2/src/InterpretKeys.c (modified) (2 diffs)
-
kapa2/src/JPEGit24.c (modified) (1 diff)
-
kapa2/src/Layout.c (modified) (1 diff)
-
kapa2/src/LoadFrame.c (modified) (1 diff)
-
kapa2/src/LoadLabels.c (modified) (1 diff)
-
kapa2/src/LoadObject.c (modified) (2 diffs)
-
kapa2/src/MemoryDump.c (deleted)
-
kapa2/src/PDF_Alpha.c (deleted)
-
kapa2/src/PDF_Frame.c (deleted)
-
kapa2/src/PDF_Image.c (deleted)
-
kapa2/src/PDF_Labels.c (deleted)
-
kapa2/src/PDF_Objects.c (deleted)
-
kapa2/src/PDF_Overlay.c (deleted)
-
kapa2/src/PDF_Pixmap.c (deleted)
-
kapa2/src/PDF_PrintUtils.c (deleted)
-
kapa2/src/PDF_Textlines.c (deleted)
-
kapa2/src/PDFit.c (deleted)
-
kapa2/src/PNGit.c (modified) (2 diffs)
-
kapa2/src/PPMit.c (modified) (1 diff)
-
kapa2/src/Refresh.c (modified) (2 diffs)
-
kapa2/src/SetColormap.c (modified) (6 diffs)
-
kapa2/src/SetUpGraphic.c (modified) (3 diffs)
-
kapa2/src/args.c (modified) (1 diff)
-
kapa2/src/bDrawImage.c (modified) (4 diffs)
-
kapa2/src/bDrawIt.c (modified) (1 diff)
-
kapa2/src/bDrawObjects.c (modified) (6 diffs)
-
kapa2/src/bDrawOverlay.c (modified) (2 diffs)
-
kapa2/src/kapa.c (modified) (1 diff)
-
libdvo/include/dvodb.h (modified) (1 diff)
-
libdvo/src/dvosorts.c (modified) (1 diff)
-
libfits/include/gfitsio.h (modified) (1 diff)
-
libfits/table/F_define_column.c (modified) (1 diff)
-
libfits/table/F_set_column.c (modified) (6 diffs)
-
libkapa/Makefile (modified) (1 diff)
-
libkapa/include/kapa.h (modified) (8 diffs)
-
libkapa/rotfont/helvetica12.h (modified) (2 diffs)
-
libkapa/src/DrawRotString.c (modified) (4 diffs)
-
libkapa/src/KapaColors.c (modified) (3 diffs)
-
libkapa/src/KapaStyles.c (modified) (1 diff)
-
libkapa/src/KapaWindow.c (modified) (1 diff)
-
libkapa/src/KiiConvert.c (modified) (1 diff)
-
libkapa/src/PDFRotFont.c (deleted)
-
libkapa/src/PSRotFont.c (modified) (1 diff)
-
libkapa/src/RotFont.c (modified) (1 diff)
-
libkapa/src/bDrawFuncs.c (modified) (17 diffs)
-
libkapa/src/bDrawRotFont.c (modified) (4 diffs)
-
libohana/include/ohana.h (modified) (1 diff)
-
libohana/include/ohana_allocate.h (modified) (1 diff)
-
libohana/include/ohana_sort.h (modified) (1 diff)
-
libohana/src/IOBufferOps.c (modified) (1 diff)
-
libohana/src/isolate_elements.c (modified) (3 diffs)
-
libohana/src/ohana_allocate.c (modified) (4 diffs)
-
libohana/src/sorts.c (modified) (1 diff)
-
opihi/cmd.astro/cdensify.c (modified) (2 diffs)
-
opihi/cmd.astro/cdhistogram.c (modified) (3 diffs)
-
opihi/cmd.astro/cgrid.c (modified) (5 diffs)
-
opihi/cmd.astro/csystem.c (modified) (3 diffs)
-
opihi/cmd.astro/fitplx_irls.c (modified) (3 diffs)
-
opihi/cmd.astro/mkgauss.c (modified) (3 diffs)
-
opihi/cmd.astro/region.c (modified) (6 diffs)
-
opihi/cmd.basic/init.c (modified) (1 diff)
-
opihi/cmd.basic/list.c (modified) (1 diff)
-
opihi/cmd.basic/memory.c (modified) (2 diffs)
-
opihi/cmd.basic/test/if.sh (modified) (1 diff)
-
opihi/cmd.basic/test/macro.sh (modified) (2 diffs)
-
opihi/cmd.basic/test/stackmath.sh (deleted)
-
opihi/cmd.basic/test/tap.sh (deleted)
-
opihi/cmd.data/Makefile (modified) (9 diffs)
-
opihi/cmd.data/antialias.c (deleted)
-
opihi/cmd.data/create.c (modified) (2 diffs)
-
opihi/cmd.data/cut.c (modified) (6 diffs)
-
opihi/cmd.data/dbselect.c (modified) (2 diffs)
-
opihi/cmd.data/extract.c (modified) (5 diffs)
-
opihi/cmd.data/init.c (modified) (16 diffs)
-
opihi/cmd.data/interpolate_presort.c (modified) (3 diffs)
-
opihi/cmd.data/kapamemory.c (deleted)
-
opihi/cmd.data/list_vectors.c (modified) (1 diff)
-
opihi/cmd.data/match1d.c (deleted)
-
opihi/cmd.data/medimage_calc.c (deleted)
-
opihi/cmd.data/medimage_commands.c (modified) (3 diffs)
-
opihi/cmd.data/mgaussdev.c (deleted)
-
opihi/cmd.data/pdf.c (deleted)
-
opihi/cmd.data/peak.c (modified) (2 diffs)
-
opihi/cmd.data/print_vectors.c (modified) (1 diff)
-
opihi/cmd.data/queue2book.c (deleted)
-
opihi/cmd.data/read_vectors.c (modified) (12 diffs)
-
opihi/cmd.data/roll.c (modified) (2 diffs)
-
opihi/cmd.data/rotate.c (modified) (4 diffs)
-
opihi/cmd.data/spline.c (modified) (3 diffs)
-
opihi/cmd.data/spline_commands.c (modified) (7 diffs)
-
opihi/cmd.data/test/cut.sh (modified) (2 diffs)
-
opihi/cmd.data/test/delete.sh (modified) (1 diff)
-
opihi/cmd.data/test/headtest.sh (deleted)
-
opihi/cmd.data/test/medimage.sh (modified) (1 diff)
-
opihi/cmd.data/test/set.sh (deleted)
-
opihi/cmd.data/test/spline.sh (deleted)
-
opihi/cmd.data/test/vsigmoid.sh (deleted)
-
opihi/cmd.data/test/vstat.sh (deleted)
-
opihi/cmd.data/threshold.c (modified) (4 diffs)
-
opihi/cmd.data/tvcolors.c (modified) (1 diff)
-
opihi/cmd.data/vgauss.c (modified) (5 diffs)
-
opihi/cmd.data/virls.c (deleted)
-
opihi/cmd.data/vsigmoid.c (deleted)
-
opihi/cmd.data/vtransitions.c (deleted)
-
opihi/cmd.data/vwtmean.c (deleted)
-
opihi/cmd.data/write_vectors.c (modified) (8 diffs)
-
opihi/dvo/Makefile (modified) (1 diff)
-
opihi/dvo/avextract.c (modified) (1 diff)
-
opihi/dvo/avmatch.c (modified) (2 diffs)
-
opihi/dvo/avperiodomatch.c (modified) (1 diff)
-
opihi/dvo/avselect.c (modified) (2 diffs)
-
opihi/dvo/cimages.c (deleted)
-
opihi/dvo/dvo_host_utils.c (modified) (1 diff)
-
opihi/dvo/images.c (modified) (4 diffs)
-
opihi/dvo/init.c (modified) (2 diffs)
-
opihi/dvo/mextract.c (modified) (1 diff)
-
opihi/dvo/mmatch.c (modified) (2 diffs)
-
opihi/dvo/skyregion.c (modified) (2 diffs)
-
opihi/include/data.h (modified) (1 diff)
-
opihi/include/deimos.h (modified) (2 diffs)
-
opihi/include/dvomath.h (modified) (4 diffs)
-
opihi/lib.data/MedImageOps.c (modified) (2 diffs)
-
opihi/lib.data/SplineOps.c (modified) (2 diffs)
-
opihi/lib.data/open_kapa.c (modified) (2 diffs)
-
opihi/lib.data/spline.c (modified) (2 diffs)
-
opihi/lib.data/starfuncs.c (modified) (1 diff)
-
opihi/lib.data/style_args.c (modified) (1 diff)
-
opihi/lib.shell/VectorIO.c (modified) (10 diffs)
-
opihi/lib.shell/VectorOps.c (modified) (9 diffs)
-
opihi/lib.shell/convert_to_RPN.c (modified) (2 diffs)
-
opihi/lib.shell/multicommand.c (modified) (2 diffs)
-
opihi/lib.shell/parse.c (modified) (2 diffs)
-
opihi/lib.shell/stack_math.c (modified) (25 diffs)
-
opihi/lib.shell/startup.c (modified) (1 diff)
-
opihi/mana/Makefile (modified) (1 diff)
-
opihi/mana/deimos.c (modified) (1 diff)
-
opihi/mana/deimos_arclines.c (modified) (2 diffs)
-
opihi/mana/deimos_fitalt.c (copied) (copied from trunk/Ohana/src/opihi/mana/deimos_fitalt.c )
-
opihi/mana/deimos_fitarc.c (deleted)
-
opihi/mana/deimos_fitobj.c (copied) (copied from trunk/Ohana/src/opihi/mana/deimos_fitobj.c )
-
opihi/mana/deimos_fitobj.v0.c (deleted)
-
opihi/mana/deimos_fitprofile.c (deleted)
-
opihi/mana/deimos_fitslit.c (modified) (4 diffs)
-
opihi/mana/deimos_getobj.c (copied) (copied from trunk/Ohana/src/opihi/mana/deimos_getobj.c )
-
opihi/mana/deimos_getobj.v0.c (deleted)
-
opihi/mana/deimos_mkalt.c (modified) (2 diffs)
-
opihi/mana/deimos_mkmodel.c (modified) (7 diffs)
-
opihi/mana/deimos_mkobj.c (modified) (7 diffs)
-
opihi/mana/deimos_mkslit.c (modified) (7 diffs)
-
opihi/mana/test (deleted)
-
opihi/pantasks/Makefile (modified) (1 diff)
-
opihi/pantasks/init.c (modified) (2 diffs)
-
opihi/pantasks/init_server.c (modified) (2 diffs)
-
opihi/pantasks/ipptool2book.c (copied) (copied from trunk/Ohana/src/opihi/pantasks/ipptool2book.c )
-
photdbc/include/photdbc.h (modified) (1 diff)
-
photdbc/src/args.c (modified) (2 diffs)
-
photdbc/src/make_subcatalog.c (modified) (1 diff)
-
photdbc/src/photdbc_catalogs.c (modified) (1 diff)
-
relphot/src/reload_catalogs.c (modified) (1 diff)
-
relphot/src/relphot_objects.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/addstar/Makefile
r41151 r41340 27 27 loadgaia : $(BIN)/loadgaia.$(ARCH) 28 28 loadgaia_dr2 : $(BIN)/loadgaia_dr2.$(ARCH) 29 loadukirt_uhs : $(BIN)/loadukirt_uhs.$(ARCH)30 29 loadstarpar : $(BIN)/loadstarpar.$(ARCH) 31 30 loadstarpar_client : $(BIN)/loadstarpar_client.$(ARCH) … … 45 44 # programs in 'SERVER' use the client-server concept and are out of date 46 45 47 INSTALL = addstar addstar_client sedstar loadgalphot loadgaia loadgaia_dr2 load ukirt_uhs loadstarpar loadstarpar_client setobjflags setobjflags_client loadICRF loadICRF_client skycells mkcmf dumpskycells findskycell load2mass loadwise loadtycho loadbsc loadsupercos46 INSTALL = addstar addstar_client sedstar loadgalphot loadgaia loadgaia_dr2 loadstarpar loadstarpar_client setobjflags setobjflags_client loadICRF loadICRF_client skycells mkcmf dumpskycells findskycell load2mass loadwise loadtycho loadbsc loadsupercos 48 47 SERVER = addstarc addstard addstart 49 48 … … 306 305 $(SRC)/psps_ids.$(ARCH).o 307 306 308 LOAD-UKIRT_UHS = \309 $(SRC)/loadukirt_uhs.$(ARCH).o \310 $(SRC)/ConfigInit.$(ARCH).o \311 $(SRC)/SetSignals.$(ARCH).o \312 $(SRC)/Shutdown.$(ARCH).o \313 $(SRC)/args_loadukirt_uhs.$(ARCH).o \314 $(SRC)/find_matches_ukirt_uhs.$(ARCH).o \315 $(SRC)/loadukirt_uhs_catalog.$(ARCH).o \316 $(SRC)/loadukirt_uhs_make_subset.$(ARCH).o \317 $(SRC)/loadukirt_uhs_readstars.$(ARCH).o \318 $(SRC)/loadukirt_uhs_readstars_uhs.$(ARCH).o \319 $(SRC)/loadukirt_uhs_readstars_ugcs.$(ARCH).o \320 $(SRC)/loadukirt_uhs_readstars_ugps.$(ARCH).o \321 $(SRC)/loadukirt_uhs_readstars_ulas.$(ARCH).o \322 $(SRC)/loadukirt_uhs_table.$(ARCH).o \323 $(SRC)/parse_csv.$(ARCH).o \324 $(SRC)/resort_catalog.$(ARCH).o \325 $(SRC)/build_links.$(ARCH).o \326 $(SRC)/strhash.$(ARCH).o \327 $(SRC)/sortIDs.$(ARCH).o \328 $(SRC)/psps_ids.$(ARCH).o329 330 307 LOAD-STARPAR = \ 331 308 $(SRC)/loadstarpar.$(ARCH).o \ … … 551 528 $(LOAD-GAIA) : $(INC)/addstar.h $(INC)/gaia.h 552 529 $(LOAD-GAIA_DR2) : $(INC)/addstar.h $(INC)/gaia_dr2.h 553 $(LOAD-UKIRT_UHS) : $(INC)/addstar.h $(INC)/ukirt_uhs.h554 530 $(LOAD-STARPAR) : $(INC)/addstar.h $(INC)/loadstarpar.h 555 531 $(LOAD-STARPAR-CLIENT) : $(INC)/addstar.h $(INC)/loadstarpar.h … … 575 551 $(BIN)/loadgaia.$(ARCH) : $(LOAD-GAIA) 576 552 $(BIN)/loadgaia_dr2.$(ARCH) : $(LOAD-GAIA_DR2) 577 $(BIN)/loadukirt_uhs.$(ARCH) : $(LOAD-UKIRT_UHS)578 553 $(BIN)/loadstarpar.$(ARCH) : $(LOAD-STARPAR) 579 554 $(BIN)/loadstarpar_client.$(ARCH) : $(LOAD-STARPAR-CLIENT) -
trunk/Ohana/src/addstar/src/ReadImageHeader.c
r41151 r41340 118 118 if (photcode == 0) { 119 119 if (!gfits_scan (header, "PHOTCODE", "%s", 1, photname)) { 120 fprintf (stderr, " failure:photcode not supplied in header\n");120 fprintf (stderr, "photcode not supplied in header\n"); 121 121 return (FALSE); 122 122 } -
trunk/Ohana/src/dvomerge/include/dvomerge.h
r41152 r41340 31 31 int IMAGES_ONLY; 32 32 int ACCEPT_MOTION; 33 34 int ACCEPT_ASTROM;35 33 int RETAIN_AVE_PHOTOMETRY; 36 37 34 char CATDIR[DVO_MAX_PATH]; 38 35 char GSCFILE[DVO_MAX_PATH]; -
trunk/Ohana/src/dvomerge/src/args.c
r41152 r41340 112 112 } 113 113 114 /* accept input database average astrometry motions*/114 /* limit the impact of a dvomerge -parallel */ 115 115 ACCEPT_MOTION = FALSE; 116 116 if ((N = get_argument (*argc, argv, "-accept-motion"))) { 117 117 remove_argument (N, argc, argv); 118 118 ACCEPT_MOTION = TRUE; 119 }120 /* accept input database average astrometry information */121 ACCEPT_ASTROM = FALSE;122 if ((N = get_argument (*argc, argv, "-accept-astrom"))) {123 remove_argument (N, argc, argv);124 ACCEPT_ASTROM = TRUE;125 119 } 126 120 … … 343 337 } 344 338 345 /* accept input database average astrometry motions*/339 /* limit the impact of a dvomerge -parallel */ 346 340 ACCEPT_MOTION = FALSE; 347 341 if ((N = get_argument (*argc, argv, "-accept-motion"))) { 348 342 remove_argument (N, argc, argv); 349 343 ACCEPT_MOTION = TRUE; 350 }351 /* accept input database average astrometry information */352 ACCEPT_ASTROM = FALSE;353 if ((N = get_argument (*argc, argv, "-accept-astrom"))) {354 remove_argument (N, argc, argv);355 ACCEPT_ASTROM = TRUE;356 344 } 357 345 -
trunk/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c
r41152 r41340 328 328 if (FORCE_MERGE) { strextend (&command, "-force-merge"); } 329 329 if (ACCEPT_MOTION) { strextend (&command, "-accept-motion"); } 330 if (ACCEPT_ASTROM) { strextend (&command, "-accept-astrom"); }331 330 if (RETAIN_AVE_PHOTOMETRY) { strextend (&command, "-retain-ave-photometry"); } 332 331 if (MATCHED_TABLES) { strextend (&command, "-matched-tables"); } -
trunk/Ohana/src/dvomerge/src/merge_catalogs_old.c
r41152 r41340 363 363 } 364 364 365 // XXX: add choice of secfilt366 365 // update the average properties to reflect the incoming entries: 367 366 // if RETAIN_AVE_PHOTOMETRY is true and the original value is NAN, but the input value is not, accept the input: … … 390 389 391 390 // we can choose to accept the proper-motion and parallax from the reference tgtcat 392 if (ACCEPT_MOTION || ACCEPT_ASTROM) {391 if (ACCEPT_MOTION) { 393 392 output[0].average[n].dR = input[0].average[N].dR; 394 393 output[0].average[n].dD = input[0].average[N].dD; … … 401 400 output[0].average[n].Tmean = input[0].average[N].Tmean; 402 401 } 403 if (ACCEPT_ASTROM) {404 output[0].average[n].R = input[0].average[N].R;405 output[0].average[n].D = input[0].average[N].D;406 }407 402 408 403 /* Nm is updated, but not written out in -update mode (for existing entries) … … 466 461 467 462 // we can choose to accept the proper-motion and parallax from the reference tgtcat 468 if (ACCEPT_MOTION || ACCEPT_ASTROM) {463 if (ACCEPT_MOTION) { 469 464 output[0].average[Nave].dR = input[0].average[N].dR; 470 465 output[0].average[Nave].dD = input[0].average[N].dD; … … 476 471 output[0].average[Nave].dP = input[0].average[N].dP; 477 472 output[0].average[Nave].Tmean = input[0].average[N].Tmean; 478 }479 if (ACCEPT_ASTROM) {480 output[0].average[Nave].R = input[0].average[N].R;481 output[0].average[Nave].D = input[0].average[N].D;482 473 } 483 474 -
trunk/Ohana/src/kapa2/Makefile
r41320 r41340 23 23 install: $(DESTBIN)/kapa 24 24 25 PDF = \26 $(SRC)/PDFit.$(ARCH).o \27 $(SRC)/PDF_Frame.$(ARCH).o \28 $(SRC)/PDF_Objects.$(ARCH).o \29 $(SRC)/PDF_Labels.$(ARCH).o \30 $(SRC)/PDF_Image.$(ARCH).o \31 $(SRC)/PDF_Overlay.$(ARCH).o \32 $(SRC)/PDF_Textlines.$(ARCH).o \33 $(SRC)/PDF_Pixmap.$(ARCH).o \34 $(SRC)/PDF_Alpha.$(ARCH).o \35 $(SRC)/PDF_PrintUtils.$(ARCH).o36 37 BDRAW = \38 $(SRC)/bDrawIt.$(ARCH).o \39 $(SRC)/bDrawFrame.$(ARCH).o \40 $(SRC)/bDrawObjects.$(ARCH).o \41 $(SRC)/bDrawLabels.$(ARCH).o \42 $(SRC)/bDrawImage.$(ARCH).o \43 $(SRC)/bDrawOverlay.$(ARCH).o44 45 PSFILES = \46 $(SRC)/PSit.$(ARCH).o \47 $(SRC)/PSFrame.$(ARCH).o \48 $(SRC)/PSObjects.$(ARCH).o \49 $(SRC)/PSLabels.$(ARCH).o \50 $(SRC)/PSimage.$(ARCH).o \51 $(SRC)/PSOverlay.$(ARCH).o \52 $(SRC)/PSTextlines.$(ARCH).o \53 $(SRC)/PSPixmap.$(ARCH).o54 55 25 KAPA = \ 56 26 $(SRC)/kapa.$(ARCH).o $(SRC)/args.$(ARCH).o \ … … 68 38 $(SRC)/DrawObjects.$(ARCH).o $(SRC)/DrawFrame.$(ARCH).o \ 69 39 $(SRC)/DrawTextlines.$(ARCH).o $(SRC)/DrawLabels.$(ARCH).o \ 70 $(SRC)/MemoryDump.$(ARCH).o \ 40 $(SRC)/PSObjects.$(ARCH).o $(SRC)/PSFrame.$(ARCH).o \ 41 $(SRC)/PSLabels.$(ARCH).o $(SRC)/PSTextlines.$(ARCH).o \ 42 $(SRC)/bDrawObjects.$(ARCH).o $(SRC)/bDrawFrame.$(ARCH).o \ 43 $(SRC)/bDrawLabels.$(ARCH).o $(SRC)/bDrawIt.$(ARCH).o \ 44 $(SRC)/bDrawImage.$(ARCH).o \ 71 45 $(SRC)/PNGit.$(ARCH).o $(SRC)/PPMit.$(ARCH).o \ 46 $(SRC)/PSit.$(ARCH).o $(SRC)/CrossHairs.$(ARCH).o \ 72 47 $(SRC)/CheckPipe.$(ARCH).o $(SRC)/EventLoop.$(ARCH).o \ 73 48 $(SRC)/Reconfig.$(ARCH).o $(SRC)/Refresh.$(ARCH).o \ … … 77 52 $(SRC)/ErasePlots.$(ARCH).o $(SRC)/EraseImage.$(ARCH).o \ 78 53 $(SRC)/EraseCurrentPlot.$(ARCH).o $(SRC)/EraseSections.$(ARCH).o \ 79 $(SRC)/SetToolbox.$(ARCH).o $(SRC)/CrossHairs.$(ARCH).o\54 $(SRC)/SetToolbox.$(ARCH).o \ 80 55 $(SRC)/SetSection.$(ARCH).o $(SRC)/DefineSection.$(ARCH).o \ 81 56 $(SRC)/SetLimits.$(ARCH).o $(SRC)/SetFont.$(ARCH).o \ … … 100 75 $(SRC)/CheckButtons.$(ARCH).o $(SRC)/InvertButton.$(ARCH).o \ 101 76 $(SRC)/UpdatePointer.$(ARCH).o $(SRC)/JPEGit24.$(ARCH).o \ 102 $(SRC)/ButtonFunctions.$(ARCH).o \ 103 $(SRC)/SetChannel.$(ARCH).o \ 77 $(SRC)/bDrawOverlay.$(ARCH).o $(SRC)/ButtonFunctions.$(ARCH).o \ 78 $(SRC)/PSimage.$(ARCH).o $(SRC)/PSPixmap.$(ARCH).o \ 79 $(SRC)/PSOverlay.$(ARCH).o $(SRC)/SetChannel.$(ARCH).o \ 104 80 $(SRC)/SetColorScale.$(ARCH).o $(SRC)/ColorCube.$(ARCH).o \ 105 81 $(SRC)/ColorHistogram.$(ARCH).o $(SRC)/CreateWide.$(ARCH).o 106 82 107 OBJ = $(KAPA) $(PDF) $(BDRAW) $(PSFILES)83 OBJ = $(KAPA) 108 84 109 85 # dependancy rules for include files ######################## -
trunk/Ohana/src/kapa2/include/prototypes.h
r41320 r41340 3 3 int args PROTO((int *argc, char **argv)); 4 4 void SetUpGraphic PROTO((int *argc, char **argv)); 5 void FreeGraphic PROTO((void));6 5 void DefineLayout PROTO((int, char **)); 7 6 int EventLoop PROTO((void)); 8 7 void CloseDisplay PROTO((void)); 9 int MemoryDump PROTO((int sock));10 int MemoryDumpLines PROTO((int sock));11 int MemoryDumpOnExit PROTO((int sock));12 int MemoryDumpSetOnExit PROTO((int state));13 int MemoryDumpAndExit PROTO((void));14 8 15 9 /* SetUpGraphic */ … … 39 33 void DrawTextlines PROTO((KapaGraphWidget *graph)); 40 34 void DrawConnect PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects)); 41 void DrawPolygon PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects));42 void DrawPolyfill PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects));43 35 void DrawHistogram PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects)); 44 36 int DrawObjectN PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects)); … … 93 85 int SetColormapFromPipe PROTO((int sock)); 94 86 int SetNanColorFromPipe PROTO((int sock)); 95 int SetSmoothSigma PROTO((int sock));96 87 97 88 int LoadVectorData PROTO((int sock, KapaGraphWidget *graph, int N, char *type)); … … 118 109 119 110 void InitLayout PROTO((int argc, char **argv)); 120 void FreeLayout PROTO((void));121 122 /* PDF drawing primitives */123 double PDF_SetLineWeight PROTO((IOBuffer *buffer, double lweightIn));124 void PDF_SetKapaColor PROTO((IOBuffer *buffer, bDrawColor color));125 void PDF_SetScaledColor PROTO((IOBuffer *buffer, float *pixel1, float *pixel2, float *pixel3, float value, int Npixels));126 void PDF_DrawCircle PROTO((IOBuffer *buffer, float Xc, float Yc, float R, int isFill));127 128 /* PDF print utils */129 PDF_FILE *PDF_Open PROTO((char *filename));130 int PDF_Print PROTO((PDF_FILE *obj, int newObject, char *format, ...));131 int PDF_Close PROTO((PDF_FILE *obj));132 int PDF_CreateStream PROTO((IOBuffer *buffer, float scale, int Xoff, int Yoff));133 int PDF_WriteStream PROTO((PDF_FILE *obj, IOBuffer *buffer));134 int PDF_WriteImage PROTO((PDF_FILE *obj, IOBuffer *buffer, int dX, int dY));135 void PDF_AlphaDump PROTO((PDF_FILE *obj));136 void PDF_AlphaSet PROTO((Gobjects *object, IOBuffer *buffer));137 void PDF_AlphaInit PROTO(());138 139 /* PDF drawing utilities */140 int PDFcommand PROTO((int sock));141 int PDFit PROTO((char *filename, char *pagename, int scaleMode, int pageMode));142 int PDF_Frame PROTO((KapaGraphWidget *graph, IOBuffer *buffer));143 int PDF_Objects PROTO((KapaGraphWidget *graph, IOBuffer *buffer));144 void PDF_Labels PROTO((KapaGraphWidget *graph, IOBuffer *buffer));145 void PDF_Textlines PROTO((KapaGraphWidget *graph, IOBuffer *buffer));146 int PDF_ObjectsN PROTO((KapaGraphWidget *graph, Gobjects *objects, IOBuffer *buffer));147 void PDF_Connect PROTO((KapaGraphWidget *graph, Gobjects *objects, IOBuffer *buffer));148 void PDF_Histogram PROTO((KapaGraphWidget *graph, Gobjects *objects, IOBuffer *buffer));149 void PDF_Points PROTO((KapaGraphWidget *graph, Gobjects *objects, IOBuffer *buffer));150 void PDF_XErrors PROTO((KapaGraphWidget *graph, Gobjects *objects, IOBuffer *buffer));151 void PDF_YErrors PROTO((KapaGraphWidget *graph, Gobjects *objects, IOBuffer *buffer));152 void PDF_Tick PROTO((Graphic *graphic, Axis *axis, int P, TickMarkData *tick, int naxis, IOBuffer *buffer));153 void PDF_ClipLine PROTO((double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0, IOBuffer *buffer));154 int PDF_Image PROTO((PDF_FILE *obj, KapaImageWidget *image, IOBuffer *buffer));155 void PDF_Overlay PROTO((KapaImageWidget *image, int N, IOBuffer *buffer, int extra));156 void PDF_Pixmap PROTO((Graphic *graphic, KapaImageWidget *image, IOBuffer *buffer));157 111 158 112 /* PS drawing utilities */ … … 188 142 void bDrawBars PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object, int mode)); 189 143 void bDrawPoints PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object)); 190 void bDrawPolygons PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object));191 void bDrawFillPolygons PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object));192 144 void bDrawXErrors PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object)); 193 145 void bDrawYErrors PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object)); … … 227 179 void InitButtonFunc PROTO((Button *button, int (*function)(Graphic *graphic, KapaImageWidget *image))); 228 180 void DrawImage PROTO((KapaImageWidget *image)); 229 void DrawImageTool PROTO((KapaImageWidget *image));230 181 void DrawButton PROTO((Graphic *graphic, Button *button)); 231 182 void DrawBitmap PROTO((Graphic *graphic, int x, int y, int dx, int dy, unsigned char *bitmap, int mode)); -
trunk/Ohana/src/kapa2/include/structures.h
r41320 r41340 48 48 unsigned long back; // basic background color 49 49 50 float smooth_sigma; // anti-aliasing smoothing scale51 52 50 unsigned long overlay_color[NOVERLAYS]; // image plotting colors 53 51 } Graphic; … … 133 131 } Overlay; 134 132 135 // a set of objects all have the same basic properties 136 typedef struct { 137 float *x; // x-coordinates of the points 138 float *y; // y-coordinates of the points 139 float *z; // size/colorscale for points 140 float *dxp; // lower-errorbar in x 141 float *dxm; // upper-errorbar in x 142 float *dyp; // lower-errorbar in y 143 float *dym; // upper-errorbar in y 144 int Npts; // number of points in this set 145 int style; // how are the object draw: CONNECT, HISTOGRAM, 146 int ptype; // shape of object at each point 147 // ptype is overloaded for NPOLYGON to be the number of points / polygon 148 int ltype; // style of line (solid, dot, dash, etc) 149 int color; // color for point (if not colorscaled) 150 int etype; // errorbars to draw (0x01 = y, 0x02 = x) 151 int ebar; // draw a cap on the error bar 152 double lweight; // line thickness 153 double size; // size of the object 133 typedef struct { 134 float *x, *y, *z, *dxp, *dxm, *dyp, *dym; 135 int Npts; 136 int style, ptype, ltype, color, etype, ebar; 137 double lweight, size; 154 138 double x0, x1, y0, y1; /* limits for this object */ 155 139 double alpha; … … 250 234 char *name; 251 235 } Section; 252 253 typedef struct {254 FILE *f;255 int Nsegment;256 int NSEGMENT;257 int *offset;258 int *objnum;259 260 int Nstream;261 int NSTREAM;262 int *streamObjnum;263 264 int Nimage;265 int NIMAGE;266 int *imageObjnum;267 } PDF_FILE;268 -
trunk/Ohana/src/kapa2/src/CheckPipe.c
r41320 r41340 94 94 } 95 95 96 if (!strcmp (word, "PDFT")) {97 status = PDFcommand (sock);98 KiiSendCommand (sock, 4, "DONE");99 FINISHED (status);100 }101 102 96 if (!strcmp (word, "PNGF")) { 103 97 status = PNGcommand (sock); … … 358 352 } 359 353 360 if (!strcmp (word, "SIGM")) {361 SetSmoothSigma (sock);362 KiiSendCommand (sock, 4, "DONE");363 FINISHED (TRUE);364 }365 366 if (!strcmp (word, "MEMD")) {367 MemoryDump (sock);368 KiiSendCommand (sock, 4, "DONE");369 FINISHED (TRUE);370 }371 372 if (!strcmp (word, "MEML")) {373 MemoryDumpLines (sock);374 KiiSendCommand (sock, 4, "DONE");375 FINISHED (TRUE);376 }377 378 if (!strcmp (word, "MEMX")) {379 MemoryDumpOnExit (sock);380 KiiSendCommand (sock, 4, "DONE");381 FINISHED (TRUE);382 }383 384 354 fprintf (stderr, "unknown signal %s\n", word); 385 355 KiiSendCommand (sock, 4, "DONE"); -
trunk/Ohana/src/kapa2/src/DrawObjects.c
r41157 r41340 97 97 switch (object[0].style) { 98 98 case KAPA_PLOT_CONNECT: 99 // fprintf (stderr, "plot KAPA_PLOT_CONNECT: \n"); 99 100 DrawConnect (graphic, graph, object); 100 101 break; 101 case KAPA_PLOT_POLYGON:102 DrawPolygon (graphic, graph, object);103 break;104 case KAPA_PLOT_POLYFILL:105 DrawPolyfill (graphic, graph, object);106 break;107 102 case KAPA_PLOT_HISTOGRAM: 103 // fprintf (stderr, "plot KAPA_PLOT_HISTOGRAM:\n"); 108 104 DrawHistogram (graphic, graph, object); 109 105 break; 110 106 case KAPA_PLOT_BARS_SOLID: 107 // fprintf (stderr, "plot KAPA_PLOT_BARS_SOLID:\n"); 111 108 DrawBars (graphic, graph, object, KAPA_PLOT_BARS_SOLID); 112 109 break; 113 110 case KAPA_PLOT_BARS_OUTLINE: 111 // fprintf (stderr, "plot KAPA_PLOT_BARS_OUTLINE:\n"); 114 112 DrawBars (graphic, graph, object, KAPA_PLOT_BARS_OUTLINE); 115 113 break; 116 114 case KAPA_PLOT_BARS_OUTFILL: 115 // fprintf (stderr, "plot KAPA_PLOT_BARS_OUTFILL:\n"); 117 116 DrawBars (graphic, graph, object, KAPA_PLOT_BARS_OUTFILL); 118 117 break; 119 118 case KAPA_PLOT_POINTS: 120 119 default: 120 // fprintf (stderr, "plot KAPA_PLOT_POINTS:\n"); 121 121 DrawPoints (graphic, graph, object); 122 122 break; … … 172 172 sx0 = sx1; sy0 = sy1; 173 173 } 174 } 175 176 /******/ 177 void DrawPolygon (Graphic *graphic, KapaGraphWidget *graph, Gobjects *object) { 178 179 float *x, *y; 180 double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by; 181 double sx0, sy0, sx1, sy1; 182 double X0, X1, Y0, Y1; 183 184 mxi = graph[0].axis[0].dfx / (object[0].x1 - object[0].x0); 185 mxj = graph[0].axis[1].dfx / (object[0].y1 - object[0].y0); 186 myi = graph[0].axis[0].dfy / (object[0].x1 - object[0].x0); 187 myj = graph[0].axis[1].dfy / (object[0].y1 - object[0].y0); 188 189 bxi = graph[0].axis[0].fx - object[0].x0*graph[0].axis[0].dfx/(object[0].x1 - object[0].x0); 190 bxj = -object[0].y0*graph[0].axis[1].dfx/(object[0].y1 - object[0].y0); 191 byi = -object[0].x0*graph[0].axis[0].dfy/(object[0].x1 - object[0].x0); 192 byj = graph[0].axis[1].fy - object[0].y0*graph[0].axis[1].dfy/(object[0].y1 - object[0].y0); 193 194 bx = bxi + bxj; 195 by = byi + byj; 196 197 X0 = graph[0].axis[0].fx; 198 X1 = graph[0].axis[0].fx + graph[0].axis[0].dfx; 199 Y0 = graph[0].axis[1].fy; 200 Y1 = graph[0].axis[1].fy + graph[0].axis[1].dfy; 201 202 x = object[0].x; y = object[0].y; 203 204 // ptype must > 2 205 // Npts % ptype must be 0 206 // who must validate that? 207 208 // each polygon is made of (N = ptype) points 209 // we connect each point and the last one back 210 for (int i = 0; i < object[0].Npts; i += object[0].ptype) { 211 // first check for any invalid values for this polygon 212 int skipObject = FALSE; 213 for (int j = 0; (j < object[0].ptype) && !skipObject; j++) { 214 int k = i + j; 215 if (!(finite(x[k]) && finite(y[k]))) skipObject = TRUE; 216 } 217 if (skipObject) continue; 218 219 for (int j = 0; (j < object[0].ptype); j++) { 220 int k = i + j; 221 sx0 = x[k]*mxi + y[k]*mxj + bx + XCENTER; 222 sy0 = x[k]*myi + y[k]*myj + by + YCENTER; 223 224 // last point connects to first 225 if (j == object[0].ptype - 1) { 226 sx1 = x[i]*mxi + y[i]*mxj + bx + XCENTER; 227 sy1 = x[i]*myi + y[i]*myj + by + YCENTER; 228 } else { 229 sx1 = x[k+1]*mxi + y[k+1]*mxj + bx + XCENTER; 230 sy1 = x[k+1]*myi + y[k+1]*myj + by + YCENTER; 231 } 232 ClipLine (graphic, sx0, sy0, sx1, sy1, X0, Y0, X1, Y1); 233 } 234 } 235 } 236 237 /******/ 238 void DrawPolyfill (Graphic *graphic, KapaGraphWidget *graph, Gobjects *object) { 239 240 float *x, *y, *z; 241 double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by; 242 double sx0, sy0; 243 // double X0, X1, Y0, Y1; 244 245 mxi = graph[0].axis[0].dfx / (object[0].x1 - object[0].x0); 246 mxj = graph[0].axis[1].dfx / (object[0].y1 - object[0].y0); 247 myi = graph[0].axis[0].dfy / (object[0].x1 - object[0].x0); 248 myj = graph[0].axis[1].dfy / (object[0].y1 - object[0].y0); 249 250 bxi = graph[0].axis[0].fx - object[0].x0*graph[0].axis[0].dfx/(object[0].x1 - object[0].x0); 251 bxj = -object[0].y0*graph[0].axis[1].dfx/(object[0].y1 - object[0].y0); 252 byi = -object[0].x0*graph[0].axis[0].dfy/(object[0].x1 - object[0].x0); 253 byj = graph[0].axis[1].fy - object[0].y0*graph[0].axis[1].dfy/(object[0].y1 - object[0].y0); 254 255 bx = bxi + bxj; 256 by = byi + byj; 257 258 /* 259 window boundary so we can clip objects 260 X0 = graph[0].axis[0].fx; 261 X1 = graph[0].axis[0].fx + graph[0].axis[0].dfx; 262 Y0 = graph[0].axis[1].fy; 263 Y1 = graph[0].axis[1].fy + graph[0].axis[1].dfy; 264 */ 265 266 x = object[0].x; y = object[0].y; z = object[0].z; 267 268 // ptype must > 2 269 // Npts % ptype must be 0 270 // who must validate that? 271 272 ALLOCATE_PTR (points, XPoint, object[0].ptype); 273 274 // NOTE that LoadObject.c:45 limits the allow 275 // object styles which may have negative (scaled) colors 276 int scaleColor = (object[0].color < 0); 277 278 // each polygon is made of (N = ptype) points 279 // we connect each point and the last one back 280 for (int i = 0; i < object[0].Npts; i += object[0].ptype) { 281 // first check for any invalid values for this polygon 282 int skipObject = FALSE; 283 for (int j = 0; (j < object[0].ptype) && !skipObject; j++) { 284 int k = i + j; 285 if (!(finite(x[k]) && finite(y[k]))) skipObject = TRUE; 286 } 287 if (skipObject) continue; 288 289 for (int j = 0; (j < object[0].ptype); j++) { 290 int k = i + j; 291 sx0 = x[k]*mxi + y[k]*mxj + bx + XCENTER; 292 sy0 = x[k]*myi + y[k]*myj + by + YCENTER; 293 294 points[j].x = sx0; 295 points[j].y = sy0; 296 } 297 298 if (scaleColor) { 299 if (!finite(z[i])) continue; 300 int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1))); 301 XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel); 302 } 303 XFillPolygon (graphic->display, graphic->window, graphic->gc, points, object[0].ptype, Convex, CoordModeOrigin); 304 } 305 306 free (points); 174 307 175 } 308 176 … … 712 580 int scaleColor = (object[0].color < 0); 713 581 714 // NOTE that LoadObject.c:45 limits the allow715 // object styles which may have negative (scaled) colors716 717 582 ds = 0.5 * (graphic->dx + graphic->dy) * 0.003 * object[0].size; 718 583 dz = 0.5 * (graphic->dx + graphic->dy) * 0.010; … … 1051 916 // for open circles, only go to the outer radius 1052 917 D = 0; 1053 if (object[0].ptype == KAPA_POINT_CIRCLE_OPEN) { D = scaleSize ? dz*z[i] : ds; }1054 if (object[0].ptype == KAPA_POINT_BOX_OPEN) { D = scaleSize ? dz*z[i] : ds; }1055 if (object[0].ptype == KAPA_POINT_TRIANGLE_OPEN) { D = scaleSize ? 0.66*dz*z[i] : 0.66*ds; }1056 if (object[0].ptype == KAPA_POINT_TRIANGLE_OPEN_DOWN) { D = scaleSize ? 0.66*dz*z[i] : 0.66*ds; }918 if (object[0].ptype == 7) { D = scaleSize ? dz*z[i] : ds; } 919 if (object[0].ptype == 1) { D = scaleSize ? dz*z[i] : ds; } 920 if (object[0].ptype == 5) { D = scaleSize ? 0.66*dz*z[i] : 0.66*ds; } 921 if (object[0].ptype == 15) { D = scaleSize ? 0.66*dz*z[i] : 0.66*ds; } 1057 922 if (!(finite(x[i]) && finite(y[i]) && finite(dxp[i]))) goto skip_dxp; 1058 923 if (D > fabs(dxp[i]*mxi)) goto skip_dxp; … … 1134 999 // for open circles, only go to the outer radius 1135 1000 D = 0; 1136 if (object[0].ptype == KAPA_POINT_CIRCLE_OPEN) { D = scaleSize ? dz*z[i] : ds; }1137 if (object[0].ptype == KAPA_POINT_BOX_OPEN) { D = scaleSize ? dz*z[i] : ds; }1138 if (object[0].ptype == KAPA_POINT_TRIANGLE_OPEN) { D = scaleSize ? 1.15*dz*z[i] : 1.15*ds; }1139 if (object[0].ptype == KAPA_POINT_TRIANGLE_OPEN_DOWN) { D = scaleSize ? 0.58*dz*z[i] : 0.58*ds; }1001 if (object[0].ptype == 7) { D = scaleSize ? dz*z[i] : ds; } 1002 if (object[0].ptype == 1) { D = scaleSize ? dz*z[i] : ds; } 1003 if (object[0].ptype == 5) { D = scaleSize ? 1.15*dz*z[i] : 1.15*ds; } 1004 if (object[0].ptype == 15) { D = scaleSize ? 0.58*dz*z[i] : 0.58*ds; } 1140 1005 if (!(finite(x[i]) && finite(y[i]) && finite(dyp[i]))) goto skip_dyp; 1141 1006 if (D > fabs(dyp[i]*myj)) goto skip_dyp; … … 1158 1023 skip_dyp: 1159 1024 if (!(finite(x[i]) && finite(y[i]) && finite(dym[i]))) continue; 1160 if (object[0].ptype == KAPA_POINT_TRIANGLE_OPEN) { D = scaleSize ? 0.58*dz*z[i] : 0.58*ds; }1161 if (object[0].ptype == KAPA_POINT_TRIANGLE_OPEN_DOWN) { D = scaleSize ? 1.15*dz*z[i] : 1.15*ds; }1025 if (object[0].ptype == 5) { D = scaleSize ? 0.58*dz*z[i] : 0.58*ds; } 1026 if (object[0].ptype == 15) { D = scaleSize ? 1.15*dz*z[i] : 1.15*ds; } 1162 1027 if (D > fabs(dym[i]*myj)) continue; 1163 1028 sx0 = x[i]*mxi + y[i]*mxj + bx + XCENTER; -
trunk/Ohana/src/kapa2/src/Image.c
r41157 r41340 148 148 void DrawImage (KapaImageWidget *image) { 149 149 150 int i; 150 151 Graphic *graphic; 151 152 … … 154 155 graphic = GetGraphic (); 155 156 157 XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].fore); 158 XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, 159 image[0].picture.x, image[0].picture.y, 160 image[0].picture.dx+1, image[0].picture.dy+1); 161 156 162 if (image[0].picture.pix) { 157 163 XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc, … … 160 166 image[0].picture.dx, image[0].picture.dy); 161 167 } 162 } 163 164 // add the zoom, pan, crosshairs, status box, buttons 165 void DrawImageTool (KapaImageWidget *image) { 166 167 int i; 168 Graphic *graphic; 169 170 if (image == NULL) return; 171 172 graphic = GetGraphic (); 173 174 XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].fore); 175 XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, 176 image[0].picture.x, image[0].picture.y, 177 image[0].picture.dx+1, image[0].picture.dy+1); 178 168 169 for (i = 0; i < NOVERLAYS; i++) { 170 if (image[0].overlay[i].active) { 171 PaintOverlay (graphic, image, i); 172 } 173 } 174 179 175 if (image[0].location) { 180 176 if (image[0].cmapbar.pix) { … … 215 211 StatusBox (graphic, image); 216 212 } 213 214 FlushDisplay (); 217 215 } 218 216 -
trunk/Ohana/src/kapa2/src/InterpretKeys.c
r41157 r41340 160 160 break; 161 161 162 case XK_plus:163 case XK_equal:164 162 case XK_KP_Add: 165 163 if (modstate & ControlMask) { … … 173 171 Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc, 0); 174 172 break; 175 176 case XK_minus:177 case XK_underscore:178 173 case XK_KP_Subtract: 179 174 if (modstate & ControlMask) { -
trunk/Ohana/src/kapa2/src/JPEGit24.c
r41157 r41340 212 212 } 213 213 bDrawBufferFree (buffer); 214 free (palette);215 214 } 216 215 -
trunk/Ohana/src/kapa2/src/Layout.c
r41157 r41340 45 45 AddSection ("default", 0.0, 0.0, 1.0, 1.0, -1); 46 46 } 47 48 void FreeLayout (void) {49 FreeSections ();50 FreeRotFonts ();51 } -
trunk/Ohana/src/kapa2/src/LoadFrame.c
r41157 r41340 93 93 SetSectionSizes (section); 94 94 Refresh(); 95 // if (USE_XWINDOW) DrawFrame (graph); 96 // FlushDisplay (); 97 98 /* XXX why did I do this??? */ 99 # if (0) 100 status = TRUE; 101 if (status) { 102 for (i = 0; i < Nsection; i++) { 103 PositionPicture (§ion[i]); 104 } 105 if (USE_XWINDOW) XClearWindow (graphic.display, graphic.window); 106 Refresh (); 107 } else { 108 FlushDisplay (); 109 } 110 # endif 95 111 96 112 return (TRUE); -
trunk/Ohana/src/kapa2/src/LoadLabels.c
r41157 r41340 26 26 label[Nbytes] = 0; 27 27 28 FREE (label);29 30 28 c = GetRotFont (&size); 31 29 -
trunk/Ohana/src/kapa2/src/LoadObject.c
r41157 r41340 42 42 graph[0].objects[N].color = KapaColormapSize() - 1; 43 43 } 44 45 // XXX watch out for this restriction in DrawObjects / bDrawObjects 46 int canScaleColor = FALSE; 47 canScaleColor |= (graph[0].objects[N].style == KAPA_PLOT_POINTS); 48 canScaleColor |= (graph[0].objects[N].style == KAPA_PLOT_POLYFILL); 49 50 if (!canScaleColor && (graph[0].objects[N].color < 0)) { 44 if ((graph[0].objects[N].style != KAPA_PLOT_POINTS) && (graph[0].objects[N].color < 0)) { 51 45 graph[0].objects[N].color = 0; 52 46 } … … 109 103 110 104 if (USE_XWINDOW) { 111 if (0) { 112 // use this if we are not using buffered plotting 113 Graphic *graphic = GetGraphic(); 114 DrawObjectN (graphic, graph, &graph[0].objects[graph[0].Nobjects-1]); 115 FlushDisplay (); 116 } else { 117 Refresh (); 118 } 119 } 105 Graphic *graphic = GetGraphic(); 106 DrawObjectN (graphic, graph, &graph[0].objects[graph[0].Nobjects-1]); 107 } 108 FlushDisplay (); 120 109 121 110 return (TRUE); -
trunk/Ohana/src/kapa2/src/PNGit.c
r41157 r41340 98 98 png_write_info (png_ptr, info_ptr); 99 99 100 if (graphic->smooth_sigma == 0.0) {101 fprintf (stderr, "making PNG without antialias smoothing\n");102 fprintf (stderr, "use 'antialias (value)' to set smoothing scale (0.4 - 0.7 recommended)\n");103 }104 105 100 if (haveImage) { 106 101 buffer = bDrawIt (palette, Npalette, 3); … … 114 109 115 110 bDrawBufferFree (buffer); 116 free (palette);117 118 111 fclose (f); 119 112 return (TRUE); -
trunk/Ohana/src/kapa2/src/PPMit.c
r41157 r41340 46 46 47 47 bDrawBufferFree (buffer); 48 free (palette);49 50 48 return (TRUE); 51 49 } -
trunk/Ohana/src/kapa2/src/Refresh.c
r41157 r41340 1 1 # include "Ximage.h" 2 2 3 # define USE_BUFFERED_DRAW 14 5 void bDrawXimage (bDrawBuffer *buffer);6 void Refresh_Buffered (void);7 void Refresh_Unbuffered (void);8 9 3 void Refresh (void) { 10 if (USE_BUFFERED_DRAW) {11 Refresh_Buffered();12 } else {13 Refresh_Unbuffered();14 }15 }16 17 void Refresh_Buffered (void) {18 19 int Npalette;20 Graphic *graphic;21 22 if (!USE_XWINDOW) return;23 // if (HAVE_BACKING) return;24 25 graphic = GetGraphic();26 27 // limit the png window to the min needed to contain the active graphic regions28 SectionMinBoundary (graphic);29 30 // is the palette reasonable in modern context?31 png_color *palette = KapaPNGPalette (&Npalette);32 33 bDrawBuffer *buffer = bDrawIt (palette, Npalette, 3);34 35 /* XClearWindow (graphic.display, graphic.window); */36 XSetForeground (graphic->display, graphic->gc, graphic->back);37 XFillRectangle (graphic->display, graphic->window, graphic->gc, 0, 0, graphic->dx, graphic->dy);38 XSetForeground (graphic->display, graphic->gc, graphic->fore);39 40 // copy buffer to Xwindow as image?41 bDrawXimage (buffer);42 bDrawBufferFree (buffer);43 free (palette);44 45 // draw image tool for all sections46 int Nsection = GetNumberOfSections ();47 for (int i = 0; i < Nsection; i++) {48 Section *section = GetSectionByNumber (i);49 50 KapaImageWidget *image = section->image;51 DrawImageTool (image);52 53 /*** PaintOverlay is called in DrawImage ***54 if (!image) continue;55 for (int j = 0; j < NOVERLAYS; j++) {56 if (image[0].overlay[j].active) {57 PaintOverlay (graphic, image, j);58 }59 }60 */61 }62 63 FlushDisplay ();64 }65 66 void Refresh_Unbuffered (void) {67 4 68 5 int i, Nsection; … … 83 20 Nsection = GetNumberOfSections (); 84 21 for (i = 0; i < Nsection; i++) { 85 section = GetSectionByNumber (i); 86 DrawSectionBG (graphic, section); 87 88 KapaImageWidget *image = section->image; 89 DrawImage (image); 90 DrawImageTool (image); 91 92 /*** the overlay is added in DrawImage ***/ 93 if (image) { 94 for (int j = 0; j < NOVERLAYS; j++) { 95 if (image[0].overlay[j].active) { 96 PaintOverlay (graphic, image, j); 97 } 98 } 99 } 100 101 DrawGraph (section->graph); 22 section = GetSectionByNumber (i); 23 DrawSectionBG (graphic, section); 24 DrawImage (section->image); 25 DrawGraph (section->graph); 102 26 } 103 27 -
trunk/Ohana/src/kapa2/src/SetColormap.c
r41157 r41340 72 72 } 73 73 } 74 //fprintf (stderr, "ruff Npix: %d vs %d\n", i, graphic[0].Npixels);74 fprintf (stderr, "ruff Npix: %d vs %d\n", i, graphic[0].Npixels); 75 75 76 76 // all other modes are 1D: set the flag: … … 217 217 !strncmp (graphic->colormapName, "lgcy:", 5) || 218 218 !strncmp (graphic->colormapName, "cetf:", 5) || 219 !strncmp (graphic->colormapName, "cetr:", 5) ||220 219 !strncmp (graphic->colormapName, "csvf:", 5)) { 221 220 … … 234 233 int isCSV = !strncmp (graphic->colormapName, "csvf:", 5); 235 234 int isCET = !strncmp (graphic->colormapName, "cetf:", 5); 236 int isCETRev = !strncmp (graphic->colormapName, "cetr:", 5);237 235 int isLegacy = !strncmp (graphic->colormapName, "lgcy:", 5); 238 236 239 237 float fracIndex, fracRed, fracBlue, fracGreen; 240 238 241 if (isCET || isCETRev) fracIndex = 0.0;239 if (isCET) fracIndex = 0.0; 242 240 243 241 while (scan_line_maxlen (f, line, 1024) != EOF) { … … 249 247 if (Nscan != 4) continue; 250 248 } 251 if (isCET || isCETRev) {249 if (isCET) { 252 250 Nscan = sscanf (line, "%f,%f,%f", &fracRed, &fracGreen, &fracBlue); 253 251 fracIndex += 1.0 / 256.0; … … 258 256 if (Nscan != 4) continue; 259 257 } 260 if (!isCSV && !isLegacy && !isCET && !isCETRev) {258 if (!isCSV && !isLegacy && !isCET) { 261 259 Nscan = sscanf (line, "%f %f %f %f", &fracIndex, &fracRed, &fracGreen, &fracBlue); 262 260 if (Nscan != 4) continue; … … 301 299 } 302 300 } 303 304 // reverse the color sequence:305 if (isCETRev) {306 for (i = 0; i < MaxValue / 2; i++) {307 unsigned short tmp;308 // fprintf (stderr, "swap: %d %d\n", graphic[0].cmap[i].red, graphic[0].cmap[MaxValue - 1 - i].red);309 tmp = graphic[0].cmap[i].red; graphic[0].cmap[i].red = graphic[0].cmap[MaxValue - 1 - i].red; graphic[0].cmap[MaxValue - 1 - i].red = tmp;310 tmp = graphic[0].cmap[i].blue; graphic[0].cmap[i].blue = graphic[0].cmap[MaxValue - 1 - i].blue; graphic[0].cmap[MaxValue - 1 - i].blue = tmp;311 tmp = graphic[0].cmap[i].green; graphic[0].cmap[i].green = graphic[0].cmap[MaxValue - 1 - i].green; graphic[0].cmap[MaxValue - 1 - i].green = tmp;312 }313 }314 315 301 goto store_colors; 316 302 } -
trunk/Ohana/src/kapa2/src/SetUpGraphic.c
r41157 r41340 32 32 graphic->pixels = NULL; 33 33 34 graphic->smooth_sigma = 0.0;35 36 34 if (!USE_XWINDOW) { 37 35 ALLOCATE (graphic[0].pixels, unsigned long, NPIXELS_STATIC); … … 52 50 CheckVisual (graphic, argc, argv); 53 51 CheckColors (graphic, argc, argv); 52 54 53 55 54 icon.width = icon_width; … … 85 84 } 86 85 87 int SetSmoothSigma (int sock) {88 89 float sigma;90 KiiScanMessage (sock, "%f", &sigma);91 92 if (isfinite(sigma)) {93 if ((sigma <= 1.1) && (sigma >= 0.0)) {94 graphic->smooth_sigma = sigma;95 }96 }97 return TRUE;98 }99 100 void FreeGraphic () {101 free (graphic->pixels);102 free (graphic->cmap);103 free (graphic->color);104 free (graphic->colormapName);105 free (graphic);106 } -
trunk/Ohana/src/kapa2/src/args.c
r41157 r41340 23 23 NAME_WINDOW = strcreate (argv[N]); 24 24 remove_argument(N, argc, argv); 25 }26 27 if ((N = get_argument (*argc, argv, "-memdump"))) {28 remove_argument(N, argc, argv);29 MemoryDumpSetOnExit (TRUE);30 25 } 31 26 -
trunk/Ohana/src/kapa2/src/bDrawImage.c
r41157 r41340 1 1 # include "Ximage.h" 2 3 // XXX for the moment, this function does NOT set the mask bits.4 // since we lay graphics on top of images, this is OK for now5 2 6 3 # define WHITE_R 255 … … 57 54 58 55 // the created buffer is supposed to contain the output windows 59 if (Xs < 0) {60 fprintf (stderr, "image display boundaries out of range of window (invalid condition) : fix Kapa\n");61 abort();62 }63 56 if (buffer[0].Nx < Xs + dx) { 64 fprintf (stderr, "image display boundaries out of range of window (invalid condition) : fix Kapa\n"); 65 abort(); 66 } 67 if (Ys < 0) { 68 fprintf (stderr, "image display boundaries out of range of window (invalid condition) : fix Kapa\n"); 57 fprintf (stderr, "invalid condition\n"); 69 58 abort(); 70 59 } 71 60 if (buffer[0].Ny < Ys + dy) { 72 fprintf (stderr, "i mage display boundaries out of range of window (invalid condition) : fix Kapa\n");61 fprintf (stderr, "invalid condition\n"); 73 62 abort(); 74 63 } … … 166 155 } 167 156 168 void bDrawXimage (bDrawBuffer *buffer) {169 170 Graphic *graphic = GetGraphic ();171 172 ALLOCATE_PTR (data, char, 4*buffer->Nx*buffer->Ny);173 174 for (int iy = 0; iy < buffer->Ny; iy++) {175 for (int ix = 0; ix < buffer->Nx; ix++) {176 data[4*(iy*buffer->Nx + ix) + 0] = buffer->pixels[iy][3*ix + 2];177 data[4*(iy*buffer->Nx + ix) + 1] = buffer->pixels[iy][3*ix + 1];178 data[4*(iy*buffer->Nx + ix) + 2] = buffer->pixels[iy][3*ix + 0];179 data[4*(iy*buffer->Nx + ix) + 3] = 0;180 }181 }182 183 XImage *pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0,184 data, buffer->Nx, buffer->Ny, 32, 0);185 186 XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc, pix, 0, 0, 1, 1, buffer->Nx, buffer->Ny);187 188 free (data);189 }190 191 157 # if (0) 192 158 … … 220 186 } 221 187 bDrawBufferFree (buffer); 222 free (palette);223 188 } 224 189 -
trunk/Ohana/src/kapa2/src/bDrawIt.c
r41157 r41340 3 3 bDrawBuffer *bDrawIt (png_color *palette, int Npalette, int Nbyte) { 4 4 5 Graphic *graphic = GetGraphic(); 6 bDrawColor black = KapaColorByName ("black"); 5 int i, j, Nsection; 6 bDrawBuffer *buffer; 7 bDrawColor black; 8 Graphic *graphic; 9 Section *section; 7 10 8 // get the number of sections 9 int Nsection = GetNumberOfSections (); 11 graphic = GetGraphic(); 10 12 11 // in order to allow the anti-aliasing to affect the text & graphs but not the images 12 // I need to generate the images in one buffer and the graphs in a second buffer 13 // then merge the two buffers. 13 black = KapaColorByName ("black"); 14 14 15 // base will hold the images 16 bDrawBuffer *base = bDrawBufferCreate (graphic->dxwin, graphic->dywin, Nbyte, palette, Npalette); 17 bDrawSetStyle (base, black, 0, 0, 1.0); 15 // if we want to trim, we'll need to carry about the start in graphic coords and 16 // the dx,dy size. 17 buffer = bDrawBufferCreate (graphic->dxwin, graphic->dywin, Nbyte, palette, Npalette); 18 bDrawSetStyle (buffer, black, 0, 0, 1.0); 18 19 19 for (int i = 0; i < Nsection; i++) { 20 Section *section = GetSectionByNumber (i); 21 bDrawImage (base, section->image, graphic); 20 // reset the sizes for all sections 21 Nsection = GetNumberOfSections (); 22 for (i = 0; i < Nsection; i++) { 23 section = GetSectionByNumber (i); 24 bDrawImage (buffer, section->image, graphic); 25 for (j = 0; section->image && (j < NOVERLAYS); j++) { 26 if (section->image->overlay[j].active) bDrawOverlay (buffer, section->image, j); 27 } 28 bDrawGraph (buffer, section->graph); 22 29 } 23 30 24 // graph will hold the graphic overlay 25 bDrawBuffer *graph = bDrawBufferCreate (graphic->dxwin, graphic->dywin, Nbyte, palette, Npalette); 26 bDrawSetStyle (graph, black, 0, 0, 1.0); 27 28 for (int i = 0; i < Nsection; i++) { 29 Section *section = GetSectionByNumber (i); 30 for (int j = 0; section->image && (j < NOVERLAYS); j++) { 31 if (section->image->overlay[j].active) bDrawOverlay (graph, section->image, j); 32 } 33 bDrawGraph (graph, section->graph); 34 } 35 36 // apply anti-aliasing only to the graph 37 if (graphic->smooth_sigma > 0.0) { 38 // anything > 1.1 blurs the image too much 39 graphic->smooth_sigma = MIN (graphic->smooth_sigma, 1.1); 40 bDrawSmooth (graph, graphic->smooth_sigma); 41 } 42 43 // place graph on base 44 bDrawMerge (base, graph); 45 bDrawBufferFree (graph); 46 47 return (base); 31 return (buffer); 48 32 } 49 33 -
trunk/Ohana/src/kapa2/src/bDrawObjects.c
r41157 r41340 9 9 # define OpenTriangle(BUF,X1,Y1,X2,Y2,X3,Y3) (bDrawTriOpen (BUF, (X1), (Y1), (X2), (Y2), (X3), (Y3))) 10 10 11 // I should not have a local static variable for this:12 // I should just pass the graphic structure to the called functions below13 11 static Graphic *graphic; 14 12 … … 37 35 case KAPA_PLOT_CONNECT: 38 36 bDrawConnect (buffer, graph, object); 39 break;40 case KAPA_PLOT_POLYGON:41 bDrawPolygons (buffer, graph, object);42 break;43 case KAPA_PLOT_POLYFILL:44 bDrawFillPolygons (buffer, graph, object);45 37 break; 46 38 case KAPA_PLOT_HISTOGRAM: … … 111 103 sx0 = sx1; sy0 = sy1; 112 104 } 113 }114 115 void bDrawPolygons (bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object) {116 117 float *x, *y;118 double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;119 double sx0, sy0, sx1, sy1;120 double X0, X1, Y0, Y1;121 122 mxi = graph[0].axis[0].dfx / (object[0].x1 - object[0].x0);123 mxj = graph[0].axis[1].dfx / (object[0].y1 - object[0].y0);124 myi = graph[0].axis[0].dfy / (object[0].x1 - object[0].x0);125 myj = graph[0].axis[1].dfy / (object[0].y1 - object[0].y0);126 127 bxi = graph[0].axis[0].fx - object[0].x0*graph[0].axis[0].dfx/(object[0].x1 - object[0].x0);128 bxj = -object[0].y0*graph[0].axis[1].dfx/(object[0].y1 - object[0].y0);129 byi = -object[0].x0*graph[0].axis[0].dfy/(object[0].x1 - object[0].x0);130 byj = graph[0].axis[1].fy - object[0].y0*graph[0].axis[1].dfy/(object[0].y1 - object[0].y0);131 132 bx = bxi + bxj;133 by = byi + byj;134 135 X0 = graph[0].axis[0].fx;136 X1 = graph[0].axis[0].fx + graph[0].axis[0].dfx;137 Y0 = graph[0].axis[1].fy;138 Y1 = graph[0].axis[1].fy + graph[0].axis[1].dfy;139 140 x = object[0].x; y = object[0].y;141 142 // ptype must > 2143 // Npts % ptype must be 0144 // who must validate that?145 146 // each polygon is made of (N = ptype) points147 // we connect each point and the last one back148 for (int i = 0; i < object[0].Npts; i += object[0].ptype) {149 // first check for any invalid values for this polygon150 int skipObject = FALSE;151 for (int j = 0; (j < object[0].ptype) && !skipObject; j++) {152 int k = i + j;153 if (!(finite(x[k]) && finite(y[k]))) skipObject = TRUE;154 }155 if (skipObject) continue;156 157 for (int j = 0; (j < object[0].ptype); j++) {158 int k = i + j;159 sx0 = x[k]*mxi + y[k]*mxj + bx;160 sy0 = x[k]*myi + y[k]*myj + by;161 162 // last point connects to first163 if (j == object[0].ptype - 1) {164 sx1 = x[i]*mxi + y[i]*mxj + bx;165 sy1 = x[i]*myi + y[i]*myj + by;166 } else {167 sx1 = x[k+1]*mxi + y[k+1]*mxj + bx;168 sy1 = x[k+1]*myi + y[k+1]*myj + by;169 }170 bDrawClipLine (buffer, sx0, sy0, sx1, sy1, X0, Y0, X1, Y1);171 }172 }173 }174 175 void bDrawFillPolygons (bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object) {176 177 float *x, *y;178 double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;179 double sx0, sy0;180 // double X0, X1, Y0, Y1;181 182 mxi = graph[0].axis[0].dfx / (object[0].x1 - object[0].x0);183 mxj = graph[0].axis[1].dfx / (object[0].y1 - object[0].y0);184 myi = graph[0].axis[0].dfy / (object[0].x1 - object[0].x0);185 myj = graph[0].axis[1].dfy / (object[0].y1 - object[0].y0);186 187 bxi = graph[0].axis[0].fx - object[0].x0*graph[0].axis[0].dfx/(object[0].x1 - object[0].x0);188 bxj = -object[0].y0*graph[0].axis[1].dfx/(object[0].y1 - object[0].y0);189 byi = -object[0].x0*graph[0].axis[0].dfy/(object[0].x1 - object[0].x0);190 byj = graph[0].axis[1].fy - object[0].y0*graph[0].axis[1].dfy/(object[0].y1 - object[0].y0);191 192 bx = bxi + bxj;193 by = byi + byj;194 195 /*196 window boundary so we can clip objects197 X0 = graph[0].axis[0].fx;198 X1 = graph[0].axis[0].fx + graph[0].axis[0].dfx;199 Y0 = graph[0].axis[1].fy;200 Y1 = graph[0].axis[1].fy + graph[0].axis[1].dfy;201 */202 203 x = object[0].x; y = object[0].y;204 205 // ptype must > 2206 // Npts % ptype must be 0207 // who must validate that?208 209 ALLOCATE_PTR (xpts, double, object[0].ptype);210 ALLOCATE_PTR (ypts, double, object[0].ptype);211 212 int scaleColor = (object[0].color < 0);213 unsigned char *pixel1, *pixel2, *pixel3;214 float *z = object[0].z;215 216 if (scaleColor) {217 // scaled colors use the colormap defined for the graphic218 ALLOCATE (pixel1, unsigned char, graphic[0].Npixels);219 ALLOCATE (pixel2, unsigned char, graphic[0].Npixels);220 ALLOCATE (pixel3, unsigned char, graphic[0].Npixels);221 222 /** cmap[i].pixel must be defined even if X is not used **/223 for (int i = 0; i < graphic[0].Npixels; i++) { /* set up pixel array */224 pixel1[i] = graphic[0].cmap[i].red >> 8;225 pixel2[i] = graphic[0].cmap[i].green >> 8;226 pixel3[i] = graphic[0].cmap[i].blue >> 8;227 }228 229 }230 231 // each polygon is made of (N = ptype) points232 // we connect each point and the last one back233 for (int i = 0; i < object[0].Npts; i += object[0].ptype) {234 // first check for any invalid values for this polygon235 int skipObject = FALSE;236 for (int j = 0; (j < object[0].ptype) && !skipObject; j++) {237 int k = i + j;238 if (!(finite(x[k]) && finite(y[k]))) skipObject = TRUE;239 }240 if (skipObject) continue;241 242 for (int j = 0; (j < object[0].ptype); j++) {243 int k = i + j;244 sx0 = x[k]*mxi + y[k]*mxj + bx;245 sy0 = x[k]*myi + y[k]*myj + by;246 247 xpts[j] = sx0;248 ypts[j] = sy0;249 }250 251 if (scaleColor) {252 if (!finite(z[i])) continue;253 int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));254 buffer->bColor_R = pixel1[pixel];255 buffer->bColor_G = pixel2[pixel];256 buffer->bColor_B = pixel3[pixel];257 }258 bDrawPolyFill (buffer, xpts, ypts, object[0].ptype);259 }260 free (xpts);261 free (ypts);262 105 } 263 106 … … 1043 886 // for open circles, only go to the outer radius 1044 887 D = 0; 1045 if (object[0].ptype == KAPA_POINT_CIRCLE_OPEN) { D = scaleSize ? dz*z[i] : ds; }1046 if (object[0].ptype == KAPA_POINT_BOX_OPEN) { D = scaleSize ? dz*z[i] : ds; }1047 if (object[0].ptype == KAPA_POINT_TRIANGLE_OPEN) { D = scaleSize ? 0.66*dz*z[i] : 0.66*ds; }1048 if (object[0].ptype == KAPA_POINT_TRIANGLE_OPEN_DOWN) { D = scaleSize ? 0.66*dz*z[i] : 0.66*ds; }888 if (object[0].ptype == 7) { D = scaleSize ? dz*z[i] : ds; } 889 if (object[0].ptype == 1) { D = scaleSize ? dz*z[i] : ds; } 890 if (object[0].ptype == 5) { D = scaleSize ? 0.66*dz*z[i] : 0.66*ds; } 891 if (object[0].ptype == 15) { D = scaleSize ? 0.66*dz*z[i] : 0.66*ds; } 1049 892 if (!(finite(x[i]) && finite(y[i]) && finite(dxp[i]))) goto skip_dxp; 1050 893 if (D > fabs(dxp[i]*mxi)) goto skip_dxp; … … 1126 969 // for open circles, only go to the outer radius 1127 970 D = 0; 1128 if (object[0].ptype == KAPA_POINT_CIRCLE_OPEN) { D = scaleSize ? dz*z[i] : ds; }1129 if (object[0].ptype == KAPA_POINT_BOX_OPEN) { D = scaleSize ? dz*z[i] : ds; }1130 if (object[0].ptype == KAPA_POINT_TRIANGLE_OPEN) { D = scaleSize ? 1.15*dz*z[i] : 1.15*ds; }1131 if (object[0].ptype == KAPA_POINT_TRIANGLE_OPEN_DOWN) { D = scaleSize ? 0.58*dz*z[i] : 0.58*ds; }971 if (object[0].ptype == 7) { D = scaleSize ? dz*z[i] : ds; } 972 if (object[0].ptype == 1) { D = scaleSize ? dz*z[i] : ds; } 973 if (object[0].ptype == 5) { D = scaleSize ? 1.15*dz*z[i] : 1.15*ds; } 974 if (object[0].ptype == 15) { D = scaleSize ? 0.58*dz*z[i] : 0.58*ds; } 1132 975 if (!(finite(x[i]) && finite(y[i]) && finite(dyp[i]))) goto skip_dyp; 1133 976 if (D > fabs(dyp[i]*myj)) goto skip_dyp; … … 1150 993 skip_dyp: 1151 994 if (!(finite(x[i]) && finite(y[i]) && finite(dym[i]))) continue; 1152 if (object[0].ptype == KAPA_POINT_TRIANGLE_OPEN) { D = scaleSize ? 0.58*dz*z[i] : 0.58*ds; }1153 if (object[0].ptype == KAPA_POINT_TRIANGLE_OPEN_DOWN) { D = scaleSize ? 1.15*dz*z[i] : 1.15*ds; }995 if (object[0].ptype == 5) { D = scaleSize ? 0.58*dz*z[i] : 0.58*ds; } 996 if (object[0].ptype == 15) { D = scaleSize ? 1.15*dz*z[i] : 1.15*ds; } 1154 997 if (D > fabs(dym[i]*myj)) continue; 1155 998 sx0 = x[i]*mxi + y[i]*mxj + bx; -
trunk/Ohana/src/kapa2/src/bDrawOverlay.c
r41157 r41340 24 24 } 25 25 26 // Xmin = 0; 27 // Ymin = 0; 28 // Xmax = image[0].picture.dx; 29 // Ymax = image[0].picture.dy; 30 31 Xmin = image[0].picture.x; 32 Ymin = image[0].picture.y; 33 Xmax = image[0].picture.x + image[0].picture.dx; // maybe this should be just dx? 34 Ymax = image[0].picture.y + image[0].picture.dy; 26 Xmin = 0; 27 Ymin = 0; 28 Xmax = image[0].picture.dx; 29 Ymax = image[0].picture.dy; 35 30 36 31 if (N == INFRONT) { … … 40 35 41 36 for (i = 0; i < image[0].overlay[N].Nobjects; i++) { 42 // XXX the 0.5,0.5 offset is apparently needed here. 43 // work on rationalizing these functions in the context of their different plotting types 44 Image_to_Screen (&X, &Y, image[0].overlay[N].objects[i].x - 0.5, image[0].overlay[N].objects[i].y - 0.5, &image[0].picture); 37 Image_to_Picture (&X, &Y, image[0].overlay[N].objects[i].x, image[0].overlay[N].objects[i].y, &image[0].picture); 45 38 dX = image[0].overlay[N].objects[i].dx * expand; 46 39 dY = image[0].overlay[N].objects[i].dy * expand; -
trunk/Ohana/src/kapa2/src/kapa.c
r41157 r41340 11 11 12 12 CloseDisplay (); 13 14 // free things 15 FreeLayout(); 16 FreeGraphic(); 17 FREE (NAME_WINDOW); 18 19 MemoryDumpAndExit (); 13 exit (0); 20 14 } -
trunk/Ohana/src/libdvo/include/dvodb.h
r41269 r41340 5 5 6 6 // Some values used by code moved to libdvo from opihi. 7 typedef enum {OPIHI_NOTYPE, OPIHI_FLT, OPIHI_INT, OPIHI_STR} opihiVectorTypes; 8 7 enum {OPIHI_NOTYPE, OPIHI_FLT, OPIHI_INT}; 9 8 # define opihi_flt double 9 // # define opihi_int int64_t 10 10 # define opihi_int long long int 11 11 # define OPIHI_INT_FMT "%lld" 12 13 // # define opihi_int int64_t14 12 15 13 typedef enum { -
trunk/Ohana/src/libdvo/src/dvosorts.c
r41155 r41340 76 76 } 77 77 78 /* sort the index of a coordinate pair (X,Y) on X (vector pair stays unsorted) */ 79 // XXX isn't this function equivalent to dsort_indexonly? 78 /* sort a coordinate pair (X,Y) and the associated index (S) */ 80 79 void sort_coords_indexonly (double *X, double *Y, off_t *S, off_t N) { 81 80 OHANA_UNUSED_PARAM(Y); -
trunk/Ohana/src/libfits/include/gfitsio.h
r41176 r41340 259 259 int gfits_read_table PROTO((char *filename, FTable *ftable)); 260 260 int gfits_set_bintable_column PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow)); 261 int gfits_set_bintable_column_reformat PROTO((Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow, int element,char nativeOrder));261 int gfits_set_bintable_column_reformat PROTO((Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow, char nativeOrder)); 262 262 int gfits_set_table_column PROTO((Header *header, FTable *table, char *label, void *data, off_t Nrow)); 263 263 int gfits_table_column PROTO((FTable *ftable, char *field, char *mode,...)) OHANA_FORMAT(printf, 3, 4); -
trunk/Ohana/src/libfits/table/F_define_column.c
r41176 r41340 56 56 char type[64], field[64]; 57 57 58 // this call supported multiple columns per named field59 58 if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return (FALSE); 60 59 -
trunk/Ohana/src/libfits/table/F_set_column.c
r41176 r41340 253 253 /***********************/ 254 254 // convert the input data array (of the specified intype) to the desired table data type. swap unless nativeOrder is requested 255 int gfits_set_bintable_column_reformat (Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow, int element,char nativeOrder) {255 int gfits_set_bintable_column_reformat (Header *header, FTable *table, char *label, char *intype, void *data, off_t Nrow, char nativeOrder) { 256 256 257 257 off_t Nx, Ny; … … 288 288 289 289 if (!gfits_bintable_format (format, outtype, &Nval, &NbytesOut)) return (FALSE); 290 if (element >= Nval) {291 fprintf (stderr, "programming error: element >= Nval for field %s, format %s\n", label, format);292 return FALSE;293 }294 290 295 291 /* check existing table dimensions */ … … 311 307 } 312 308 313 // NOTE: we are inserting a single column into the output314 // table. If the output field is multi-value, the resulting315 // array is inserted into the appropriate bytes in that output field316 317 309 /* make duplicate of data with correct type 318 310 byte swap and Bzero/Bscale */ 319 ALLOCATE (array, char, NbytesOut*N row);311 ALLOCATE (array, char, NbytesOut*Nval*Nrow); 320 312 Pin = data; 321 Pout = array; //313 Pout = array; 322 314 323 315 // # define ASSIGN_DATA(ITYPE,INAME,ISIZE,OTYPE,ONAME) … … 329 321 if (!strcmp (outtype, OUTNAME) && !strcmp (intype, INNAME)) { \ 330 322 int NbytesIn = NBYTES_IN; \ 331 for (i = 0; i < N row; i++, Pin += NbytesIn, Pout += NbytesOut) { \323 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { \ 332 324 if (directCopy) { \ 333 325 *(OUTTYPE *)Pout = *(INTYPE *)Pin; \ … … 393 385 SET_VALUES("double", double, "double", double, SWAP_DBLE, 8); 394 386 387 # if (0) 388 /** input == char **/ 389 if (!strcmp (outtype, "char") && !strcmp (intype, "char")) { 390 int NbytesIn = 1; 391 for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) { 392 if (directCopy) { *(char *)Pout = *(char *)Pin; } else { 393 *(char *)Pout = (*(char *)Pin - Bzero) / Bscale; 394 } 395 } 396 } 397 if (!strcmp (outtype, "byte") && !strcmp (intype, "char")) { 398 int NbytesIn = 1; 399 for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) { 400 if (directCopy) { *(char *)Pout = *(char *)Pin; } else { 401 *(char *)Pout = (*(char *)Pin - Bzero) / Bscale; 402 } 403 } 404 } 405 if (!strcmp (outtype, "short") && !strcmp (intype, "char")) { 406 int NbytesIn = 1; 407 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 408 if (directCopy) { *(short *)Pout = *(char *)Pin; } else { 409 *(short *)Pout = (*(char *)Pin - Bzero) / Bscale; 410 } 411 # ifdef BYTE_SWAP 412 if (!nativeOrder) { SWAP_BYTE; } 413 # endif 414 } 415 } 416 if (!strcmp (outtype, "int") && !strcmp (intype, "char")) { 417 int NbytesIn = 1; 418 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 419 *(int *)Pout = (*(char *)Pin - Bzero) / Bscale; 420 # ifdef BYTE_SWAP 421 if (!nativeOrder) { SWAP_WORD; } 422 # endif 423 } 424 } 425 if (!strcmp (outtype, "int64_t") && !strcmp (intype, "char")) { 426 int NbytesIn = 1; 427 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 428 *(int64_t *)Pout = (*(char *)Pin - Bzero) / Bscale; 429 # ifdef BYTE_SWAP 430 if (!nativeOrder) { SWAP_DBLE; } 431 # endif 432 } 433 } 434 if (!strcmp (outtype, "float") && !strcmp (intype, "char")) { 435 int NbytesIn = 1; 436 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 437 *(float *)Pout = (*(char *)Pin - Bzero) / Bscale; 438 # ifdef BYTE_SWAP 439 if (!nativeOrder) { SWAP_WORD; } 440 # endif 441 } 442 } 443 if (!strcmp (outtype, "double") && !strcmp (intype, "char")) { 444 int NbytesIn = 1; 445 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 446 *(double *)Pout = (*(char *)Pin - Bzero) / Bscale; 447 # ifdef BYTE_SWAP 448 if (!nativeOrder) { SWAP_DBLE; } 449 # endif 450 } 451 } 452 453 /** input == byte **/ 454 if (!strcmp (outtype, "char") && !strcmp (intype, "byte")) { 455 int NbytesIn = 1; 456 for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) { 457 *(char *)Pout = (*(char *)Pin - Bzero) / Bscale; 458 } 459 } 460 if (!strcmp (outtype, "byte") && !strcmp (intype, "byte")) { 461 int NbytesIn = 1; 462 for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) { 463 *(char *)Pout = (*(char *)Pin - Bzero) / Bscale; 464 } 465 } 466 if (!strcmp (outtype, "short") && !strcmp (intype, "byte")) { 467 int NbytesIn = 1; 468 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 469 *(short *)Pout = (*(char *)Pin - Bzero) / Bscale; 470 # ifdef BYTE_SWAP 471 if (!nativeOrder) { SWAP_BYTE; } 472 # endif 473 } 474 } 475 if (!strcmp (outtype, "int") && !strcmp (intype, "byte")) { 476 int NbytesIn = 1; 477 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 478 *(int *)Pout = (*(char *)Pin - Bzero) / Bscale; 479 # ifdef BYTE_SWAP 480 if (!nativeOrder) { SWAP_WORD; } 481 # endif 482 } 483 } 484 if (!strcmp (outtype, "int64_t") && !strcmp (intype, "byte")) { 485 int NbytesIn = 1; 486 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 487 *(int64_t *)Pout = (*(char *)Pin - Bzero) / Bscale; 488 # ifdef BYTE_SWAP 489 if (!nativeOrder) { SWAP_DBLE; } 490 # endif 491 } 492 } 493 if (!strcmp (outtype, "float") && !strcmp (intype, "byte")) { 494 int NbytesIn = 1; 495 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 496 *(float *)Pout = (*(char *)Pin - Bzero) / Bscale; 497 # ifdef BYTE_SWAP 498 if (!nativeOrder) { SWAP_WORD; } 499 # endif 500 } 501 } 502 if (!strcmp (outtype, "double") && !strcmp (intype, "byte")) { 503 int NbytesIn = 1; 504 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 505 *(double *)Pout = (*(char *)Pin - Bzero) / Bscale; 506 # ifdef BYTE_SWAP 507 if (!nativeOrder) { SWAP_DBLE; } 508 # endif 509 } 510 } 511 512 /** input == short **/ 513 if (!strcmp (outtype, "char") && !strcmp (intype, "short")) { 514 int NbytesIn = 2; 515 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 516 *(char *)Pout = (*(short *)Pin - Bzero) / Bscale; 517 } 518 } 519 if (!strcmp (outtype, "byte") && !strcmp (intype, "short")) { 520 int NbytesIn = 2; 521 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 522 *(char *)Pout = (*(short *)Pin - Bzero) / Bscale; 523 } 524 } 525 if (!strcmp (outtype, "short") && !strcmp (intype, "short")) { 526 int NbytesIn = 2; 527 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 528 *(short *)Pout = (*(short *)Pin - Bzero) / Bscale; 529 # ifdef BYTE_SWAP 530 if (!nativeOrder) { SWAP_BYTE; } 531 # endif 532 } 533 } 534 if (!strcmp (outtype, "int") && !strcmp (intype, "short")) { 535 int NbytesIn = 2; 536 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 537 *(int *)Pout = (*(short *)Pin - Bzero) / Bscale; 538 # ifdef BYTE_SWAP 539 if (!nativeOrder) { SWAP_WORD; } 540 # endif 541 } 542 } 543 if (!strcmp (outtype, "int64_t") && !strcmp (intype, "short")) { 544 int NbytesIn = 2; 545 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 546 *(int64_t *)Pout = (*(short *)Pin - Bzero) / Bscale; 547 # ifdef BYTE_SWAP 548 if (!nativeOrder) { SWAP_DBLE; } 549 # endif 550 } 551 } 552 if (!strcmp (outtype, "float") && !strcmp (intype, "short")) { 553 int NbytesIn = 2; 554 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 555 *(float *)Pout = (*(short *)Pin - Bzero) / Bscale; 556 # ifdef BYTE_SWAP 557 if (!nativeOrder) { SWAP_WORD; } 558 # endif 559 } 560 } 561 if (!strcmp (outtype, "double") && !strcmp (intype, "short")) { 562 int NbytesIn = 2; 563 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 564 *(double *)Pout = (*(short *)Pin - Bzero) / Bscale; 565 # ifdef BYTE_SWAP 566 if (!nativeOrder) { SWAP_DBLE; } 567 # endif 568 } 569 } 570 571 /** input == int **/ 572 if (!strcmp (outtype, "char") && !strcmp (intype, "int")) { 573 int NbytesIn = 4; 574 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 575 *(char *)Pout = (*(int *)Pin - Bzero) / Bscale; 576 } 577 } 578 if (!strcmp (outtype, "byte") && !strcmp (intype, "int")) { 579 int NbytesIn = 4; 580 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 581 *(char *)Pout = (*(int *)Pin - Bzero) / Bscale; 582 } 583 } 584 if (!strcmp (outtype, "short") && !strcmp (intype, "int")) { 585 int NbytesIn = 4; 586 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 587 *(short *)Pout = (*(int *)Pin - Bzero) / Bscale; 588 # ifdef BYTE_SWAP 589 if (!nativeOrder) { SWAP_BYTE; } 590 # endif 591 } 592 } 593 if (!strcmp (outtype, "int") && !strcmp (intype, "int")) { 594 int NbytesIn = 4; 595 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 596 *(int *)Pout = (*(int *)Pin - Bzero) / Bscale; 597 # ifdef BYTE_SWAP 598 if (!nativeOrder) { SWAP_WORD; } 599 # endif 600 } 601 } 602 if (!strcmp (outtype, "int64_t") && !strcmp (intype, "int")) { 603 int NbytesIn = 4; 604 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 605 *(int64_t *)Pout = (*(int *)Pin - Bzero) / Bscale; 606 # ifdef BYTE_SWAP 607 if (!nativeOrder) { SWAP_DBLE; } 608 # endif 609 } 610 } 611 if (!strcmp (outtype, "float") && !strcmp (intype, "int")) { 612 int NbytesIn = 4; 613 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 614 *(float *)Pout = (*(int *)Pin - Bzero) / Bscale; 615 # ifdef BYTE_SWAP 616 if (!nativeOrder) { SWAP_WORD; } 617 # endif 618 } 619 } 620 if (!strcmp (outtype, "double") && !strcmp (intype, "int")) { 621 int NbytesIn = 4; 622 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 623 *(double *)Pout = (*(int *)Pin - Bzero) / Bscale; 624 # ifdef BYTE_SWAP 625 if (!nativeOrder) { SWAP_DBLE; } 626 # endif 627 } 628 } 629 630 /** input == int64_t **/ 631 if (!strcmp (outtype, "char") && !strcmp (intype, "int64_t")) { 632 int NbytesIn = 8; 633 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 634 *(char *)Pout = (*(int64_t *)Pin - Bzero) / Bscale; 635 } 636 } 637 if (!strcmp (outtype, "byte") && !strcmp (intype, "int64_t")) { 638 int NbytesIn = 8; 639 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 640 *(char *)Pout = (*(int64_t *)Pin - Bzero) / Bscale; 641 } 642 } 643 if (!strcmp (outtype, "short") && !strcmp (intype, "int64_t")) { 644 int NbytesIn = 8; 645 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 646 *(short *)Pout = (*(int64_t *)Pin - Bzero) / Bscale; 647 # ifdef BYTE_SWAP 648 if (!nativeOrder) { SWAP_BYTE; } 649 # endif 650 } 651 } 652 if (!strcmp (outtype, "int") && !strcmp (intype, "int64_t")) { 653 int NbytesIn = 8; 654 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 655 *(int *)Pout = (*(int64_t *)Pin - Bzero) / Bscale; 656 # ifdef BYTE_SWAP 657 if (!nativeOrder) { SWAP_WORD; } 658 # endif 659 } 660 } 661 if (!strcmp (outtype, "int64_t") && !strcmp (intype, "int64_t")) { 662 int NbytesIn = 8; 663 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 664 *(int64_t *)Pout = (*(int64_t *)Pin - Bzero) / Bscale; 665 # ifdef BYTE_SWAP 666 if (!nativeOrder) { SWAP_DBLE; } 667 # endif 668 } 669 } 670 if (!strcmp (outtype, "float") && !strcmp (intype, "int64_t")) { 671 int NbytesIn = 8; 672 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 673 *(float *)Pout = (*(int64_t *)Pin - Bzero) / Bscale; 674 # ifdef BYTE_SWAP 675 if (!nativeOrder) { SWAP_WORD; } 676 # endif 677 } 678 } 679 if (!strcmp (outtype, "double") && !strcmp (intype, "int64_t")) { 680 int NbytesIn = 8; 681 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 682 *(double *)Pout = (*(int64_t *)Pin - Bzero) / Bscale; 683 # ifdef BYTE_SWAP 684 if (!nativeOrder) { SWAP_DBLE; } 685 # endif 686 } 687 } 688 689 /** input == float **/ 690 if (!strcmp (outtype, "char") && !strcmp (intype, "float")) { 691 int NbytesIn = 4; 692 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 693 *(char *)Pout = (*(float *)Pin - Bzero) / Bscale; 694 } 695 } 696 if (!strcmp (outtype, "byte") && !strcmp (intype, "float")) { 697 int NbytesIn = 4; 698 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 699 *(char *)Pout = (*(float *)Pin - Bzero) / Bscale; 700 } 701 } 702 if (!strcmp (outtype, "short") && !strcmp (intype, "float")) { 703 int NbytesIn = 4; 704 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 705 *(short *)Pout = (*(float *)Pin - Bzero) / Bscale; 706 # ifdef BYTE_SWAP 707 if (!nativeOrder) { SWAP_BYTE; } 708 # endif 709 } 710 } 711 if (!strcmp (outtype, "int") && !strcmp (intype, "float")) { 712 int NbytesIn = 4; 713 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 714 *(int *)Pout = (*(float *)Pin - Bzero) / Bscale; 715 # ifdef BYTE_SWAP 716 if (!nativeOrder) { SWAP_WORD; } 717 # endif 718 } 719 } 720 if (!strcmp (outtype, "int64_t") && !strcmp (intype, "float")) { 721 int NbytesIn = 4; 722 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 723 *(int64_t *)Pout = (*(float *)Pin - Bzero) / Bscale; 724 # ifdef BYTE_SWAP 725 if (!nativeOrder) { SWAP_DBLE; } 726 # endif 727 } 728 } 729 if (!strcmp (outtype, "float") && !strcmp (intype, "float")) { 730 int NbytesIn = 4; 731 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 732 *(float *)Pout = (*(float *)Pin - Bzero) / Bscale; 733 # ifdef BYTE_SWAP 734 if (!nativeOrder) { SWAP_WORD; } 735 # endif 736 } 737 } 738 if (!strcmp (outtype, "double") && !strcmp (intype, "float")) { 739 int NbytesIn = 4; 740 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 741 *(double *)Pout = (*(float *)Pin - Bzero) / Bscale; 742 # ifdef BYTE_SWAP 743 if (!nativeOrder) { SWAP_DBLE; } 744 # endif 745 } 746 } 747 748 /** input == double **/ 749 if (!strcmp (outtype, "char") && !strcmp (intype, "double")) { 750 int NbytesIn = 8; 751 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 752 *(char *)Pout = (*(double *)Pin - Bzero) / Bscale; 753 } 754 } 755 if (!strcmp (outtype, "byte") && !strcmp (intype, "double")) { 756 int NbytesIn = 8; 757 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 758 *(char *)Pout = (*(double *)Pin - Bzero) / Bscale; 759 } 760 } 761 if (!strcmp (outtype, "short") && !strcmp (intype, "double")) { 762 int NbytesIn = 8; 763 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 764 *(short *)Pout = (*(double *)Pin - Bzero) / Bscale; 765 # ifdef BYTE_SWAP 766 if (!nativeOrder) { SWAP_BYTE; } 767 # endif 768 } 769 } 770 if (!strcmp (outtype, "int") && !strcmp (intype, "double")) { 771 int NbytesIn = 8; 772 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 773 *(int *)Pout = (*(double *)Pin - Bzero) / Bscale; 774 # ifdef BYTE_SWAP 775 if (!nativeOrder) { SWAP_WORD; } 776 # endif 777 } 778 } 779 if (!strcmp (outtype, "int64_t") && !strcmp (intype, "double")) { 780 int NbytesIn = 8; 781 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 782 *(int64_t *)Pout = (*(double *)Pin - Bzero) / Bscale; 783 # ifdef BYTE_SWAP 784 if (!nativeOrder) { SWAP_DBLE; } 785 # endif 786 } 787 } 788 if (!strcmp (outtype, "float") && !strcmp (intype, "double")) { 789 int NbytesIn = 8; 790 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 791 *(float *)Pout = (*(double *)Pin - Bzero) / Bscale; 792 # ifdef BYTE_SWAP 793 if (!nativeOrder) { SWAP_WORD; } 794 # endif 795 } 796 } 797 if (!strcmp (outtype, "double") && !strcmp (intype, "double")) { 798 int NbytesIn = 8; 799 for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) { 800 *(double *)Pout = (*(double *)Pin - Bzero) / Bscale; 801 # ifdef BYTE_SWAP 802 if (!nativeOrder) { SWAP_DBLE; } 803 # endif 804 } 805 } 806 # endif 807 395 808 /* check array space */ 396 809 if (Nx*Ny < Nx*(Nrow - 1) + Nstart + Nval*NbytesOut) { … … 400 813 401 814 /* insert bytes from array into appropriate section of buffer */ 402 Pout = table[0].buffer + Nstart + element*NbytesOut;815 Pout = table[0].buffer + Nstart; 403 816 Pin = array; 404 for (i = 0; i < Nrow; i++, Pout += Nx, Pin += N bytesOut) {405 memcpy (Pout, Pin, N bytesOut);817 for (i = 0; i < Nrow; i++, Pout += Nx, Pin += Nval*NbytesOut) { 818 memcpy (Pout, Pin, Nval*NbytesOut); 406 819 } 407 820 -
trunk/Ohana/src/libkapa/Makefile
r41319 r41340 42 42 $(SRC)/RotFont.$(ARCH).o \ 43 43 $(SRC)/DrawRotString.$(ARCH).o \ 44 $(SRC)/PDFRotFont.$(ARCH).o \45 44 $(SRC)/PSRotFont.$(ARCH).o 46 45 -
trunk/Ohana/src/libkapa/include/kapa.h
r41319 r41340 45 45 KAPA_PLOT_BARS_OUTLINE = 4, 46 46 KAPA_PLOT_BARS_OUTFILL = 5, 47 KAPA_PLOT_POLYGON = 6, 48 KAPA_PLOT_POLYFILL = 7, 49 KAPA_PLOT_INVALID_MAX = 8, 47 KAPA_PLOT_INVALID_MAX = 6, 50 48 } KapaPlotStyle; 51 49 … … 174 172 int Nx, Ny, Nbyte; 175 173 bDrawColor **pixels; 176 char **mask;177 174 png_color *palette; 178 175 int Npalette; 179 180 176 // current drawing values: 181 177 int bWeight; … … 222 218 int KapaPNG (int fd, const char *filename); 223 219 int KapaPPM (int fd, const char *filename); 224 int KapaPDF (int fd, const char *filename, int scaleMode, int pageMode, char *pagename);225 220 226 221 /* KiiCursor.c */ … … 261 256 int KapaGetImageData (int fd, KapaImageData *graphmode); 262 257 int KapaSetToolbox (int fd, int location); 263 int KapaSetSmoothSigma (int fd, float sigma);264 int KapaMemoryDump (int fd);265 int KapaMemoryDumpLines (int fd, int Nlines);266 int KapaMemoryDumpOnExit (int fd, int state);267 258 268 259 /* KapaColors */ … … 281 272 /* RotFont.c */ 282 273 void InitRotFonts PROTO((void)); 283 void FreeRotFonts PROTO((void));284 274 int SetRotFont PROTO((char *name, int size)); 285 275 char *GetRotFont PROTO((int *size)); … … 292 282 int DrawRotTextInit (Display *display, Window window, GC gc, unsigned long fore, unsigned long back); 293 283 294 /* PDFRotFont.c */295 void PDFRotText (IOBuffer *buffer, int x, int y, char *string, int pos, double angle);296 284 297 285 /* PSRotFont.c */ 298 286 void PSRotText PROTO((FILE *f, int x, int y, char *string, int pos, double angle)); 287 void PSDumpRotSegment PROTO((FILE *f, char *segment, int *Nseg)); 288 void PSSetFont PROTO((FILE *f, char *name, int size)); 299 289 int PSRotStrlen PROTO((char *c)); 300 290 … … 302 292 bDrawBuffer *bDrawBufferCreate (int Nx, int Ny, int Nbyte, png_color *palette, int Npalette); 303 293 void bDrawBufferFree (bDrawBuffer *buffer); 304 int bDrawMerge (bDrawBuffer *base, bDrawBuffer *layer);305 294 void bDrawSetBuffer (bDrawBuffer *buffer); 306 295 void bDrawSetColor (bDrawBuffer *buffer, bDrawColor color); … … 323 312 void bDrawTriOpen (bDrawBuffer *buffer, double x1, double y1, double x2, double y2, double x3, double y3); 324 313 void bDrawTriFill (bDrawBuffer *buffer, double x1, double y1, double dx, double dy); 325 void bDrawPolyFill (bDrawBuffer *buffer, double *x, double *y, int Npoints);326 327 void bDrawSmooth (bDrawBuffer *buffer, float sigma);328 314 329 315 /* bDrawRotFont.c */ -
trunk/Ohana/src/libkapa/rotfont/helvetica12.h
r41270 r41340 565 565 { 9, 9, 10.67, 9, helvetica12_37_bits}, 566 566 { 7, 9, 8.00, 9, helvetica12_38_bits}, 567 { 2, 3, 2.6 6, 9, helvetica12_39_bits},567 { 2, 3, 2.65, 9, helvetica12_39_bits}, 568 568 { 3, 12, 3.99, 9, helvetica12_40_bits}, 569 569 { 3, 12, 3.99, 9, helvetica12_41_bits}, … … 621 621 { 2, 12, 3.34, 9, helvetica12_93_bits}, 622 622 { 5, 3, 5.62, 8, helvetica12_94_bits}, 623 { 7, 1, 6.67, 1, helvetica12_95_bits},623 { 7, 1, 6.67, -1, helvetica12_95_bits}, 624 624 { 2, 3, 2.66, 9, helvetica12_96_bits}, 625 625 { 6, 7, 6.67, 7, helvetica12_97_bits}, -
trunk/Ohana/src/libkapa/src/DrawRotString.c
r41319 r41340 77 77 78 78 YoffBase = Yoff; 79 int Ydelta = 0;80 79 /* draw characters one-by-one */ 81 82 // successive subscripts / superscripts drop the line by83 // same amount each time, but size remains 0.884 // sub followed by sup, or vice versa, should clear and do basic sup/sub85 86 80 unsigned int i; 81 // unsigned char *tmpstring = (unsigned char *) string; 82 87 83 for (i = 0; i < strlen(string); i++) { 88 84 // N = (unsigned int)(tmpstring[i]); … … 102 98 SetRotFont (currentname, (int)(0.8*currentsize)); 103 99 currentfont = GetRotFontData (¤tscale); 104 105 if (Ydelta > 0) { Ydelta = 0; Yoff = YoffBase; }106 Ydelta --;107 100 Yoff -= 0.5*currentscale*dY; 108 101 continue; … … 112 105 SetRotFont (currentname, (int)(0.8*currentsize)); 113 106 currentfont = GetRotFontData (¤tscale); 114 115 if (Ydelta < 0) { Ydelta = 0; Yoff = YoffBase; }116 Ydelta ++;117 107 Yoff += 0.5*currentscale*dY; 118 108 continue; … … 123 113 currentfont = GetRotFontData (¤tscale); 124 114 Yoff = YoffBase; 125 Ydelta = 0;126 115 continue; 127 116 } -
trunk/Ohana/src/libkapa/src/KapaColors.c
r41319 r41340 4 4 5 5 static char KAPA_COLORS[N_KAPA_COLORS][3][16] = { 6 {"black", "black", "0.00 0.00 0.00"},7 {"white", "white", "1.00 1.00 1.00"},8 {"red", "red", "1.00 0.00 0.00"},9 {"pink", "pink", "1.00 0.75 0.80"},10 {"orange", "orange", "1.00 0.65 0.00"},11 {"yellow", "yellow", "1.00 1.00 0.00"},12 {"wheat", "wheat", "0.96 0.87 0.70"},13 {"gold", "gold", "1.00 0.84 0.00"},14 {"green", "green", "0.00 1.00 0.00"},15 {"darkgreen", "darkgreen", "0.00 0.40 0.00"},16 {"darkblue", "darkblue", "0.50 0.50 1.00"},17 {"blue", "blue", "0.00 0.00 1.00"},18 {"skyblue", "skyblue", "0.53 0.81 0.92"},19 {"indigo", "mediumpurple", "0.57 0.44 0.86"},20 {"violet", "darkviolet", "0.58 0.00 0.88"},21 {"blue10", "rgb:00/00/33", "0.00 0.00 0.20"},22 {"blue20", "rgb:00/00/66", "0.00 0.00 0.40"},23 {"blue30", "rgb:00/00/99", "0.00 0.00 0.60"},24 {"blue40", "rgb:00/00/cc", "0.00 0.00 0.80"},25 {"blue50", "rgb:00/00/ff", "0.00 0.00 1.00"},26 {"blue60", "rgb:33/33/ff", "0.20 0.20 1.00"},27 {"blue70", "rgb:66/66/ff", "0.40 0.40 1.00"},28 {"blue80", "rgb:99/99/ff", "0.60 0.60 1.00"},29 {"blue90", "rgb:cc/cc/ff", "0.80 0.80 1.00"},6 {"black", "black", "0.00 0.00 0.00"}, 7 {"white", "white", "1.00 1.00 1.00"}, 8 {"red", "red", "1.00 0.00 0.00"}, 9 {"pink", "pink", "1.00 0.75 0.80"}, 10 {"orange", "orange", "1.00 0.65 0.00"}, 11 {"yellow", "yellow", "1.00 1.00 0.00"}, 12 {"wheat", "wheat", "0.96 0.87 0.70"}, 13 {"gold", "gold", "1.00 0.84 0.00"}, 14 {"green", "green", "0.00 1.00 0.00"}, 15 {"darkgreen", "darkgreen", "0.00 0.40 0.00"}, 16 {"darkblue", "darkblue", "0.50 0.50 1.00"}, 17 {"blue", "blue", "0.00 0.00 1.00"}, 18 {"skyblue", "skyblue", "0.53 0.81 0.92"}, 19 {"indigo", "mediumpurple", "0.57 0.44 0.86"}, 20 {"violet", "darkviolet", "0.58 0.00 0.88"}, 21 {"blue10", "rgb:00/00/33", "0.00 0.00 0.20"}, 22 {"blue20", "rgb:00/00/66", "0.00 0.00 0.40"}, 23 {"blue30", "rgb:00/00/99", "0.00 0.00 0.60"}, 24 {"blue40", "rgb:00/00/cc", "0.00 0.00 0.80"}, 25 {"blue50", "rgb:00/00/ff", "0.00 0.00 1.00"}, 26 {"blue60", "rgb:33/33/ff", "0.20 0.20 1.00"}, 27 {"blue70", "rgb:66/66/ff", "0.40 0.40 1.00"}, 28 {"blue80", "rgb:99/99/ff", "0.60 0.60 1.00"}, 29 {"blue90", "rgb:cc/cc/ff", "0.80 0.80 1.00"}, 30 30 {"red10", "rgb:33/00/00", "0.20 0.00 0.00"}, 31 31 {"red20", "rgb:66/00/00", "0.40 0.00 0.00"}, … … 37 37 {"red80", "rgb:ff/99/99", "1.00 0.60 0.60"}, 38 38 {"red90", "rgb:ff/cc/cc", "1.00 0.80 0.80"}, 39 {"grey10", "grey10", "0.10 0.10 0.10"},40 {"grey20", "grey20", "0.20 0.20 0.20"},41 {"grey30", "grey30", "0.30 0.30 0.30"},42 {"grey40", "grey40", "0.40 0.40 0.40"},43 {"grey50", "grey50", "0.50 0.50 0.50"},44 {"grey60", "grey60", "0.60 0.60 0.60"},45 {"grey70", "grey70", "0.70 0.70 0.70"},46 {"grey80", "grey80", "0.80 0.80 0.80"},47 {"grey90", "grey90", "0.90 0.90 0.90"}};39 {"grey10", "grey10", "0.10 0.10 0.10"}, 40 {"grey20", "grey20", "0.20 0.20 0.20"}, 41 {"grey30", "grey30", "0.30 0.30 0.30"}, 42 {"grey40", "grey40", "0.40 0.40 0.40"}, 43 {"grey50", "grey50", "0.50 0.50 0.50"}, 44 {"grey60", "grey60", "0.60 0.60 0.60"}, 45 {"grey70", "grey70", "0.70 0.70 0.70"}, 46 {"grey80", "grey80", "0.80 0.80 0.80"}, 47 {"grey90", "grey90", "0.90 0.90 0.90"}}; 48 48 49 49 int KapaColorByName (char *name) { … … 70 70 71 71 char *KapaColorRGBString (int N) { 72 int Nused = MAX (0, MIN (N_KAPA_COLORS, N)); 73 return (KAPA_COLORS[Nused][2]); 72 return (KAPA_COLORS[N][2]); 74 73 } 75 74 76 75 char *KapaColorName (int N) { 77 int Nused = MAX (0, MIN (N_KAPA_COLORS, N)); 78 return (KAPA_COLORS[Nused][0]); 76 return (KAPA_COLORS[N][0]); 79 77 } 80 78 -
trunk/Ohana/src/libkapa/src/KapaStyles.c
r41156 r41340 54 54 if (!strcasecmp (string, "outline")) return KAPA_PLOT_BARS_OUTLINE; 55 55 if (!strcasecmp (string, "outfill")) return KAPA_PLOT_BARS_OUTFILL; 56 57 if (!strcasecmp (string, "polygon")) return KAPA_PLOT_POLYGON;58 if (!strcasecmp (string, "polyfill")) return KAPA_PLOT_POLYFILL;59 56 60 57 if (strlen(string) > 2) { -
trunk/Ohana/src/libkapa/src/KapaWindow.c
r41156 r41340 455 455 } 456 456 457 int KapaSetSmoothSigma (int fd, float sigma) {458 459 KiiSendCommand (fd, 4, "SIGM");460 KiiSendMessage (fd, "%4.1f ", sigma);461 KiiWaitAnswer (fd, "DONE");462 return (TRUE);463 }464 465 int KapaMemoryDump (int fd) {466 467 KiiSendCommand (fd, 4, "MEMD");468 KiiWaitAnswer (fd, "DONE");469 return (TRUE);470 }471 472 int KapaMemoryDumpLines (int fd, int Nlines) {473 474 KiiSendCommand (fd, 4, "MEML");475 KiiSendMessage (fd, "%d ", Nlines);476 KiiWaitAnswer (fd, "DONE");477 return (TRUE);478 }479 480 int KapaMemoryDumpOnExit (int fd, int state) {481 482 KiiSendCommand (fd, 4, "MEMX");483 KiiSendMessage (fd, "%d ", state);484 KiiWaitAnswer (fd, "DONE");485 return (TRUE);486 }487 -
trunk/Ohana/src/libkapa/src/KiiConvert.c
r41319 r41340 32 32 return (TRUE); 33 33 } 34 35 int KapaPDF (int fd, const char *filename, int scaleMode, int pageMode, char *pagename) {36 37 KiiSendCommand (fd, 4, "PDFT");38 KiiSendMessage (fd, "%s %s %d %d", filename, pagename, scaleMode, pageMode);39 KiiWaitAnswer (fd, "DONE");40 return (TRUE);41 } -
trunk/Ohana/src/libkapa/src/PSRotFont.c
r41319 r41340 1 1 # include <kapa_internal.h> 2 2 # define NROTCHARS 256 3 4 // local functions:5 void PSDumpRotSegment (FILE *f, char *segment, int *Nseg);6 void PSSetFont (FILE *f, char *name, int size);7 3 8 4 /* writes commands to print string at location and angle using -
trunk/Ohana/src/libkapa/src/RotFont.c
r41156 r41340 32 32 strncpy (currentname, RotFonts[DEFFONT].name, 63); currentname[63] = 0; 33 33 currentsize = RotFonts[DEFFONT].size; 34 }35 36 void FreeRotFonts (void) {37 free (RotFonts);38 RotFonts = FALSE;39 RotFontInited = FALSE;40 34 } 41 35 -
trunk/Ohana/src/libkapa/src/bDrawFuncs.c
r41156 r41340 1 1 # include <kapa_internal.h> 2 2 3 // buffer->pixels carries the plot image 4 // buffer->mask is 0 if the pixel is untouched, 1 if the pixel has data 3 // move these to the bDrawBuffer type 4 // static int bWeight; 5 // static int bType; 6 // static bDrawColor bColor; 7 // static bDrawColor bColor_R; 8 // static bDrawColor bColor_G; 9 // static bDrawColor bColor_B; 10 // static bDrawBuffer *bBuffer; 5 11 6 12 void bDrawCircleSingle (bDrawBuffer *buffer, double xc, double yc, double radius); 7 8 int bDrawMerge (bDrawBuffer *base, bDrawBuffer *layer) {9 10 // the two bDrawBuffers must match in size and depth11 12 if (base->Nx != layer->Nx) return FALSE;13 if (base->Ny != layer->Ny) return FALSE;14 if (base->Nbyte != layer->Nbyte) return FALSE;15 16 for (int j = 0; j < base->Ny; j++) {17 for (int i = 0; i < base->Nx; i++) {18 19 if (!layer->mask[j][i]) continue;20 21 // completely opaque top layer:22 if (base->Nbyte == 1) {23 base->pixels[j][i] = layer->pixels[j][i];24 } else {25 base->pixels[j][3*i+0] = layer->pixels[j][3*i+0];26 base->pixels[j][3*i+1] = layer->pixels[j][3*i+1];27 base->pixels[j][3*i+2] = layer->pixels[j][3*i+2];28 }29 }30 }31 return TRUE;32 }33 13 34 14 // create a drawing buffer with either 1 or 3 byte colors … … 55 35 56 36 ALLOCATE (buffer[0].pixels, bDrawColor *, Ny); 57 ALLOCATE (buffer[0].mask, char *, Ny);58 37 for (i = 0; i < Ny; i++) { 59 38 ALLOCATE (buffer[0].pixels[i], bDrawColor, Nbyte*Nx); 60 ALLOCATE (buffer[0].mask[i], char, Nx);61 39 for (j = 0; j < Nx; j++) { 62 40 if (Nbyte == 1) { … … 67 45 buffer[0].pixels[i][3*j+2] = white_B; 68 46 } 69 buffer[0].mask[i][j] = 0; // for now: 0 = no data, 1 = data70 47 } 71 48 } … … 86 63 for (i = 0; i < buffer[0].Ny; i++) { 87 64 free (buffer[0].pixels[i]); 88 free (buffer[0].mask[i]);89 65 } 90 66 free (buffer[0].pixels); 91 free (buffer[0].mask); 92 // free (buffer[0].palette); 67 free (buffer[0].palette); 93 68 free (buffer); 94 69 return; … … 146 121 buffer[0].pixels[y][x] = buffer->bColor; 147 122 } else { 148 buffer[0].pixels[y][3*x+0] = MAX (0x00, MIN(0xff, beta * buffer[0].pixels[y][3*x+0] + alpha * buffer->bColor_R)); // was just buffer->bColor_R, etc 123 // buffer[0].pixels[y][3*x+0] = buffer->bColor_R; 124 // buffer[0].pixels[y][3*x+1] = buffer->bColor_G; 125 // buffer[0].pixels[y][3*x+2] = buffer->bColor_B; 126 buffer[0].pixels[y][3*x+0] = MAX (0x00, MIN(0xff, beta * buffer[0].pixels[y][3*x+0] + alpha * buffer->bColor_R)); 149 127 buffer[0].pixels[y][3*x+1] = MAX (0x00, MIN(0xff, beta * buffer[0].pixels[y][3*x+1] + alpha * buffer->bColor_G)); 150 128 buffer[0].pixels[y][3*x+2] = MAX (0x00, MIN(0xff, beta * buffer[0].pixels[y][3*x+2] + alpha * buffer->bColor_B)); 151 129 } 152 buffer[0].mask[y][x] = 1;153 130 return; 154 131 } … … 173 150 void bDrawRectOpen (bDrawBuffer *buffer, double x1, double y1, double x2, double y2) { 174 151 152 int X1, Y1, X2, Y2; 153 175 154 if (x1 > x2) SWAP (x1, x2); 176 155 if (y1 > y2) SWAP (y1, y2); 177 156 178 int X1 = MIN (MAX (ROUND (x1), 0), buffer[0].Nx - 1); 179 int X2 = MIN (MAX (ROUND (x2), 1), buffer[0].Nx - 1); 180 181 int Y1 = MIN (MAX (ROUND (y1), 0), buffer[0].Ny - 1); 182 int Y2 = MIN (MAX (ROUND (y2), 1), buffer[0].Ny - 1); 183 184 int dNs = -0.5*(buffer->bWeight - 1); 185 /* 0, 0, 0, -1, -1, -2, -2 */ 186 187 int dNe = +0.5*buffer->bWeight + 1; 188 /* 1, 1, 2, 2, 2, 3, 3 */ 189 190 for (int dN = dNs; dN < dNe; dN ++) { 191 // line on the bottom needs to run longer for the negative dN values 192 bDrawLineHorizontal (buffer, X1 + dN, X2 + 1 - dN, Y1 + dN); 193 194 // line on the top needs to run longer for the positive dN values 195 bDrawLineHorizontal (buffer, X1 + dN, X2 + 1 - dN, Y2 - dN); 196 197 // line on the left needs to run longer for the negative dN values 198 bDrawLineVertical (buffer, X1 + dN, Y1 + dN, Y2 - dN); 199 200 // line on the right needs to run longer for the positive dN values 201 bDrawLineVertical (buffer, X2 - dN, Y1 + dN, Y2 - dN); 202 } 157 X1 = MIN (MAX (ROUND (x1), 0), buffer[0].Nx - 1); 158 X2 = MIN (MAX (ROUND (x2), 1), buffer[0].Nx - 1); 159 160 Y1 = MIN (MAX (ROUND (y1), 0), buffer[0].Ny - 1); 161 Y2 = MIN (MAX (ROUND (y2), 1), buffer[0].Ny - 1); 162 163 bDrawLineHorizontal (buffer, X1, X2 + 1, Y1); 164 bDrawLineHorizontal (buffer, X1, X2 + 1, Y2); 165 bDrawLineVertical (buffer, X1, Y1, Y2); 166 bDrawLineVertical (buffer, X2, Y1, Y2); 203 167 return; 204 168 } … … 219 183 220 184 for (i = Y1; i < Y2; i++) { 221 // this should be a line of width 1 or we duplicate pixels222 185 bDrawLineHorizontal (buffer, X1, X2, i); 223 186 } … … 272 235 // use the Bresenham line drawing technique 273 236 // integer-only Bresenham line-draw version which is fast 274 // bresenham assumes x1 < x2 and (y2 - y1) < (x2 - x1)275 237 void bDrawLineBresen (bDrawBuffer *buffer, int X1, int Y1, int X2, int Y2, int swapcoords) { 276 238 … … 337 299 buffer[0].pixels[Y][3*i+1] = MAX (0x00, MIN(0xff, beta * buffer[0].pixels[Y][3*i+1] + alpha * buffer->bColor_G)); 338 300 buffer[0].pixels[Y][3*i+2] = MAX (0x00, MIN(0xff, beta * buffer[0].pixels[Y][3*i+2] + alpha * buffer->bColor_B)); 339 } 340 buffer[0].mask[Y][i] = 1; 301 // buffer[0].pixels[Y][3*i+0] = buffer->bColor_R; 302 // buffer[0].pixels[Y][3*i+1] = buffer->bColor_G; 303 // buffer[0].pixels[Y][3*i+2] = buffer->bColor_B; 304 } 341 305 } 342 306 return; … … 362 326 buffer[0].pixels[i][3*X+1] = MAX (0x00, MIN(0xff, beta * buffer[0].pixels[i][3*X+1] + alpha * buffer->bColor_G)); 363 327 buffer[0].pixels[i][3*X+2] = MAX (0x00, MIN(0xff, beta * buffer[0].pixels[i][3*X+2] + alpha * buffer->bColor_B)); 364 } 365 buffer[0].mask[i][X] = 1; 328 // buffer[0].pixels[i][3*X+0] = buffer->bColor_R; 329 // buffer[0].pixels[i][3*X+1] = buffer->bColor_G; 330 // buffer[0].pixels[i][3*X+2] = buffer->bColor_B; 331 } 366 332 } 367 333 return; … … 418 384 419 385 return; 420 }421 422 # define BOT_LEFT 0423 # define BOT_RGHT 1424 # define TOP_LEFT 2425 # define TOP_RGHT 3426 427 // I should probably look up an appropriate recipe for this428 // source code for XDrawPolyFill?429 430 int GetNextSeqNumber (int seq, int Npoint, int Clockwise, int LeftSide);431 int bDrawFillBetweenSegments (bDrawBuffer *buffer, int *x, int *y, int ystart);432 433 void bDrawPolyFill (bDrawBuffer *buffer, double *x, double *y, int Npoints) {434 435 // The coord list which is passed in (x,y) must be in order around the contour436 for (int i = 0; i < Npoints; i++) {437 fprintf (stderr, "%d : %f,%f\n", i, x[i], y[i]);438 }439 440 // First, find the lowest point and start at that sequence number441 int iMin = 0;442 double yMin = y[iMin];443 for (int i = 1; i < Npoints; i++) {444 if (y[i] < yMin) { iMin = i; yMin = y[iMin]; }445 }446 447 // we generate two line segments and will fill between them448 int xval[4];449 int yval[4];450 451 // the starting point is a vertex452 xval[BOT_LEFT] = x[iMin]; yval[BOT_LEFT] = y[iMin];453 xval[BOT_RGHT] = x[iMin]; yval[BOT_RGHT] = y[iMin];454 455 // get iNext, iPrev assuming ClockWise, then test456 int isCW = TRUE;457 int iNextLeft = GetNextSeqNumber (iMin, Npoints, isCW, TRUE); // TRUE => left-side458 int iNextRght = GetNextSeqNumber (iMin, Npoints, isCW, FALSE);459 460 // if this is true, the points are not clockwise461 if (x[iNextLeft] > x[iNextRght]) {462 isCW = FALSE;463 int tmp = iNextLeft;464 iNextLeft = iNextRght;465 iNextRght = tmp;466 }467 468 int iTL = iNextLeft; // sequence number of the top,left point469 int iTR = iNextRght; // sequence number of the top,right point470 xval[TOP_LEFT] = x[iTL]; yval[TOP_LEFT] = y[iTL];471 xval[TOP_RGHT] = x[iTR]; yval[TOP_RGHT] = y[iTR];472 473 // we need to track the starting row, start at the bottom474 int ystart = yval[BOT_LEFT];475 476 while (TRUE) {477 int isLeft = bDrawFillBetweenSegments (buffer, xval, yval, ystart);478 479 // the last pair of segments in the sequence end at the same top point:480 if (iTL == iTR) break;481 482 // after one pass, if isLeft is true, then cycle the points on the left483 // segment, otherwise cycle the right segment:484 485 if (isLeft) {486 iTL = GetNextSeqNumber (iTL, Npoints, isCW, TRUE);487 xval[BOT_LEFT] = xval[TOP_LEFT]; yval[BOT_LEFT] = yval[TOP_LEFT];488 xval[TOP_LEFT] = x[iTL]; yval[TOP_LEFT] = y[iTL];489 ystart = yval[BOT_LEFT];490 } else {491 iTR = GetNextSeqNumber (iTR, Npoints, isCW, FALSE);492 xval[BOT_RGHT] = xval[TOP_RGHT]; yval[BOT_RGHT] = yval[TOP_RGHT];493 xval[TOP_RGHT] = x[iTR]; yval[TOP_RGHT] = y[iTR];494 ystart = yval[BOT_RGHT];495 }496 }497 return;498 }499 500 // we have two line segments defined by x[],y[].501 502 // [0],[1] is the left-side segment503 // [2],[3] is the right-side segment504 505 // Fill the region between the two segments until506 // the lower of the two y coordinates y[1], y[3]507 508 // return which of y[1] or y[3] was the ending row509 510 int bDrawFillBetweenSegments (bDrawBuffer *buffer, int *x, int *y, int ystart) {511 512 int dY_L = y[TOP_LEFT] - y[BOT_LEFT];513 int dX_L = x[TOP_LEFT] - x[BOT_LEFT];514 515 int dY_R = y[TOP_RGHT] - y[BOT_RGHT];516 int dX_R = x[TOP_RGHT] - x[BOT_RGHT];517 518 double Slope_L = (dY_L == 0) ? NAN : dX_L / (double) dY_L;519 double Slope_R = (dY_R == 0) ? NAN : dX_R / (double) dY_R;520 521 // stop at whichever comes first522 // XXX not sure if I need to use < or <= here:523 // with <=, the value of Y after the loop will be one too high.524 int Y;525 for (Y = ystart; (Y < y[TOP_LEFT]) && (Y < y[TOP_RGHT]); Y++) {526 527 // calculating X_L, X_R based on the slope and current y point528 int X_L = (dY_L == 0) ? x[BOT_LEFT] : (Y - y[BOT_LEFT]) * Slope_L + x[BOT_LEFT];529 int X_R = (dY_R == 0) ? x[BOT_RGHT] : (Y - y[BOT_RGHT]) * Slope_R + x[BOT_RGHT];530 531 // draw horizontal line from X_L to X_R at Y532 bDrawLineHorizontal (buffer, X_L, X_R, Y);533 }534 535 if (Y == y[TOP_LEFT]) {536 return TRUE; // TRUE is LEFT SIDE537 } else {538 return FALSE;539 }540 }541 542 int GetNextSeqNumber (int seq, int Npoints, int Clockwise, int LeftSide) {543 544 int iNext;545 546 if (Clockwise) {547 if (LeftSide) {548 // next point is next in sequence549 iNext = (seq < Npoints - 1) ? seq + 1 : 0;550 } else {551 // next point is prev in sequence552 iNext = (seq > 0) ? seq - 1 : Npoints - 1;553 }554 } else {555 if (LeftSide) {556 // next point is prev in sequence557 iNext = (seq > 0) ? seq - 1 : Npoints - 1;558 } else {559 // next point is next in sequence560 iNext = (seq < Npoints - 1) ? seq + 1 : 0;561 }562 }563 return iNext;564 386 } 565 387 … … 763 585 if (x == 0) { 764 586 if (decrementY) { 765 // this should must be a line or width 1 or we duplicate pixels766 587 bDrawLineHorizontal (buffer, Xc , Xc + 1, Yc + y); 767 588 bDrawLineHorizontal (buffer, Xc , Xc + 1, Yc - y); … … 769 590 770 591 // center line 771 // this should must be a line or width 1 or we duplicate pixels772 592 bDrawLineHorizontal (buffer, Xc - y, Xc + y + 1, Yc ); 773 593 return; … … 775 595 776 596 if (x == y) { 777 // this should must be a line or width 1 or we duplicate pixels778 597 bDrawLineHorizontal (buffer, Xc - x, Xc + x + 1, Yc + y); 779 598 bDrawLineHorizontal (buffer, Xc - x, Xc + x + 1, Yc - y); … … 783 602 // only draw these two lines if we decrement y 784 603 if (decrementY) { 785 // this must be a line or width 1 or we duplicate pixels786 604 bDrawLineHorizontal (buffer, Xc - x, Xc + x + 1, Yc + y); 787 605 bDrawLineHorizontal (buffer, Xc - x, Xc + x + 1, Yc - y); … … 789 607 790 608 // always draw these two lines: 791 // this must be a line or width 1 or we duplicate pixels792 609 bDrawLineHorizontal (buffer, Xc - y, Xc + y + 1, Yc + x); 793 610 bDrawLineHorizontal (buffer, Xc - y, Xc + y + 1, Yc - x); … … 831 648 } 832 649 833 // run a smoothing kernel on each channel for anti-aliasing834 // XXX I need to consider the mask as well835 void bDrawSmooth (bDrawBuffer *buffer, float sigma) {836 837 // generate a temp buffer for storage of the smoothed result838 int Nx = buffer[0].Nx;839 int Ny = buffer[0].Ny;840 ALLOCATE_PTR (temp, bDrawColor, Nx*Ny);841 842 //* build a 1D gaussian843 int Nsigma = 2;844 int Ns = (int) (Nsigma*sigma + 0.5);845 int Ngauss = 2*Ns + 1;846 ALLOCATE_PTR (gaussnorm, float, Ngauss);847 float *gauss = &gaussnorm[Ns];848 for (int i = -Ns; i < Ns + 1; i++) {849 gauss[i] = exp ((i*i)/(-2*sigma*sigma));850 }851 852 // NOTE XXX: need to handle Nbyte = 1 or 3853 int Nchannel = 3;854 855 // we need to smooth the 3 channels independently, do this as three passes856 for (int ch = 0; ch < Nchannel; ch++) {857 858 // smooth in X direction859 for (int j = 0; j < Ny; j++) {860 bDrawColor *vi = (bDrawColor *) &buffer[0].pixels[j][ch];861 bDrawColor *vo = &temp[j*Nx];862 for (int i = 0; i < Nx; i++, vo++, vi += Nchannel) {863 float g = 0.0, s = 0.0;864 for (int n = -Ns; n <= Ns; n++) {865 if (i+n < 0) continue;866 if (i+n >= Nx) continue;867 s += gauss[n]*vi[Nchannel*n];868 g += gauss[n];869 }870 *vo = s / g;871 }872 }873 874 // NOTE: output maps back into original image875 // careful on the counting876 877 /* smooth in Y direction */878 for (int i = 0; i < Nx; i++) {879 bDrawColor *vi = &temp[i];880 for (int j = 0; j < Ny; j++) {881 float g = 0.0, s = 0.0;882 for (int n = -Ns; n <= Ns; n++) {883 if (j+n < 0) continue;884 if (j+n >= Ny) continue;885 s += gauss[n]*vi[(n+j)*Nx]; // vi is a single-index array, so this is stepping by rows886 g += gauss[n];887 }888 buffer[0].pixels[j][Nchannel*i + ch] = s / g;889 }890 }891 }892 893 // smooth the mask894 ALLOCATE_PTR (temp_mask, float, Nx*Ny);895 896 // smooth in X direction897 for (int j = 0; j < Ny; j++) {898 char *vi = (char *) &buffer[0].mask[j][0];899 float *vo = &temp_mask[j*Nx];900 for (int i = 0; i < Nx; i++, vo++, vi++) {901 float g = 0.0, s = 0.0;902 for (int n = -Ns; n <= Ns; n++) {903 if (i+n < 0) continue;904 if (i+n >= Nx) continue;905 s += gauss[n]*vi[n];906 g += gauss[n];907 }908 *vo = s / g;909 }910 }911 912 // NOTE: output maps back into original image913 // careful on the counting914 915 /* smooth in Y direction */916 for (int i = 0; i < Nx; i++) {917 float *vi = &temp_mask[i];918 for (int j = 0; j < Ny; j++) {919 float g = 0.0, s = 0.0;920 for (int n = -Ns; n <= Ns; n++) {921 if (j+n < 0) continue;922 if (j+n >= Ny) continue;923 s += gauss[n]*vi[(n+j)*Nx]; // vi is a single-index array, so this is stepping by rows924 g += gauss[n];925 }926 buffer[0].mask[j][i] = (s / g > 0.05) ? 1 : 0;927 }928 }929 930 free (temp);931 free (temp_mask);932 free (gaussnorm);933 934 return;935 }936 937 650 /* 938 NOTES on Bresenham-style circles:939 651 the discriminant of inside or outside the circle is: 940 652 -
trunk/Ohana/src/libkapa/src/bDrawRotFont.c
r41319 r41340 57 57 58 58 YoffBase = Yoff; 59 int Ydelta = 0;60 59 /* draw characters one-by-one */ 61 62 // successive subscripts / superscripts drop the line by63 // same amount each time, but size remains 0.864 // sub followed by sup, or vice versa, should clear and do basic sup/sub65 60 66 61 unsigned int i; … … 78 73 SetRotFont (currentname, (int)(0.8*currentsize)); 79 74 currentfont = GetRotFontData (¤tscale); 80 81 if (Ydelta > 0) { Ydelta = 0; Yoff = YoffBase; } 82 Ydelta --; 83 Yoff -= 0.75*currentscale*dY; 75 Yoff -= 0.5*currentscale*dY; 84 76 continue; 85 77 } … … 87 79 SetRotFont (currentname, (int)(0.8*currentsize)); 88 80 currentfont = GetRotFontData (¤tscale); 89 90 if (Ydelta < 0) { Ydelta = 0; Yoff = YoffBase; } 91 Ydelta ++; 92 Yoff += 0.75*currentscale*dY; 81 Yoff += 0.5*currentscale*dY; 93 82 continue; 94 83 } … … 97 86 currentfont = GetRotFontData (¤tscale); 98 87 Yoff = YoffBase; 99 Ydelta = 0;100 88 continue; 101 89 } -
trunk/Ohana/src/libohana/include/ohana.h
r41321 r41340 391 391 int PrintIOBuffer PROTO((IOBuffer *buffer, char *format, ...)) OHANA_FORMAT(printf, 2, 3); 392 392 int vPrintIOBuffer PROTO((IOBuffer *buffer, char *format, va_list argp)); 393 int WriteToIOBuffer PROTO((IOBuffer *buffer, char *input, int Ninput));394 393 395 394 /* communication functions */ -
trunk/Ohana/src/libohana/include/ohana_allocate.h
r41154 r41340 44 44 void ohana_memcheck_block_func (const char *myFile, int myLine, const char *myFunc, void *in); 45 45 void real_free (void *in); 46 47 void ohana_memdump_strings_file (FILE *f, int VERBOSE);48 void ohana_memdump_set_maxlines (int N);49 46 50 47 # define ohana_memcheck(X) ohana_memcheck_func (__FILE__, __LINE__, __func__, X) -
trunk/Ohana/src/libohana/include/ohana_sort.h
r41154 r41340 83 83 void isortfour (int *X, int *Y, int *Z, int *W, int N); 84 84 85 void dsort_indexonly (double *X, off_t *S, off_t N);86 void dsort_int_indexonly (double *X, int *S, int N);87 88 85 #endif -
trunk/Ohana/src/libohana/src/IOBufferOps.c
r41321 r41340 129 129 } 130 130 131 /* write the bytes to the IOBuffer */132 int WriteToIOBuffer (IOBuffer *buffer, char *input, int Ninput) {133 134 // extend the buffer if needed135 if (buffer[0].Nbuffer + Ninput + 1 >= buffer[0].Nalloc) {136 buffer[0].Nalloc = buffer[0].Nbuffer + Ninput + 64;137 REALLOCATE (buffer[0].buffer, char, buffer[0].Nalloc);138 }139 140 memcpy (&buffer[0].buffer[buffer[0].Nbuffer], input, Ninput);141 buffer[0].Nbuffer += Ninput;142 buffer[0].buffer[buffer[0].Nbuffer] = 0;143 144 return (TRUE);145 }146 -
trunk/Ohana/src/libohana/src/isolate_elements.c
r41176 r41340 186 186 if (!strncmp (c, "+", 1)) return (TRUE); 187 187 if (!strncmp (c, "-", 1)) return (TRUE); 188 if (!strncmp (c, "&", 1)) return (TRUE); 189 if (!strncmp (c, "|", 1)) return (TRUE); 190 191 if (!strncmp (c, "<", 1)) return (TRUE); 192 if (!strncmp (c, ">", 1)) return (TRUE); 188 193 189 194 if (!strncmp (c, "(", 1)) return (TRUE); … … 198 203 if (!strncmp (c, "<=", 2)) return (TRUE); 199 204 if (!strncmp (c, ">=", 2)) return (TRUE); 200 if (!strncmp (c, "<~", 2)) return (TRUE);201 if (!strncmp (c, "~>", 2)) return (TRUE);202 203 if (!strncmp (c, "<", 1)) return (TRUE);204 if (!strncmp (c, ">", 1)) return (TRUE);205 if (!strncmp (c, "&", 1)) return (TRUE);206 if (!strncmp (c, "|", 1)) return (TRUE);207 205 208 206 return (FALSE); … … 220 218 if (!strncmp (c, "<=", 2)) return (TRUE); 221 219 if (!strncmp (c, ">=", 2)) return (TRUE); 222 if (!strncmp (c, "<~", 2)) return (TRUE);223 if (!strncmp (c, "~>", 2)) return (TRUE);224 220 225 221 return (FALSE); -
trunk/Ohana/src/libohana/src/ohana_allocate.c
r41154 r41340 45 45 46 46 static pthread_mutex_t memBlockListMutex = PTHREAD_MUTEX_INITIALIZER; 47 48 static int NblockMaxDump = 100;49 47 50 48 void ohana_meminit () { … … 437 435 fprintf (stderr, "memory corruption\n"); 438 436 } 439 if (Nbad < NblockMaxDump) {437 if (Nbad < 100) { 440 438 fprintf (stderr, " file: %s, line: %d, func: %s\n", thisBlock->file, thisBlock->line, thisBlock->func); 441 439 } … … 615 613 Nbytes += thisBlock->size; 616 614 617 if (Ntotal < NblockMaxDump) {615 if (Ntotal < 100) { 618 616 if (good) { 619 617 fprintf (f, " %zd %zd %zd GOOD %s %d, func: %s\n", Ntotal, thisBlock->size, Nbytes, thisBlock->file, thisBlock->line, thisBlock->func); … … 679 677 return memstats; 680 678 } 681 682 void ohana_memdump_strings_file (FILE *f, int VERBOSE) {683 684 if (!lastBlock) {685 if (VERBOSE) fprintf (f, "no memory allocated\n");686 return;687 }688 689 OhanaMemblock *thisBlock = lastBlock;690 691 size_t Ntotal = 0;692 size_t Nbytes = 0;693 size_t Nstring = 0;694 695 fprintf (f, " entry | bytes | cumulative : line : string\n");696 697 while (thisBlock) {698 699 // pointer to the start of the user memory700 char *ptr = (char *)(thisBlock + 1);701 702 Ntotal ++;703 Nbytes += thisBlock->size;704 705 int N = strlen(thisBlock->file);706 if (N > 22) {707 int found = !strcmp("libohana/src/string.c", &thisBlock->file[N - 21]);708 if (found) {709 if (Nstring < NblockMaxDump) {710 fprintf (f, " %8zd | %8zd | %10zd : %4d : %s\n", Ntotal, thisBlock->size, Nbytes, thisBlock->line, ptr);711 }712 Nstring ++;713 }714 thisBlock = thisBlock->prevBlock;715 }716 }717 718 if (Nstring || VERBOSE) {719 fprintf (f, "%zd strings allocated\n", Nstring);720 }721 722 return;723 }724 725 void ohana_memdump_set_maxlines (int N) {726 NblockMaxDump = N;727 } -
trunk/Ohana/src/libohana/src/sorts.c
r41154 r41340 196 196 } 197 197 198 /* sort the index of a vector (vector stays unsorted) */199 void dsort_indexonly (double *X, off_t *S, off_t N) {200 201 # define SWAPFUNC(A,B){ off_t itmp; \202 itmp = S[A]; S[A] = S[B]; S[B] = itmp; \203 }204 # define COMPARE(A,B)((!isfinite(X[S[A]]) && isfinite(X[S[B]])) || (X[S[A]] < X[S[B]]))205 206 OHANA_SORT (N, COMPARE, SWAPFUNC);207 208 # undef SWAPFUNC209 # undef COMPARE210 211 }212 213 /* sort the index of a vector (vector stays unsorted) */214 void dsort_int_indexonly (double *X, int *S, int N) {215 216 # define SWAPFUNC(A,B){ int itmp; \217 itmp = S[A]; S[A] = S[B]; S[B] = itmp; \218 }219 # define COMPARE(A,B)((!isfinite(X[S[A]]) && isfinite(X[S[B]])) || (X[S[A]] < X[S[B]]))220 221 OHANA_SORT (N, COMPARE, SWAPFUNC);222 223 # undef SWAPFUNC224 # undef COMPARE225 226 }227 228 -
trunk/Ohana/src/opihi/cmd.astro/cdensify.c
r41158 r41340 39 39 } 40 40 41 int binning = 1;42 if ((N = get_argument (argc, argv, "-binning"))) {43 remove_argument (N, &argc, argv);44 binning = atoi(argv[N]);45 remove_argument (N, &argc, argv);46 }47 48 41 int PSFTYPE = IS_DOT; 49 42 if ((N = get_argument (argc, argv, "-psf"))) { … … 87 80 Ymax = graphmode.ymax; 88 81 Ymin = graphmode.ymin; 89 90 // (dX, dY) are the pixel scale of the output image (output pixels / input pixels) 91 92 dX = binning * (Xmax - Xmin) / (Xpix - 1); 93 dY = binning * (Ymax - Ymin) / (Ypix - 1); 82 dX = (Xmax - Xmin) / (Xpix - 1); 83 dY = (Ymax - Ymin) / (Ypix - 1); 94 84 95 85 CHECKVAL(Xmin); -
trunk/Ohana/src/opihi/cmd.astro/cdhistogram.c
r41158 r41340 13 13 int kapa; 14 14 Graphdata graphmode; 15 16 int binning = 1;17 if ((N = get_argument (argc, argv, "-binning"))) {18 remove_argument (N, &argc, argv);19 binning = atoi(argv[N]);20 remove_argument (N, &argc, argv);21 }22 15 23 16 range = NULL; … … 86 79 Ymax = graphmode.ymax; 87 80 Ymin = graphmode.ymin; 88 89 // (dX, dY) are the pixel scale of the output image (output pixels / input pixels) 90 91 dX = binning * (Xmax - Xmin) / (Xpix - 1); 92 dY = binning * (Ymax - Ymin) / (Ypix - 1); 81 dX = (Xmax - Xmin) / (Xpix - 1); 82 dY = (Ymax - Ymin) / (Ypix - 1); 93 83 94 84 CHECKVAL(Xmin); … … 100 90 CHECKVAL(dY); 101 91 102 int Nx = abs((Xmax - Xmin) / dX)+ 1;103 int Ny = abs((Ymax - Ymin) / dY)+ 1;92 int Nx = (Xmax - Xmin) / dX + 1; 93 int Ny = (Ymax - Ymin) / dY + 1; 104 94 105 95 Coords newcoords = graphmode.coords; -
trunk/Ohana/src/opihi/cmd.astro/cgrid.c
r41326 r41340 83 83 Graphdata graphmode; 84 84 85 if ((N = get_argument (argc, argv, "-h"))) goto usage;86 if ((N = get_argument (argc, argv, "--help"))) goto usage;87 88 85 RAbyHour = FALSE; 89 86 if ((N = get_argument (argc, argv, "-ra-by-hour"))) { … … 118 115 } 119 116 120 int JustifyRA = 8;121 int JustifyDEC = 2;117 int JustifyRA = 5; 118 double JustifyDEC = 5; 122 119 if ((N = get_argument (argc, argv, "-justify-ra"))) { 123 120 remove_argument (N, &argc, argv); … … 154 151 if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE; 155 152 156 if (argc != 1) goto usage; 153 if (argc != 1) { 154 gprint (GP_ERR, "USAGE: cgrid [style] [-ra-by-hour] [-labels]\n"); 155 return (FALSE); 156 } 157 157 158 158 /* are we plotting one of the poles? */ … … 182 182 } 183 183 } 184 185 184 186 185 /* set spacings for DEC */ … … 346 345 return (TRUE); 347 346 348 usage:349 350 gprint (GP_ERR, "USAGE: cgrid [style] [options]\n");351 gprint (GP_ERR, " options:\n");352 gprint (GP_ERR, " -h, --help: show this list\n");353 gprint (GP_ERR, " -ra-by-hour : RA grid lines will be space on rounded hour lines (default is degrees)\n");354 gprint (GP_ERR, " -labels : add RA & dec coordinates\n");355 gprint (GP_ERR, " -major-spacing : grid lines drawn at major tickmarks, not minor tickmarks\n");356 gprint (GP_ERR, " -ra-spacing : specify size of RA grid steps in degrees (ignores -ra-by-hour)\n");357 gprint (GP_ERR, " -dec-spacing : specify size of dec grid steps in degrees\n");358 gprint (GP_ERR, " -justify-ra : choose how RA labels are justified (see below)\n");359 gprint (GP_ERR, " -justify-dec : choose how dec labels are justified (see below)\n");360 gprint (GP_ERR, " -label-ra : RA coordinate of the Dec-line labels\n");361 gprint (GP_ERR, " -label-dec : Dec coordinate of the RA-line labels\n");362 gprint (GP_ERR, " -label-color : color for the labels (independent of grid lines)\n");363 gprint (GP_ERR, " text justification: text is justified horizontally and vertically based on the following numbers:\n");364 gprint (GP_ERR, " 6 7 8\n");365 gprint (GP_ERR, " 3 4 5\n");366 gprint (GP_ERR, " 0 1 2\n");367 return (FALSE);368 347 } 369 -
trunk/Ohana/src/opihi/cmd.astro/csystem.c
r41305 r41340 12 12 Vector *uxvec = NULL; 13 13 Vector *uyvec = NULL; 14 15 int Quiet = FALSE;16 if ((N = get_argument (argc, argv, "-q"))) {17 Quiet = TRUE;18 remove_argument (N, &argc, argv);19 }20 if ((N = get_argument (argc, argv, "-quiet"))) {21 Quiet = TRUE;22 remove_argument (N, &argc, argv);23 }24 14 25 15 // transform proper motions at the same time … … 94 84 95 85 if (uXname) { 96 if (!Quiet) { 97 gprint (GP_LOG, "%10.6f %10.6f @ %10.6f %10.6f\n", x, y, ux, uy); 98 switch (output) { 99 case COORD_CELESTIAL: 100 set_variable ("uR", ux); 101 set_variable ("uD", uy); 102 break; 103 case COORD_ECLIPTIC: 104 set_variable ("uL", ux); 105 set_variable ("uB", uy); 106 break; 107 case COORD_GALACTIC: 108 case COORD_GALACTIC_REID_2004: 109 set_variable ("uLon", ux); 110 set_variable ("uLat", uy); 111 break; 112 default: 113 break; 114 } 115 } 86 gprint (GP_LOG, "%10.6f %10.6f @ %10.6f %10.6f\n", x, y, ux, uy); 116 87 } else { 117 if (!Quiet) { 118 gprint (GP_LOG, "%10.6f %10.6f\n", x, y); 119 } 120 } 121 switch (output) { 122 case COORD_CELESTIAL: 123 set_variable ("RA", x); 124 set_variable ("DEC", y); 125 break; 126 case COORD_ECLIPTIC: 127 set_variable ("Lambda", x); 128 set_variable ("Beta", y); 129 break; 130 case COORD_GALACTIC: 131 case COORD_GALACTIC_REID_2004: 132 set_variable ("gLon", x); 133 set_variable ("gLat", y); 134 break; 135 default: 136 break; 88 gprint (GP_LOG, "%10.6f %10.6f\n", x, y); 137 89 } 138 90 free (transform); … … 202 154 gprint (GP_ERR, " e.g. : csystem C G R D -pm uR uD -> R D will contain glon, glat; uR, uD will contain uL, uB\n"); 203 155 gprint (GP_ERR, " e.g. : csystem C G R D -pmback uL uB -> R D will contain glon, glat; uL, uB will contain uR, uD\n"); 204 gprint (GP_ERR, " : if input values are vectors, their values are replaced with the transformed values\n");205 gprint (GP_ERR, " : if input values are scalars, the transformed coordinates are printed (disable with -q)\n");206 gprint (GP_ERR, " : and the following output variables will be set (names depend on output system)\n");207 gprint (GP_ERR, " : output positions (RA, DEC), (Lambda, Beta), (gLon, gLat)\n");208 gprint (GP_ERR, " : output motions (uR, uD), (uL, uB), (uLon, uLat)\n");209 156 return FALSE; 210 157 } -
trunk/Ohana/src/opihi/cmd.astro/fitplx_irls.c
r41322 r41340 11 11 remove_argument (N, &argc, argv); 12 12 if ((mvec = SelectVector (argv[N], ANYVECTOR, TRUE)) == NULL) return (FALSE); 13 remove_argument (N, &argc, argv);14 }15 16 Vector *WxOutV = NULL; // mask vector17 if ((N = get_argument (argc, argv, "-Wxvec"))) {18 remove_argument (N, &argc, argv);19 if ((WxOutV = SelectVector (argv[N], ANYVECTOR, TRUE)) == NULL) return (FALSE);20 remove_argument (N, &argc, argv);21 }22 Vector *WyOutV = NULL; // mask vector23 if ((N = get_argument (argc, argv, "-Wyvec"))) {24 remove_argument (N, &argc, argv);25 if ((WyOutV = SelectVector (argv[N], ANYVECTOR, TRUE)) == NULL) return (FALSE);26 13 remove_argument (N, &argc, argv); 27 14 } … … 114 101 mask = mvec->elements.Int; 115 102 } 116 }117 118 if (WxOutV) {119 ResetVector (WxOutV, OPIHI_FLT, Ntotal);120 for (i = 0; i < Ntotal; i++) { WxOutV->elements.Flt[i] = NAN; }121 }122 if (WyOutV) {123 ResetVector (WyOutV, OPIHI_FLT, Ntotal);124 for (i = 0; i < Ntotal; i++) { WyOutV->elements.Flt[i] = NAN; }125 103 } 126 104 … … 191 169 } 192 170 } 193 }194 }195 if (WxOutV) {196 // save the calculated weights197 for (i = 0; i < fitdata.Npts; i++) {198 // fitdata only includes the previously unmasked points199 int n = fitdata.index[i];200 WxOutV->elements.Flt[n] = fitdata.Wx[i];201 }202 }203 if (WyOutV) {204 // save the calculated weights205 for (i = 0; i < fitdata.Npts; i++) {206 // fitdata only includes the previously unmasked points207 int n = fitdata.index[i];208 WyOutV->elements.Flt[n] = fitdata.Wy[i];209 171 } 210 172 } -
trunk/Ohana/src/opihi/cmd.astro/mkgauss.c
r41305 r41340 10 10 double x, y, r, f, Xo, Yo; 11 11 Buffer *buf; 12 13 int Normalize = FALSE;14 if ((N = get_argument (argc, argv, "-norm"))) {15 Normalize = TRUE;16 remove_argument (N, &argc, argv);17 }18 12 19 13 // this should be Nx/2, Ny/2 if not set … … 66 60 /* f = exp (-r), r = (x^2 / 2Sx) + (y^2 / 2Sy) + Sxy*x*y */ 67 61 68 double Io = Normalize ? 1.0 / (2.0 * M_PI * Sig_x * Sig_y) : 1.0;69 70 62 in = (float *) buf[0].matrix.buffer; 71 63 for (j = 0; j < Ny; j++) { … … 75 67 y = j - Yo; 76 68 r = 0.5*x*x/Sx + 0.5*y*y/Sy + x*y*Sxy; 77 f = Io *exp (-r);69 f = exp (-r); 78 70 *in += f; 79 71 } -
trunk/Ohana/src/opihi/cmd.astro/region.c
r41158 r41340 3 3 int region (int argc, char **argv) { 4 4 5 double Ra, Dec ;5 double Ra, Dec, Radius; 6 6 float dx, dy; 7 7 int N, kapa, NoClear, dXpix, dYpix; … … 54 54 } 55 55 56 float XSIZE = NAN;57 if ((N = get_argument (argc, argv, "-xsize"))) {58 remove_argument (N, &argc, argv);59 XSIZE = atof (argv[N]);60 remove_argument (N, &argc, argv);61 if (XSIZE <= 0) {62 gprint (GP_ERR, "ERROR: xsize <= 0\n");63 return FALSE;64 }65 }66 67 float YSIZE = NAN;68 if ((N = get_argument (argc, argv, "-ysize"))) {69 remove_argument (N, &argc, argv);70 YSIZE = atof (argv[N]);71 remove_argument (N, &argc, argv);72 if (YSIZE <= 0) {73 gprint (GP_ERR, "ERROR: xsize <= 0\n");74 return FALSE;75 }76 }77 78 56 if ((N = get_argument (argc, argv, "-ew"))) { 79 57 remove_argument (N, &argc, argv); … … 103 81 } 104 82 105 int RadiusArg, CtypeArg; 106 if (!isnan(XSIZE) || !isnan(YSIZE)) { 107 RadiusArg = -1; 108 CtypeArg = 3; 109 if ((argc != 3) && (argc != 4)) { 110 gprint (GP_ERR, "USAGE: region Ra Dec [projection] [-xsize deg] [-ysize deg]\n"); 111 gprint (GP_ERR, " OR: region Ra Dec Radius [projection]\n"); 83 if ((argc != 4) && (argc != 5)) { 84 gprint (GP_ERR, "USAGE: region Ra Dec Radius [projection] [orientation]\n"); 112 85 gprint (GP_ERR, " [-image] [-ew] [+ew] [-ns] [+ns] [-no-clear] [-angle theta]\n"); 113 86 gprint (GP_ERR, " current: %f %f (%f x %f) (%s)\n", … … 117 90 &graphmode.coords.ctype[5]); 118 91 return (FALSE); 119 } 120 } else { 121 RadiusArg = 3; 122 CtypeArg = 4; 123 if ((argc != 4) && (argc != 5)) { 124 gprint (GP_ERR, "USAGE: region Ra Dec Radius [projection]\n"); 125 gprint (GP_ERR, " OR: region Ra Dec [projection] [-xsize deg] [-ysize deg]\n"); 126 gprint (GP_ERR, " [-image] [-ew] [+ew] [-ns] [+ns] [-no-clear] [-angle theta]\n"); 127 gprint (GP_ERR, " current: %f %f (%f x %f) (%s)\n", 128 graphmode.coords.crval1, graphmode.coords.crval2, 129 fabs(graphmode.xmax - graphmode.xmin), 130 fabs(graphmode.ymax - graphmode.ymin), 131 &graphmode.coords.ctype[5]); 132 return (FALSE); 133 } 134 } 92 } 93 135 94 if (!ohana_str_to_radec (&Ra, &Dec, argv[1], argv[2])) return (FALSE); 95 Radius = atof (argv[3]); 96 InitCoords (&graphmode.coords, "DEC--TAN"); 136 97 137 // region 0 0 sin -- should raise an error (radius = 0 or non-numeric) 138 139 // I want to be able to support the old style call in which both of these were valid: 140 // region 0 0 90 ait 141 // region 0 0 90 <- uses existing, sticky projection type 142 // but I also want to be able to use 143 // region 0 0 ait -xsize 5 144 // region 0 0 ait -ysize 5 145 146 double Radius = NAN; 147 if (RadiusArg >= 0) { 148 Radius = atof (argv[RadiusArg]); 98 if (argc == 5) { 99 if (!strcasecmp (argv[4], "TAN")) 100 strcpy (graphmode.coords.ctype, "DEC--TAN"); 101 if (!strcasecmp (argv[4], "SIN")) 102 strcpy (graphmode.coords.ctype, "DEC--SIN"); 103 if (!strcasecmp (argv[4], "ARC")) 104 strcpy (graphmode.coords.ctype, "DEC--ARC"); 105 if (!strcasecmp (argv[4], "STG")) 106 strcpy (graphmode.coords.ctype, "DEC--STG"); 107 if (!strcasecmp (argv[4], "ZEA")) 108 strcpy (graphmode.coords.ctype, "DEC--ZEA"); 109 if (!strcasecmp (argv[4], "AIT")) 110 strcpy (graphmode.coords.ctype, "DEC--AIT"); 111 if (!strcasecmp (argv[4], "GLS")) 112 strcpy (graphmode.coords.ctype, "DEC--GLS"); 113 if (!strcasecmp (argv[4], "PAR")) 114 strcpy (graphmode.coords.ctype, "DEC--PAR"); 149 115 } 150 151 InitCoords (&graphmode.coords, "DEC--TAN");152 if (argc == CtypeArg + 1) {153 if (!strcasecmp (argv[CtypeArg], "TAN")) { strcpy (graphmode.coords.ctype, "DEC--TAN"); goto got_ctype; }154 if (!strcasecmp (argv[CtypeArg], "SIN")) { strcpy (graphmode.coords.ctype, "DEC--SIN"); goto got_ctype; }155 if (!strcasecmp (argv[CtypeArg], "ARC")) { strcpy (graphmode.coords.ctype, "DEC--ARC"); goto got_ctype; }156 if (!strcasecmp (argv[CtypeArg], "STG")) { strcpy (graphmode.coords.ctype, "DEC--STG"); goto got_ctype; }157 if (!strcasecmp (argv[CtypeArg], "ZEA")) { strcpy (graphmode.coords.ctype, "DEC--ZEA"); goto got_ctype; }158 if (!strcasecmp (argv[CtypeArg], "AIT")) { strcpy (graphmode.coords.ctype, "DEC--AIT"); goto got_ctype; }159 if (!strcasecmp (argv[CtypeArg], "GLS")) { strcpy (graphmode.coords.ctype, "DEC--GLS"); goto got_ctype; }160 if (!strcasecmp (argv[CtypeArg], "PAR")) { strcpy (graphmode.coords.ctype, "DEC--PAR"); goto got_ctype; }161 gprint (GP_ERR, "ERROR: invalid projection type %s\n", argv[CtypeArg]);162 gprint (GP_ERR, "allowed values: TAN, SIN, ARC, STG, ZEA, AIT, GLS, PAR\n");163 return FALSE;164 }165 got_ctype:166 116 167 117 graphmode.coords.crval1 = Ra; … … 176 126 graphmode.coords.pc2_2 = cos(Angle*RAD_DEG)*pc2_2; 177 127 178 // ask kapa for coordinate limits, to get the right aspect ratio 179 // dx, dy are the size of the graph region in pixels 128 /* ask kapa for coordinate limits, to get the right aspect ratio */ 180 129 KapaGetLimits (kapa, &dx, &dy); 181 130 dx = fabs (dx); … … 183 132 184 133 /* define limits for Ra, Dec at center, grid in degrees */ 185 if (RadiusArg >= 0) { 186 // force non-anamorphic projection with Radius set to smaller axis 187 if (dy < dx) { 188 graphmode.xmin = -(dx/dy)*Radius; 189 graphmode.ymin = -Radius; 190 graphmode.xmax = (dx/dy)*Radius; 191 graphmode.ymax = Radius; 192 } else { 193 graphmode.xmin = -Radius; 194 graphmode.ymin = -(dy/dx)*Radius; 195 graphmode.xmax = Radius; 196 graphmode.ymax = (dy/dx)*Radius; 197 } 134 if (dy < dx) { 135 graphmode.xmin = -(dx/dy)*Radius; 136 graphmode.ymin = -Radius; 137 graphmode.xmax = (dx/dy)*Radius; 138 graphmode.ymax = Radius; 198 139 } else { 199 if (isnan(XSIZE)) { 200 graphmode.xmin = -(dx/dy)*YSIZE/2.0; 201 graphmode.ymin = -YSIZE/2.0; 202 graphmode.xmax = (dx/dy)*YSIZE/2.0; 203 graphmode.ymax = YSIZE/2.0; 204 } 205 if (isnan(YSIZE)) { 206 graphmode.xmin = -XSIZE/2.0; 207 graphmode.ymin = -(dy/dx)*XSIZE/2.0; 208 graphmode.xmax = XSIZE/2.0; 209 graphmode.ymax = (dy/dx)*XSIZE/2.0; 210 } 211 // anamorphic projection: 212 if (!isnan(XSIZE) && !isnan(YSIZE)) { 213 graphmode.xmin = -XSIZE/2.0; 214 graphmode.ymin = -YSIZE/2.0; 215 graphmode.xmax = XSIZE/2.0; 216 graphmode.ymax = YSIZE/2.0; 217 } 218 } 140 graphmode.xmin = -Radius; 141 graphmode.ymin = -(dy/dx)*Radius; 142 graphmode.xmax = Radius; 143 graphmode.ymax = (dy/dx)*Radius; 144 } 219 145 220 146 set_variable ("XMIN", graphmode.xmin); -
trunk/Ohana/src/opihi/cmd.basic/init.c
r41160 r41340 73 73 {1, "??", list_vars, "list variables *"}, 74 74 {1, "#", nop, "a NOP function"}, 75 {1, "##", nop, "a NOP function"},76 {1, "###", nop, "a NOP function"},77 75 {1, "local", local, "define local variables"}, 78 76 {1, "macro", macro, "deal with the macros *"}, -
trunk/Ohana/src/opihi/cmd.basic/list.c
r41268 r41340 263 263 gprint (GP_ERR, "USAGE: list (root) -split (words) : create list from words\n"); 264 264 gprint (GP_ERR, "USAGE: list (root) -splitbychar (char) (word) [(words)..] : create list from words\n"); 265 gprint (GP_ERR, "USAGE: list (root) -join (varname) : convert a list to a single variable (space separated)\n");266 265 gprint (GP_ERR, "USAGE: list (root) -add (words) : extend a list\n"); 267 266 gprint (GP_ERR, "USAGE: list (root) -copy (list) : copy a list to a new name\n"); 268 267 gprint (GP_ERR, "USAGE: list (root) -del (word) : delete the entry by value\n"); 269 gprint (GP_ERR, "USAGE: list (root) -glob (word) : create a list from a file glob\n");270 gprint (GP_ERR, "USAGE: list (root) -file (word) : create a list from lines in a file\n");271 272 gprint (GP_ERR, "OPTIONS: -excel : generate names of the for foo:A\n");273 gprint (GP_ERR, "OPTIONS: -excel-style : generate names of the for foo:A\n");274 268 return (FALSE); 275 269 } -
trunk/Ohana/src/opihi/cmd.basic/memory.c
r41160 r41340 5 5 6 6 if (argc < 2) goto usage; 7 8 if (!strcasecmp (argv[1], "max-lines")) {9 if (argc != 3) goto usage;10 int MaxLines = atoi(argv[2]);11 ohana_memdump_set_maxlines (MaxLines);12 return TRUE;13 }14 7 15 8 if (!strcasecmp (argv[1], "all")) { … … 50 43 } 51 44 52 if (!strncasecmp ("strings", argv[1], strlen(argv[1]))) {53 ohana_memdump_strings_file (stderr, FALSE);54 return (TRUE);55 }56 57 45 usage: 58 gprint (GP_ERR, "USAGE: memory (mode) [-max-lines]\n"); 59 gprint (GP_ERR, "USAGE: memory (max-lines) (N)\n"); 60 gprint (GP_ERR, " mode options: all, leaks, check, checkfree, variables, vectors, buffers, macros, commands, strings\n"); 46 gprint (GP_ERR, "USAGE: memory (all/leaks)\n"); 61 47 return (FALSE); 62 48 } -
trunk/Ohana/src/opihi/cmd.basic/test/if.sh
r41160 r41340 320 320 end 321 321 end 322 323 # check memleaks324 macro memtest1325 326 local a b i N327 328 $i = 0329 $a = 1330 331 memory check332 output /dev/null333 for i 0 1000334 if ($a == 1)335 echo "run"336 end337 end338 output stdout339 memory check340 end341 342 # check memleaks343 macro memtest2344 345 local a b i N346 347 $i = 0348 $a = 1349 $b = 2350 351 memory check352 output /dev/null353 for i 0 1000354 if (($a == 1) && ($b == 2))355 echo "run"356 end357 end358 output stdout359 memory check360 end361 362 # memory test using continue363 macro memtest3364 365 local a b i N366 367 $i = 0368 $a = 1369 $b = 2370 371 memory check372 output /dev/null373 for i 0 1000374 if (($a == 1) && ($b == 2))375 continue376 echo "run"377 end378 end379 output stdout380 memory check381 end382 383 # memory test using continue384 macro memtest4385 386 local a b i N bool387 388 389 $i = 0390 $a = 1391 $b = 2392 $bool = 0393 394 memory check395 output /dev/null396 for i 0 1000397 $bool = (($a == 1) && ($b == 2))398 end399 output stdout400 memory check401 end -
trunk/Ohana/src/opihi/cmd.basic/test/macro.sh
r41160 r41340 7 7 # Is the macro working? 8 8 macro test_prep 9 $test_var1 = check110 $test_var2 = check211 $var_count = $012 end13 14 # Is the macro working?15 macro test_local16 local test_var test_var2 var_count17 18 9 $test_var1 = check1 19 10 $test_var2 = check2 … … 56 47 end 57 48 end 58 59 # Memory Test for macro60 macro memtest261 62 $i = 063 test_prep64 65 memory check66 for i 0 1000067 test_prep68 end69 memory check70 71 end72 73 # Memory Test for macro74 macro memtest375 76 $i = 077 test_local78 79 memory check80 for i 0 1000081 test_local82 end83 memory check84 85 end -
trunk/Ohana/src/opihi/cmd.data/Makefile
r41322 r41340 19 19 $(SRC)/init.$(ARCH).o \ 20 20 $(SRC)/accum.$(ARCH).o \ 21 $(SRC)/antialias.$(ARCH).o \22 21 $(SRC)/applyfit1d.$(ARCH).o \ 23 22 $(SRC)/applyfit2d.$(ARCH).o \ … … 79 78 $(SRC)/join.$(ARCH).o \ 80 79 $(SRC)/jpeg.$(ARCH).o \ 81 $(SRC)/kapamemory.$(ARCH).o \82 80 $(SRC)/kern.$(ARCH).o \ 83 81 $(SRC)/keyword.$(ARCH).o \ … … 91 89 $(SRC)/lookup.$(ARCH).o \ 92 90 $(SRC)/matrix.$(ARCH).o \ 93 $(SRC)/match1d.$(ARCH).o \94 91 $(SRC)/match2d.$(ARCH).o \ 95 92 $(SRC)/mkrgb.$(ARCH).o \ 96 93 $(SRC)/mcreate.$(ARCH).o \ 97 94 $(SRC)/medacc.$(ARCH).o \ 98 $(SRC)/mgaussdev.$(ARCH).o \99 95 $(SRC)/mget.$(ARCH).o \ 100 96 $(SRC)/mget3d.$(ARCH).o \ … … 103 99 $(SRC)/medimage.$(ARCH).o \ 104 100 $(SRC)/medimage_commands.$(ARCH).o \ 105 $(SRC)/medimage_calc.$(ARCH).o \106 101 $(SRC)/mset.$(ARCH).o \ 107 102 $(SRC)/needles.$(ARCH).o \ … … 117 112 $(SRC)/point.$(ARCH).o \ 118 113 $(SRC)/ps.$(ARCH).o \ 119 $(SRC)/pdf.$(ARCH).o \120 114 $(SRC)/print_vectors.$(ARCH).o \ 121 115 $(SRC)/mprint.$(ARCH).o \ … … 130 124 $(SRC)/queuesubstr.$(ARCH).o \ 131 125 $(SRC)/queueinit.$(ARCH).o \ 132 $(SRC)/queue2book.$(ARCH).o \133 126 $(SRC)/radial.$(ARCH).o \ 134 127 $(SRC)/rd.$(ARCH).o \ … … 176 169 $(SRC)/vgauss.$(ARCH).o \ 177 170 $(SRC)/vlorentz.$(ARCH).o \ 178 $(SRC)/vsigmoid.$(ARCH).o \179 171 $(SRC)/vellipse.$(ARCH).o \ 180 172 $(SRC)/vmaxwell.$(ARCH).o \ … … 184 176 $(SRC)/vzload.$(ARCH).o \ 185 177 $(SRC)/vpeaks.$(ARCH).o \ 186 $(SRC)/vtransitions.$(ARCH).o \187 178 $(SRC)/vpop.$(ARCH).o \ 188 179 $(SRC)/vroll.$(ARCH).o \ … … 191 182 $(SRC)/vsmooth.$(ARCH).o \ 192 183 $(SRC)/vstats.$(ARCH).o \ 193 $(SRC)/virls.$(ARCH).o \194 $(SRC)/vwtmean.$(ARCH).o \195 184 $(SRC)/xsection.$(ARCH).o \ 196 185 $(SRC)/vsh.$(ARCH).o \ -
trunk/Ohana/src/opihi/cmd.data/create.c
r41269 r41340 7 7 Vector *vec; 8 8 9 // create a vector of empty strings10 if ((N = get_argument (argc, argv, "-str"))) {11 remove_argument (N, &argc, argv);12 13 char *stringValue = NULL;14 if ((N = get_argument (argc, argv, "-value"))) {15 remove_argument (N, &argc, argv);16 stringValue = strcreate (argv[N]);17 remove_argument (N, &argc, argv);18 }19 20 if (argc != 3) {21 gprint (GP_ERR, "USAGE: create vector Nelements -value word\n");22 return (FALSE);23 }24 25 if ((vec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) return (FALSE);26 int Nelements = atoi (argv[2]);27 28 // a newly reset vector has NULL-valued pointers29 ResetVector (vec, OPIHI_STR, Nelements);30 for (int i = 0; i < Nelements; i++) {31 vec[0].elements.Str[i] = stringValue ? strcreate (stringValue) : strcreate ("");32 }33 return TRUE;34 }35 36 9 INT = FALSE; 37 10 if ((N = get_argument (argc, argv, "-int"))) { … … 43 16 gprint (GP_ERR, "USAGE: create vector start end [delta] [-int]\n"); 44 17 gprint (GP_ERR, " -int : resulting vector is integer type (delta must be integer)\n"); 45 gprint (GP_ERR, " -str : resulting vector is string type (only give number of elements)\n");46 18 return (FALSE); 47 19 } -
trunk/Ohana/src/opihi/cmd.data/cut.c
r41164 r41340 1 1 # include "data.h" 2 2 3 enum {SUM, MEAN, MEDIAN, INNER, NGOOD}; 4 5 double cutstat (float *value, int Nvalue, int mode) { 6 7 double output = 0.0; 8 9 if (Nvalue == 0) return NAN; 10 11 if (mode == MEDIAN) { 12 fsort (value, Nvalue); 13 if (Nvalue % 2) { 14 int Ncenter = Nvalue / 2; 15 myAssert ((Ncenter >= 0) && (Ncenter < Nvalue), "cutstat"); 16 output = value[Ncenter]; 17 } else { 18 int Ncenter = Nvalue / 2 - 1; 19 myAssert ((Ncenter >= 0) && (Ncenter < Nvalue - 1), "cutstat"); 20 output = 0.5*(value[Ncenter] + value[Ncenter + 1]); 21 } 22 return output; 23 } 24 if (mode == INNER) { 25 fsort (value, Nvalue); 26 27 int Ns = 0, Ne = 0; 28 if (Nvalue % 2) { 29 // for an odd number of points take the same number below 30 // and above the center value 31 int Ncenter = Nvalue / 2; 32 int Nquarter = 0.25*Nvalue; 33 Ns = Ncenter - Nquarter; 34 Ne = Ncenter + Nquarter; 35 } else { 36 // for an even number, the middle lies between two points 37 // take the same number below as above 38 int Ncenter = (int)(Nvalue / 2) - 1; 39 int Nquarter = 0.25*Nvalue; 40 Ns = Ncenter - Nquarter; 41 Ne = Ncenter + 1 + Nquarter; 42 } 43 int Nv = 0; 44 for (int i = Ns; i <= Ne; i++) { 45 myAssert ((i >= 0) && (i < Nvalue), "cutstat"); 46 output += value[i]; 47 Nv ++; 48 } 49 output /= Nv; 50 return output; 51 } 52 if (mode == NGOOD) { 53 return Nvalue; 54 } 55 if ((mode == MEAN) || (mode == SUM)) { 56 for (int i = 0; i < Nvalue; i++) { 57 myAssert ((i >= 0) && (i < Nvalue), "cutstat"); 58 output += value[i]; 59 } 60 if (mode == MEAN) { output /= Nvalue; } 61 return output; 62 } 63 return NAN; 64 } 3 enum {SUM, MEAN, MEDIAN}; 65 4 66 5 int cut (int argc, char **argv) { 67 6 68 7 int i, j, N, Nx, Ny, Mode; 69 float *Vin, *Vbuf ;8 float *Vin, *Vbuf, value; 70 9 int sx, sy, nx, ny; 71 10 Vector *xvec, *yvec; … … 73 12 74 13 Mode = SUM; 75 if ((N = get_argument (argc, argv, "-sum"))) {76 remove_argument (N, &argc, argv);77 Mode = SUM;78 }79 14 if ((N = get_argument (argc, argv, "-median"))) { 80 15 remove_argument (N, &argc, argv); … … 84 19 remove_argument (N, &argc, argv); 85 20 Mode = MEAN; 86 }87 if ((N = get_argument (argc, argv, "-inner"))) {88 remove_argument (N, &argc, argv);89 Mode = INNER;90 }91 if ((N = get_argument (argc, argv, "-ngood"))) {92 remove_argument (N, &argc, argv);93 Mode = NGOOD;94 21 } 95 22 … … 109 36 Ny = buf[0].matrix.Naxis[1]; 110 37 111 // ny & nx do not need to be constrained by the buffer, but they do need to be sensible 112 if ((nx < 0) || (ny < 0) || (nx > 1e8) || (ny > 1e8)) { 113 gprint (GP_ERR, "warning : extraction size is crazy: %d,%d\n", nx, ny); 38 if ((sx < 0) || (sy < 0) || (sx+nx > Nx) || (sy+ny > Ny)) { 39 gprint (GP_ERR, "region out of range\n"); 114 40 return (FALSE); 115 41 } … … 131 57 132 58 for (i = 0; i < nx; i++) { 133 / / for out-of-range areas, set the output pixels to NAN134 if (i + sx < 0) {135 yvec[0].elements.Flt[i] = NAN; 136 continue;59 /* accumulate values */ 60 Vin = (float *)(buf[0].matrix.buffer) + sy*Nx + sx + i; 61 for (j = 0; j < ny; j++, Vin += Nx) { 62 Vbuf[j] = *Vin; 137 63 } 138 if (i + sx >= Nx) { 139 yvec[0].elements.Flt[i] = NAN; 140 continue; 64 /* apply stat of choice */ 65 if (Mode == MEDIAN) { 66 fsort (Vbuf, ny); 67 value = Vbuf[(int)(0.5*ny)]; 68 } else { 69 value = 0; 70 for (j = 0; j < ny; j++) { 71 value += Vbuf[j]; 72 } 73 if (Mode == MEAN) { value /= ny; } 141 74 } 142 143 /* accumulate values */ 144 // skip out-of-range areas in y 145 if (sy < 0) { 146 ny += sy; 147 sy = 0; 148 } 149 if (sy > Ny) sy = Ny; 150 if (sy + ny >= Ny) ny = Ny - sy; 151 152 Vin = (float *)(buf[0].matrix.buffer) + sy*Nx + sx + i; 153 int Npix = 0; 154 for (j = 0; j < ny; j++, Vin += Nx) { 155 if (!isfinite(*Vin)) continue; 156 Vbuf[Npix] = *Vin; 157 Npix ++; 158 } 159 yvec[0].elements.Flt[i] = cutstat (Vbuf, Npix, Mode); 75 yvec[0].elements.Flt[i] = value; 160 76 } 161 77 free (Vbuf); … … 173 89 174 90 for (i = 0; i < ny; i++) { 175 / / for out-of-range areas, set the output pixels to NAN176 if (i + sy < 0) {177 yvec[0].elements.Flt[i] = NAN; 178 continue;91 /* accumulate values */ 92 Vin = (float *)(buf[0].matrix.buffer) + (sy + i)*Nx + sx; 93 for (j = 0; j < nx; j++, Vin ++) { 94 Vbuf[j] = *Vin; 179 95 } 180 if (i + sy >= Ny) { 181 yvec[0].elements.Flt[i] = NAN; 182 continue; 96 /* apply stat of choice */ 97 if (Mode == MEDIAN) { 98 fsort (Vbuf, nx); 99 value = Vbuf[(int)(0.5*nx)]; 100 } else { 101 value = 0; 102 for (j = 0; j < nx; j++) { 103 value += Vbuf[j]; 104 } 105 if (Mode == MEAN) { value /= nx; } 183 106 } 184 185 /* accumulate values */ 186 // skip out-of-range areas in x 187 if (sx < 0) { 188 nx += sx; 189 sx = 0; 190 } 191 if (sx > Nx) sx = Nx; 192 if (sx + nx >= Nx) nx = Nx - sx; 193 194 Vin = (float *)(buf[0].matrix.buffer) + (sy + i)*Nx + sx; 195 int Npix = 0; 196 for (j = 0; j < nx; j++, Vin ++) { 197 if (!isfinite(*Vin)) continue; 198 Vbuf[Npix] = *Vin; 199 Npix ++; 200 } 201 yvec[0].elements.Flt[i] = cutstat (Vbuf, Npix, Mode); 107 yvec[0].elements.Flt[i] = value; 202 108 } 203 109 free (Vbuf); -
trunk/Ohana/src/opihi/cmd.data/dbselect.c
r41283 r41340 80 80 case FIELD_TYPE_DOUBLE: 81 81 case FIELD_TYPE_TIME: 82 case FIELD_TYPE_TIMESTAMP:83 82 case FIELD_TYPE_DATE: 84 83 case FIELD_TYPE_DATETIME: … … 116 115 break; 117 116 case FIELD_TYPE_TIME: 118 case FIELD_TYPE_TIMESTAMP:119 117 case FIELD_TYPE_DATE: 120 118 case FIELD_TYPE_DATETIME: -
trunk/Ohana/src/opihi/cmd.data/extract.c
r41164 r41340 1 1 # include "data.h" 2 3 /* <from> : source image, must exist4 <to> : target image -- if it does not exist, it is created of size (Nx,Ny)5 sx, sy : source starting coordinate -- need not be on a valid image pixel6 nx, ny : number of source pixels -- currently must not go out of bounds -> allow out-of-bounds7 Sx, Sy : target starting coordinate -- need not be on a valid image pixel8 Nx, Ny : redundant information UNLESS <to> does exist (in which case it is required information) -> make Nx,Ny optional if <to> exists?9 */10 2 11 3 int extract (int argc, char **argv) { 12 4 13 int N; 5 int i, j; 6 float *Vin, *Vout; 7 int sx, sy, nx, ny, NX, NY; 8 int Sx, Sy, Nx, Ny; 14 9 Buffer *in, *out; 15 16 float initValue = 0.0;17 int initOutput = FALSE;18 if ((N = get_argument (argc, argv, "-init"))) {19 remove_argument (N, &argc, argv);20 initValue = atof (argv[N]);21 remove_argument (N, &argc, argv);22 initOutput = TRUE;23 }24 10 25 11 if (argc != 11) { … … 29 15 30 16 if ((in = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE); 31 intNX = in[0].matrix.Naxis[0];32 intNY = in[0].matrix.Naxis[1];17 NX = in[0].matrix.Naxis[0]; 18 NY = in[0].matrix.Naxis[1]; 33 19 34 intsx = atof (argv[3]);35 intsy = atof (argv[4]);36 intnx = atof (argv[5]);37 intny = atof (argv[6]);20 sx = atof (argv[3]); 21 sy = atof (argv[4]); 22 nx = atof (argv[5]); 23 ny = atof (argv[6]); 38 24 39 intSx = atof (argv[7]);40 intSy = atof (argv[8]);41 intNx = atof (argv[9]);42 intNy = atof (argv[10]);25 Sx = atof (argv[7]); 26 Sy = atof (argv[8]); 27 Nx = atof (argv[9]); 28 Ny = atof (argv[10]); 43 29 44 30 if ((Sy + ny > Ny) || (Sx + nx > Nx)) { 45 gprint (GP_ERR, " source pixels extend beyond target pixels\n");31 gprint (GP_ERR, "mismatch between source and dest regions\n"); 46 32 gprint (GP_ERR, "%d + %d > %d or %d + %d > %d\n", Sy, ny, Ny, Sx, nx, Nx); 47 //return (FALSE);33 return (FALSE); 48 34 } 49 50 // XXX : allow source region to fall outside source image51 35 52 36 /* region is not on first image */ … … 55 39 (sy > in[0].matrix.Naxis[1])) { 56 40 gprint (GP_ERR, "region outside of source image\n"); 57 //return (FALSE);41 return (FALSE); 58 42 } 59 43 44 if ((Sx + nx > Nx) || (Sy + ny > Ny)) { 45 gprint (GP_ERR, "source region larger than dest region\n"); 46 return (FALSE); 47 } 60 48 if ((Sx < 0) || (Sy < 0)) { 61 49 gprint (GP_ERR, "dest region out of range\n"); 62 //return (FALSE);50 return (FALSE); 63 51 } 64 52 … … 88 76 } 89 77 90 // (NX,NY) : source image dimensions 91 // (Nx,Ny) : target image dimensions 92 93 // allow (sx, sy), (Sx, Sy) to be off image 94 // allow (sx+nx, sy+ny) to be off image 95 96 // if (sx < 0) { 97 // nx += sx; 98 // sx = 0; 99 // } 100 // if (sx > NX) sx = NX; 101 // 102 // if (Sx < 0) { 103 // Nx += sx; 104 // sx = 0; 105 // } 106 // if (sx > NX) sx = NX; 107 108 float *Vin = (float *)(in[0].matrix.buffer); 109 float *Vout = (float *)(out[0].matrix.buffer); 110 111 if (initOutput) { 112 for (int j = 0; j < Ny; j++) { 113 for (int i = 0; i < Nx; i++) { 114 Vout[i + Nx*j] = initValue; 115 } 116 } 117 } 118 119 int Nps = NX*NY; 120 int Npt = Nx*Ny; 121 122 for (int j = 0; j < ny; j++) { 123 if (j + sy < 0) continue; // not yet on source image 124 if (j + Sy < 0) continue; // not yet on target image 125 if (j + sy >= NY) continue; // past edge of source image 126 if (j + Sy >= Ny) continue; // past edge of target image 127 128 // Vin = (float *)(in[0].matrix.buffer) + (j + sy)*in[0].matrix.Naxis[0] + sx; 129 // Vout = (float *)(out[0].matrix.buffer) + (j + Sy)*out[0].matrix.Naxis[0] + Sx; 130 131 for (int i = 0; i < nx; i++) { 78 for (j = 0; j < ny; j++) { 79 if (j + sy < 0) continue; 80 if (j + sy >= NY) continue; 81 Vin = (float *)(in[0].matrix.buffer) + (j + sy)*in[0].matrix.Naxis[0] + sx; 82 Vout = (float *)(out[0].matrix.buffer) + (j + Sy)*out[0].matrix.Naxis[0] + Sx; 83 for (i = 0; i < nx; i++, Vin++, Vout++) { 132 84 if (i + sx < 0) continue; 133 85 if (i + sx >= NX) continue; 134 if (i + Sx < 0) continue; 135 if (i + Sx >= Nx) continue; 136 137 int ps = i + sx + (j + sy)*NX; 138 int pt = i + Sx + (j + Sy)*Nx; 139 140 myAssert (pt >= 0, "oops 1"); 141 myAssert (pt < Npt, "oops 2"); 142 143 myAssert (ps >= 0, "oops 3"); 144 myAssert (ps < Nps, "oops 4"); 145 146 Vout[pt] = Vin[ps]; 86 *Vout = *Vin; 147 87 } 148 88 } … … 151 91 152 92 } 93 -
trunk/Ohana/src/opihi/cmd.data/init.c
r41322 r41340 3 3 4 4 int accum PROTO((int, char **)); 5 int antialias PROTO((int, char **));6 5 int applyfit PROTO((int, char **)); 7 6 int applyfit1d PROTO((int, char **)); … … 68 67 int join PROTO((int, char **)); 69 68 int jpeg PROTO((int, char **)); 70 int kapamemory PROTO((int, char **));71 69 int kern PROTO((int, char **)); 72 70 int keyword PROTO((int, char **)); … … 81 79 int lookup PROTO((int, char **)); 82 80 int matrix PROTO((int, char **)); 83 int match1d PROTO((int, char **));84 81 int match2d PROTO((int, char **)); 85 82 int mkrgb PROTO((int, char **)); 86 83 int mcreate PROTO((int, char **)); 87 84 int medacc PROTO((int, char **)); 88 int mgaussdev PROTO((int, char **));89 85 int mget PROTO((int, char **)); 90 86 int mget3d PROTO((int, char **)); … … 103 99 int parity PROTO((int, char **)); 104 100 int point PROTO((int, char **)); 105 int pdf PROTO((int, char **));106 101 int ps PROTO((int, char **)); 107 102 int vprint PROTO((int, char **)); … … 116 111 int queuesubstr PROTO((int, char **)); 117 112 int queuesize PROTO((int, char **)); 118 int queue2book PROTO((int, char **));119 113 int rd PROTO((int, char **)); 120 114 int rdseg PROTO((int, char **)); … … 162 156 int vgauss PROTO((int, char **)); 163 157 int vlorentz PROTO((int, char **)); 164 int vsigmoid PROTO((int, char **));165 158 int vellipse PROTO((int, char **)); 166 159 int vmaxwell PROTO((int, char **)); … … 170 163 int vzload PROTO((int, char **)); 171 164 int vstats PROTO((int, char **)); 172 int vstats PROTO((int, char **));173 int virls PROTO((int, char **));174 int vwtmean PROTO((int, char **));175 165 int vroll PROTO((int, char **)); 176 166 int vshift PROTO((int, char **)); 177 167 int vpeaks PROTO((int, char **)); 178 int vtransitions PROTO((int, char **));179 168 int vpop PROTO((int, char **)); 180 169 int vsmooth PROTO((int, char **)); … … 198 187 static Command cmds[] = { 199 188 {1, "accum", accum, "accumulate vector values in another vector"}, 200 {1, "antialias", antialias, "set anti-alias sigma value for display"},201 189 {1, "applyfit", applyfit1d, "apply 1-d fit to new vector"}, 202 190 {1, "applyfit1d", applyfit1d, "apply 1-d fit to new vector"}, … … 267 255 {1, "join", join, "find the join of two ID vectors"}, 268 256 {1, "jpeg", jpeg, "convert display image to JPEG"}, 269 {1, "kapamemory", kapamemory, "manage kapa memory dump options"},270 257 {1, "kern", kern, "convolve with 3x3 kernel"}, 271 258 {1, "keyword", keyword, "extract a FITS keyword from image header"}, … … 278 265 {1, "imcreate", mcreate, "create an image"}, 279 266 {1, "medacc", medacc, "accumulate vector values in another vector"}, 280 {1, "mgaussdev", mgaussdev, "generate a gaussian deviate image"},281 267 {1, "mget", mget, "extract a vector from an image"}, 282 268 {1, "mget3d", mget3d, "extract a vector from a 3D image"}, … … 287 273 {1, "medimage", medimage_command, "median image manipulation"}, 288 274 {1, "matrix", matrix, "matrix math operations"}, 289 {1, "match1d", match1d, "match 2 vectors and return matched indexes"},290 275 {1, "match2d", match2d, "match 2 pairs of X,Y vectors and return matched indexes"}, 291 276 {1, "mkrgb", mkrgb, "convert 3 images to rgb jpeg (use Kapa for better control)"}, … … 304 289 {1, "ppm", jpeg, "convert display graphic to PPM"}, 305 290 {1, "ps", ps, "convert display to PostScript"}, 306 {1, "pdf", pdf, "convert display to PDF"},307 291 {1, "print_vectors", vprint, "print a set of vectors"}, 308 292 {1, "vprint", vprint, "print a set of vectors"}, … … 317 301 {1, "queuesize", queuesize, "show queue size"}, 318 302 {1, "queuesubstr", queuesubstr, "bulk replace strings in queue"}, 319 {1, "queue2book", queue2book, "convert queue with ipptool output to book"},320 {1, "ipptool2book", queue2book, "convert queue with ipptool output to book"},321 303 {1, "rd", rd, "load fits image"}, 322 304 {1, "rdseg", rdseg, "read a segment of an image from a file"}, … … 365 347 {1, "vgauss", vgauss, "fit a Gaussian to a vector"}, 366 348 {1, "vlorentz", vlorentz, "fit a Lorentzian to a vector"}, 367 {1, "vsigmoid", vsigmoid, "fit a Sigmoid to a vector"},368 349 {1, "vellipse", vellipse, "fit a Ellipse to a vector pair"}, 369 350 {1, "vgrid", vgrid, "generate an image from a triplet of vectors"}, … … 373 354 {1, "vload", vload, "load vectors as overlay on image display"}, 374 355 {1, "vmaxwell", vmaxwell, "fit a Maxwellian to a vector"}, 375 {1, "vpeaks", vpeaks, "find coord and flux of peaks in vector"}, 376 {1, "vtransitions", vtransitions, "find points in vector that cross the transition value"}, 356 {1, "vpeaks", vpeaks, "fine coord and flux of peaks in vector"}, 377 357 {1, "vpop", vpop, "remove first element of a vector"}, 378 358 {1, "vroll", vroll, "roll vector elements by 1 entry"}, … … 380 360 {1, "vsmooth", vsmooth, "Gaussian smooth of a vector"}, 381 361 {1, "vstats", vstats, "statistics on a vector"}, 382 {1, "vwtmean", vwtmean, "weighted mean of a vector"},383 {1, "virls", virls, "IRLS mean of a vector"},384 362 {1, "vzload", vzload, "load vectors as overlay on image display (scaled points)"}, 385 363 {1, "vsh", vsh, "Vector Spherical Harmonics"}, -
trunk/Ohana/src/opihi/cmd.data/interpolate_presort.c
r41164 r41340 7 7 double x0, dx, dy, y0; 8 8 Vector *xout, *yout, *xin, *yin; 9 10 int N;11 int FillEnds = FALSE;12 if ((N = get_argument (argc, argv, "-fill-ends"))) {13 FillEnds = TRUE;14 remove_argument (N, &argc, argv);15 }16 9 17 10 /** check basic syntax **/ … … 43 36 y0 = yin[0].elements.Flt[0]; 44 37 45 // fill in the start with NANs 46 for (i = 0; (i < xout[0].Nelements) && (xout[0].elements.Flt[i] < xin[0].elements.Flt[0]); i++) { 47 yout[0].elements.Flt[i] = FillEnds ? yin[0].elements.Flt[0] : NAN; 48 } 38 /* in and out vectors are sorted */ 39 j = 0; 49 40 50 41 // every output pixel should get a value unless 51 42 // we are below the lowest in or above the highest in 52 for ( j = 0; (i < xout[0].Nelements) && (j < xin[0].Nelements - 1); ) {43 for (i = 0, j = 0; (i < xout[0].Nelements) && (j < xin[0].Nelements - 1); ) { 53 44 54 45 yout[0].elements.Flt[i] = NAN; … … 75 66 76 67 // fill in the rest with NANs 77 int NinLast = xin[0].Nelements - 1;78 68 while (i < yout[0].Nelements) { 79 yout[0].elements.Flt[i] = FillEnds ? yin[0].elements.Flt[NinLast] :NAN;69 yout[0].elements.Flt[i] = NAN; 80 70 i++; 81 71 } 82 72 83 73 return (TRUE); 74 84 75 } -
trunk/Ohana/src/opihi/cmd.data/list_vectors.c
r41269 r41340 32 32 } 33 33 34 switch (vec->type) { 35 case OPIHI_FLT: 36 if (Variable) { 37 set_str_variable (Variable, "FLT"); 38 } else { 39 gprint (GP_LOG, "%s : FLT\n", argv[1]); 40 } 41 break; 42 case OPIHI_INT: 43 if (Variable) { 44 set_str_variable (Variable, "INT"); 45 } else { 46 gprint (GP_LOG, "%s : INT\n", argv[1]); 47 } 48 break; 49 case OPIHI_STR: 50 if (Variable) { 51 set_str_variable (Variable, "STR"); 52 } else { 53 gprint (GP_LOG, "%s : STR\n", argv[1]); 54 } 55 break; 34 if (vec->type == OPIHI_FLT) { 35 if (Variable) { 36 set_str_variable (Variable, "FLT"); 37 } else { 38 gprint (GP_LOG, "%s : FLT\n", argv[1]); 39 } 40 } else { 41 if (Variable) { 42 set_str_variable (Variable, "INT"); 43 } else { 44 gprint (GP_LOG, "%s : INT\n", argv[1]); 45 } 56 46 } 57 47 if (Variable) free (Variable); -
trunk/Ohana/src/opihi/cmd.data/medimage_commands.c
r41164 r41340 15 15 int medimage_add (int argc, char **argv) { 16 16 17 int N;18 17 Buffer *image; 19 Buffer *var = NULL; 20 21 if ((N = get_argument (argc, argv, "-variance"))) { 22 remove_argument (N, &argc, argv); 23 if ((var = SelectBuffer (argv[N], OLDBUFFER, TRUE)) == NULL) return (FALSE); 24 remove_argument (N, &argc, argv); 25 } 26 27 if (argc != 3) { 28 gprint (GP_ERR, "USAGE: medimage add (name) (image) [-variance variance]\n"); 18 19 if (argc != 3) { 20 gprint (GP_ERR, "USAGE: medimage add (name) (image)\n"); 29 21 gprint (GP_ERR, " add the given image to the set of images to be medianed\n"); 30 gprint (GP_ERR, " optionally supply variance image (for weighted calculations)\n");31 22 return FALSE; 32 23 } 33 24 34 25 if ((image = SelectBuffer (argv[2], OLDBUFFER, TRUE)) == NULL) return (FALSE); 35 36 if (var) {37 if ((var->matrix.Naxis[0] != image->matrix.Naxis[0]) ||38 (var->matrix.Naxis[1] != image->matrix.Naxis[1])) {39 gprint (GP_ERR, "variance buffer does not match image buffer dimensions\n");40 return FALSE;41 }42 }43 26 44 27 MedImageType *median = FindMedImage (argv[1]); … … 63 46 // new image should match existing medimage dimensions 64 47 65 // AddMedImage (median, image, var);66 48 int Ninput = median->Ninput; 67 49 median->Ninput ++; 68 REALLOCATE (median->flx, float *, median->Ninput); 69 REALLOCATE (median->var, float *, median->Ninput); 70 71 ALLOCATE (median->flx[Ninput], float, median->Nx*median->Ny); 72 memcpy (median->flx[Ninput], image->matrix.buffer, sizeof(float)*median->Nx*median->Ny); 73 74 median->var[Ninput] = NULL; 75 if (var) { 76 ALLOCATE (median->var[Ninput], float, median->Nx*median->Ny); 77 memcpy (median->var[Ninput], var->matrix.buffer, sizeof(float)*median->Nx*median->Ny); 50 REALLOCATE (median->buffers, float *, median->Ninput); 51 52 ALLOCATE (median->buffers[Ninput], float, median->Nx*median->Ny); 53 memcpy (median->buffers[Ninput], image->matrix.buffer, sizeof(float)*median->Nx*median->Ny); 54 55 return TRUE; 56 } 57 58 int medimage_calc (int argc, char **argv) { 59 60 int ix, iy, n, N; 61 Buffer *output; 62 63 int CALC_MEAN = FALSE; 64 if ((N = get_argument (argc, argv, "-mean"))) { 65 CALC_MEAN = TRUE; 66 remove_argument (N, &argc, argv); 67 } 68 69 if (argc != 3) { 70 gprint (GP_ERR, "USAGE: medimage calc (name) (output) [-mean]\n"); 71 gprint (GP_ERR, " calculate the median image for the median image set\n"); 72 return FALSE; 73 } 74 75 MedImageType *median = FindMedImage (argv[1]); 76 if (!median) { 77 gprint (GP_ERR, "median image %s not found\n", argv[1]); 78 return FALSE; 79 } 80 81 if ((output = SelectBuffer (argv[2], ANYBUFFER, TRUE)) == NULL) return (FALSE); 82 83 int Ninput = median->Ninput; 84 int Nx = median->Nx; 85 int Ny = median->Ny; 86 87 float *value = NULL; 88 ALLOCATE (value, float, Ninput); 89 90 gfits_free_matrix (&output->matrix); 91 gfits_free_header (&output->header); 92 if (!CreateBuffer (output, Nx, Ny, -32, 0.0, 1.0)) return FALSE; 93 94 float *outvalue = (float *) output->matrix.buffer; 95 96 for (iy = 0; iy < Ny; iy++) { 97 for (ix = 0; ix < Nx; ix++) { 98 99 int N = 0; 100 int Npix = ix + Nx*iy; 101 for (n = 0; n < Ninput; n++) { 102 float v = median->buffers[n][Npix]; 103 if (!isfinite(v)) continue; 104 value[N] = v; 105 N++; 106 } 107 if (N == 0) continue; 108 109 if (CALC_MEAN) { 110 float sum = 0.0; 111 for (n = 0; n < N; n++) { 112 sum += value[n]; 113 } 114 outvalue[Npix] = sum / (float) N; 115 } else { 116 fsort (value, N); 117 outvalue[Npix] = value[(int)(0.5*N)]; 118 } 119 } 78 120 } 79 121 … … 82 124 83 125 /* 84 int medimage_save (int argc, char **argv) {85 86 int N;87 88 int APPEND = FALSE;89 if ((N = get_argument (argc, argv, "-append"))) {90 APPEND = TRUE;91 remove_argument (N, &argc, argv);92 }93 94 if (argc != 3) {95 gprint (GP_ERR, "USAGE: medimage save (name) (filename) [-append]\n");96 return FALSE;97 }98 99 if (!SaveMedImage(argv[2], argv[1], APPEND)) {100 gprint (GP_ERR, "failed to save medimage %s\n", argv[1]);101 return (FALSE);102 }103 return TRUE;104 }105 106 int medimage_load (int argc, char **argv) {107 108 if (argc != 3) {109 gprint (GP_ERR, "USAGE: medimage load (name) (filename)\n");110 return FALSE;111 }112 113 if (!LoadMedImage(argv[2], argv[1])) {114 gprint (GP_ERR, "failed to load medimage %s\n", argv[1]);115 return (FALSE);116 }117 return TRUE;118 }126 int medimage_save (int argc, char **argv) { 127 128 int N; 129 130 int APPEND = FALSE; 131 if ((N = get_argument (argc, argv, "-append"))) { 132 APPEND = TRUE; 133 remove_argument (N, &argc, argv); 134 } 135 136 if (argc != 3) { 137 gprint (GP_ERR, "USAGE: medimage save (name) (filename) [-append]\n"); 138 return FALSE; 139 } 140 141 if (!SaveMedImage(argv[2], argv[1], APPEND)) { 142 gprint (GP_ERR, "failed to save medimage %s\n", argv[1]); 143 return (FALSE); 144 } 145 return TRUE; 146 } 147 148 int medimage_load (int argc, char **argv) { 149 150 if (argc != 3) { 151 gprint (GP_ERR, "USAGE: medimage load (name) (filename)\n"); 152 return FALSE; 153 } 154 155 if (!LoadMedImage(argv[2], argv[1])) { 156 gprint (GP_ERR, "failed to load medimage %s\n", argv[1]); 157 return (FALSE); 158 } 159 return TRUE; 160 } 119 161 */ 120 162 -
trunk/Ohana/src/opihi/cmd.data/peak.c
r41164 r41340 39 39 if (*X < start) continue; 40 40 if (*X > end) continue; 41 if (!isfinite(*Y)) continue;42 41 if (*Y < ymax) continue; 43 42 xmax = *X; … … 64 63 if (*X < start) continue; 65 64 if (*X > end) continue; 66 if (!isfinite(*Y)) continue;67 65 if (*Y < ymax) continue; 68 66 xmax = *X; -
trunk/Ohana/src/opihi/cmd.data/print_vectors.c
r41269 r41340 56 56 if (vec[i][0].type == OPIHI_FLT) { 57 57 gprint (GP_LOG, "%f ", vec[i][0].elements.Flt[j]); 58 } 59 if (vec[i][0].type == OPIHI_INT) { 58 } else { 60 59 gprint (GP_LOG, OPIHI_INT_FMT" ", vec[i][0].elements.Int[j]); 61 } 62 if (vec[i][0].type == OPIHI_STR) { 63 gprint (GP_LOG, "%s ", vec[i][0].elements.Str[j]); 64 } 60 } 65 61 } 66 62 } -
trunk/Ohana/src/opihi/cmd.data/read_vectors.c
r41305 r41340 35 35 36 36 // vector types 37 enum {COLTYPE_NONE, COLTYPE_FLT, COLTYPE_INT, COLTYPE_TIME, COLTYPE_ DATE, COLTYPE_CHAR, COLTYPE_STR, COLTYPE_HMS};37 enum {COLTYPE_NONE, COLTYPE_FLT, COLTYPE_INT, COLTYPE_TIME, COLTYPE_CHAR}; 38 38 39 39 static int Nvec = 0; … … 91 91 gprint (GP_ERR, " -skip N : skip N lines before reading\n"); 92 92 gprint (GP_ERR, " column names may include a type: name:type\n"); 93 gprint (GP_ERR, " type is int, float, char, str, time, date, hms\n");93 gprint (GP_ERR, " type is int, float, char, time\n"); 94 94 gprint (GP_ERR, " for char, values are placed into a list $name:0 - $name:n\n"); 95 gprint (GP_ERR, " for str, values are placed into a string-typed vector\n");96 gprint (GP_ERR, " for hms, values are sexigesimal values HH:MM:SS (good for degrees as well)\n");97 gprint (GP_ERR, " for date, values are human-readable date strings YYYY/MM/DD\n");98 95 gprint (GP_ERR, " for time, values are human-readable date/time strings YYYY/MM/DD,hh:mm:ss\n"); 99 gprint (GP_ERR, " date & time values are stored as a float using the TIMEFORMAT, TIMEREF values for the conversion\n");96 gprint (GP_ERR, " the resulting vector is a float based on the TIMEFORMAT, TIMEREF values\n"); 100 97 101 98 gprint (GP_ERR, " -fits options:\n"); … … 155 152 if (!strcasecmp(ptr, "int")) { coltype[i] = COLTYPE_INT; } 156 153 if (!strcasecmp(ptr, "char")) { coltype[i] = COLTYPE_CHAR; } 157 if (!strcasecmp(ptr, "str")) { coltype[i] = COLTYPE_STR; }158 if (!strcasecmp(ptr, "date")) { coltype[i] = COLTYPE_DATE; }159 154 if (!strcasecmp(ptr, "time")) { coltype[i] = COLTYPE_TIME; } 160 if (!strcasecmp(ptr, "hms")) { coltype[i] = COLTYPE_HMS; }161 155 if (!coltype[i]) goto bad_colname; 162 156 } … … 216 210 break; 217 211 case COLTYPE_FLT: 218 case COLTYPE_HMS:219 212 case COLTYPE_TIME: 220 case COLTYPE_DATE: 213 // note that COLTYPE_TIME is a type of float 221 214 ResetVector (vec[i], OPIHI_FLT, NELEM); 222 break;223 case COLTYPE_STR:224 ResetVector (vec[i], OPIHI_STR, NELEM);225 215 break; 226 216 case COLTYPE_CHAR: … … 297 287 time_t tvalue; 298 288 int readStatus = FALSE; 299 int dataStatus = FALSE;300 289 // need to make the if cases for coltype[i] 301 290 switch (coltype[i]) { … … 322 311 break; 323 312 } 324 case COLTYPE_STR:325 {326 // I need to get an isolated word in 'value' with the string value of this field327 char *ptr = IsCSV ? ptrparse_csv (col[i], c0) : ptrparse (col[i], c0);328 char *value = NULL;329 if (IsCSV) {330 char *end = parse_nextword_csv (ptr);331 if (end) {332 value = end ? strncreate (ptr, end - ptr) : strcreate (ptr);333 }334 } else {335 value = thisword(ptr);336 }337 vec[i][0].elements.Str[Nelem] = value; // needs to be freed later.338 break;339 }340 313 case COLTYPE_FLT: 341 314 readStatus = IsCSV ? dparse_csv (&dvalue, col[i], c0) : dparse (&dvalue, col[i], c0); … … 347 320 vec[i][0].elements.Flt[Nelem] = readStatus ? dvalue : NAN; 348 321 break; 349 case COLTYPE_DATE: {350 char *string = NULL;351 if (IsCSV) {352 char *ptr = ptrparse_csv (col[i], c0);353 string = strcreate (ptr); // create separate string (NULL-safe)354 ptr = (string == NULL) ? NULL : strchr (string, ',');355 if (ptr != NULL) *ptr = 0; // place an EOL here so parsing does not go past the comma356 } else {357 char *ptr = ptrparse (col[i], c0); // NULL-safe358 string = getword (ptr); // NULL-safe359 }360 tvalue = ohana_date_to_sec (string); // NULL-safe (returns 0)361 dvalue = TimeValue (tvalue, TimeReference, TimeFormat);362 vec[i][0].elements.Flt[Nelem] = string ? dvalue : NAN;363 FREE (string);364 break;365 }366 case COLTYPE_HMS: {367 char *ptr = IsCSV ? ptrparse_csv (col[i], c0) : ptrparse (col[i], c0);368 char *string = strcreate (ptr); // make a copy so we can munge it in ohana_dms_to_ddd369 dataStatus = ohana_dms_to_ddd (&dvalue, string);370 vec[i][0].elements.Flt[Nelem] = ((string != NULL) && dataStatus) ? dvalue : NAN;371 FREE (string);372 break;373 }374 322 } 375 323 if (!readStatus && VERBOSE) { … … 397 345 break; 398 346 case COLTYPE_FLT: 399 case COLTYPE_HMS:400 347 case COLTYPE_TIME: 401 case COLTYPE_DATE:402 348 ResetVector (vec[i], OPIHI_FLT, NELEM); 403 break;404 case COLTYPE_STR:405 ResetVector (vec[i], OPIHI_STR, NELEM);406 349 break; 407 350 case COLTYPE_CHAR: … … 423 366 break; 424 367 case COLTYPE_FLT: 425 case COLTYPE_HMS:426 368 case COLTYPE_TIME: 427 case COLTYPE_DATE:428 369 ResetVector (vec[i], OPIHI_FLT, Nelem); 429 break;430 case COLTYPE_STR:431 ResetVector (vec[i], OPIHI_STR, Nelem);432 370 break; 433 371 case COLTYPE_CHAR: … … 531 469 } 532 470 533 // by default, we now store a string-type field as a string-type vector. 534 535 // if CharAsList is selected (and My < 10000), char fields will be saved as $NAME:0 - $NAME:m for m rows 536 537 // if CharAsVectors is selected, char fields will be saved as vectors NAME:0 -- NAME:n for n characters 538 471 // if CharAsVectors, char fields will be saved as vectors NAME:0 -- NAME:n for n characters 472 // else char fields will be saved as $NAME:0 - $NAME:m for m rows 539 473 // if (Ny > 10000), force CharAsVectors 540 474 int CharAsVectors = FALSE; … … 542 476 remove_argument (N, &argc, argv); 543 477 CharAsVectors = TRUE; 544 }545 int CharAsList = FALSE;546 if ((N = get_argument (argc, argv, "-char-list"))) {547 remove_argument (N, &argc, argv);548 CharAsList = TRUE;549 478 } 550 479 … … 722 651 if (!FITS_TRANSPOSE) { 723 652 // read string column into a list rather than a vector 724 if (!strcmp (type, "char")) { 725 // save char-type field as a List: 726 if (CharAsList && (Ny < 3000)) { 727 char *fieldName = argv[i]; 728 char *Ptr = data; 729 char varname[1024]; // used as a buffer for the names of string fields 730 for (j = 0; j < Ny; j++) { 731 set_list_varname (varname, fieldName, j, FALSE); 732 char *value = strncreate (&Ptr[j*Nval], Nval); 733 // replace instances of $ with _ 734 char *p = strchr (value, '$'); 735 while (p) { 736 *p = '_'; 737 p = strchr (p, '$'); 738 } 739 set_str_variable (varname, value); 740 free (value); 653 if (!strcmp (type, "char") && !CharAsVectors && (Ny < 3000)) { 654 char *fieldName = argv[i]; 655 char *Ptr = data; 656 char varname[1024]; // used as a buffer for the names of string fields 657 for (j = 0; j < Ny; j++) { 658 set_list_varname (varname, fieldName, j, FALSE); 659 char *value = strncreate (&Ptr[j*Nval], Nval); 660 // replace instances of $ with _ 661 char *p = strchr (value, '$'); 662 while (p) { 663 *p = '_'; 664 p = strchr (p, '$'); 741 665 } 742 sprintf (varname, "%s:n", fieldName); 743 set_int_variable (varname, Ny); 744 continue; 666 set_str_variable (varname, value); 667 free (value); 745 668 } 746 // save char-type field as a string-type vector: 747 if (!CharAsVectors) { 748 Vector *myVector = NULL; 749 sprintf (name, "%s", argv[i]); 750 if ((myVector = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name\n"); 751 ResetVector (myVector, OPIHI_STR, Ny); 752 753 char *Ptr = data; 754 for (j = 0; j < Ny; j++) { 755 myVector[0].elements.Str[j] = strncreate (&Ptr[j*Nval], Nval); 756 // replace instances of $ with _ 757 char *p = strchr (myVector[0].elements.Str[j], '$'); 758 while (p) { *p = '_'; p = strchr (p, '$'); } 759 } 760 continue; 761 } 669 sprintf (varname, "%s:n", fieldName); 670 set_int_variable (varname, Ny); 671 continue; 762 672 } 763 673 764 674 // define the multifield vector names (Nval vectors x Ny elements) 765 // CharAsVectors is handled below automatically766 675 ALLOCATE (vec, Vector *, Nval); 767 676 for (j = 0; j < Nval; j++) { -
trunk/Ohana/src/opihi/cmd.data/roll.c
r41164 r41340 3 3 int roll (int argc, char **argv) { 4 4 5 int Nbytes, Nextra; 6 int dX, dx, dy, nx, ny; 5 7 Buffer *buf; 6 7 // this function is probably not needed8 gprint (GP_ERR, "ERROR: use 'shift' instead of 'roll'\n");9 return (FALSE);10 8 11 9 if (argc != 4) { … … 16 14 if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE); 17 15 18 int dx = atoi (argv[2]); 19 int dy = atoi (argv[3]); 20 21 /* if (dx,dy < 0), we are moving the start position backwards, 22 if (dx,dy > 0), we are moving the start position forward */ 23 24 int Nx = buf[0].matrix.Naxis[0]; 25 int Ny = buf[0].matrix.Naxis[1]; 26 27 if (dy == 0) { 28 // moves in just dx can be done row-by-row 29 30 int dX = abs(dx); 31 int Nbytes = (Nx * Ny - dX) * sizeof (float); 32 int Nextra = dX * sizeof (float); 33 34 if (dx < 0) { 35 memmove (buf[0].matrix.buffer, &buf[0].matrix.buffer[dX*sizeof(float)], Nbytes); 36 memset (&buf[0].matrix.buffer[Nbytes], 0, Nextra); 37 } else { 38 memmove (&buf[0].matrix.buffer[dX*sizeof(float)], buf[0].matrix.buffer, Nbytes); 39 memset (buf[0].matrix.buffer, 0, Nextra); 40 } 41 42 return TRUE; 16 dx = atof (argv[2]); 17 dy = atof (argv[3]); 18 if (dy != 0) { 19 gprint (GP_ERR, "only x rolls implemented for now\n"); 43 20 } 44 21 45 if (dx == 0) { 46 // moves in just dy can be done row-by-row 22 /* if (dx < 0), we are moving the start position back by dx pixels, 23 if (dx > 0), we are moving the start position forward by dx pixels */ 24 25 nx = buf[0].matrix.Naxis[0]; 26 ny = buf[0].matrix.Naxis[1]; 47 27 48 ALLOCATE_PTR (output, float, Nx*Ny); 28 dX = abs(dx); 29 Nbytes = nx * ny * sizeof (float); 30 Nextra = (nx * ny + dX) * sizeof (float); 49 31 50 float *input = (float *) buf[0].matrix.buffer;32 REALLOCATE (buf[0].matrix.buffer, char, Nextra); 51 33 52 for (int iy = 0; iy < Ny; iy++) { 53 if (iy + dy < 0) continue; 54 if (iy + dy >= Ny) continue; 55 memcpy (&output[iy*Nx], &input[(iy + dy)*Nx], Nx); 56 } 57 if (dy > 0) { 58 memset (output, 0, dy*Nx*sizeof(float)); 59 } else { 60 int Nbytes = Nx * (Ny - abs(dy)) * sizeof (float); 61 int Nextra = abs(dy) * Nx * sizeof (float); 62 memset (&output[Nbytes], 0, Nextra); 63 } 64 free (buf[0].matrix.buffer); 65 buf[0].matrix.buffer = (char *) output; 66 return TRUE; 34 if (dx < 0) { 35 memmove (buf[0].matrix.buffer, &buf[0].matrix.buffer[dX*sizeof(float)], Nbytes); 36 } else { 37 memmove (&buf[0].matrix.buffer[dX*sizeof(float)], buf[0].matrix.buffer, Nbytes); 67 38 } 68 39 69 ALLOCATE_PTR (output, float, Nx*Ny); 70 float *input = (float *) buf[0].matrix.buffer; 40 REALLOCATE (buf[0].matrix.buffer, char, Nbytes); 71 41 72 for (int iy = 0; iy < Ny; iy++) { 73 if (iy + dy < 0) continue; 74 if (iy + dy >= Ny) continue; 75 for (int ix = 0; ix < Nx; ix++) { 76 if (ix + dx < 0) continue; 77 if (ix + dx >= Nx) continue; 78 output[ix + iy*Nx] = input[(ix + dx) + (iy + dy)*Nx]; 79 } 80 } 81 free (buf[0].matrix.buffer); 82 buf[0].matrix.buffer = (char *) output; 83 return TRUE; 42 return (TRUE); 43 84 44 } 85 45 86 -
trunk/Ohana/src/opihi/cmd.data/rotate.c
r41269 r41340 3 3 int rotate (int argc, char **argv) { 4 4 5 int i, j, NX, NY ;5 int i, j, NX, NY, X, Y, Lx, Ly, N; 6 6 float *in_buff, *out_buff, *c; 7 double Xo, Yo, x, y, X1, Y1;7 double angle, CosAngle, SinAngle, Xo, Yo, dX, dY, fx, fy, x, y, X1, Y1; 8 8 double pc11, pc12, pc21, pc22, PC11, PC12, PC21, PC22; 9 9 Buffer *buf; 10 10 11 //Xo = 0;12 //Yo = 0;13 //if ((N = get_argument (argc, argv, "-center"))) {14 //remove_argument (N, &argc, argv);15 //Xo = atof(argv[N]);16 //remove_argument (N, &argc, argv);17 //Yo = atof(argv[N]);18 //remove_argument (N, &argc, argv);19 //}11 Xo = 0; 12 Yo = 0; 13 if ((N = get_argument (argc, argv, "-center"))) { 14 remove_argument (N, &argc, argv); 15 Xo = atof(argv[N]); 16 remove_argument (N, &argc, argv); 17 Yo = atof(argv[N]); 18 remove_argument (N, &argc, argv); 19 } 20 20 21 21 if (argc != 3) { … … 221 221 } 222 222 223 doubleangle = atof (argv[2]);224 doubleCosAngle = cos (angle*RAD_DEG);225 doubleSinAngle = sin (angle*RAD_DEG);223 angle = atof (argv[2]); 224 CosAngle = cos (angle*RAD_DEG); 225 SinAngle = sin (angle*RAD_DEG); 226 226 227 227 gprint (GP_ERR, "rotating: %f %f %f\n", angle, CosAngle, SinAngle); 228 228 229 // we are rotating about the center pixel, (NX/2, NY/2),230 // but we are then putting the result in a new image231 // of size (Lx,Ly).232 233 / / (x,y) = (i - Nx/2),(j - Ny/2)234 // (x',y') = R(theta) (x,y)235 // (I,J) = (x' + Lx/2),(y' + Ly/2)236 237 int Lx = NX*fabs(CosAngle) + NY*fabs(SinAngle);238 int Ly = NX*fabs(SinAngle) + NY*fabs(CosAngle);229 Lx = NX*fabs(CosAngle) + NY*fabs(SinAngle); 230 Ly = NX*fabs(SinAngle) + NY*fabs(CosAngle); 231 dX = MAX(0,NY*SinAngle); 232 dY = MAX(0,-NX*SinAngle); 233 /* 234 gprint (GP_ERR, "%f %f --> ", Xo, Yo); 235 X1 = Xo*CosAngle - Yo*SinAngle + dX; 236 Y1 = Xo*SinAngle + Yo*CosAngle + dY; 237 gprint (GP_ERR, "%f %f\n", X1, Y1); 238 */ 239 239 240 240 /* fix reference pixel */ 241 241 gfits_scan (&buf[0].header, "CRPIX1", "%lf", 1, &Xo); 242 242 gfits_scan (&buf[0].header, "CRPIX2", "%lf", 1, &Yo); 243 X1 = (Xo - NX/2)*CosAngle + (Yo - NY/2)*SinAngle + Lx/2; 244 Y1 = (NX/2 - Xo)*SinAngle + (Yo - NY/2)*CosAngle + Ly/2; 243 /* 244 X1 = (Xo - dX)*CosAngle - (Yo - dY)*SinAngle; 245 Y1 = (dX - Xo)*SinAngle + (Yo - dY)*CosAngle; 246 */ 247 X1 = Xo*CosAngle - Yo*SinAngle + dX; 248 Y1 = Xo*SinAngle + Yo*CosAngle + dY; 245 249 gfits_modify (&buf[0].header, "CRPIX1", "%lf", 1, X1); 246 250 gfits_modify (&buf[0].header, "CRPIX2", "%lf", 1, Y1); … … 251 255 gfits_scan (&buf[0].header, "PC002001", "%lf", 1, &pc21); 252 256 gfits_scan (&buf[0].header, "PC002002", "%lf", 1, &pc22); 253 PC11 = pc11*CosAngle +pc21*SinAngle;254 PC12 = pc12*CosAngle +pc22*SinAngle;255 PC21 = pc21*CosAngle -pc11*SinAngle;256 PC22 = pc22*CosAngle -pc12*SinAngle;257 PC11 = pc11*CosAngle - pc21*SinAngle; 258 PC12 = pc12*CosAngle - pc22*SinAngle; 259 PC21 = pc21*CosAngle + pc11*SinAngle; 260 PC22 = pc22*CosAngle + pc12*SinAngle; 257 261 gfits_modify (&buf[0].header, "PC001001", "%le", 1, PC11); 258 262 gfits_modify (&buf[0].header, "PC001002", "%le", 1, PC12); … … 266 270 gfits_create_matrix (&buf[0].header, &buf[0].matrix); 267 271 gfits_print_alt (&buf[0].header, "HISTORY", "%S", 1, "WARNING: rotated image!"); 268 269 272 out_buff = (float *)buf[0].matrix.buffer; 270 271 273 for (j = 0; j < Ly; j++) { 272 274 for (i = 0; i < Lx; i++, out_buff++) { 273 275 274 float xo = (i - Lx/2); 275 float yo = (j - Ly/2); 276 277 x = xo*CosAngle + yo*SinAngle; 278 y = -xo*SinAngle + yo*CosAngle; 279 280 int I = x + NX/2; 281 int J = y + NY/2; 282 283 if (I < 0) continue; 284 if (I >= NX - 1) continue; 285 if (J < 0) continue; 286 if (J >= NY - 1) continue; 287 288 c = &in_buff[I + NX*J]; 289 290 int X = (int) x; 291 int Y = (int) y; 292 double fx = x - X; 293 double fy = y - Y; 294 276 x = (i - dX)*CosAngle + (j - dY)*SinAngle; 277 y = (dX - i)*SinAngle + (j - dY)*CosAngle; 278 X = (int) x; 279 Y = (int) y; 280 281 if (X < 0) continue; 282 if (X >= NX - 1) continue; 283 if (Y < 0) continue; 284 if (Y >= NY - 1) continue; 285 286 c = &in_buff[X + NX*Y]; 287 fx = x - X; 288 fy = y - Y; 295 289 *out_buff = (c[0]*(1-fx) + c[1]*fx)*(1-fy) + (c[NX+1]*fx + c[NX]*(1-fx))*fy; 296 // *out_buff = c[0];297 290 } 298 291 } -
trunk/Ohana/src/opihi/cmd.data/spline.c
r41164 r41340 7 7 int spline_load (int argc, char **argv); 8 8 int spline_save (int argc, char **argv); 9 int spline_print (int argc, char **argv);10 9 int spline_delete (int argc, char **argv); 11 10 int spline_rename (int argc, char **argv); … … 19 18 {1, "load", spline_load, "write a spline to a FITS file"}, 20 19 {1, "save", spline_save, "read a spline from a FITS file"}, 21 {1, "print", spline_print, "print a spline to stdout"},22 20 {1, "delete", spline_delete, "delete a spline"}, 23 21 {1, "rename", spline_rename, "rename a spline"}, … … 37 35 gprint (GP_ERR, " spline load (spline) (filename) : load a spline from a FITS file\n"); 38 36 gprint (GP_ERR, " spline save (spline) (filename) [-append] : save a spline in FITS format\n"); 39 gprint (GP_ERR, " spline print (spline) : print a spline to stdout\n");40 37 41 38 return FALSE; -
trunk/Ohana/src/opihi/cmd.data/spline_commands.c
r41164 r41340 28 28 if (xvec->Nelements != yvec->Nelements) { 29 29 gprint (GP_ERR, "x and y vectors must be the same length\n"); 30 return FALSE;31 }32 33 if (xvec->Nelements < 3) {34 gprint (GP_ERR, "cannot make a spline with fewer than 3 knots\n");35 30 return FALSE; 36 31 } … … 98 93 } 99 94 100 int spline_print (int argc, char **argv) {101 102 int i;103 104 if (argc != 2) {105 gprint (GP_ERR, "USAGE: spline print (name)\n");106 return FALSE;107 }108 109 Spline *myspline = FindSpline (argv[1]);110 if (!myspline) {111 gprint (GP_ERR, "spline %s not found\n", argv[1]);112 return (FALSE);113 }114 115 for (i = 0; i < myspline->Nknots; i++) {116 gprint (GP_LOG, "%lf : %lf : %lf\n", myspline->xk[i], myspline->yk[i], myspline->y2[i]);117 }118 119 return TRUE;120 }121 122 95 int spline_load (int argc, char **argv) { 123 96 … … 136 109 int spline_delete (int argc, char **argv) { 137 110 138 int N, status; 139 140 int QUIET = FALSE; 141 if ((N = get_argument (argc, argv, "-q"))) { 142 QUIET = TRUE; 143 remove_argument (N, &argc, argv); 144 } 111 int status; 112 Spline *spline; 145 113 146 114 if (argc != 2) { … … 149 117 } 150 118 151 Spline *spline = FindSpline (argv[1]);119 spline = FindSpline (argv[1]); 152 120 if (spline == NULL) { 153 if (QUIET) return TRUE;154 121 gprint (GP_ERR, "spline %s not found\n", argv[1]); 155 122 return FALSE; … … 163 130 int spline_rename (int argc, char **argv) { 164 131 132 Spline *spline; 133 165 134 if (argc != 3) { 166 135 gprint (GP_ERR, "USAGE: spline rename (spline) (newname)\n"); … … 168 137 } 169 138 170 Spline *spline = FindSpline (argv[1]);139 spline = FindSpline (argv[1]); 171 140 if (spline == NULL) { 172 141 gprint (GP_ERR, "spline %s not found\n", argv[1]); 173 142 return FALSE; 174 }175 176 Spline *newname = FindSpline (argv[2]);177 if (newname != NULL) {178 DeleteSpline (newname);179 143 } 180 144 … … 183 147 return TRUE; 184 148 } 149 150 /* 151 int spline_listspline (int argc, char **argv) { 152 153 Spline *spline; 154 155 if (argc != 2) { 156 gprint (GP_ERR, "USAGE: spline listspline (spline)\n"); 157 return FALSE; 158 } 159 160 spline = FindSpline (argv[1]); 161 if (spline == NULL) { 162 gprint (GP_ERR, "spline %s not found\n", argv[1]); 163 return FALSE; 164 } 165 166 ListPages (spline); 167 return TRUE; 168 } 169 */ 170 -
trunk/Ohana/src/opihi/cmd.data/test/cut.sh
r41164 r41340 4 4 memtest1 5 5 end 6 7 macro test28 9 mgaussdev z 50 100 0.0 1.010 11 cut z x y_sum x 0 0 z[][0] z[0][]12 cut z x y_median x 0 0 z[][0] z[0][] -median13 cut z x y_mean x 0 0 z[][0] z[0][] -mean14 cut z x y_inner x 0 0 z[][0] z[0][] -inner15 16 end17 18 macro checkrange19 if ($0 != 2)20 echo "USAGE: checkrange (Npts)"21 break22 end23 24 $Npts = $125 if ($Npts % 2)26 $Ncenter = int($Npts / 2)27 $Nquarter = int(0.25 * $Npts)28 $Ns = $Ncenter - $Nquarter29 $Ne = $Ncenter + $Nquarter30 else31 $Ncenter = int($Npts / 2) - 132 $Nquarter = int(0.25 * $Npts)33 $Ns = $Ncenter - $Nquarter34 $Ne = $Ncenter + $Nquarter + 135 end36 if ($Ns < 0)37 echo "error: Ns < 0: $Ns $Ncenter $Nquarter"38 end39 if ($Ne >= $Npts)40 echo "error: Ne >= Npts: $Ne $Ncenter $Nquarter"41 end42 echo "$Npts : $Ncenter : $Nquarter : $Ns $Ne"43 for i 0 $Npts44 echo $i {($i >= $Ns) && ($i <= $Ne)}45 end46 end47 48 6 49 7 # Test if cut works … … 79 37 end 80 38 end 81 82 macro memtest183 84 $i = 085 mcreate tim 100 10086 cut tim xdir imx X 40 4 60 687 # do one to set up memory that should stay used88 89 memory check90 for i 0 10091 cut tim xdir imx X 40 4 60 692 end93 memory check94 95 for i 0 10096 cut tim xdir imx y 40 4 60 697 end98 memory check99 100 for i 0 100101 cut -median tim xdir imx X 40 4 60 6102 end103 memory check104 105 for i 0 100106 cut -median tim xdir imx y 40 4 60 6107 end108 memory check109 110 for i 0 100111 cut -mean tim xdir imx X 40 4 60 6112 end113 memory check114 115 for i 0 100116 cut -mean tim xdir imx y 40 4 60 6117 end118 memory check119 120 end -
trunk/Ohana/src/opihi/cmd.data/test/delete.sh
r41164 r41340 49 49 50 50 end 51 52 # Test delete53 macro test254 55 $PASS = 156 57 for i 0 100058 create v 0 20059 delete v60 end61 end -
trunk/Ohana/src/opihi/cmd.data/test/medimage.sh
r41164 r41340 1 1 2 macro test.mean 3 4 $Nsample = 16 5 medimage delete -q t1 6 for i 0 $Nsample 7 mgaussdev t 50 50 0.0 1.0 8 medimage add t1 t 9 imhist -q t x y -range -10 10 -delta 0.1 10 11 $C0 = 0 12 $C1 = 1.5 13 $C2 = 400 14 $C3 = 0 15 vgauss -q x y con yf 16 # echo $C1 2 macro go 3 mcreate a 30 30 4 for i 0 40 5 set a$i = zero(a) + $i 17 6 end 18 7 19 medimage calc t1 T -mean 20 21 imhist -q T x y -range -10 10 -delta 0.1 22 lim -n 1 x y; clear; box; plot -x hist x y 23 $C0 = 0 24 $C1 = 1.5 25 $C2 = 400 26 $C3 = 0 27 vgauss -q x y con yf 28 echo "expect {1/sqrt($Nsample)} : $C1" 29 plot -c red -x line x yf 8 for i 0 40 9 medimage add t1 a$i 10 end 30 11 end 31 32 macro test.median33 34 $Nsample = 1635 medimage delete -q t136 for i 0 $Nsample37 mgaussdev t 50 50 0.0 1.038 medimage add t1 t39 imhist -q t x y -range -10 10 -delta 0.140 41 $C0 = 042 $C1 = 1.543 $C2 = 40044 $C3 = 045 vgauss -q x y con yf46 end47 48 # note that median of a gaussian distributed variable is not distributed with sigma' = sigma / sqrt(N)49 # (somewhat higher scatter)50 medimage calc t1 T51 52 imhist -q T x y -range -10 10 -delta 0.153 lim -n 1 x y; clear; box; plot -x hist x y54 $C0 = 055 $C1 = 1.556 $C2 = 40057 $C3 = 058 vgauss -q x y con yf59 echo "expect {1/sqrt($Nsample)} : $C1 (actually should be a bit higher)"60 plot -c red -x line x yf61 end62 63 macro test.wtmean64 65 $Nsample = 866 $sig1 = 1.067 $sig2 = 3.068 69 medimage delete -q t170 for i 0 $Nsample71 mgaussdev t 50 50 0.0 $sig172 set v = $sig1^2 + zero(t)73 medimage add t1 t -variance v74 imhist -q t x y -range -10 10 -delta 0.175 76 $C0 = 077 $C1 = 1.578 $C2 = 40079 $C3 = 080 vgauss -q x y con yf81 # echo $C182 end83 84 for i 0 $Nsample85 mgaussdev t 50 50 0.0 $sig286 set v = $sig2^2 + zero(t)87 medimage add t1 t -variance v88 imhist -q t x y -range -10 10 -delta 0.189 90 $C0 = 091 $C1 = 1.592 $C2 = 40093 $C3 = 094 vgauss -q x y con yf95 # echo $C196 end97 98 # note that median of a gaussian distributed variable is not distributed with sigma' = sigma / sqrt(N)99 # (somewhat higher scatter)100 medimage calc t1 T -wtmean101 102 imhist -q T x y -range -10 10 -delta 0.1103 lim -n 1 x y; clear; box; plot -x hist x y104 $C0 = 0105 $C1 = 1.5106 $C2 = 400107 $C3 = 0108 vgauss -q x y con yf109 $S1 = $Nsample / $sig1^2 + $Nsample / $sig2^2110 echo "expect {1/sqrt($S1)} : $C1"111 plot -c red -x line x yf112 end113 114 macro test.irls115 medimage delete -q t1116 $Nsample = 16117 $sig = 1.0118 for i 0 $Nsample119 mgaussdev t 50 50 0.0 $sig120 set v = $sig^2 + zero(t)121 122 set bad = (rnd(t) < 0.05) ? 10*rnd(t) + 5 : zero(t)123 set ts = t + bad124 125 medimage add t1 ts -variance v126 imhist -q t x y -range -10 10 -delta 0.1127 128 $C0 = 0129 $C1 = 1.5130 $C2 = 400131 $C3 = 0132 vgauss -q x y con yf133 # echo $C1134 end135 136 # get stats for straight mean:137 medimage calc t1 Tm -mean138 139 imhist -q Tm x y -range -10 10 -delta 0.1140 lim -n 1 x y; clear; box; plot -x hist x y141 $C0 = 0142 $C1 = 1.5143 $C2 = 400144 $C3 = 0145 vgauss -q x y con yf146 echo "sigma from straight stdev: $C1"147 # stats Tm148 149 plot -c red -x line x yf150 151 # get stats for irls152 medimage calc t1 Ti -irls153 154 imhist -q Ti x y -range -10 10 -delta 0.1155 lim -n 2 x y; clear; box; plot -x hist x y156 $C0 = 0157 $C1 = 1.5158 $C2 = 400159 $C3 = 0160 vgauss -q x y con yf161 echo "sigma from irls: $C1 (ideal is {$sig/sqrt($Nsample)})"162 # stats Ti163 164 plot -c red -x line x yf165 end166 167 168 ###################33169 170 171 macro test.mean.var172 173 $Nsample = 64174 $sig = 2.0175 medimage delete -q t1176 for i 0 $Nsample177 mgaussdev t 100 100 0.0 $sig178 medimage add t1 t179 imhist -q t x y -range -10 10 -delta 0.1180 181 $C0 = 0182 $C1 = 1.5183 $C2 = 400184 $C3 = 0185 vgauss -q x y con yf186 # echo $C1187 end188 189 medimage calc t1 T -mean -variance Tv190 191 imhist -q T x y -range -10 10 -delta 0.1192 lim -n 1 x y; clear; box; plot -x hist x y193 $C0 = 0194 $C1 = 1.5195 $C2 = 400196 $C3 = 0197 vgauss -q x y con yf198 plot -c red -x line x yf199 200 imhist Tv xv yv -range -1 4 -delta 0.1201 lim -n 2 xv yv; clear; box; plot xv yv -x hist202 203 stat Tv204 echo "$C1 vs {sqrt($MEDIAN)} : expect {$sig/sqrt($Nsample)}"205 end206 207 macro test.median.var208 209 $Nsample = 64210 $sig = 2.0211 medimage delete -q t1212 for i 0 $Nsample213 mgaussdev t 50 50 0.0 $sig214 medimage add t1 t215 imhist -q t x y -range -10 10 -delta 0.1216 217 $C0 = 0218 $C1 = 1.5219 $C2 = 400220 $C3 = 0221 vgauss -q x y con yf222 # echo $C1223 end224 225 # note that median of a gaussian distributed variable is not distributed with sigma' = sigma / sqrt(N)226 # (somewhat higher scatter)227 medimage calc t1 T -variance Tv228 229 imhist -q T x y -range -10 10 -delta 0.1230 lim -n 1 x y; clear; box; plot -x hist x y231 $C0 = 0232 $C1 = 1.5233 $C2 = 400234 $C3 = 0235 vgauss -q x y con yf236 plot -c red -x line x yf237 238 imhist Tv xv yv -range -1 4 -delta 0.1239 lim -n 2 xv yv; clear; box; plot xv yv -x hist240 241 stat Tv242 echo "$C1 vs {sqrt($MEDIAN)} : expect {$sig/sqrt($Nsample)}"243 end244 245 macro test.wtmean.var246 247 $Nsample = 32248 $sig1 = 1.0249 $sig2 = 1.0250 251 medimage delete -q t1252 for i 0 $Nsample253 mgaussdev t 50 50 0.0 $sig1254 set v = $sig1^2 + zero(t)255 medimage add t1 t -variance v256 imhist -q t x y -range -10 10 -delta 0.1257 258 $C0 = 0259 $C1 = 1.5260 $C2 = 400261 $C3 = 0262 vgauss -q x y con yf263 # echo $C1264 end265 266 for i 0 $Nsample267 mgaussdev t 50 50 0.0 $sig2268 set v = $sig2^2 + zero(t)269 medimage add t1 t -variance v270 imhist -q t x y -range -10 10 -delta 0.1271 272 $C0 = 0273 $C1 = 1.5274 $C2 = 400275 $C3 = 0276 vgauss -q x y con yf277 # echo $C1278 end279 280 # note that median of a gaussian distributed variable is not distributed with sigma' = sigma / sqrt(N)281 # (somewhat higher scatter)282 medimage calc t1 T -wtmean -variance Tv283 284 imhist -q T x y -range -10 10 -delta 0.1285 lim -n 1 x y; clear; box; plot -x hist x y286 $C0 = 0287 $C1 = 1.5288 $C2 = 400289 $C3 = 0290 vgauss -q x y con yf291 plot -c red -x line x yf292 293 stat -q Tv294 $S1 = $Nsample / $sig1^2 + $Nsample / $sig2^2295 echo $C1 vs {sqrt($MEDIAN)} : expect {1/sqrt($S1)}296 end297 298 macro test.irls.var299 300 $Nsample = 16301 $sig = 1.0302 303 medimage delete -q t1304 for i 0 $Nsample305 mgaussdev t 50 50 0.0 $sig306 set v = $sig^2 + zero(t)307 308 set bad = (rnd(t) < 0.05) ? 10*rnd(t) + 5 : zero(t)309 set ts = t + bad310 311 medimage add t1 ts -variance v312 imhist -q t x y -range -10 10 -delta 0.1313 314 $C0 = 0315 $C1 = 1.5316 $C2 = 400317 $C3 = 0318 vgauss -q x y con yf319 # echo $C1320 end321 322 # get stats for straight mean:323 medimage calc t1 Tm -mean -variance Tv324 325 imhist -q Tm x y -range -10 10 -delta 0.1326 lim -n 1 x y; clear; box; plot -x hist x y327 $C0 = 0328 $C1 = 1.5329 $C2 = 400330 $C3 = 0331 vgauss -q x y con yf332 echo "sigma from straight stdev: $C1"333 # stats Tm334 335 plot -c red -x line x yf336 337 # get stats for irls338 medimage calc t1 Ti -irls -variance Tv339 340 imhist -q Ti x y -range -10 10 -delta 0.1341 lim -n 2 x y; clear; box; plot -x hist x y342 $C0 = 0343 $C1 = 1.5344 $C2 = 400345 $C3 = 0346 vgauss -q x y con yf347 echo "sigma from irls: $C1 (ideal is {$sig/sqrt($Nsample)})"348 # stats Ti349 350 plot -c red -x line x yf351 352 set dTv = sqrt(Tv)353 imhist dTv xv yv -range -1 4 -delta 0.02; lim -n 3 xv yv; clear; box; plot xv yv -x hist354 355 stat -q Tv356 echo $C1 vs {sqrt($MEDIAN)} (ideal is {$sig/sqrt($Nsample)})"357 end358 359 macro test.irls.boot.var360 361 $Nsample = 64362 $sig = 1.0363 364 medimage delete -q t1365 for i 0 $Nsample366 mgaussdev t 200 200 0.0 $sig367 set v = $sig^2 + zero(t)368 369 set bad = (rnd(t) < 0.05) ? 10*rnd(t) + 5 : zero(t)370 set ts = t + bad371 372 mgaussdev noise 200 200 0.0 0.5373 set ts = ts + noise374 375 medimage add t1 ts -variance v376 imhist -q t x y -range -10 10 -delta 0.1377 378 $C0 = 0379 $C1 = 1.5380 $C2 = 400381 $C3 = 0382 vgauss -q x y con yf383 # echo $C1384 end385 386 # get stats for straight mean:387 medimage calc t1 Tm -mean -variance Tv388 389 imhist -q Tm x y -range -10 10 -delta 0.02390 lim -n 1 x y; clear; box; plot -x hist x y391 peak -q x y392 $C0 = $peakpos393 $C1 = 1.5*$sig / sqrt($Nsample)394 $C2 = $peakval395 $C3 = 0396 vgauss -q x y con yf397 echo "sigma from straight stdev: $C1"398 # stats Tm399 400 plot -c red -x line x yf401 402 # get stats for irls403 date404 medimage calc t1 Ti -irls -variance Tv -bootstrap-iter 100405 date406 407 imhist -q Ti x y -range -10 10 -delta 0.02408 lim -n 2 x y; clear; box; plot -x hist x y409 peak -q x y410 $C0 = $peakpos411 $C1 = 1.5*$sig / sqrt($Nsample)412 $C2 = $peakval413 $C3 = 0414 vgauss -q x y con yf415 echo "sigma from irls: $C1 (ideal is {$sig/sqrt($Nsample)})"416 # stats Ti417 418 plot -c red -x line x yf419 420 set dTv = sqrt(Tv)421 imhist dTv xv yv -range 0 {5*$sig/sqrt($Nsample)} -delta 0.02; lim -n 3 xv yv; clear; box; plot xv yv -x hist422 423 stat -q Tv424 echo $C1 vs {sqrt($MEDIAN)} (ideal is {$sig/sqrt($Nsample)})"425 end426 427 ##############################428 macro test.irls.boot.test429 430 $Nsample = 100431 $sig1 = 1.0432 433 medimage delete -q t1434 for i 0 $Nsample435 mgaussdev t 100 100 0.0 $sig1436 set v = $sig1^2 + zero(t)437 438 medimage add t1 t -variance v439 end440 441 # get stats for irls442 medimage calc t1 Ti -irls -variance Tv -bootstrap443 444 imhist -q Ti x y -range {-10*$sig1/sqrt($Nsample)} {10*$sig1/sqrt($Nsample)} -delta 0.01445 lim -n 2 x y; clear; box; plot -x hist x y446 peak -q x y447 $C0 = $peakpos448 $C1 = 1.5*$sig1/sqrt($Nsample)449 $C2 = $peakval450 $C3 = 0451 vgauss x y con yf452 echo "sigma from irls: $C1 (ideal is {$sig1/sqrt($Nsample)})"453 # stats Ti454 455 plot -c red -x line x yf456 457 set dTv = sqrt(Tv)458 imhist dTv xv yv -range 0 {5*$sig1/sqrt($Nsample)} -delta 0.02; lim -n 3 xv yv; clear; box; plot xv yv -x hist459 460 stat -q irls_npt461 $Npix = $MEAN462 463 stat -q Tv464 echo "sigma of irls average: $C1, sqrt(mean) of irls variance: {sqrt($MEAN)}, (ideal is {$sig1/sqrt($Npix)})"465 end466 467 macro test.irls.range.var468 medimage delete -q t1469 for i 0 8470 mgaussdev t 50 50 0.0 1.0471 set v = 1.0 + zero(t)472 473 set bad = (rnd(t) < 0.05) ? 10*rnd(t) + 5 : zero(t)474 set ts = t + bad475 476 medimage add t1 ts -variance v477 imhist -q t x y -range -10 10 -delta 0.1478 479 $C0 = 0480 $C1 = 1.5481 $C2 = 400482 $C3 = 0483 vgauss -q x y con yf484 echo $C1485 end486 487 for i 0 8488 mgaussdev t 50 50 0.0 3.0489 set v = 3.0 + zero(t)490 491 set bad = (rnd(t) < 0.05) ? 10*rnd(t) + 5 : zero(t)492 set ts = t + bad493 494 medimage add t1 ts -variance v495 imhist -q t x y -range -10 10 -delta 0.1496 497 $C0 = 0498 $C1 = 1.5499 $C2 = 400500 $C3 = 0501 vgauss -q x y con yf502 echo $C1503 end504 505 # get stats for straight mean:506 medimage calc t1 Tm -mean -variance Tv507 508 imhist -q Tm x y -range -10 10 -delta 0.1509 lim -n 1 x y; clear; box; plot -x hist x y510 $C0 = 0511 $C1 = 1.5512 $C2 = 400513 $C3 = 0514 vgauss -q x y con yf515 echo $C1516 stats Tm517 518 plot -c red -x line x yf519 520 # get stats for irls521 medimage calc t1 Ti -irls -variance Tv522 523 imhist -q Ti x y -range -10 10 -delta 0.1524 lim -n 2 x y; clear; box; plot -x hist x y525 $C0 = 0526 $C1 = 1.5527 $C2 = 400528 $C3 = 0529 vgauss -q x y con yf530 echo $C1531 stats Ti532 533 plot -c red -x line x yf534 535 stat -q Tv536 echo $C1 vs {sqrt($MEDIAN)}537 538 set dTv = sqrt(Tv)539 imhist dTv xv yv -range -1 4 -delta 0.02; lim -n 3 xv yv; clear; box; plot xv yv -x hist540 end -
trunk/Ohana/src/opihi/cmd.data/threshold.c
r41164 r41340 25 25 remove_argument (N, &argc, argv); 26 26 BinMax = atoi (argv[N]); 27 remove_argument (N, &argc, argv);28 }29 30 float ValMin = NAN;31 float ValMax = NAN;32 if ((N = get_argument (argc, argv, "-vrange"))) {33 remove_argument (N, &argc, argv);34 ValMin = atof (argv[N]);35 remove_argument (N, &argc, argv);36 ValMax = atof (argv[N]);37 27 remove_argument (N, &argc, argv); 38 28 } … … 74 64 } 75 65 76 // ValMin, ValMax not compatible with BinMin, BinMax77 if (isfinite(ValMin)) {78 int binTest = ohana_bisection_double (vecx[0].elements.Flt, vecx[0].Nelements, ValMin);79 BinMin = (vecx[0].elements.Flt[binTest+1] == ValMin) ? binTest : binTest + 1;80 // XXX dangerous: check that this does not run off the end, etc81 }82 if (isfinite(ValMax)) {83 int binTest = ohana_bisection_double (vecx[0].elements.Flt, vecx[0].Nelements, ValMax);84 BinMax = (vecx[0].elements.Flt[binTest+1] == ValMax) ? binTest : binTest + 1;85 // XXX dangerous: check that this does not run off the end, etc86 }87 88 66 // use bisection to find the value 89 67 … … 93 71 94 72 if (!REVERSE) { 95 // this algorithm assumes vecy[BinMax] > threshold, vecy[BinMin] < threshold96 if (vecy[0].elements.Flt[BinMin] > value) {97 gprint (GP_ERR, "ERROR: all values above threshold\n");98 return FALSE;99 }100 if (vecy[0].elements.Flt[BinMax] < value) {101 gprint (GP_ERR, "ERROR: all values below threshold\n");102 return FALSE;103 }104 73 while (Nhi - Nlo > 10) { 105 74 N = 0.5*(Nlo + Nhi); … … 120 89 } 121 90 } else { 122 // this algorithm assumes vecy[BinMin] > threshold, vecy[BinMax] < threshold123 if (vecy[0].elements.Flt[BinMin] < value) {124 gprint (GP_ERR, "ERROR: all values below threshold\n");125 return FALSE;126 }127 if (vecy[0].elements.Flt[BinMax] > value) {128 gprint (GP_ERR, "ERROR: all values above threshold\n");129 return FALSE;130 }131 91 while (Nhi - Nlo > 10) { 132 92 N = 0.5*(Nlo + Nhi); -
trunk/Ohana/src/opihi/cmd.data/tvcolors.c
r41269 r41340 37 37 gprint (GP_ERR, "USAGE: tvcolors (colormap) [-nan red green blue]\n"); 38 38 gprint (GP_ERR, " colormap options : greyscale, -greyscale, rainbow, heat, fullcolor, ruffcolor (also grayscale, -grayscale)\n"); 39 gprint (GP_ERR, " colormap file: if colormap name is given as file:path/to/file, the colormap is read from the file\n"); 39 gprint (GP_ERR, " colormap file name of the for WORD:PATH where WORD = (file,csvf,lgcy,cetf)\n"); 40 gprint (GP_ERR, " lgcy:\n"); 41 gprint (GP_ERR, " the colormap file must contain 4 columns: f R B G; each line defines a color transition.\n"); 42 gprint (GP_ERR, " f: 0 - 1 defines the scale value for the transition\n"); 43 gprint (GP_ERR, " R,B,G: 0 - 1 define the value of the color at the transition point\n"); 44 gprint (GP_ERR, " file:\n"); 40 45 gprint (GP_ERR, " the colormap file must contain 4 columns: f R G B; each line defines a color transition.\n"); 41 46 gprint (GP_ERR, " f: 0 - 1 defines the scale value for the transition\n"); 42 47 gprint (GP_ERR, " R,G,B: 0 - 1 define the value of the color at the transition point\n"); 48 gprint (GP_ERR, " csvf:\n"); 49 gprint (GP_ERR, " the colormap file must contain 4 columns: f,R,G,B separate by commas; each line defines a color transition.\n"); 50 gprint (GP_ERR, " f: 0 - 1 defines the scale value for the transition\n"); 51 gprint (GP_ERR, " R,G,B: 0 - 1 define the value of the color at the transition point\n"); 52 gprint (GP_ERR, " cetf:\n"); 53 gprint (GP_ERR, " the colormap file must 256 rows contain 3 columns: R,G,B separate by commas; each line defines a color transition.\n"); 54 gprint (GP_ERR, " R,G,B: 0 - 1 define the value of the color at the transition point\n"); 55 gprint (GP_ERR, " CETF-format files can be found at : https://peterkovesi.com/projects/colourmaps\n"); 43 56 return (FALSE); 44 57 } -
trunk/Ohana/src/opihi/cmd.data/vgauss.c
r41164 r41340 3 3 /* local private functions */ 4 4 opihi_flt fgaussOD (opihi_flt, opihi_flt *, int, opihi_flt *); 5 int vgauss_apply (int argc, char **argv);6 5 7 6 # define GET_VAR(V,A) \ … … 21 20 Vector *xvec, *yvec, *svec, *ovec; 22 21 char *c, name[16]; 23 24 if ((N = get_argument (argc, argv, "-apply"))) {25 remove_argument (N, &argc, argv);26 int status = vgauss_apply (argc, argv);27 return status;28 }29 22 30 23 Quiet = FALSE; … … 111 104 } 112 105 if (!Quiet) gprint (GP_ERR, "%d iterations\n", i); 113 set_variable ("Chisq", chisq);114 set_variable ("ChisqNu", chisq / (float) (Npts - Npar));115 106 116 107 for (i = 0; i < Npts; i++) { … … 134 125 } 135 126 136 int vgauss_apply (int argc, char **argv) {137 138 opihi_flt par[4];139 Vector *xvec, *ovec;140 char *c;141 142 // NOTE: -apply has already been stripped by vgauss call143 if (argc != 3) {144 gprint (GP_ERR, "USAGE: vgauss -apply <x> <out>\n");145 return (FALSE);146 }147 148 if ((xvec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);149 if ((ovec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) return (FALSE);150 151 CastVector (xvec, OPIHI_FLT);152 153 GET_VAR (par[0], "C0");154 GET_VAR (par[1], "C1");155 GET_VAR (par[2], "C2");156 GET_VAR (par[3], "C3");157 int Npar = 4;158 159 int Npts = xvec[0].Nelements;160 ResetVector (ovec, OPIHI_FLT, Npts);161 162 for (int i = 0; i < Npts; i++) {163 ovec[0].elements.Flt[i] = fgaussOD (xvec[0].elements.Flt[i], par, Npar, NULL);164 }165 ovec[0].Nelements = Npts;166 167 return TRUE;168 }169 170 127 /* pars: x_o, sigma, I, back */ 171 128 opihi_flt fgaussOD (opihi_flt x, opihi_flt *par, int Npar, opihi_flt *dpar) { … … 178 135 f = par[2]*r + par[3]; 179 136 180 if (dpar) { 181 dpar[0] = par[2]*r*z/par[1]; 182 dpar[1] = par[2]*r*z*z/par[1]; 183 dpar[2] = r; 184 dpar[3] = 1; 185 } 137 dpar[0] = par[2]*r*z/par[1]; 138 dpar[1] = par[2]*r*z*z/par[1]; 139 dpar[2] = r; 140 dpar[3] = 1; 186 141 187 142 return (f); -
trunk/Ohana/src/opihi/cmd.data/write_vectors.c
r41269 r41340 32 32 } 33 33 34 // option generate a FITS output table (FITS holds the filename) 35 // in FITS output context, -header is interpretted as a buffer containing 36 // header keywords to supplement the FITS table header 34 /* option generate a FITS output table */ 37 35 char *FITS = NULL; 38 Header *fitsheader = NULL;39 Buffer *headbuffer = NULL;40 36 if ((N = get_argument (argc, argv, "-fits"))) { 41 37 remove_argument (N, &argc, argv); 42 38 FITS = strcreate (argv[N]); 43 39 remove_argument (N, &argc, argv); 44 45 if ((N = get_argument (argc, argv, "-header"))) { 46 remove_argument (N, &argc, argv); 47 if ((headbuffer = SelectBuffer (argv[N], OLDBUFFER, TRUE)) == NULL) return (FALSE); 48 fitsheader = &headbuffer->header; 49 remove_argument (N, &argc, argv); 50 } 51 } 52 40 } 41 53 42 /* option generate a FITS output table */ 54 43 int CSV = FALSE; … … 135 124 136 125 if (FITS) { 137 int status = WriteVectorTableFITS (argv[1], FITS, fitsheader,vec, Nvec, append, compress, format, Ntile);126 int status = WriteVectorTableFITS (argv[1], FITS, vec, Nvec, append, compress, format, Ntile); 138 127 free (vec); 139 128 return status; … … 154 143 if (ADD_HEADER) { 155 144 for (j = 0; j < Nvec; j++) { 156 if (j == 0) fprintf (f, "# ");157 145 if (CSV) { 158 146 fprintf (f, "%s,", vec[j][0].name); 159 147 } else { 148 if (j == 0) fprintf (f, "# "); 160 149 fprintf (f, "%s ", vec[j][0].name); 161 150 } … … 166 155 /* default output format */ 167 156 if (format == (char *) NULL) { 168 char padChar = CSV ? ',' : ' ';169 157 for (i = 0; i < vec[0][0].Nelements; i++) { 170 158 for (j = 0; j < Nvec; j++) { 171 switch (vec[j][0].type) { 172 case OPIHI_FLT: 173 fprintf (f, "%.12g%c", vec[j][0].elements.Flt[i], padChar); 174 break; 175 case OPIHI_INT: 176 fprintf (f, OPIHI_INT_FMT"%c", vec[j][0].elements.Int[i], padChar); 177 break; 178 case OPIHI_STR: 179 fprintf (f, "%s%c", vec[j][0].elements.Str[i], padChar); 180 break; 159 if (vec[j][0].type == OPIHI_FLT) { 160 if (CSV) { 161 fprintf (f, "%.12g,", vec[j][0].elements.Flt[i]); 162 } else { 163 fprintf (f, "%.12g ", vec[j][0].elements.Flt[i]); 164 } 165 } else { 166 if (CSV) { 167 fprintf (f, OPIHI_INT_FMT",", vec[j][0].elements.Int[i]); 168 } else { 169 fprintf (f, OPIHI_INT_FMT" ", vec[j][0].elements.Int[i]); 170 } 181 171 } 182 172 } … … 225 215 fmttype[j] = 'd'; 226 216 break; 227 case 's':228 fmttype[j] = 's';229 break;230 217 default: 231 gprint (GP_ERR, "syntax error in format (only e,f,d,c,x ,sallowed)\n");218 gprint (GP_ERR, "syntax error in format (only e,f,d,c,x allowed)\n"); 232 219 return (FALSE); 233 220 } … … 236 223 strcat (fmtlist[Nvec-1], p0); 237 224 238 // check format types against vector types:239 for (j = 0; j < Nvec; j++) {240 switch (vec[j][0].type) {241 case OPIHI_FLT:242 case OPIHI_INT:243 if (fmttype[j] == 's') {244 gprint (GP_ERR, "mismatch between string format and numerical vector for %s\n", vec[j][0].name);245 return FALSE;246 }247 break;248 case OPIHI_STR:249 if (fmttype[j] != 's') {250 gprint (GP_ERR, "mismatch between numerical format and string vector for %s\n", vec[j][0].name);251 return FALSE;252 }253 break;254 }255 }256 257 225 for (i = 0; i < vec[0][0].Nelements; i++) { 258 226 for (j = 0; j < Nvec; j++) { … … 271 239 } 272 240 } 273 if (fmttype[j] == 's') {274 fprintf (f, fmtlist[j], vec[j][0].elements.Str[i]);275 }276 241 } 277 242 fprintf (f, "\n"); … … 295 260 gprint (GP_ERR, " -append : write to the end of the existing file\n"); 296 261 gprint (GP_ERR, " -fits NAME : write a fits table (extention name is NAME, column names match vector names)\n"); 297 gprint (GP_ERR, " in FITS output context, -header takes an additional argument which is interpretted\n");298 gprint (GP_ERR, " as a buffer containing header keywords to supplement the FITS table header\n");299 262 gprint (GP_ERR, " -csv : write a comma-separated values file (eg, to read in excel)\n"); 300 263 gprint (GP_ERR, " -f \"format\" : provide formatting codes for output:\n"); -
trunk/Ohana/src/opihi/dvo/Makefile
r41163 r41340 67 67 $(SRC)/gstar.$(ARCH).o \ 68 68 $(SRC)/hosts.$(ARCH).o \ 69 $(SRC)/cimages.$(ARCH).o \70 69 $(SRC)/images.$(ARCH).o \ 71 70 $(SRC)/imbox.$(ARCH).o \ -
trunk/Ohana/src/opihi/dvo/avextract.c
r41163 r41340 272 272 // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere) 273 273 if (RESULT_FILE && !SKIP_RESULTS) { 274 int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", NULL,vec, Nreturn, FALSE, FALSE, NULL, 0);274 int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nreturn, FALSE, FALSE, NULL, 0); 275 275 if (!status) { 276 276 goto escape; -
trunk/Ohana/src/opihi/dvo/avmatch.c
r41163 r41340 114 114 115 115 CoordsFile = abspath("coords.fits", 1024); 116 int status = WriteVectorTableFITS (CoordsFile, "COORDS", NULL,vec, 2, FALSE, FALSE, NULL, 0);116 int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, FALSE, NULL, 0); 117 117 if (!status) goto escape; 118 118 } … … 301 301 vec[i][0].Nelements = Nfound; 302 302 } 303 int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", NULL,vec, Nfields + 1, FALSE, FALSE, NULL, 0);303 int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields + 1, FALSE, FALSE, NULL, 0); 304 304 free (vec[Nfields]->elements.Int); 305 305 free (vec[Nfields]); -
trunk/Ohana/src/opihi/dvo/avperiodomatch.c
r41163 r41340 99 99 100 100 CoordsFile = abspath("coords.fits", 1024); 101 int status = WriteVectorTableFITS (CoordsFile, "COORDS", NULL,vec, 2, FALSE, FALSE, NULL, 0);101 int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, FALSE, NULL, 0); 102 102 if (!status) goto escape; 103 103 free (vec); -
trunk/Ohana/src/opihi/dvo/avselect.c
r41163 r41340 132 132 133 133 CoordsFile = abspath("coords.fits", 1024); 134 int status = WriteVectorTableFITS (CoordsFile, "COORDS", NULL,vec, 2, FALSE, FALSE, NULL, 0);134 int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, FALSE, NULL, 0); 135 135 if (!status) goto escape; 136 136 } … … 327 327 vec[NfieldsOut-1] = RADvec; 328 328 } 329 int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", NULL,vec, NfieldsOut, FALSE, FALSE, NULL, 0);329 int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, NfieldsOut, FALSE, FALSE, NULL, 0); 330 330 if (!status) goto escape; 331 331 } -
trunk/Ohana/src/opihi/dvo/dvo_host_utils.c
r41163 r41340 233 233 // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere) 234 234 if (ResultFile) { 235 int status = WriteVectorTableFITS (ResultFile, "RESULT", NULL,vec, Nvec, FALSE, FALSE, NULL, 0);235 int status = WriteVectorTableFITS (ResultFile, "RESULT", vec, Nvec, FALSE, FALSE, NULL, 0); 236 236 if (!status) { 237 237 gprint (GP_ERR, "failed to write result file %s\n", ResultFile); -
trunk/Ohana/src/opihi/dvo/images.c
r41163 r41340 12 12 13 13 off_t i, Nimage, Nmosaic; 14 int j, status, InPic, leftside, TimeSelect, ByName; 15 // int *plist, n, npts; -- what is/was plist? 14 int j, status, InPic, leftside, *plist, TimeSelect, ByName; 16 15 int WITH_MOSAIC, SOLO_MOSAIC; 17 16 time_t tzero, tend; 18 int n, N, NPTS, Npts, kapa, *foundMosaic;17 int N, NPTS, n, npts, Npts, kapa, *foundMosaic; 19 18 Vector Xvec, Yvec; 20 19 double r[8], d[8], x[8], y[8], Rmin, Rmax, Rmid, trange, Radius; … … 149 148 int TrianglePts = wordhash ("TRI-"); 150 149 151 // npts = 200 152 NPTS = 200; 150 npts = NPTS = 200; 153 151 SetVector (&Xvec, OPIHI_FLT, NPTS); 154 152 SetVector (&Yvec, OPIHI_FLT, NPTS); … … 156 154 Image *mosaic = NULL; 157 155 158 /******** stage 1 : find the images to plot *********/ 159 160 // ALLOCATE (plist, int, NPTS); 161 n = 0; // tracks number of images 162 N = 0; // tracks number of vertices 156 ALLOCATE (plist, int, NPTS); 157 n = N = 0; 163 158 for (i = 0; i < Nimage; i++) { 164 159 if (ByName && strncmp (image[i].name, name, strlen(name))) continue; … … 340 335 if (!InPic) continue; 341 336 342 // plist[n] = i; 343 // n++; 344 // if (n > npts - 1) { 345 // npts += 200; 346 // REALLOCATE (plist, int, npts); 347 // } 348 n ++; 349 N += 2*Npts; 337 plist[n] = i; 338 n++; 339 if (n > npts - 1) { 340 npts += 200; 341 REALLOCATE (plist, int, npts); 342 } 343 N+=2*Npts; 350 344 if (N + 16 >= NPTS) { /* need to leave room for 8 point image */ 351 345 NPTS += 400; -
trunk/Ohana/src/opihi/dvo/init.c
r41163 r41340 14 14 int catdir_define PROTO((int, char **)); 15 15 int ccd PROTO((int, char **)); 16 int cimages PROTO((int, char **));17 16 int cmatch PROTO((int, char **)); 18 17 int cmd PROTO((int, char **)); … … 81 80 {1, "catdir", catdir_define,"re-define CATDIR"}, 82 81 // {1, "ccd", ccd, "plot color-color diagram"}, 83 {1, "cimages", cimages, "fill image boxes with a color"},84 82 {1, "cmatch", cmatch, "match two catalogs"}, 85 83 // {1, "cmd", cmd, "plot cmd of stars in current region"}, -
trunk/Ohana/src/opihi/dvo/mextract.c
r41163 r41340 352 352 // write vectors to a table (this is used by parallel dvo operations, but can be used elsewhere) 353 353 if (RESULT_FILE && !SKIP_RESULTS) { 354 int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", NULL,vec, Nreturn, FALSE, FALSE, NULL, 0);354 int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nreturn, FALSE, FALSE, NULL, 0); 355 355 if (!status) goto escape; 356 356 } -
trunk/Ohana/src/opihi/dvo/mmatch.c
r41163 r41340 148 148 // XXX this is now set for both cases... 149 149 CoordsFile = abspath("coords.fits", 1024); 150 int status = WriteVectorTableFITS (CoordsFile, "COORDS", NULL,vec, 2, FALSE, FALSE, NULL, 0);150 int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, FALSE, NULL, 0); 151 151 if (!status) goto escape; 152 152 } … … 349 349 vec[Nfields-1] = IDXvec; 350 350 } 351 int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", NULL,vec, Nfields, FALSE, FALSE, NULL, 0);351 int status = WriteVectorTableFITS (RESULT_FILE, "RESULT", vec, Nfields, FALSE, FALSE, NULL, 0); 352 352 if (!status) goto escape; 353 353 } -
trunk/Ohana/src/opihi/dvo/skyregion.c
r41305 r41340 5 5 6 6 int N; 7 8 // alternate call form: skyregion -box Rcenter Dcenter radius9 if ((N = get_argument (argc, argv, "-box"))) {10 if ((N != 1) && (argc != 5)) {11 gprint (GP_ERR, "USAGE: skyregion -box (Rcenter) (Dcenter) (radius)\n");12 gprint (GP_ERR, " Rcenter, Dcenter, radius in decimal degrees\n");13 return (FALSE);14 }15 16 // argv[1] = -box17 double Rcenter = atof(argv[2]);18 double Dcenter = atof(argv[3]);19 double Radius = atof(argv[4]);20 21 double Rmin = Rcenter - Radius/cos(DEG_RAD*Dcenter);22 double Rmax = Rcenter + Radius/cos(DEG_RAD*Dcenter);23 double Dmin = Dcenter - Radius;24 double Dmax = Dcenter + Radius;25 26 set_skyregion (Rmin, Rmax, Dmin, Dmax);27 return TRUE;28 }29 30 7 31 8 // dvo_client should have 2 standard arguments: -hostID and -hostdir … … 49 26 gprint (GP_ERR, "current skyregion: %f - %f : %f - %f\n", Rmin, Rmax, Dmin, Dmax); 50 27 gprint (GP_ERR, "USAGE: skyregion (min RA) (max RA) (min DEC) (max DEC)\n"); 51 gprint (GP_ERR, " skyregion -box (RA) (DEC) (radius) [sets Rmin,Rmax & Dmin,Dmax]\n");52 28 return FALSE; 53 29 } -
trunk/Ohana/src/opihi/include/data.h
r41165 r41340 48 48 int Nx; 49 49 int Ny; 50 float **flx; 51 float **var; 50 float **buffers; 52 51 } MedImageType; 53 52 -
trunk/Ohana/src/opihi/include/deimos.h
r41165 r41340 7 7 } DeimosResult; 8 8 9 float *deimos_make_model (opihi_flt *obj, opihi_flt *sky, opihi_flt *bck, Vector *psf, Vector *profile, Spline * slit_trace_red, Spline *slit_trace_blu, float redlimit, Spline *psf_trace, int Nx, int Ny, int row);9 float *deimos_make_model (opihi_flt *obj, opihi_flt *sky, opihi_flt *bck, Vector *psf, Vector *profile, Spline *trace, int Nx, int Ny, int row); 10 10 void deimos_make_kernel (float stilt, int Nx); 11 11 void deimos_free_kernel (); … … 13 13 14 14 // internal to make_model: 15 float *deimos_make_straight_image (opihi_flt *obj, opihi_flt *sky, Vector *psf, Spline *psf_trace,int Nx, int Ny, int row);15 float *deimos_make_straight_image (opihi_flt *obj, opihi_flt *sky, Vector *psf, int Nx, int Ny, int row); 16 16 float *deimos_apply_tilt (float *input, int Nx, int Ny); 17 17 void deimos_apply_profile (Vector *profile, float *out, int Nx, int Ny); 18 18 void deimos_add_background (opihi_flt *backgnd, float *out, int Nx, int Ny, int row); 19 float *deimos_apply_trace (Spline * slit_trace_red, Spline *slit_trace_blu, float redlimit, float *input, int Nx, int Ny, int row);19 float *deimos_apply_trace (Spline *trace, float *input, int Nx, int Ny, int row); 20 20 -
trunk/Ohana/src/opihi/include/dvomath.h
r41269 r41340 6 6 # define OPIHI_NAME_SIZE 1024 7 7 8 /* OPIHI_FLT, OPIHI_INT and related are defined in libdvo/include/dvodb.h */9 10 8 # define NCHARS 256 9 // # define opihi_flt double 10 // # define opihi_int int 11 // NOTE: if opihi_int is changed to unsigned, all subtraction and negation operations 12 // need to result in a float value (or 3 - 5 will yield the unexpected value 2^32 - 2) 11 13 12 14 # define REQUIRE_VECTOR_FLT(VECT,RVAL) { \ … … 24 26 enum {ANYVECTOR, NEWVECTOR, OLDVECTOR}; 25 27 enum {ANYBUFFER, NEWBUFFER, OLDBUFFER}; 28 #ifdef NOT_MOVED_TO_LIBDVO 29 enum {OPIHI_FLT, OPIHI_INT}; 30 #endif 26 31 27 32 typedef struct { /* representation of a variable (0-D) */ … … 35 40 union { 36 41 void *Ptr; 37 char **Str;38 42 opihi_flt *Flt; 39 43 opihi_int *Int; … … 165 169 166 170 /* vector IO functions */ 167 int WriteVectorTableFITS PROTO((char *filename, char *extname, Header *extraheader,Vector **vec, int Nvec, int append, char *compress, char *format, int Ntile));171 int WriteVectorTableFITS PROTO((char *filename, char *extname, Vector **vec, int Nvec, int append, char *compress, char *format, int Ntile)); 168 172 Vector **ReadVectorTableFITS PROTO((char *filename, char *extname, int *Nvec)); 169 173 -
trunk/Ohana/src/opihi/lib.data/MedImageOps.c
r41162 r41340 32 32 free (medimage[0].name); 33 33 for (i = 0; i < medimage[0].Ninput; i++) { 34 free (medimage[0].flx[i]); 35 FREE (medimage[0].var[i]); 34 free (medimage[0].buffers[i]); 36 35 } 37 free (medimage[0].flx); 38 free (medimage[0].var); 36 free (medimage[0].buffers); 39 37 free (medimage); 40 38 } … … 77 75 medimage->Nx = Nx; 78 76 medimage->Ny = Ny; 79 ALLOCATE (medimage->flx, float *, 1); 80 ALLOCATE (medimage->var, float *, 1); 77 ALLOCATE (medimage->buffers, float *, 1); 81 78 82 79 medimages[N] = medimage; -
trunk/Ohana/src/opihi/lib.data/SplineOps.c
r41176 r41340 41 41 ALLOCATE (spline[0].y2, opihi_flt, spline[0].Nknots); 42 42 } 43 if (spline[0].Nknots) { 44 memset (spline[0].xk, 0, spline[0].Nknots * sizeof(opihi_flt)); 45 memset (spline[0].yk, 0, spline[0].Nknots * sizeof(opihi_flt)); 46 memset (spline[0].y2, 0, spline[0].Nknots * sizeof(opihi_flt)); 47 } 43 memset (spline[0].xk, 0, spline[0].Nknots * sizeof(opihi_flt)); 44 memset (spline[0].yk, 0, spline[0].Nknots * sizeof(opihi_flt)); 45 memset (spline[0].y2, 0, spline[0].Nknots * sizeof(opihi_flt)); 48 46 } 49 47 … … 181 179 182 180 // NOTE: if we want to compress the output table, use native byte order here (last element) 183 gfits_set_bintable_column_reformat (&theader, &ftable, "X_KNOT", "double", myspline->xk, myspline->Nknots, 0,FALSE);184 gfits_set_bintable_column_reformat (&theader, &ftable, "Y_KNOT", "double", myspline->yk, myspline->Nknots, 0,FALSE);185 gfits_set_bintable_column_reformat (&theader, &ftable, "DY2_DX", "double", myspline->y2, myspline->Nknots, 0,FALSE);181 gfits_set_bintable_column_reformat (&theader, &ftable, "X_KNOT", "double", myspline->xk, myspline->Nknots, FALSE); 182 gfits_set_bintable_column_reformat (&theader, &ftable, "Y_KNOT", "double", myspline->yk, myspline->Nknots, FALSE); 183 gfits_set_bintable_column_reformat (&theader, &ftable, "DY2_DX", "double", myspline->y2, myspline->Nknots, FALSE); 186 184 187 185 if (!append) { -
trunk/Ohana/src/opihi/lib.data/open_kapa.c
r41162 r41340 266 266 int close_kapa (char *name) { 267 267 268 struct timespec request, remain;269 268 int N; 270 269 … … 275 274 } 276 275 DelKapaDevice (name); 277 278 // avoid blocking on waitpid, test every 1 msec, up to 500 msec279 request.tv_sec = 0;280 request.tv_nsec = 1000000;281 282 // try to harvest the child PID283 int waitstatus = 0;284 int result = waitpid (-1, &waitstatus, WNOHANG);285 for (int i = 0; (i < 500) && (result == 0); i++) {286 nanosleep (&request, &remain);287 result = waitpid (-1, &waitstatus, WNOHANG);288 }289 290 if ((result == -1) && (errno != ECHILD)) {291 fprintf (stderr, "unexpected error from waitpid (%d): programming error\n", errno);292 }293 if (result == 0) {294 fprintf (stderr, "child did not exit (close_kapa), timeout");295 }296 297 276 return (TRUE); 298 277 } -
trunk/Ohana/src/opihi/lib.data/spline.c
r41162 r41340 7 7 float dy, dx, *tmp; 8 8 9 // spline is not valid with < 3 points10 if (N < 3) return;11 12 9 ALLOCATE (tmp, float, N); 13 10 … … 72 69 opihi_flt dy, dx, *tmp; 73 70 74 // spline is not valid with < 3 points75 if (N < 3) return;76 77 71 ALLOCATE (tmp, opihi_flt, N); 78 72 -
trunk/Ohana/src/opihi/lib.data/starfuncs.c
r41305 r41340 75 75 FWHMx = 2.355*sqrt (fabs(x2 / I - x*x)); 76 76 FWHMy = 2.355*sqrt (fabs(y2 / I - y*y)); 77 78 // fprintf (stderr, "Mxx, Myy: %f, %f\n", x2/I - x*x, y2/I - y*y);79 77 Sxy = xy / I - x*y; 80 78 mag = -2.5*log10(I); -
trunk/Ohana/src/opihi/lib.data/style_args.c
r41162 r41340 72 72 } 73 73 74 if ((graphmode[0].style == KAPA_PLOT_POLYGON) || (graphmode[0].style == KAPA_PLOT_POLYFILL)) {75 if ((N = get_argument (*argc, argv, "-npoint"))) {76 remove_argument (N, argc, argv);77 graphmode[0].ptype = atoi (argv[N]);78 remove_argument (N, argc, argv);79 } else {80 gprint (GP_ERR, "polygon & polyfill styles require number of points argument: -npoint N\n");81 return FALSE;82 }83 }84 74 return (TRUE); 85 75 } -
trunk/Ohana/src/opihi/lib.shell/VectorIO.c
r41269 r41340 2 2 void gfits_compress_timing (); 3 3 4 static int VectorGetMaxStringLength (Vector *vec) {5 6 int MaxLength = 0;7 8 if (vec[0].type != OPIHI_STR) return 0;9 10 for (int i = 0; i < vec[0].Nelements; i++) {11 MaxLength = MAX (MaxLength, strlen(vec[0].elements.Str[i]));12 }13 return MaxLength;14 }15 16 4 // write a set of vectors to a FITS FTable structure (vectors names become fits column names) 17 5 static int WriteVectorTable (FTable *ftable, char *extname, Vector **vec, int Nvec, char *format, char nativeOrder) { … … 19 7 int j; 20 8 9 char *tformat = NULL; 10 21 11 Header *theader = ftable->header; 22 12 gfits_create_table_header (theader, "BINTABLE", extname); 23 13 24 // allocate an array of strings to represent the format for each output field 25 // formats include single column formats (BIJKDE) and multi-column formats (e.g., 2I) 26 // we will have no more than Nvec fields (but we can have fewer) 27 int Nfield = 0; 28 ALLOCATE_PTR (tformat, char *, Nvec); 29 ALLOCATE_PTR (Nelement, int, Nvec); 30 14 ALLOCATE (tformat, char, 2*Nvec); 31 15 if (format) { 32 // the bintable format string can defines the byte-width of each field and number of elements (columns per field). 33 // valid output columns are currently: 16 // the bintable format string can only define the byte-width of each field. valid output columns are currently: 34 17 // B (char), I (16 bit short), J (32 bit int), E (32 bit float), D (64 bit double). 35 // the format string is just the sequence of types, eg: LIIJEED. 36 // it may have spaces or integer element counts: 37 // "2D 4I EEJ" 38 39 // *** validate the format string 40 41 // as I parse each elements, if it is a digit, I need parse that value 42 18 // the format string is just the sequence of types, eg: LIIJEED 19 // validate the format string 43 20 char *ptr = format; 44 for (j = 0; j < Nvec; ) {21 for (j = 0; j < Nvec; j++) { 45 22 while (*ptr && OHANA_WHITESPACE (*ptr)) ptr++; 46 23 if (*ptr == 0) { … … 48 25 goto escape; 49 26 } 50 51 // is there a leading integer? 52 char *endptr; 53 Nelement[Nfield] = strtol (ptr, &endptr, 10); 54 if (endptr == ptr) { 55 Nelement[Nfield] = 1; 56 } 57 ptr = endptr; // this should now point at the letter that is the format type 58 if ((*ptr != 'B') && (*ptr != 'I') && (*ptr != 'J') && (*ptr != 'K') && (*ptr != 'D') && (*ptr != 'E') && (*ptr != 'A')) { 27 if ((*ptr != 'B') && (*ptr != 'I') && (*ptr != 'J') && (*ptr != 'K') && (*ptr != 'D') && (*ptr != 'E')) { 59 28 gprint (GP_ERR, "error in binary table format %s: invalid character %c\n", format, *ptr); 60 29 goto escape; 61 30 } 62 63 int Nchar = snprintf (tformat[Nfield], 0, "%d%c", Nelement[Nfield], *ptr); 64 ALLOCATE (tformat[Nfield], char, Nchar + 1); 65 int Nout = snprintf (tformat[Nfield], Nchar + 1, "%d%c", Nelement[Nfield], *ptr); 66 myAssert (Nout <= Nchar, "oops"); 67 68 // tformat[2*j + 0] = *ptr; 69 // tformat[2*j + 1] = 0; // a bit sleazy : use a 2xN string to store N 1-byte strings 70 71 // For numeric multi-valued fields, the number of elements from the format defines the number of 72 // vectors which go into that field. For string-type vectors, the format specifies the maximum number of characters 73 // that go into the field. 74 75 // for example, a format code of 3E should match a list of three numeric-type vectors while a format code of 15A should 76 // match a single string-type vector which will supply up to 15 chars per row. 77 78 if (*ptr != 'A') { 79 j += Nelement[Nfield]; // advance past Nelement vectors 80 } else { 81 if (vec[j][0].type != OPIHI_STR) { 82 gprint (GP_ERR, "error in binary table format %s (mismatch between string format and numeric vector %s)\n", format, vec[j][0].name); 83 goto escape; 84 } 85 j ++; // advance past a single string-type vector (validate that?) 86 } 87 if (j > Nvec) { 88 gprint (GP_ERR, "error in binary table format %s (too few vectors for listed field)\n", format); 89 goto escape; 90 } 91 31 tformat[2*j + 0] = *ptr; 32 tformat[2*j + 1] = 0; // a bit sleazy : use a 2xN string to store N 1-byte strings 92 33 ptr ++; 93 Nfield ++;94 34 } 95 35 while (*ptr && OHANA_WHITESPACE (*ptr)) ptr++; … … 100 40 } else { 101 41 for (j = 0; j < Nvec; j++) { 102 switch (vec[j][0].type) { 103 case OPIHI_FLT: 104 case OPIHI_INT: 105 // if the format is not defined, just use the native byte-widths 106 ALLOCATE (tformat[j], char, 2); 107 tformat[j][0] = (vec[j][0].type == OPIHI_FLT) ? 'D' : 'K'; 108 tformat[j][1] = 0; 109 Nelement[j] = 1; 110 break; 111 case OPIHI_STR: 112 // we need to examine the vector to determine the length 113 Nelement[j] = VectorGetMaxStringLength(vec[j]); 114 int Nchar = snprintf (tformat[j], 0, "%d%c", Nelement[j], 'A'); 115 ALLOCATE (tformat[j], char, Nchar + 1); 116 int Nout = snprintf (tformat[j], Nchar + 1, "%d%c", Nelement[j], 'A'); 117 myAssert (Nout <= Nchar, "oops"); 118 break; 119 } 120 } 121 Nfield = Nvec; 42 // if the format is not defined, just use the native byte-widths 43 tformat[2*j + 0] = (vec[j][0].type == OPIHI_FLT) ? 'D' : 'K'; // this depends on opihi_int == int64_t for Int 44 tformat[2*j + 1] = 0; 45 } 122 46 } 123 47 … … 125 49 // output table (because the data goes to the named column below). need to enforce 126 50 // this somehow 127 int ivec = 0; 128 for (j = 0; j < Nfield; j++) { 129 // XX need to loop over fields, and skip the additional vectors that are part of a field 130 // this call supported multiple columns per named field 131 gfits_define_bintable_column (theader, tformat[j], vec[ivec][0].name, NULL, NULL, 1.0, 0.0); 132 if (vec[ivec][0].type == OPIHI_STR) { 133 ivec ++; 134 } else { 135 ivec += Nelement[j]; 136 } 137 } 138 139 // need to free the array 140 for (j = 0; j < Nfield; j++) { 141 free (tformat[j]); 51 for (j = 0; j < Nvec; j++) { 52 gfits_define_bintable_column (theader, &tformat[2*j], vec[j][0].name, NULL, NULL, 1.0, 0.0); 142 53 } 143 54 free (tformat); … … 146 57 gfits_create_table (theader, ftable); 147 58 148 // I need to add each vector in order, but I need to149 // track which field it corresponds to.150 151 59 // add the vectors to the output array 152 for (ivec = 0, j = 0; j < Nfield; j++) { 153 // the first vector provides the name for the field 154 char *fieldname = vec[ivec][0].name; 155 156 if (vec[ivec][0].type == OPIHI_STR) { 157 // string-type vectors need to be copied into a contiguous buffer with the right dimensions: 158 Vector *thisvec = vec[ivec]; 159 160 ALLOCATE_PTR (strbuffer, char, Nelement[j]*thisvec->Nelements); 161 for (int i = 0; i < thisvec->Nelements; i++) { 162 int nChar = MIN (strlen (thisvec->elements.Str[i]), Nelement[j]); 163 // fprintf (stderr, "%d %d %d : %d : %d : %s\n", ivec, j, i, Nelement[j], nChar, thisvec->elements.Str[i]); 164 memcpy (&strbuffer[i*Nelement[j]], thisvec->elements.Str[i], nChar); 165 } 166 gfits_set_bintable_column (theader, ftable, fieldname, strbuffer, thisvec->Nelements); 167 free (strbuffer); 168 ivec ++; 60 for (j = 0; j < Nvec; j++) { 61 if (vec[j][0].type == OPIHI_FLT) { 62 gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "double", vec[j][0].elements.Flt, vec[j][0].Nelements, nativeOrder); 169 63 } else { 170 for (int k = 0; k < Nelement[j]; k++, ivec++) { 171 Vector *thisvec = vec[ivec]; 172 switch (thisvec->type) { 173 case OPIHI_FLT: 174 gfits_set_bintable_column_reformat (theader, ftable, fieldname, "double", thisvec->elements.Flt, thisvec->Nelements, k, nativeOrder); 175 break; 176 case OPIHI_INT: 177 gfits_set_bintable_column_reformat (theader, ftable, fieldname, "int64_t", thisvec->elements.Int, thisvec->Nelements, k, nativeOrder); 178 break; 179 } 180 } 64 // gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "int", vec[j][0].elements.Int, vec[j][0].Nelements, nativeOrder); 65 gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "int64_t", vec[j][0].elements.Int, vec[j][0].Nelements, nativeOrder); 181 66 } 182 67 } … … 225 110 } 226 111 227 // insert a new header line, return end pointer228 char *gfits_insert_header_line (Header *header, char *endptr, char *newline) {229 230 if (0) {231 char temp1[32], temp2[32];232 memset (temp1, 0, 32);233 memset (temp2, 0, 32);234 235 if (endptr) {236 memcpy (temp1, endptr, 8);237 }238 memcpy (temp2, newline, 8);239 fprintf (stderr, "insert: %s : %s\n", temp1, temp2);240 }241 242 /* find the END of the header, if not supplied */243 if (!endptr) {244 endptr = gfits_header_field (header, "END", 1);245 if (endptr == NULL) return NULL;246 }247 248 /* is there enough space for 1 more line? */249 if (header[0].datasize - (endptr - (header[0].buffer)) < 2*FT_LINE_LENGTH) {250 // no, so expand by a full header block (FT_RECORD_SIZE = 32*80 = 2880)251 header[0].datasize += FT_RECORD_SIZE;252 REALLOCATE (header[0].buffer, char, header[0].datasize);253 // re-find the "END" marker, in case new memory block is used254 endptr = gfits_header_field (header, "END", 1);255 if (endptr == NULL) return NULL;256 memset (endptr + FT_LINE_LENGTH, ' ', FT_RECORD_SIZE);257 }258 259 /* push END line back 1 */260 memmove ((endptr + FT_LINE_LENGTH), endptr, FT_LINE_LENGTH);261 memset (endptr, ' ', FT_LINE_LENGTH);262 263 strncpy (endptr, newline, 80);264 endptr += FT_LINE_LENGTH;265 266 return endptr;267 }268 269 static char *rawkeywords[] = {"SIMPLE", "BITPIX", "NAXIS", "PCOUNT", "GCOUNT", "EXTEND", "EXTNAME", "BSCALE", "BZERO", "TFIELDS", "TFORM", "TZERO", "TSCAL", " ", NULL};270 271 112 // write a set of vectors to a FITS file (vectors names become fits column names) 272 int WriteVectorTableFITS (char *filename, char *extname, Header *extraheader,Vector **vec, int Nvec, int append, char *compress, char *format, int Ntile) {113 int WriteVectorTableFITS (char *filename, char *extname, Vector **vec, int Nvec, int append, char *compress, char *format, int Ntile) { 273 114 274 115 Header rawheader; … … 298 139 rawtable.header = &rawheader; 299 140 if (!WriteVectorTable (&rawtable, extname, vec, Nvec, format, (compress != NULL))) goto escape; 300 // NOTE : for compression, the table is constructed in native by teorder141 // NOTE : for compression, the table is constructed in native by order 301 142 302 143 FTable *outtable = &rawtable; … … 322 163 323 164 if (!append) { 324 // generate a blank PHU header325 165 Header header; 326 166 Matrix matrix; … … 336 176 } 337 177 338 if (extraheader) {339 // copy keywords which are not the standard or table keywords340 char *buf = extraheader->buffer;341 char *endptr = NULL;342 for (int i = 0; i < extraheader->datasize; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {343 344 if (0) {345 char temp1[32];346 memset (temp1, 0, 32);347 memcpy (temp1, buf, 8);348 fprintf (stderr, "buffer: %s\n", temp1);349 }350 351 for (int j = 0; rawkeywords[j] != NULL; j++) {352 if (!strncmp (buf, rawkeywords[j], strlen(rawkeywords[j]))) goto skip_insert;353 }354 endptr = gfits_insert_header_line (outheader, endptr, buf);355 if (!endptr) {356 gprint (GP_ERR, "failed to update FITS header with extra keywords\n");357 return (FALSE);358 }359 skip_insert:360 continue;361 }362 }363 364 178 // write the actual table data 365 179 gfits_fwrite_Theader (f, outheader); -
trunk/Ohana/src/opihi/lib.shell/VectorOps.c
r41269 r41340 129 129 if (mode == NEWVECTOR) goto error; 130 130 if (vectors[i]) { 131 // XXX warning: this will be a leak if vector is type OPIHI_STR132 131 if (vectors[i][0].elements.Ptr) free (vectors[i][0].elements.Ptr); 133 132 free (vectors[i]); … … 151 150 if (i == Nvectors) return (FALSE); 152 151 153 // XXX warning: this will be a leak if vector is type OPIHI_STR154 152 if (vectors[i][0].elements.Ptr) free (vectors[i][0].elements.Ptr); 155 153 free (vectors[i]); … … 172 170 if (i == Nvectors) return (FALSE); 173 171 174 // XXX warning: this will be a leak if vector is type OPIHI_STR175 172 if (vectors[i][0].elements.Ptr) free (vectors[i][0].elements.Ptr); 176 173 free (vectors[i]); … … 194 191 195 192 int CopyVector (Vector *out, Vector *in) { 196 // XXX warning: this will be a leak if vector is type OPIHI_STR197 193 if (out[0].elements.Ptr) free (out[0].elements.Ptr); 198 194 out[0].Nelements = in[0].Nelements; … … 212 208 213 209 int MatchVector(Vector *out, Vector *in, char type) { 214 // XXX warning: this will be a leak if vector is type OPIHI_STR215 210 if (out[0].elements.Ptr) free (out[0].elements.Ptr); 216 211 out[0].Nelements = in[0].Nelements; … … 227 222 int ResetVector (Vector *vec, char type, int Nelements) { 228 223 229 // if the supplied vector is a string but the output is not a string, we need to free230 // the unused elements231 if ((vec[0].type == OPIHI_STR) && (vec[0].type != type)) {232 for (int i = 0; i < vec[0].Nelements; i++) {233 FREE (vec[0].elements.Str[i]);234 }235 }236 237 224 // a vector can only have >= 0 elements 238 225 vec[0].Nelements = MAX(Nelements,0); 239 240 switch (type) { 241 case OPIHI_FLT: 242 REALLOCATE (vec[0].elements.Flt, opihi_flt, MAX(1, Nelements)); 243 vec[0].type = OPIHI_FLT; 244 break; 245 case OPIHI_INT: 246 REALLOCATE (vec[0].elements.Int, opihi_int, MAX(1, Nelements)); 247 vec[0].type = OPIHI_INT; 248 break; 249 case OPIHI_STR: 250 REALLOCATE (vec[0].elements.Str, char *, MAX(1, Nelements)); 251 vec[0].type = OPIHI_STR; 252 break; 226 if (type == OPIHI_FLT) { 227 REALLOCATE (vec[0].elements.Flt, opihi_flt, MAX(1, Nelements)); 228 vec[0].type = OPIHI_FLT; 229 } else { 230 REALLOCATE (vec[0].elements.Int, opihi_int, MAX(1, Nelements)); 231 vec[0].type = OPIHI_INT; 253 232 } 254 233 return TRUE; … … 272 251 273 252 // SetVector (vecx, OPIHI_FLT, MAX (Npts, 1)); 274 // Use this for an unallocated vector (e.g., static variable)275 253 int SetVector (Vector *vec, char type, int Nelements) { 276 254 277 255 vec[0].Nelements = MAX(Nelements,0); 278 279 switch (type) { 280 case OPIHI_FLT: 281 ALLOCATE (vec[0].elements.Flt, opihi_flt, MAX(1,Nelements)); 282 vec[0].type = OPIHI_FLT; 283 break; 284 case OPIHI_INT: 285 ALLOCATE (vec[0].elements.Int, opihi_int, MAX(1,Nelements)); 286 vec[0].type = OPIHI_INT; 287 break; 288 case OPIHI_STR: 289 ALLOCATE (vec[0].elements.Ptr, char *, MAX(1,Nelements)); 290 vec[0].type = OPIHI_STR; 291 break; 256 if (type == OPIHI_FLT) { 257 ALLOCATE (vec[0].elements.Flt, opihi_flt, MAX(1,Nelements)); 258 vec[0].type = OPIHI_FLT; 259 } else { 260 ALLOCATE (vec[0].elements.Int, opihi_int, MAX(1,Nelements)); 261 vec[0].type = OPIHI_INT; 292 262 } 293 263 return TRUE; … … 302 272 if (vec[0].type == type) return TRUE; 303 273 304 switch (type) { 305 case OPIHI_FLT: { 306 opihi_flt *temp; 307 ALLOCATE (temp, opihi_flt, vec[0].Nelements); 308 opihi_flt *vo = temp; 309 opihi_int *vi = vec[0].elements.Int; 310 for (i = 0; i < vec[0].Nelements; i++, vo++, vi++) { 311 *vo = *vi; 312 } 313 free (vec[0].elements.Int); 314 vec[0].elements.Flt = temp; 315 vec[0].type = OPIHI_FLT; 316 break; 317 } 318 case OPIHI_INT: { 319 opihi_int *temp; 320 ALLOCATE (temp, opihi_int, vec[0].Nelements); 321 opihi_int *vo = temp; 322 opihi_flt *vi = vec[0].elements.Flt; 323 for (i = 0; i < vec[0].Nelements; i++, vo++, vi++) { 324 *vo = *vi; 325 } 326 free (vec[0].elements.Flt); 327 vec[0].elements.Int = temp; 328 vec[0].type = OPIHI_INT; 329 break; 330 } 331 case OPIHI_STR: 332 default: 333 // does it make sense to cast an int/flt vector to string? 334 break; 274 if (type == OPIHI_FLT) { 275 opihi_flt *temp; 276 ALLOCATE (temp, opihi_flt, vec[0].Nelements); 277 opihi_flt *vo = temp; 278 opihi_int *vi = vec[0].elements.Int; 279 for (i = 0; i < vec[0].Nelements; i++, vo++, vi++) { 280 *vo = *vi; 281 } 282 free (vec[0].elements.Int); 283 vec[0].elements.Flt = temp; 284 vec[0].type = OPIHI_FLT; 285 } else { 286 opihi_int *temp; 287 ALLOCATE (temp, opihi_int, vec[0].Nelements); 288 opihi_int *vo = temp; 289 opihi_flt *vi = vec[0].elements.Flt; 290 for (i = 0; i < vec[0].Nelements; i++, vo++, vi++) { 291 *vo = *vi; 292 } 293 free (vec[0].elements.Flt); 294 vec[0].elements.Int = temp; 295 vec[0].type = OPIHI_INT; 335 296 } 336 297 return TRUE; … … 381 342 gprint (GP_LOG, " N name size\n"); 382 343 for (i = 0; i < Nvectors; i++) { 383 switch (vectors[i][0].type) { 384 case OPIHI_FLT: 385 gprint (GP_LOG, "%5d %10s %10d (FLT)\n", i, vectors[i][0].name, vectors[i][0].Nelements); 386 break; 387 case OPIHI_INT: 388 gprint (GP_LOG, "%5d %10s %10d (INT)\n", i, vectors[i][0].name, vectors[i][0].Nelements); 389 break; 390 case OPIHI_STR: 391 gprint (GP_LOG, "%5d %10s %10d (STR)\n", i, vectors[i][0].name, vectors[i][0].Nelements); 392 break; 344 if (vectors[i][0].type == OPIHI_FLT) { 345 gprint (GP_LOG, "%5d %10s %10d (FLT)\n", i, vectors[i][0].name, vectors[i][0].Nelements); 346 } else { 347 gprint (GP_LOG, "%5d %10s %10d (INT)\n", i, vectors[i][0].name, vectors[i][0].Nelements); 393 348 } 394 349 } -
trunk/Ohana/src/opihi/lib.shell/convert_to_RPN.c
r41176 r41340 78 78 if (!strcmp (argv[i], "atan2")) { type = ST_BINARY; strcpy (argv[i], "a"); goto gotit; } 79 79 if (!strcmp (argv[i], "datan2")) { type = ST_BINARY; strcpy (argv[i], "d"); goto gotit; } 80 81 if (!strcmp (argv[i], "<~")) { type = ST_BINARY; strcpy (argv[i], "l"); goto gotit; }82 if (!strcmp (argv[i], "~>")) { type = ST_BINARY; strcpy (argv[i], "r"); goto gotit; }83 84 80 if (!strcmp (argv[i], ",")) { type = ST_COMMA; goto gotit; } 85 81 … … 103 99 if (!strcmp (argv[i], ">>")) { type = ST_LOGIC; strcpy (argv[i], "U"); goto gotit; } 104 100 if (!strcmp (argv[i], "<<")) { type = ST_LOGIC; strcpy (argv[i], "D"); goto gotit; } 105 106 /* XXX I would like to change the syntax to allow << and >> to mean bitshifts107 but that means breaking these older values which means MIN and MAX */108 // for now, use <- and -> to mean bitshift109 101 110 102 if (!strcmp (argv[i], "&&")) { type = ST_AND; strcpy (argv[i], "A"); goto gotit; } -
trunk/Ohana/src/opihi/lib.shell/multicommand.c
r41161 r41340 63 63 64 64 p = line; 65 int Nline = strlen(line);66 67 65 done = FALSE; 68 66 status = TRUE; … … 76 74 tmpline = strncreate (p, q - p); 77 75 stripwhite (tmpline); 78 myAssert (tmpline, "oops");76 if (*tmpline) { 79 77 80 // empty command, free and continue 81 if (*tmpline == 0) { 82 free (tmpline); 83 if (q == line + Nline) { 84 done = TRUE; 85 } else { 86 p = q + 1; 87 myAssert (p - line <= Nline, "oops"); 78 if (bufferPending) { 79 // flush old messages 80 ExpectMessage (server, 0.2, &message); 81 bufferPending = FALSE; 88 82 } 89 continue;90 }91 83 92 if (bufferPending) { 93 // flush old messages 94 ExpectMessage (server, 0.2, &message); 95 bufferPending = FALSE; 96 } 84 status = command (tmpline, &outline, verbose); 97 85 98 // input tmpline is freed by command 99 status = command (tmpline, &outline, verbose); 86 if (status == -1) { 87 if (server) { 88 // send the command to the server instead 89 if (!SendMessage (server, "%s", outline)) { 90 switch (errno) { 91 case EPIPE: 92 gprint (GP_ERR, "server connection has died\n"); 93 exit (32); 94 default: 95 gprint (GP_ERR, "server is busy...32\n"); 96 bufferPending = TRUE; 97 goto escape; 98 } 99 } 100 100 101 if (status == -1) { 102 if (server) { 103 // send the command to the server instead 104 if (!SendMessage (server, "%s", outline)) { 105 switch (errno) { 106 case EPIPE: 107 gprint (GP_ERR, "server connection has died\n"); 108 exit (32); 109 default: 110 gprint (GP_ERR, "server is busy...32\n"); 111 bufferPending = TRUE; 112 goto escape; 101 // receive the command exit status 102 if (ExpectMessage (server, MSG_TIMEOUT, &message)) { 103 switch (errno) { 104 case EPIPE: 105 gprint (GP_ERR, "server connection has died\n"); 106 exit (33); 107 default: 108 gprint (GP_ERR, "server is busy...33\n"); 109 bufferPending = TRUE; 110 goto escape; 111 } 112 } else { 113 sscanf (message.buffer, "STATUS %d", &status); 113 114 } 114 }115 115 116 // receive the command exit status 117 if (ExpectMessage (server, MSG_TIMEOUT, &message)) { 118 switch (errno) { 119 case EPIPE: 120 gprint (GP_ERR, "server connection has died\n"); 121 exit (33); 122 default: 123 gprint (GP_ERR, "server is busy...33\n"); 124 bufferPending = TRUE; 125 goto escape; 116 // receive the resulting stderr 117 if (ExpectMessage (server, MSG_TIMEOUT, &message)) { 118 switch (errno) { 119 case EPIPE: 120 gprint (GP_ERR, "server connection has died\n"); 121 exit (34); 122 default: 123 gprint (GP_ERR, "server is busy...34\n"); 124 bufferPending = TRUE; 125 goto escape; 126 } 127 } else { 128 gwrite (message.buffer, 1, message.Nbuffer, GP_ERR); 129 } 130 131 // receive the resulting stdout 132 if (ExpectMessage (server, MSG_TIMEOUT, &message)) { 133 switch (errno) { 134 case EPIPE: 135 gprint (GP_ERR, "server connection has died\n"); 136 exit (35); 137 default: 138 gprint (GP_ERR, "server is busy...35\n"); 139 bufferPending = TRUE; 140 goto escape; 141 } 142 } else { 143 gwrite (message.buffer, 1, message.Nbuffer, GP_LOG); 126 144 } 127 145 } else { 128 sscanf (message.buffer, "STATUS %d", &status); 129 } 130 131 // receive the resulting stderr 132 if (ExpectMessage (server, MSG_TIMEOUT, &message)) { 133 switch (errno) { 134 case EPIPE: 135 gprint (GP_ERR, "server connection has died\n"); 136 exit (34); 137 default: 138 gprint (GP_ERR, "server is busy...34\n"); 139 bufferPending = TRUE; 140 goto escape; 141 } 142 } else { 143 gwrite (message.buffer, 1, message.Nbuffer, GP_ERR); 144 } 145 146 // receive the resulting stdout 147 if (ExpectMessage (server, MSG_TIMEOUT, &message)) { 148 switch (errno) { 149 case EPIPE: 150 gprint (GP_ERR, "server connection has died\n"); 151 exit (35); 152 default: 153 gprint (GP_ERR, "server is busy...35\n"); 154 bufferPending = TRUE; 155 goto escape; 156 } 157 } else { 158 gwrite (message.buffer, 1, message.Nbuffer, GP_LOG); 159 } 160 } else { 161 // if no server is defined, we treat an unknown command as an error 162 status = FALSE; 163 } 146 // if no server is defined, we treat an unknown command as an error 147 status = FALSE; 148 } 149 } 150 escape: 151 if (outline != NULL) free (outline); 152 if (!status && auto_break) done = TRUE; 164 153 } 165 escape:166 if (outline != NULL) free (outline);167 if (!status && auto_break) done = TRUE;168 169 154 p = q + 1; 170 155 } -
trunk/Ohana/src/opihi/lib.shell/parse.c
r41176 r41340 66 66 /* dvomath returns a new string, or NULL, with the result of the expression */ 67 67 val = dvomath (1, &V1, &size, 0); 68 if (val == NULL) { print_error (); goto error; }68 if (val == NULL) goto error; 69 69 fval += atof(val); 70 70 // save the result … … 88 88 /* dvomath returns a new string, or NULL, with the result of the expression */ 89 89 val = dvomath (1, &V1, &size, 0); 90 if (val == NULL) { print_error (); goto error; }90 if (val == NULL) goto error; 91 91 fval -= atof(val); 92 92 // save the result -
trunk/Ohana/src/opihi/lib.shell/stack_math.c
r41176 r41340 34 34 case '?': SSS_FUNC(M1 ? M2: M3); 35 35 default: 36 snprintf (line, 512, "error: op %c not defined as scalar trinary op!", op[0]);36 snprintf (line, 512, "error: op %c not defined!", op[0]); 37 37 push_error (line); 38 38 return (FALSE); … … 162 162 case '?': VVV_FUNC(*M1 ? *M2: *M3); 163 163 default: 164 snprintf (line, 512, "error: op %c not defined as vector trinary op!", op[0]);164 snprintf (line, 512, "error: op %c not defined!", op[0]); 165 165 push_error (line); 166 166 return (FALSE); … … 227 227 case '?': MMM_FUNC(*M1 ? *M2: *M3); 228 228 default: 229 snprintf (line, 512, "error: op %c not defined as matrix trinary op!", op[0]);229 snprintf (line, 512, "error: op %c not defined!", op[0]); 230 230 push_error (line); 231 231 return (FALSE); … … 357 357 case 'A': VV_FUNC(ST_SCALAR_INT, (*M1 && *M2) ? 1 : 0); 358 358 case 'O': VV_FUNC(ST_SCALAR_INT, (*M1 || *M2) ? 1 : 0); 359 360 // for the bitshift operators, we have to treat the INT and FLT values differently361 // this makes the operator incompatible with the macros used above362 case 'l': {363 CopyVector (OUT[0].vector, V1[0].vector);364 if ((V1->vector->type == OPIHI_FLT) || (V2->vector->type == OPIHI_FLT)) {365 // bitshift is not valid with float valuess366 for (i = 0; i < Nx; i++) {367 OUT[0].vector[0].elements.Flt[i] = NAN;368 }369 break;370 }371 // I could just do this for all types and bitshift regardless...372 opihi_int *M1 = V1[0].vector[0].elements.Int;373 opihi_int *M2 = V2[0].vector[0].elements.Int;374 opihi_int *out = OUT[0].vector[0].elements.Int;375 for (i = 0; i < Nx; i++, out++, M1++, M2++) {376 *out = *M1 << *M2;377 }378 break;379 }380 381 case 'r': {382 CopyVector (OUT[0].vector, V1[0].vector);383 if ((V1->vector->type == OPIHI_FLT) || (V2->vector->type == OPIHI_FLT)) {384 // bitshift is not valid with float valuess385 CopyVector (OUT[0].vector, V1[0].vector);386 for (i = 0; i < Nx; i++) {387 OUT[0].vector[0].elements.Flt[i] = NAN;388 }389 break;390 }391 // I could just do this for all types and bitshift regardless...392 opihi_int *M1 = V1[0].vector[0].elements.Int;393 opihi_int *M2 = V2[0].vector[0].elements.Int;394 opihi_int *out = OUT[0].vector[0].elements.Int;395 for (i = 0; i < Nx; i++, out++, M1++, M2++) {396 *out = *M1 >> *M2;397 }398 break;399 }400 401 359 default: 402 snprintf (line, 512, "error: op %c not defined for (vector OP vector)!", op[0]);360 snprintf (line, 512, "error: op %c not defined!", op[0]); 403 361 push_error (line); 404 362 return (FALSE); … … 511 469 case 'A': SV_FUNC(ST_SCALAR_INT, (M1 && *M2) ? 1 : 0); 512 470 case 'O': SV_FUNC(ST_SCALAR_INT, (M1 || *M2) ? 1 : 0); 513 514 // for the bitshift operators, we have to treat the INT and FLT values differently515 // this makes the operator incompatible with the macros used above516 case 'l': {517 CopyVector (OUT[0].vector, V2[0].vector);518 if ((V1->type == ST_SCALAR_FLT) || (V2->vector->type == OPIHI_FLT)) {519 // bitshift is not valid with float valuess520 for (i = 0; i < Nx; i++) {521 OUT[0].vector[0].elements.Flt[i] = NAN;522 }523 break;524 }525 opihi_int M1 = V1[0].IntValue; \526 opihi_int *M2 = V2[0].vector[0].elements.Int;527 opihi_int *out = OUT[0].vector[0].elements.Int;528 for (i = 0; i < Nx; i++, out++, M2++) {529 *out = M1 << *M2;530 }531 break;532 }533 534 case 'r': {535 CopyVector (OUT[0].vector, V2[0].vector);536 if ((V1->type == ST_SCALAR_FLT) || (V2->vector->type == OPIHI_FLT)) {537 // bitshift is not valid with float valuess538 for (i = 0; i < Nx; i++) {539 OUT[0].vector[0].elements.Flt[i] = NAN;540 }541 break;542 }543 opihi_int M1 = V1[0].IntValue; \544 opihi_int *M2 = V2[0].vector[0].elements.Int;545 opihi_int *out = OUT[0].vector[0].elements.Int;546 for (i = 0; i < Nx; i++, out++, M2++) {547 *out = M1 >> *M2;548 }549 break;550 }551 552 471 default: 553 snprintf (line, 512, "error: op %c not defined for (scalar OP vector)!", op[0]);472 snprintf (line, 512, "error: op %c not defined!", op[0]); 554 473 push_error (line); 555 474 return (FALSE); … … 658 577 case 'A': VS_FUNC(ST_SCALAR_INT, (*M1 && M2) ? 1 : 0); 659 578 case 'O': VS_FUNC(ST_SCALAR_INT, (*M1 || M2) ? 1 : 0); 660 661 case 'l': {662 CopyVector (OUT[0].vector, V1[0].vector);663 if ((V1->vector->type == OPIHI_FLT) || (V2->type == ST_SCALAR_FLT)) {664 // bitshift is not valid with float valuess665 for (i = 0; i < Nx; i++) {666 OUT[0].vector[0].elements.Flt[i] = NAN;667 }668 break;669 }670 opihi_int *M1 = V1[0].vector[0].elements.Int;671 opihi_int M2 = V2[0].IntValue; \672 opihi_int *out = OUT[0].vector[0].elements.Int;673 for (i = 0; i < Nx; i++, out++, M1++) {674 *out = *M1 << M2;675 }676 break;677 }678 679 case 'r': {680 CopyVector (OUT[0].vector, V1[0].vector);681 if ((V1->vector->type == OPIHI_FLT) || (V2->type == ST_SCALAR_FLT)) {682 // bitshift is not valid with float valuess683 CopyVector (OUT[0].vector, V1[0].vector);684 for (i = 0; i < Nx; i++) {685 OUT[0].vector[0].elements.Flt[i] = NAN;686 }687 break;688 }689 opihi_int *M1 = V1[0].vector[0].elements.Int;690 opihi_int M2 = V2[0].IntValue; \691 opihi_int *out = OUT[0].vector[0].elements.Int;692 for (i = 0; i < Nx; i++, out++, M1++) {693 *out = *M1 >> M2;694 }695 break;696 }697 698 579 default: 699 snprintf (line, 512, "error: op %c not defined for (vector OP scalar)!", op[0]);580 snprintf (line, 512, "error: op %c not defined!", op[0]); 700 581 push_error (line); 701 582 return (FALSE); … … 789 670 case 'A': MV_FUNC((*M1 && *M2) ? 1 : 0); 790 671 case 'O': MV_FUNC((*M1 || *M2) ? 1 : 0); 791 792 672 default: 793 snprintf (line, 512, "error: op %c not defined for (matrix OP vector)!", op[0]);673 snprintf (line, 512, "error: op %c not defined!", op[0]); 794 674 push_error (line); 795 675 return (FALSE); … … 888 768 case 'O': VM_FUNC((*M1 || *M2) ? 1 : 0); 889 769 default: 890 snprintf (line, 512, "error: op %c not defined for (vector OP matrix)!", op[0]);770 snprintf (line, 512, "error: op %c not defined!", op[0]); 891 771 push_error (line); 892 772 return (FALSE); … … 969 849 case 'O': MM_FUNC((*M1 || *M2) ? 1 : 0); 970 850 default: 971 snprintf (line, 512, "error: op %c not defined for (matrix OP matrix)!", op[0]);851 snprintf (line, 512, "error: op %c not defined!", op[0]); 972 852 push_error (line); 973 853 return (FALSE); … … 1055 935 case 'O': MS_FUNC((*M1 || M2) ? 1 : 0); 1056 936 default: 1057 snprintf (line, 512, "error: op %c not defined for (matrix OP scalar)!", op[0]);937 snprintf (line, 512, "error: op %c not defined!", op[0]); 1058 938 push_error (line); 1059 939 return (FALSE); … … 1132 1012 case 'O': SM_FUNC((M1 || *M2) ? 1 : 0); 1133 1013 default: 1134 snprintf (line, 512, "error: op %c not defined for (scalar OP matrix)!", op[0]);1014 snprintf (line, 512, "error: op %c not defined!", op[0]); 1135 1015 push_error (line); 1136 1016 return (FALSE); … … 1214 1094 case 'A': SS_FUNC(ST_SCALAR_INT, (M1 && M2) ? 1 : 0); 1215 1095 case 'O': SS_FUNC(ST_SCALAR_INT, (M1 || M2) ? 1 : 0); 1216 1217 // for the bitshift operators, we have to treat the INT and FLT values differently1218 // this makes the operator incompatible with the macros used above1219 case 'l': {1220 if ((V1->type == ST_SCALAR_FLT) || (V2->type == ST_SCALAR_FLT)) {1221 // bitshift is not valid with float valuess1222 OUT[0].type = ST_SCALAR_FLT;1223 OUT[0].FltValue = NAN;1224 break;1225 }1226 opihi_int M1 = V1[0].IntValue;1227 opihi_int M2 = V2[0].IntValue;1228 OUT[0].type = ST_SCALAR_INT;1229 OUT[0].IntValue = M1 << M2;1230 break;1231 }1232 1233 case 'r': {1234 if ((V1->type == ST_SCALAR_FLT) || (V2->type == ST_SCALAR_FLT)) {1235 // bitshift is not valid with float valuess1236 OUT[0].type = ST_SCALAR_FLT;1237 OUT[0].FltValue = NAN;1238 break;1239 }1240 opihi_int M1 = V1[0].IntValue;1241 opihi_int M2 = V2[0].IntValue;1242 OUT[0].type = ST_SCALAR_INT;1243 OUT[0].IntValue = M1 >> M2;1244 break;1245 }1246 1247 1096 default: 1248 snprintf (line, 512, "error: op %c not defined for (scalar OP scalar)!", op[0]);1097 snprintf (line, 512, "error: op %c not defined!", op[0]); 1249 1098 push_error (line); 1250 1099 return (FALSE); … … 1319 1168 int S_unary (StackVar *OUT, StackVar *V1, char *op) { 1320 1169 1170 char line[512]; // this is only used to report an error 1171 1321 1172 # define S_FUNC(OP,FTYPE) { \ 1322 1173 if (V1->type == ST_SCALAR_FLT) { \ … … 1359 1210 if (!strcmp (op, "asinh")) S_FUNC(asinh (M1), ST_SCALAR_FLT); 1360 1211 if (!strcmp (op, "acosh")) S_FUNC(acosh (M1), ST_SCALAR_FLT); 1212 if (!strcmp (op, "lgamma")) S_FUNC(lgamma (M1), ST_SCALAR_FLT); 1361 1213 if (!strcmp (op, "sin")) S_FUNC(sin (M1), ST_SCALAR_FLT); 1362 1214 if (!strcmp (op, "cos")) S_FUNC(cos (M1), ST_SCALAR_FLT); … … 1371 1223 if (!strcmp (op, "dacos")) S_FUNC(acos (M1)*DEG_RAD, ST_SCALAR_FLT); 1372 1224 if (!strcmp (op, "datan")) S_FUNC(atan (M1)*DEG_RAD, ST_SCALAR_FLT); 1373 if (!strcmp (op, "lgamma")) S_FUNC(lgamma (M1), ST_SCALAR_FLT);1374 1225 if (!strcmp (op, "rnd")) S_FUNC(0.0*M1 + drand48(), ST_SCALAR_FLT); 1375 1226 if (!strcmp (op, "drnd")) S_FUNC(0.0*M1 + drand48(), ST_SCALAR_FLT); … … 1384 1235 1385 1236 clear_stack (V1); 1386 1387 char line[512]; // this is only used to report an error 1388 snprintf (line, 512, "error: op %s not defined as unary scalar op!", op); 1237 snprintf (line, 512, "error: op %s not defined!", op); 1389 1238 push_error (line); 1390 1239 return (FALSE); 1240 1391 1241 } 1392 1242 … … 1445 1295 if (!strcmp (op, "asinh")) V_FUNC(asinh(*M1), ST_SCALAR_FLT); 1446 1296 if (!strcmp (op, "acosh")) V_FUNC(acosh(*M1), ST_SCALAR_FLT); 1297 if (!strcmp (op, "lgamma")) V_FUNC(lgamma(*M1), ST_SCALAR_FLT); 1447 1298 if (!strcmp (op, "sin")) V_FUNC(sin(*M1), ST_SCALAR_FLT); 1448 1299 if (!strcmp (op, "cos")) V_FUNC(cos(*M1), ST_SCALAR_FLT); … … 1457 1308 if (!strcmp (op, "dacos")) V_FUNC(acos(*M1)*DEG_RAD, ST_SCALAR_FLT); 1458 1309 if (!strcmp (op, "datan")) V_FUNC(atan(*M1)*DEG_RAD, ST_SCALAR_FLT); 1459 if (!strcmp (op, "lgamma")) V_FUNC(lgamma(*M1), ST_SCALAR_FLT);1460 1310 if (!strcmp (op, "rnd")) V_FUNC(drand48(), ST_SCALAR_FLT); 1461 1311 if (!strcmp (op, "drnd")) V_FUNC(drand48(), ST_SCALAR_FLT); 1462 1312 if (!strcmp (op, "lrnd")) V_FUNC(lrand48(), ST_SCALAR_INT); 1463 1313 if (!strcmp (op, "mrnd")) V_FUNC(mrand48(), ST_SCALAR_INT); 1314 if (!strcmp (op, "ramp")) V_FUNC(i, ST_SCALAR_INT); 1315 if (!strcmp (op, "zero")) V_FUNC(0, ST_SCALAR_INT); 1464 1316 if (!strcmp (op, "not")) V_FUNC(!(*M1), ST_SCALAR_INT); 1465 1317 if (!strcmp (op, "--")) V_FUNC(-1*(*M1), ST_SCALAR_INT); // NOTE: opihi_int is signed 1466 1318 if (!strcmp (op, "isinf")) V_FUNC(!finite(*M1), ST_SCALAR_FLT); 1467 1319 if (!strcmp (op, "isnan")) V_FUNC(isnan((opihi_flt)(*M1)), ST_SCALAR_FLT); 1468 if (!strcmp (op, "ramp")) V_FUNC(i, ST_SCALAR_INT);1469 1320 if (!strcmp (op, "xramp")) V_FUNC(i, ST_SCALAR_INT); 1470 1321 if (!strcmp (op, "yramp")) V_FUNC(0, ST_SCALAR_INT); 1471 1322 if (!strcmp (op, "zramp")) V_FUNC(0, ST_SCALAR_INT); 1472 if (!strcmp (op, "zero")) V_FUNC(0, ST_SCALAR_INT);1473 1323 /* xramp, yramp, zramp above only make sense for matrices. for vectors, xramp = ramp, yramp = zero */ 1474 1324 1475 1325 # undef V_FUNC 1476 1326 1477 // free the temp vector if needed 1327 escape: 1328 1478 1329 if (V1[0].type == ST_VECTOR_TMP) { 1479 1330 free (V1[0].vector[0].elements.Ptr); … … 1483 1334 1484 1335 clear_stack (V1); 1485 1486 char line[512]; // this is only used to report an error 1487 snprintf (line, 512, "error: op %s not defined as unary vector op!", op); 1488 push_error (line); 1489 return (FALSE); 1490 1491 escape: 1492 1493 if (V1[0].type == ST_VECTOR_TMP) { 1494 free (V1[0].vector[0].elements.Ptr); 1495 free (V1[0].vector); 1496 V1[0].vector = NULL; 1497 } 1498 1499 clear_stack (V1); 1500 return (TRUE); 1501 1502 } 1503 1504 # define M_FUNC(OP) { for (i = 0; i < Npix; i++, out++, M1++) { *out = (OP); } goto escape; } 1336 return (TRUE); 1337 1338 } 1339 1340 # define M_FUNC(OP) { for (i = 0; i < Npix; i++, out++, M1++) { *out = (OP); }} 1505 1341 1506 1342 int M_unary (StackVar *OUT, StackVar *V1, char *op) { … … 1524 1360 // if (!strcmp (op, "rint")) { for (i = 0; i < Npix; i++, out++, M1++) { *out = nearbyint (*M1); }} 1525 1361 1526 if (!strcmp (op, "=")) { goto escape;}1362 if (!strcmp (op, "=")) { } 1527 1363 if (!strcmp (op, "abs")) M_FUNC(fabs(*M1)); 1528 1364 if (!strcmp (op, "int")) M_FUNC((opihi_flt)(long long)(*M1)); … … 1539 1375 if (!strcmp (op, "asinh")) M_FUNC(asinh(*M1)); 1540 1376 if (!strcmp (op, "acosh")) M_FUNC(acosh(*M1)); 1377 if (!strcmp (op, "lgamma")) M_FUNC(lgamma(*M1)); 1541 1378 if (!strcmp (op, "sin")) M_FUNC(sin(*M1)); 1542 1379 if (!strcmp (op, "cos")) M_FUNC(cos(*M1)); … … 1551 1388 if (!strcmp (op, "dacos")) M_FUNC(acos(*M1)*DEG_RAD); 1552 1389 if (!strcmp (op, "datan")) M_FUNC(atan(*M1)*DEG_RAD); 1553 if (!strcmp (op, "lgamma")) M_FUNC(lgamma(*M1)); 1390 if (!strcmp (op, "not")) M_FUNC(!(*M1)); 1391 if (!strcmp (op, "--")) M_FUNC(-(*M1)); 1554 1392 if (!strcmp (op, "rnd")) M_FUNC(drand48()); 1555 1393 if (!strcmp (op, "drnd")) M_FUNC(drand48()); 1556 1394 if (!strcmp (op, "lrnd")) M_FUNC(lrand48()); 1557 1395 if (!strcmp (op, "mrnd")) M_FUNC(mrand48()); 1558 if (!strcmp (op, "not")) M_FUNC(!(*M1));1559 if (!strcmp (op, "--")) M_FUNC(-(*M1));1560 1396 if (!strcmp (op, "ramp")) M_FUNC(i); 1397 if (!strcmp (op, "zero")) M_FUNC(0); 1561 1398 if (!strcmp (op, "isinf")) M_FUNC(!finite(*M1)); 1562 1399 if (!strcmp (op, "isnan")) M_FUNC(isnan(*M1)); 1563 if (!strcmp (op, "zero")) M_FUNC(0);1564 1400 1565 1401 /* xrm and yrm only make sense for 2D matrices. see special meaning for vectors */ … … 1575 1411 } 1576 1412 } 1577 goto escape;1578 1413 } 1579 1414 if (!strcmp (op, "yramp")) { … … 1588 1423 } 1589 1424 } 1590 goto escape;1591 1425 } 1592 1426 if (!strcmp (op, "zramp")) { … … 1601 1435 } 1602 1436 } 1603 goto escape; 1604 } 1605 1606 if (V1[0].type == ST_MATRIX_TMP) { 1607 free (V1[0].buffer[0].header.buffer); 1608 free (V1[0].buffer[0].matrix.buffer); 1609 free (V1[0].buffer); 1610 } 1611 1612 clear_stack (V1); 1613 1614 char line[512]; // this is only used to report an error 1615 snprintf (line, 512, "error: op %s not defined as unary matrix op!", op); 1616 push_error (line); 1617 return (FALSE); 1618 1619 escape: 1620 1437 } 1438 1621 1439 if (V1[0].type == ST_MATRIX_TMP) { 1622 1440 free (V1[0].buffer[0].header.buffer); -
trunk/Ohana/src/opihi/lib.shell/startup.c
r41161 r41340 107 107 LOAD_RC = FALSE; 108 108 } 109 if ((N = get_argument (*argc, argv, "--no-rc"))) {110 remove_argument (N, argc, argv);111 LOAD_RC = FALSE;112 }113 if ((N = get_argument (*argc, argv, "-norc"))) {114 remove_argument (N, argc, argv);115 LOAD_RC = FALSE;116 }117 if ((N = get_argument (*argc, argv, "-no-rc"))) {118 remove_argument (N, argc, argv);119 LOAD_RC = FALSE;120 }121 109 122 110 ONLY_INPUT = FALSE; -
trunk/Ohana/src/opihi/mana/Makefile
r41159 r41340 26 26 $(SRC)/deimos_getobj.$(ARCH).o \ 27 27 $(SRC)/deimos_fitobj.$(ARCH).o \ 28 $(SRC)/deimos_fitalt.$(ARCH).o \ 29 $(SRC)/deimos_mkalt.$(ARCH).o \ 28 30 $(SRC)/deimos_mkmodel.$(ARCH).o \ 29 31 $(SRC)/deimos_arclines.$(ARCH).o \ 30 $(SRC)/deimos_fitarc.$(ARCH).o \31 $(SRC)/deimos_fitprofile.$(ARCH).o \32 32 $(SRC)/findrowpeaks.$(ARCH).o 33 33 -
trunk/Ohana/src/opihi/mana/deimos.c
r41159 r41340 4 4 int deimos_fitslit (int argc, char **argv); 5 5 int deimos_mkobj (int argc, char **argv); 6 int deimos_mkalt (int argc, char **argv); 6 7 int deimos_getobj (int argc, char **argv); 7 // int deimos_getalt (int argc, char **argv);8 8 int deimos_fitobj (int argc, char **argv); 9 //int deimos_fitalt (int argc, char **argv);9 int deimos_fitalt (int argc, char **argv); 10 10 int deimos_arclines (int argc, char **argv); 11 int deimos_fitarc (int argc, char **argv);12 int deimos_fitprofile (int argc, char **argv);13 11 14 12 static Command deimos_commands[] = { 15 {1, "fitobj", deimos_fitobj, "fit for object parameters using LMM"}, 16 {1, "fitalt", deimos_fitobj, "fit for object parameters using LMM"}, 17 {1, "getobj", deimos_getobj, "determine crude object parameters"}, 18 {1, "getalt", deimos_getobj, "determine crude object parameters"}, 19 {1, "mkobj", deimos_mkobj, "make a full object image"}, 20 {1, "mkslit", deimos_mkslit, "make a slit image"}, 21 {1, "fitslit", deimos_fitslit, "fit slit image to observed slit flux"}, 22 {1, "arclines", deimos_arclines, "detect arclines using LSF and STILT"}, 23 {1, "fitarc", deimos_fitarc, "fit arclamp lines"}, 24 {1, "fitprofile", deimos_fitprofile, "fit slit profile"}, 13 {1, "fitobj", deimos_fitobj, "fit for object parameters"}, 14 {1, "fitalt", deimos_fitalt, "fit for object parameters using LMM"}, 15 {1, "getobj", deimos_getobj, "determine crude object parameters"}, 16 {1, "mkobj", deimos_mkobj, "make a full object image"}, 17 {1, "mkalt", deimos_mkalt, "make a full object image (uses deimos_make_object, for a test)"}, 18 {1, "mkslit", deimos_mkslit, "make a slit image"}, 19 {1, "fitslit", deimos_fitslit, "fit slit image to observed slit flux"}, 20 {1, "arclines", deimos_arclines, "detect arclines using LSF and STILT"}, 25 21 }; 26 22 -
trunk/Ohana/src/opihi/mana/deimos_arclines.c
r41159 r41340 53 53 deimos_make_LSF_kernel (LSF, stilt, Nx); 54 54 55 // FILE *Fout = NULL;56 57 55 // loop over the rows 58 56 for (int iy = 0; iy < Ny; iy++) { 59 57 float Fsum = 0; 60 float Ksum = 0;61 62 // if (iy == 5802) Fout = fopen ("test.5802.dat", "w");63 // if (iy == 5815) Fout = fopen ("test.5815.dat", "w");64 65 58 // cross-correlation of buffer values and kernel values 66 59 for (int ix = 0; ix < Nx; ix++) { … … 69 62 if ((iy + ky) < 0) continue; 70 63 if ((iy + ky) >= Ny) continue; 71 if (!isfinite(Fin[ix + (iy + ky)*Nx])) continue;72 if (!isfinite(kernel[ix + ko*Nx])) continue;73 64 Fsum += Fin[ix + (iy + ky)*Nx] * kernel[ix + ko*Nx]; 74 Ksum += kernel[ix + ko*Nx];75 // if ((iy == 5815) || (iy == 5802)) {76 // fprintf (Fout, "%d %d %d : %f %f\n", iy, ix, ky, Fin[ix + (iy + ky)*Nx], kernel[ix + ko*Nx]);77 // }78 65 } 79 66 } 80 81 // if ((iy == 5815) || (iy == 5802)) fclose (Fout);82 83 67 coord->elements.Flt[iy] = iy; 84 68 flux->elements.Flt[iy] = Fsum; -
trunk/Ohana/src/opihi/mana/deimos_fitslit.c
r41159 r41340 1 1 # include "data.h" 2 # define IRLS_TOLERANCE 1e-43 4 float weight_cauchy_square_flt (float x2);5 static void fitflux (float *Fwind, float *Fprof, float *weight, int Nx, double *flux, double *sky);6 2 7 3 int deimos_fitslit (int argc, char **argv) { 8 4 9 // fitslit (window) (vari) (slit) (flux) (sky) 5 // fitslit (window) (slit) (flux) (sky) 6 7 // int N; 10 8 11 9 Vector *flux = NULL; … … 13 11 14 12 Buffer *wind = NULL; 15 Buffer *vari = NULL;16 13 Buffer *slit = NULL; 17 14 18 int N; 19 int Niter = 10; 20 if ((N = get_argument (argc, argv, "-irls-iter"))) { 21 remove_argument (N, &argc, argv); 22 Niter = atoi (argv[N]); 23 remove_argument (N, &argc, argv); 24 } 25 26 Buffer *model = NULL; 27 if ((N = get_argument (argc, argv, "-model"))) { 28 remove_argument (N, &argc, argv); 29 if ((model = SelectBuffer (argv[N], ANYBUFFER, TRUE)) == NULL) return (FALSE); 30 remove_argument (N, &argc, argv); 31 } 32 33 if (argc != 6) { 34 gprint (GP_ERR, "USAGE: deimos fitslit (window) (variance) (slit) (flux) (sky)\n"); 35 gprint (GP_ERR, " inputs: window (observed 2D flux), variance (on 2D flux), slit (model 2D flux)\n"); 15 if (argc != 5) { 16 gprint (GP_ERR, "USAGE: deimos fitslit (window) (slit) (flux) (sky)\n"); 17 gprint (GP_ERR, " inputs: window (observed 2D flux), slit (model 2D flux)\n"); 36 18 gprint (GP_ERR, " outputs: flux (best-fit 1D flux), sky (best-fit 1D background)\n"); 37 19 return FALSE; … … 40 22 // XXX I probably should rename FindSpline as SelectSpline and give it the same behavior 41 23 if ((wind = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE); 42 if ((vari = SelectBuffer (argv[2], OLDBUFFER, TRUE)) == NULL) return (FALSE); 43 if ((slit = SelectBuffer (argv[3], OLDBUFFER, TRUE)) == NULL) return (FALSE); 44 if ((flux = SelectVector (argv[4], ANYVECTOR, TRUE)) == NULL) return (FALSE); 45 if ((sky = SelectVector (argv[5], ANYVECTOR, TRUE)) == NULL) return (FALSE); 24 if ((slit = SelectBuffer (argv[2], OLDBUFFER, TRUE)) == NULL) return (FALSE); 25 if ((flux = SelectVector (argv[3], ANYVECTOR, TRUE)) == NULL) return (FALSE); 26 if ((sky = SelectVector (argv[4], ANYVECTOR, TRUE)) == NULL) return (FALSE); 27 28 // XXX confirm slit and wind have same dimensions 46 29 47 30 // define the output window … … 49 32 int Ny = wind[0].matrix.Naxis[1]; 50 33 51 // confirm wind, vari, slit have same dimensions52 34 if (Nx != slit[0].matrix.Naxis[0]) { gprint (GP_ERR, "size mismatch in fitslit for window and slit\n"); return FALSE; } 53 35 if (Ny != slit[0].matrix.Naxis[1]) { gprint (GP_ERR, "size mismatch in fitslit for window and slit\n"); return FALSE; } 54 if (Nx != vari[0].matrix.Naxis[0]) { gprint (GP_ERR, "size mismatch in fitslit for window and variance\n"); return FALSE; }55 if (Ny != vari[0].matrix.Naxis[1]) { gprint (GP_ERR, "size mismatch in fitslit for window and variance\n"); return FALSE; }56 36 57 37 ResetVector (flux, OPIHI_FLT, Ny); 58 38 ResetVector (sky, OPIHI_FLT, Ny); 59 39 60 if (model) {61 if (!CreateBuffer (model, Nx, Ny, -32, 1.0, 0.0)) { gprint (GP_ERR, "error generating output model buffer\n"); return FALSE; }62 }63 64 40 float *Fwind = (float *) wind[0].matrix.buffer; 65 float *Fvari = (float *) vari[0].matrix.buffer;66 41 float *Fprof = (float *) slit[0].matrix.buffer; 67 float *FmodOut = model ? (float *) model[0].matrix.buffer : NULL;68 69 ALLOCATE_PTR (weight, float, Nx);70 ALLOCATE_PTR (rawwgt, float, Nx);71 42 72 43 // loop over the rows 73 44 for (int iy = 0; iy < Ny; iy++) { 74 45 75 double F = 0.0, S = 0.0;46 // calculate elements of the chi-square for this row: 76 47 77 // set weight based on the variance 48 double R = 0.0, P = 0.0, P2 = 0.0, f = 0.0, fp = 0.0; 49 double wt = 1.0; 50 78 51 for (int ix = 0; ix < Nx; ix++) { 79 float vari = Fvari[ix + iy*Nx]; 80 weight[ix] = !isfinite(vari) || (fabs(vari) < 1e-6) ? 1.0 : 1.0 / vari; 81 rawwgt[ix] = weight[ix]; 52 53 float fxy = Fwind[ix + iy*Nx]; 54 float pxy = Fprof[ix + iy*Nx]; 55 56 R += wt; 57 P += pxy*wt; 58 P2 += pxy*pxy*wt; 59 f += fxy*wt; 60 fp += fxy*pxy*wt; 82 61 } 83 62 84 // calculate elements of the chi-square for this row: 85 fitflux (&Fwind[iy*Nx], &Fprof[iy*Nx], weight, Nx, &F, &S); 86 87 // do an IRLS loop here to reject outliers 88 int converged = FALSE; 89 for (int iter = 0; (iter < Niter) && !converged; iter++) { 90 91 double Flast = F; 92 double Slast = S; 93 94 // calculate weight modification based on distances (squared). 95 // use modifier to calculate new weighted mean 96 for (int ix = 0; ix < Nx; ix++) { 97 98 // F & S are model parameters; compare the model and observed values for each pixel 99 float Fmodel = S + F*Fprof[ix + iy*Nx]; 100 float dV = (Fwind[ix + iy*Nx] - Fmodel); 101 float d2 = SQ(dV) * rawwgt[ix]; 102 103 float Mod = weight_cauchy_square_flt (d2); 104 weight[ix] = Mod * rawwgt[ix]; 105 } 106 fitflux (&Fwind[iy*Nx], &Fprof[iy*Nx], weight, Nx, &F, &S); 107 108 float dF = fabs(F - Flast); 109 float dS = fabs(S - Slast); 110 111 if ((dF < F * IRLS_TOLERANCE) && (dS < S * IRLS_TOLERANCE)) converged = TRUE; 112 } 113 114 if (FmodOut) { 115 for (int ix = 0; ix < Nx; ix++) { 116 // F & S are model parameters; compare the model and observed values for each pixel 117 float Fmodel = S + F*Fprof[ix + iy*Nx]; 118 float dV = (Fwind[ix + iy*Nx] - Fmodel); 119 float d2 = SQ(dV) * rawwgt[ix]; 120 float Mod = weight_cauchy_square_flt (d2); 121 if (Mod < 0.1) { 122 FmodOut[ix + iy*Nx] = NAN; 123 } else { 124 FmodOut[ix + iy*Nx] = Fmodel; 125 } 126 } 127 } 63 double det = R*P2 - P*P; 64 double S = (P2*f - P*fp) / det; 65 double F = (R*fp - P*f) / det; 128 66 129 67 flux->elements.Flt[iy] = F; 130 68 sky->elements.Flt[iy] = S; 131 69 } 70 132 71 return TRUE; 133 72 } 134 73 135 // weight is 1 / variance136 // Fwind, Fprof are pointers to the start of a single row137 // Fwind is the observed flux in the window138 // Fprof is the slit profile139 void fitflux (float *Fwind, float *Fprof, float *weight, int Nx, double *flux, double *sky) {140 141 // calculate elements of the chi-square fit for this row:142 143 double R = 0.0, P = 0.0, P2 = 0.0, f = 0.0, fp = 0.0;144 145 for (int ix = 0; ix < Nx; ix++) {146 147 double fxy = Fwind[ix];148 double pxy = Fprof[ix];149 150 // skip NAN / Inf pixels in either window or slit151 if (!isfinite(fxy)) continue;152 if (!isfinite(pxy)) continue;153 154 double wt = (weight == NULL) ? 1.0 : weight[ix];155 R += wt;156 P += pxy*wt;157 P2 += pxy*pxy*wt;158 f += fxy*wt;159 fp += fxy*pxy*wt;160 }161 162 double det = R*P2 - P*P;163 *sky = (P2*f - P*fp) / det;164 *flux = (R*fp - P*f) / det;165 } -
trunk/Ohana/src/opihi/mana/deimos_mkalt.c
r41159 r41340 1 1 # include "data.h" 2 2 # include "deimos.h" 3 4 XXX: deprecated5 3 6 4 // Use this to test the deimos_make_object function used by deimos_fitobj … … 94 92 95 93 // generate the model based on the test values 96 float *model = deimos_make_model (objV, skyV, bckV, psf, profile, trace, N ULL, Nx, Ny, 0);94 float *model = deimos_make_model (objV, skyV, bckV, psf, profile, trace, Nx, Ny, 0); 97 95 98 96 ResetBuffer (output, Nx, Ny, -32, 0.0, 1.0); -
trunk/Ohana/src/opihi/mana/deimos_mkmodel.c
r41159 r41340 86 86 // generate a subimage of the full model for the range row - row + Ny 87 87 // obj,sky,bck are subset vectors corresponding to the range row to row+Ny 88 // the slit_trace_* and psf_trace refer to the full image starting at row 89 float *deimos_make_model (opihi_flt *obj, opihi_flt *sky, opihi_flt *bck, Vector *psf, Vector *profile, Spline *slit_trace_red, Spline *slit_trace_blu, float redlimit, Spline *psf_trace, int Nx, int Ny, int row) { 90 91 float *raw = deimos_make_straight_image (obj, sky, psf, psf_trace, Nx, Ny, row); 88 float *deimos_make_model (opihi_flt *obj, opihi_flt *sky, opihi_flt *bck, Vector *psf, Vector *profile, Spline *trace, int Nx, int Ny, int row) { 89 90 float *raw = deimos_make_straight_image (obj, sky, psf, Nx, Ny, row); 92 91 float *new = deimos_apply_tilt (raw, Nx, Ny); 93 92 deimos_apply_profile (profile, new, Nx, Ny); 94 93 deimos_add_background (bck, new, Nx, Ny, row); 95 float *out = deimos_apply_trace ( slit_trace_red, slit_trace_blu, redlimit, new, Nx, Ny, row);94 float *out = deimos_apply_trace (trace, new, Nx, Ny, row); 96 95 97 96 free (raw); … … 105 104 // *** generate a raw image with no slit tilt and no trace offsets. apply the PSF to the 106 105 // object flux, add in the sky flux 107 float *deimos_make_straight_image (opihi_flt *obj, opihi_flt *sky, Vector *psf, Spline *psf_trace,int Nx, int Ny, int row) {106 float *deimos_make_straight_image (opihi_flt *obj, opihi_flt *sky, Vector *psf, int Nx, int Ny, int row) { 108 107 OHANA_UNUSED_PARAM(row); 109 108 … … 114 113 115 114 // Xref is a global supplied by the user (defaults to Nx/2 if < 0) 116 int Xoff Ref= (int)(Xref - Npsf);115 int Xoff = (int)(Xref - Npsf); 117 116 118 117 // Nx : width of output window … … 124 123 125 124 // we are generating the image for just the row range row to row+Ny 126 // note that obj & sky are subset vectors for just this range of pixels127 125 opihi_flt objVy = obj[iy]; // if we shift to using the row offset: obj[iy + row] 128 126 opihi_flt skyVy = sky[iy]; // if we shift to using the row offset: sky[iy + row] 129 127 130 // integral and fractional pixel offsets of PSF (none, by default)131 int dxi = 0;132 float dxf = 0.0, dxr = 1.0;133 int Xoff = XoffRef;134 135 if (psf_trace) {136 // the psf_trace is referenced against the full image, so we need to add row to iy:137 float dx = spline_apply_dbl (psf_trace->xk, psf_trace->yk, psf_trace->y2, psf_trace->Nknots, iy + row);138 dxi = floor(dx);139 dxf = dx - dxi; // -1.7 -> +0.3, -0.5 -> +0.5, +0.5 ->+0.5, +1.7 -> +0.7140 dxr = 1 - dxf;141 Xoff += dxi;142 // fprintf (stderr, "%d: %f : %d\n", iy + row, dx, Xoff);143 }144 145 // if fractional offset is small, do not interpolate146 int doInterp = fabs(dxf) < 1e-5 ? FALSE : TRUE;147 148 128 // flux = obj * PSF + sky 149 129 for (int ix = 0; ix < Nx; ix++) { … … 156 136 // only add in the flux if we are in range of the PSF 157 137 if ((n >= 0) && (n < NpsfFull)) { 158 if (doInterp) { 159 if ((n > 0) && (n < NpsfFull)) { 160 if (isfinite(psfV[n]) && isfinite(psfV[n-1])) { 161 value += objVy*psfV[n]*dxr + objVy*psfV[n-1]*dxf; 162 } 163 } 164 if (n == 0) { 165 if (isfinite(psfV[n])) { 166 value += objVy*psfV[n]*dxr; 167 } 168 } 169 } else { 170 if (isfinite(psfV[n])) { 171 value += objVy * psfV[n]; 172 } 173 } 138 value += objVy * psfV[n]; 174 139 } 175 140 out[ix + iy*Nx] = value; … … 254 219 255 220 // shift pixels in x based on the trace 256 float *deimos_apply_trace (Spline * slit_trace_red, Spline *slit_trace_blu, float redlimit, float *input, int Nx, int Ny, int row) {221 float *deimos_apply_trace (Spline *trace, float *input, int Nx, int Ny, int row) { 257 222 258 223 ALLOCATE_PTR (output, float, Nx*Ny); … … 262 227 // evaluate the trace spline at this y-coord to find the x-coord offset of the profile center 263 228 // NOTE: spline is evaluated at full dispersion coordinate 264 int iy_full = iy + row; 265 Spline *slit_trace = (iy_full < redlimit) ? slit_trace_red : slit_trace_blu; 266 float dx = -spline_apply_dbl (slit_trace->xk, slit_trace->yk, slit_trace->y2, slit_trace->Nknots, iy_full); 229 float dx = -spline_apply_dbl (trace->xk, trace->yk, trace->y2, trace->Nknots, iy + row); 267 230 268 231 // extract the integer pixel offset and the fractional offset -
trunk/Ohana/src/opihi/mana/deimos_mkobj.c
r41159 r41340 6 6 7 7 // input parameters: 8 // * slit_trace_red : spline fit of slit central x pos vs y-coord for red chip 9 // * slit_trace_blu : spline fit of slit central x pos vs y-coord for blu chip 10 // * psf_trace : spline fit of psf central x pos vs y-coord 11 // * profile : slit window profile (vector) 12 // * object : vector of object flux vs y-coord 13 // * sky : vector of local sky signal vs y-coord 14 // * backgnd : vector of extra-slit background flux vs y-coord 15 // * PSF : point-spread function vector (flux normalized, x-dir) 16 // * LSF : sline-spread function vector (flux normalized, y-dir) 17 // * stilt : slit tilt response : 2D kernel? 18 19 // * redlimit : pixel break between red and blu chips 20 // * Nwave : number of wavelength pixels in output image 8 // * trace : spline fit of slit central x pos vs y-coord 9 // * profile : slit window profile (vector) 10 // * object : vector of object flux vs y-coord 11 // * sky : vector of local sky signal vs y-coord 12 // * background : vector of extra-slit background flux vs y-coord 13 // * PSF : point-spread function vector (flux normalized, x-dir) 14 // * LSF : sline-spread function vector (flux normalized, y-dir) 15 // * stilt : slit tilt response : 2D kernel? 21 16 22 17 int N; 23 18 24 19 // if any of these are not defined, they will have assumed identity values 25 Spline *slit_trace_red = NULL; 26 Spline *slit_trace_blu = NULL; 27 Spline *psf_trace = NULL; 28 Vector *profile = NULL; 29 Vector *object = NULL; 30 Vector *sky = NULL; 31 Vector *backgnd = NULL; 32 33 Vector *psf = NULL; 34 Vector *lsf = NULL; 20 Spline *trace = NULL; 21 Vector *profile = NULL; 22 Vector *object = NULL; 23 Vector *sky = NULL; 24 Vector *backgnd = NULL; 25 26 Vector *psf = NULL; 27 Vector *lsf = NULL; 35 28 // add tilt later 36 29 37 Buffer *output = NULL;30 Buffer *output = NULL; 38 31 39 32 float stilt = 0.0; // angle of the slit 40 33 41 // for a red vs blu spline, we need to specify the split point 42 // XXX this is REALLY ad-hoc for Deimos. not sure how to make 43 // this more generic (need to define the ranges somewhere) 44 int redlimit = 4096; 45 if ((N = get_argument (argc, argv, "-redlimit"))) { 46 remove_argument (N, &argc, argv); 47 redlimit = atoi (argv[N]); 48 remove_argument (N, &argc, argv); 49 } 50 51 if ((N = get_argument (argc, argv, "-slit-trace-red"))) { 52 remove_argument (N, &argc, argv); 53 if ((slit_trace_red = FindSpline (argv[N])) == NULL) return (FALSE); 54 remove_argument (N, &argc, argv); 55 } 56 if ((N = get_argument (argc, argv, "-slit-trace-blu"))) { 57 remove_argument (N, &argc, argv); 58 if ((slit_trace_blu = FindSpline (argv[N])) == NULL) return (FALSE); 59 remove_argument (N, &argc, argv); 60 } 61 if ((N = get_argument (argc, argv, "-psf-trace"))) { 62 remove_argument (N, &argc, argv); 63 if ((psf_trace = FindSpline (argv[N])) == NULL) return (FALSE); 34 if ((N = get_argument (argc, argv, "-trace"))) { 35 remove_argument (N, &argc, argv); 36 if ((trace = FindSpline (argv[N])) == NULL) return (FALSE); 64 37 remove_argument (N, &argc, argv); 65 38 } … … 108 81 } 109 82 110 int VERBOSE = FALSE;111 if ((N = get_argument (argc, argv, "-v"))) {112 remove_argument (N, &argc, argv);113 VERBOSE = TRUE;114 }115 116 83 if (argc != 3) { 117 gprint (GP_ERR, "USAGE: deimos mkobj (buffer) (Ncross) [-object vector] [-sky vector] [-backgnd vector] [-slit-trace-red spline] [-slit-trace-blu spline] [-psf-trace spline] [-profile vector] [-psf vector] [-lsf vector] [-stilt angle] [-Nwave Npixel] [-redlimit pixel]\n"); 118 gprint (GP_ERR, " slit_trace_red : spline fit of slit central x pos vs y-coord for red chip\n"); 119 gprint (GP_ERR, " slit_trace_blu : spline fit of slit central x pos vs y-coord for blu chip\n"); 120 gprint (GP_ERR, " psf_trace : spline fit of psf central x pos vs y-coord\n"); 121 gprint (GP_ERR, " profile : slit window profile (vector)\n"); 122 gprint (GP_ERR, " object : vector of object flux vs y-coord \n"); 123 gprint (GP_ERR, " sky : vector of local sky signal vs y-coord\n"); 124 gprint (GP_ERR, " backgnd : vector of extra-slit background flux vs y-coord\n"); 125 gprint (GP_ERR, " PSF : point-spread function vector (flux normalized, x-dir)\n"); 126 gprint (GP_ERR, " LSF : sline-spread function vector (flux normalized, y-dir)\n"); 127 gprint (GP_ERR, " stilt : slit tilt response : 2D kernel? \n"); 128 gprint (GP_ERR, " redlimit : pixel break between red and blu chips\n"); 129 gprint (GP_ERR, " Nwave : number of wavelength pixels in output image\n"); 84 gprint (GP_ERR, "USAGE: deimos mkobj (buffer) (Ncross) [-Nwave N] [-object vector] [-sky vector] [-backgnd vector] [-trace spline] [-profile vector]\n"); 130 85 return FALSE; 131 86 } … … 168 123 // if we are appying a trace offset spline, we need to generate an output window which 169 124 // is Nx + the full swing of the trace, then window back down 170 if ( slit_trace_red && slit_trace_blu) {125 if (trace) { 171 126 float dXmin = +1000; 172 127 float dXmax = -1000; 173 128 for (int iy = 0; iy < Ny; iy++) { 174 129 // evaluate the trace spline at this y-coord to find the x-coord offset of the profile center 175 Spline *slit_trace = (iy < redlimit) ? slit_trace_red : slit_trace_blu; 176 float dx = spline_apply_dbl (slit_trace->xk, slit_trace->yk, slit_trace->y2, slit_trace->Nknots, iy); 130 float dx = spline_apply_dbl (trace->xk, trace->yk, trace->y2, trace->Nknots, iy); 177 131 dXmin = MIN (dx, dXmin); 178 132 dXmax = MAX (dx, dXmax); … … 227 181 if (psf) Npof -= Npsf; 228 182 229 // integral and fractional pixel offsets of PSF (none, by default)230 int dxi = 0;231 float dxf = 0.0, dxr = 1.0;232 233 if (psf_trace) {234 float dx = spline_apply_dbl (psf_trace->xk, psf_trace->yk, psf_trace->y2, psf_trace->Nknots, iy);235 dxi = floor(dx);236 dxf = dx - dxi; // -1.7 -> +0.3, -0.5 -> +0.5, +0.5 ->+0.5, +1.7 -> +0.7237 dxr = 1 - dxf;238 Npof += dxi;239 // fprintf (stderr, "%d: %f : %d\n", iy, dx, Npof);240 if (VERBOSE && (iy % 200 == 0)) { gprint (GP_ERR, "%d : %f : %d : %f %f\n", iy, dx, dxi, dxf, dxr); }241 }242 243 // if fractional offset is small, do not interpolate244 int doInterp = fabs(dxf) < 1e-5 ? FALSE : TRUE;245 246 183 // flux = obj * PSF + sky 247 184 for (int ix = 0; ix < Nx; ix++) { … … 254 191 // only add in the flux if we are in range of the PSF 255 192 if ((n >= 0) && (n < NpsfFull)) { 256 if (doInterp) { 257 if ((n > 0) && (n < NpsfFull)) { 258 if (isfinite(psfV[n]) && isfinite(psfV[n-1])) { 259 value += objVy*psfV[n]*dxr + objVy*psfV[n-1]*dxf; 260 } 261 } 262 if (n == 0) { 263 if (isfinite(psfV[n])) { 264 value += objVy*psfV[n]*dxr; 265 } 266 } 267 } else { 268 if (isfinite(psfV[n])) { 269 value += objVy*psfV[n]; 270 } 271 } 193 value += objVy * psfV[n]; 272 194 } 273 195 } else { … … 407 329 408 330 // shift pixels in x based on the trace 409 if ( slit_trace_red && slit_trace_blu) {331 if (trace) { 410 332 ALLOCATE_PTR (outTraceBuffer, char, NxBase*Ny*sizeof(float)); 411 333 float *outTrace = (float *) outTraceBuffer; … … 415 337 416 338 // evaluate the trace spline at this y-coord to find the x-coord offset of the profile center 417 Spline *slit_trace = (iy < redlimit) ? slit_trace_red : slit_trace_blu; 418 float dx = -spline_apply_dbl (slit_trace->xk, slit_trace->yk, slit_trace->y2, slit_trace->Nknots, iy); 339 float dx = -spline_apply_dbl (trace->xk, trace->yk, trace->y2, trace->Nknots, iy); 419 340 420 341 // extract the integer pixel offset and the fractional offset -
trunk/Ohana/src/opihi/mana/deimos_mkslit.c
r41159 r41340 7 7 // input parameters: 8 8 // slit profile response : vector of fractional flux vs x-coord 9 // trace_ref,trace_blu : spline fit of slit central x pos vs y-coord 10 // flux (optional) : vector of input signal vs y-coord 11 // sky (optional) : vector of input signal vs y-coord 12 // fluxbins (optional) : size of output image in y-direction 13 // NOTE: one of flux, sky, or fluxbins must be defined 14 15 // output : buff (an image with Nx defined by profile and Ny defined 16 // by flux, sky, or fluxbins) 9 // trace : spline fit of slit central x pos vs y-coord 10 // flux : vector of input signal vs y-coord 17 11 18 12 int N; 19 13 20 Vector *profile = NULL; 21 Vector *flux = NULL; 22 Vector *sky = NULL; 23 Spline *trace_red = NULL; 24 Spline *trace_blu = NULL; 25 Buffer *buff = NULL; 14 Vector *profile = NULL; 15 Vector *flux = NULL; 16 Vector *sky = NULL; 17 Spline *trace = NULL; 18 Buffer *buff = NULL; 26 19 27 20 // user-specified flux value (otherwise assumed to be 1) … … 47 40 } 48 41 49 // either flux or fluxbins must be specified to define output size 50 int profilebins = 0; 51 if ((N = get_argument (argc, argv, "-profilebins"))) { 52 remove_argument (N, &argc, argv); 53 profilebins = atoi (argv[N]); 54 remove_argument (N, &argc, argv); 55 } 56 57 // for a red vs blu spline, we need to specify the split point 58 // XXX this is REALLY ad-hoc for Deimos. not sure how to make 59 // this more generic (need to define the ranges somewhere) 60 int redlimit = 4096; 61 if ((N = get_argument (argc, argv, "-redlimit"))) { 62 remove_argument (N, &argc, argv); 63 redlimit = atoi (argv[N]); 64 remove_argument (N, &argc, argv); 65 } 66 67 if (argc != 5) { 68 gprint (GP_ERR, "USAGE: deimos mkslit (profile) (trace_red) (trace_blu) (buffer) [-flux vector] [-fluxbins N] [-sky vector]\n"); 42 if (argc != 4) { 43 gprint (GP_ERR, "USAGE: deimos mkslit (profile) (trace) (buffer) [-flux vector] [-fluxbins N] [-sky vector]\n"); 69 44 return FALSE; 70 45 } … … 76 51 77 52 // XXX I probably should rename FindSpline as SelectSpline and give it the same behavior 78 if ((profile = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE); 79 if ((trace_red = FindSpline (argv[2])) == NULL) return (FALSE); 80 if ((trace_blu = FindSpline (argv[3])) == NULL) return (FALSE); 81 if ((buff = SelectBuffer (argv[4], ANYBUFFER, TRUE)) == NULL) return (FALSE); 53 if ((profile = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE); 54 if ((trace = FindSpline (argv[2])) == NULL) return (FALSE); 55 if ((buff = SelectBuffer (argv[3], ANYBUFFER, TRUE)) == NULL) return (FALSE); 82 56 83 57 // define the output window 84 // if no profile half-width is specified, use supplied profile 85 int Nx = profilebins ? 2*profilebins + 1 : 2*profile[0].Nelements + 1; 58 int Nx = 2*profile[0].Nelements + 1; 86 59 int Ny = flux ? flux[0].Nelements : fluxbins; 87 60 … … 100 73 101 74 // evaluate the trace spline at this y-coord to find the x-coord offset of the profile center 102 Spline *trace = (iy < redlimit) ? trace_red : trace_blu;103 75 float dx = spline_apply_dbl (trace->xk, trace->yk, trace->y2, trace->Nknots, iy); 104 76 … … 118 90 119 91 // set the sky in the entire window 120 out[ix + iy*Nx] = NAN;92 out[ix + iy*Nx] = sky ? sky->elements.Flt[iy] : 0.0; 121 93 122 94 // equivalent coord in the profile: … … 126 98 127 99 // a default value: 128 float vsky = sky ? sky->elements.Flt[iy] : 0.0;129 100 float vout = NAN; 130 101 … … 150 121 if (flux) vout *= flux->elements.Flt[iy]; 151 122 152 out[ix + iy*Nx] = vsky +vout;123 out[ix + iy*Nx] += vout; 153 124 } 154 125 } -
trunk/Ohana/src/opihi/pantasks/Makefile
r41281 r41340 92 92 $(SRC)/task_command.$(ARCH).o \ 93 93 $(SRC)/task_options.$(ARCH).o \ 94 $(SRC)/version.$(ARCH).o 94 $(SRC)/version.$(ARCH).o \ 95 $(SRC)/ipptool2book.$(ARCH).o 95 96 96 97 libs = \ -
trunk/Ohana/src/opihi/pantasks/init.c
r41281 r41340 25 25 int verbose PROTO((int, char **)); 26 26 int version PROTO((int, char **)); 27 int ipptool2book PROTO((int, char **)); 27 28 28 29 static Command cmds[] = { … … 34 35 {1, "host", task_host, "define host machine for a task"}, 35 36 {1, "nice", task_nice, "set nice level for a task"}, 37 {1, "ipptool2book", ipptool2book, "convert queue with ipptool output to book"}, 36 38 {1, "kill", kill_job, "kill job"}, 37 39 {1, "nmax", task_nmax, "define maximum number of jobs for a task"}, -
trunk/Ohana/src/opihi/pantasks/init_server.c
r41281 r41340 23 23 int version PROTO((int, char **)); 24 24 int server PROTO((int, char **)); 25 int ipptool2book PROTO((int, char **)); 25 26 26 27 int server_run PROTO((int, char **)); … … 35 36 {1, "host", task_host, "define host machine for a task"}, 36 37 {1, "nice", task_nice, "set nice level for a task"}, 38 {1, "ipptool2book", ipptool2book, "convert queue with ipptool output to book"}, 37 39 {1, "kill", kill_job, "kill job"}, 38 40 {1, "nmax", task_nmax, "define maximum number of jobs for a task"}, -
trunk/Ohana/src/photdbc/include/photdbc.h
r40874 r41340 44 44 int SKIP_IMAGES; 45 45 int ONLY_IMAGES; 46 47 int SKIP_MEASURE;48 int SKIP_MISSING;49 int SKIP_LENSING;50 int SKIP_LENSOBJ;51 int SKIP_STARPAR;52 int SKIP_GALPHOT;53 54 46 int SHOW_PARAMS; 55 47 int VERBOSE; -
trunk/Ohana/src/photdbc/src/args.c
r40874 r41340 29 29 } 30 30 ONLY_IMAGES = TRUE; 31 remove_argument (N, &argc, argv);32 }33 34 /** allow only certain tables to be copied **/35 SKIP_MEASURE = FALSE;36 if ((N = get_argument (argc, argv, "-skip-measure"))) {37 SKIP_MEASURE = TRUE;38 remove_argument (N, &argc, argv);39 }40 SKIP_MISSING = FALSE;41 if ((N = get_argument (argc, argv, "-skip-missing"))) {42 SKIP_MISSING = TRUE;43 remove_argument (N, &argc, argv);44 }45 SKIP_LENSING = FALSE;46 if ((N = get_argument (argc, argv, "-skip-lensing"))) {47 SKIP_LENSING = TRUE;48 remove_argument (N, &argc, argv);49 }50 SKIP_LENSOBJ = FALSE;51 if ((N = get_argument (argc, argv, "-skip-lensobj"))) {52 SKIP_LENSOBJ = TRUE;53 remove_argument (N, &argc, argv);54 }55 SKIP_STARPAR = FALSE;56 if ((N = get_argument (argc, argv, "-skip-starpar"))) {57 SKIP_STARPAR = TRUE;58 remove_argument (N, &argc, argv);59 }60 SKIP_GALPHOT = FALSE;61 if ((N = get_argument (argc, argv, "-skip-galphot"))) {62 SKIP_GALPHOT = TRUE;63 31 remove_argument (N, &argc, argv); 64 32 } … … 278 246 remove_argument (N, &argc, argv); 279 247 MAX_MIN_MAG = atof(argv[N]); 280 remove_argument (N, &argc, argv);281 }282 283 /** allow only certain tables to be copied **/284 SKIP_MEASURE = FALSE;285 if ((N = get_argument (argc, argv, "-skip-measure"))) {286 SKIP_MEASURE = TRUE;287 remove_argument (N, &argc, argv);288 }289 SKIP_MISSING = FALSE;290 if ((N = get_argument (argc, argv, "-skip-missing"))) {291 SKIP_MISSING = TRUE;292 remove_argument (N, &argc, argv);293 }294 SKIP_LENSING = FALSE;295 if ((N = get_argument (argc, argv, "-skip-lensing"))) {296 SKIP_LENSING = TRUE;297 remove_argument (N, &argc, argv);298 }299 SKIP_LENSOBJ = FALSE;300 if ((N = get_argument (argc, argv, "-skip-lensobj"))) {301 SKIP_LENSOBJ = TRUE;302 remove_argument (N, &argc, argv);303 }304 SKIP_STARPAR = FALSE;305 if ((N = get_argument (argc, argv, "-skip-starpar"))) {306 SKIP_STARPAR = TRUE;307 remove_argument (N, &argc, argv);308 }309 SKIP_GALPHOT = FALSE;310 if ((N = get_argument (argc, argv, "-skip-galphot"))) {311 SKIP_GALPHOT = TRUE;312 248 remove_argument (N, &argc, argv); 313 249 } -
trunk/Ohana/src/photdbc/src/make_subcatalog.c
r40874 r41340 1 1 # include "photdbc.h" 2 3 # define SKIP_MEASURE FALSE 4 # define SKIP_LENSING FALSE 5 # define SKIP_LENSOBJ FALSE 6 # define SKIP_STARPAR FALSE 7 # define SKIP_GALPHOT FALSE 2 8 3 9 // copy a catalog to a new subcatalog, applying some filters -
trunk/Ohana/src/photdbc/src/photdbc_catalogs.c
r40874 r41340 152 152 if (CATMODE) { strextend (&command, "-set-mode %s", CATMODE); } 153 153 154 if (SKIP_MEASURE) { strextend (&command, "-skip-measure"); }155 if (SKIP_MISSING) { strextend (&command, "-skip-missing"); }156 if (SKIP_LENSING) { strextend (&command, "-skip-lensing"); }157 if (SKIP_LENSOBJ) { strextend (&command, "-skip-lensobj"); }158 if (SKIP_GALPHOT) { strextend (&command, "-skip-galphot"); }159 if (SKIP_STARPAR) { strextend (&command, "-skip-starpar"); }160 161 154 if (PARALLEL_OUTHOSTS) { 162 155 tmppath = abspath (table_output->hosts[i].pathname, DVO_MAX_PATH); -
trunk/Ohana/src/relphot/src/reload_catalogs.c
r41153 r41340 62 62 63 63 catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT; 64 // if we are going to update the format, we should update all tables65 if (UPDATE_CATFORMAT) {66 catalog.catflags |= DVO_LOAD_LENSING | DVO_LOAD_LENSOBJ | DVO_LOAD_STARPAR | DVO_LOAD_GALPHOT;67 }68 64 catalog.Nsecfilt = GetPhotcodeNsecfilt (); // set the desired number in case we need to create the catalog 69 65 -
trunk/Ohana/src/relphot/src/relphot_objects.c
r41153 r41340 73 73 74 74 catalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT; 75 // if we are going to update the format, we should update all tables76 if (UPDATE_CATFORMAT) {77 catalog.catflags |= DVO_LOAD_LENSING | DVO_LOAD_LENSOBJ | DVO_LOAD_STARPAR | DVO_LOAD_GALPHOT;78 }79 75 catalog.Nsecfilt = GetPhotcodeNsecfilt (); 80 76 … … 166 162 // we can optionally convert output format here 167 163 // but it would be better to define a dvo crawler program to do this 168 // catalog.catformat = DVO_FORMAT_PS1_V1; 169 170 // modify the output format as desired (ignore current format on disk) 171 if (UPDATE_CATFORMAT) { 172 catalog.catformat = dvo_catalog_catformat (UPDATE_CATFORMAT); 173 } 174 164 // catalog.catformat = DVO_FORMAT_PS1_V1; 175 165 SetProtect (TRUE); 176 166 if (!dvo_catalog_save (&catalog, VERBOSE)) { fprintf (stderr, "ERROR: failed to save %s\n", catalog.filename); exit (1); }
Note:
See TracChangeset
for help on using the changeset viewer.
