diff --git a/calcAP/Makefile b/calcAP/Makefile new file mode 100644 index 0000000..4e9dbc7 --- /dev/null +++ b/calcAP/Makefile @@ -0,0 +1,14 @@ +LDFLAGS = -lm -lsla -lsofa_c +SRCS = $(wildcard *.c) +CC = gcc +DEFINES = -D_XOPEN_SOURCE=1111 +CFLAGS = -Wall -Werror -Wextra $(DEFINES) +TARGS = $(SRCS:.c=) +all : $(TARGS) +slalib_and_sofa : slalib_and_sofa.c + $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ +slalib_sofa_nova : slalib_sofa_nova.c + $(CC) $(CFLAGS) $(LDFLAGS) -lnova -lerfa $< -o $@ + +clean: + /bin/rm -f *.o *~ diff --git a/calcAP/Readme b/calcAP/Readme new file mode 100644 index 0000000..e56c7f9 --- /dev/null +++ b/calcAP/Readme @@ -0,0 +1 @@ +Comparison of apparent place calculation in different libraries diff --git a/calcAP/slalib_and_sofa.c b/calcAP/slalib_and_sofa.c new file mode 100644 index 0000000..fd91486 --- /dev/null +++ b/calcAP/slalib_and_sofa.c @@ -0,0 +1,189 @@ +/* + * slalib_and_sofa.c - calculate apparent place by slalib & libsofa + * + * Copyright 2016 Edward V. Emelianov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#define _GNU_SOURCE 1111 // strcasecmp + +#include "sofa.h" +#include +#include +#include + +#define DBG(...) printf(__VA_ARGS__) + +extern void sla_caldj(int*, int*, int*, double*, int*); +extern void sla_amp(double*, double*, double*, double*, double*, double*); +extern void sla_map(double*, double*, double*, double*, double*,double*, double*, double*, double*, double*); +void slacaldj(int y, int m, int d, double *djm, int *j){ + int iy = y, im = m, id = d; + sla_caldj(&iy, &im, &id, djm, j); +} +void slaamp(double ra, double da, double date, double eq, double *rm, double *dm ){ + double r = ra, d = da, mjd = date, equi = eq; + sla_amp(&r, &d, &mjd, &equi, rm, dm); +} +// rm,dm - mean RA,Dec (rad), pr,pd - RA,Dec changes per Julian year (dRA/dt, dDec/dt) +// px - parallax (arcsec), rv - radial speed (km/sec, +ve if receding) +// eq - epoch and equinox of star data (Julian) +// date - TDB for apparent place (JD-2400000.5) +void slamap(double rm, double dm, double pr, double pd, + double px, double rv, double eq, double date, + double *ra, double *da){ + double r = rm, d = dm, p1 = pr, p2 = pd, ppx = px, prv = rv, equi = eq, dd = date; + sla_map(&r, &d, &p1, &p2, &ppx, &prv, &equi, &dd, ra, da); +} + +void reprd(char* s, double ra, double dc){ + char pm; + int i[4]; + printf ( "%30s", s ); + iauA2tf ( 7, ra, &pm, i ); + printf ( " %2.2d %2.2d %2.2d.%7.7d", i[0],i[1],i[2],i[3] ); + iauA2af ( 6, dc, &pm, i ); + printf ( " %c%2.2d %2.2d %2.2d.%6.6d\n", pm, i[0],i[1],i[2],i[3] ); +} + +void radtodeg(double r){ + int i[4]; char pm; + int rem = (int)(r / D2PI); + if(rem) r -= D2PI * rem; + if(r > DPI) r -= D2PI; + else if(r < -DPI) r += D2PI; + iauA2af (2, r, &pm, i); + printf("%c%02d %02d %02d.%2.d", pm, i[0],i[1],i[2],i[3]); +} + +double getta(char *str){ + int a,b,s = 1; double c; + if(3 != sscanf(str, "%d:%d:%lf", &a,&b,&c)) return -1; + if(a < 0){ s = -1; a = -a;} + c /= 3600.; + c += a + b/60.; + c *= s; + return c; +} + +int main (int argc, char **argv){ + double rc, dc; + if(argc == 3){ + rc = getta(argv[1]) * DPI / 12; + dc = getta(argv[2]) * DD2R; + }else{ + /* Star ICRS RA,Dec (radians). */ + if ( iauTf2a ( ' ', 19, 50, 47.6, &rc ) ) return -1; + if ( iauAf2a ( '+', 8, 52, 12.3, &dc ) ) return -1; + } + reprd ( "ICRS, epoch J2000.0:", rc, dc ); + + struct tm tms; + time_t t = time(NULL); + gmtime_r(&t, &tms); + int y, m, d, err; + y = 1900 + tms.tm_year; + m = tms.tm_mon + 1; + d = tms.tm_mday; + double mjd, add = ((double)tms.tm_hour + (double)tms.tm_min/60.0 + tms.tm_sec/3600.0) / 24.; + DBG("Date: (d/m/y +frac) %d/%d/%d +%g\n", d, m, y, add); + slacaldj(y, m, d, &mjd, &err); + if(err){ + fprintf(stderr, "slacaldj(): Wrong %s!", (err == 1) ? "year" : + (err == 2? "month" : "day")); + return -1; + } + mjd += add; + DBG("MJD by slalib: %g\n", mjd); + double utc1, utc2; + /* UTC date. */ + if(iauDtf2d("UTC", y, m, d, tms.tm_hour, tms.tm_min, tms.tm_sec, + &utc1, &utc2)) return -1; + DBG("UTC by sofa: %g, %g\n", utc1 - 2400000.5, utc2); + double tai1, tai2, tt1, tt2; + /* TT date. */ + if ( iauUtctai ( utc1, utc2, &tai1, &tai2 ) ) return -1; + if ( iauTaitt ( tai1, tai2, &tt1, &tt2 ) ) return -1; + DBG("date by sofa (utc/tt): %g/%g & %g/%g\n", tai1 - 2400000.5, tt1 - 2400000.5, tai2, tt2); + + double pmra=0, pr=0, pd=0, px=0, rv=0; + /* + // Proper motion: RA/Dec derivatives, epoch J2000.0. + pmra = 536.23e-3 * DAS2R; + pr = atan2 ( pmra, cos(dc) ); + pd = 385.29e-3 * DAS2R; + // Parallax (arcsec) and recession speed (km/s). + px = 0.19495; + rv = -26.1;*/ + double ri, di, eo; + /* ICRS to CIRS (geocentric observer). */ + iauAtci13 ( rc, dc, pr, pd, px, rv, tt1, tt2, &ri, &di, &eo ); + reprd ( "catalog -> CIRS:", ri, di ); + double rca, dca; + /* CIRS to ICRS (astrometric). */ + iauAtic13 ( ri, di, tt1, tt2, &rca, &dca, &eo ); + reprd ( "CIRS -> astrometric:", rca, dca ); + /* ICRS (astrometric) to CIRS (geocentric observer). */ + iauAtci13 ( rca, dca, 0.0, 0.0, 0.0, 0.0, tt1, tt2, &ri, &di, &eo ); + reprd ( "astrometric -> CIRS:", ri, di ); + double ra, da; + /* Apparent place. */ + ra = iauAnp ( ri - eo ); + da = di; + reprd ( "geocentric apparent:", ra, da ); + slamap(rc, dc, pmra, pd, px, rv, 2000., mjd, &ra, &da); + reprd ( "geocentric apparent (sla):", ra, da ); + double ra2000, decl2000; + slaamp(ra, da, mjd, 2000.0, &ra2000, &decl2000); + reprd ( "apparent -> astrometric (sla):", ra2000, decl2000); + + double elong, phi, hm, phpa, tc, rh, wl, xp, yp, dut1; + /* Site longitude, latitude (radians) and height above the geoid (m). */ + iauAf2a ( '+', 41, 26, 26.45, &elong ); + iauAf2a ( '+', 43, 39, 12.69, &phi ); + hm = 2070.0; + /* Ambient pressure (HPa), temperature (C) and rel. humidity (frac). */ + phpa = 770.0; // milliBar or hectopascal + tc = -5.0; + rh = 0.7; + /* Effective wavelength (microns) */ + wl = 0.55; + /* EOPs: polar motion in radians, UT1-UTC in seconds. */ + xp = 0.1074 * DAS2R; //polarX + yp = 0.2538 * DAS2R;//polarY + dut1 = 0.13026 ; // DUT1 + /* ICRS to observed. */ + double aob, zob, hob, dob, rob; + if ( iauAtco13 ( rc, dc, pr, + pd, px, rv, utc1, utc2, dut1, elong, phi, + hm, xp, yp, phpa, tc, rh, wl, &aob, &zob, + &hob, &dob, &rob, &eo ) ) return -1; + reprd ( "ICRS -> observed:", rob, dob ); + printf("A(bta)/Z: "); + radtodeg(aob); + printf("("); radtodeg(DPI-aob); + printf(")/"); radtodeg(zob); + printf("\n"); + if( iauAtoc13 ( "R", rc, dc, utc1, utc2, dut1, + //if( iauAtoc13 ( "R", rob, dob, 2451545, 0, dut1, + elong, phi, hm, xp, yp, phpa, tc, rh, wl, &rca, &dca )) return -1; + reprd ( "observed -> astrometric:", rca, dca ); + return 0; +} + + diff --git a/calcAP/slalib_sofa_nova.c b/calcAP/slalib_sofa_nova.c new file mode 100644 index 0000000..c00ed72 --- /dev/null +++ b/calcAP/slalib_sofa_nova.c @@ -0,0 +1,317 @@ +/* + * slalib_and_sofa.c - calculate apparent place by slalib & libsofa + * + * Copyright 2016 Edward V. Emelianov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#define _GNU_SOURCE 1111 // strcasecmp + +/** + SOFA - NOVA - SLA + comparison +**/ + +#include +#include +#include +#include +#include +#include //- the same data as SOFA +#include + +#define DBG(...) printf(__VA_ARGS__) + +extern void sla_caldj(int*, int*, int*, double*, int*); +extern void sla_amp(double*, double*, double*, double*, double*, double*); +extern void sla_map(double*, double*, double*, double*, double*,double*, double*, double*, double*, double*); +void slacaldj(int y, int m, int d, double *djm, int *j){ + int iy = y, im = m, id = d; + sla_caldj(&iy, &im, &id, djm, j); +} +void slaamp(double ra, double da, double date, double eq, double *rm, double *dm ){ + double r = ra, d = da, mjd = date, equi = eq; + sla_amp(&r, &d, &mjd, &equi, rm, dm); +} +// apparent->observed +extern void sla_aop(double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*); +/* +* Given: +* RAP d geocentric apparent right ascension +* DAP d geocentric apparent declination +* DATE d UTC date/time (Modified Julian Date, JD-2400000.5) +* DUT d delta UT: UT1-UTC (UTC seconds) +* ELONGM d mean longitude of the observer (radians, east +ve) +* PHIM d mean geodetic latitude of the observer (radians) +* HM d observer's height above sea level (metres) +* XP d polar motion x-coordinate (radians) +* YP d polar motion y-coordinate (radians) +* TDK d local ambient temperature (K; std=273.15D0) +* PMB d local atmospheric pressure (mb; std=1013.25D0) +* RH d local relative humidity (in the range 0D0-1D0) +* WL d effective wavelength (micron, e.g. 0.55D0) +* TLR d tropospheric lapse rate (K/metre, e.g. 0.0065D0) +* +* Returned: +* AOB d observed azimuth (radians: N=0,E=90) +* ZOB d observed zenith distance (radians) +* HOB d observed Hour Angle (radians) +* DOB d observed Declination (radians) +* ROB d observed Right Ascension (radians) +*/ +void slaaop(double rap, double dap, double date, double dut, double elongm, double phim, + double hm, double xp, double yp, double tdk, double pmb, double rh, double wl, + double tlr, + double* aob, double* zob, double* hob, double* dob, double* rob){ + double _rap=rap, _dap=dap, _date=date, _dut=dut, _elongm=elongm, _phim=phim, + _hm=hm, _xp=xp, _yp=yp, _tdk=tdk, _pmb=pmb, _rh=rh, _wl=wl, _tlr=tlr; + sla_aop(&_rap, &_dap, &_date, &_dut, &_elongm, &_phim, &_hm, &_xp, &_yp, &_tdk, + &_pmb, &_rh, &_wl, &_tlr, aob, zob, hob, dob, rob); +} + +// rm,dm - mean RA,Dec (rad), pr,pd - RA,Dec changes per Julian year (dRA/dt, dDec/dt) +// px - parallax (arcsec), rv - radial speed (km/sec, +ve if receding) +// eq - epoch and equinox of star data (Julian) +// date - TDB for apparent place (JD-2400000.5) +void slamap(double rm, double dm, double pr, double pd, + double px, double rv, double eq, double date, + double *ra, double *da){ + double r = rm, d = dm, p1 = pr, p2 = pd, ppx = px, prv = rv, equi = eq, dd = date; + sla_map(&r, &d, &p1, &p2, &ppx, &prv, &equi, &dd, ra, da); +} + +void reprd(char* s, double ra, double dc){ + char pm; + int i[4]; + printf ( "%30s", s ); + iauA2tf ( 7, ra, &pm, i ); + printf ( " %2.2d %2.2d %2.2d.%7.7d", i[0],i[1],i[2],i[3] ); + iauA2af ( 6, dc, &pm, i ); + printf ( " %c%2.2d %2.2d %2.2d.%6.6d\n", pm, i[0],i[1],i[2],i[3] ); +} + +void radtodeg(double r){ + int i[4]; char pm; + int rem = (int)(r / D2PI); + if(rem) r -= D2PI * rem; + if(r > DPI) r -= D2PI; + else if(r < -DPI) r += D2PI; + iauA2af (2, r, &pm, i); + printf("%c%02d %02d %02d.%2.d", pm, i[0],i[1],i[2],i[3]); +} + +double getta(char *str){ + int a,b,s = 1; double c; + if(3 != sscanf(str, "%d:%d:%lf", &a,&b,&c)) return -1; + if(a < 0){ s = -1; a = -a;} + c /= 3600.; + c += a + b/60.; + c *= s; + return c; +} + +int main (int argc, char **argv){ + double rc, dc; + if(argc == 3){ + rc = getta(argv[1]) * DPI / 12; + dc = getta(argv[2]) * DD2R; + }else{ + /* Star ICRS RA,Dec (radians). */ + if ( iauTf2a ( ' ', 19, 50, 47.6, &rc ) ) return -1; + if ( iauAf2a ( '+', 8, 52, 12.3, &dc ) ) return -1; + } + reprd ( "ICRS (catalog), epoch J2000.0:", rc, dc ); + + struct tm tms; + struct timeval currentTime; + gettimeofday(¤tTime, NULL); + gmtime_r(¤tTime.tv_sec, &tms); + double tSeconds = tms.tm_sec + ((double)currentTime.tv_usec)/1e6; + int y, m, d, err; + y = 1900 + tms.tm_year; + m = tms.tm_mon + 1; + d = tms.tm_mday; + double mjd, add = ((double)tms.tm_hour + (double)tms.tm_min/60.0 + tSeconds/3600.0) / 24.; + DBG("Date: (d/m/y +frac) %d/%d/%d +%.8f\n", d, m, y, add); + slacaldj(y, m, d, &mjd, &err); + if(err){ + fprintf(stderr, "slacaldj(): Wrong %s!", (err == 1) ? "year" : + (err == 2? "month" : "day")); + return -1; + } + mjd += add; + DBG("MJD by slalib: %.8f\n", mjd); + double utc1, utc2; + /* UTC date. */ + if(iauDtf2d("UTC", y, m, d, tms.tm_hour, tms.tm_min, tSeconds, + &utc1, &utc2)) return -1; + DBG("UTC by sofa: %g, %.8f\n", utc1 - 2400000.5, utc2); + double tai1, tai2, tt1, tt2; + /* TT date. */ + if ( iauUtctai ( utc1, utc2, &tai1, &tai2 ) ) return -1; + if ( iauTaitt ( tai1, tai2, &tt1, &tt2 ) ) return -1; + DBG("date by sofa (TAI/TT): %g/%g & %g/%g\n", tai1 - 2400000.5, tt1 - 2400000.5, tai2, tt2); + + double pmra=0; + double pr = 0.0; // RA proper motion (radians/year; Note 2) + double pd = 0.0; // Dec proper motion (radians/year) + double px = 0.0; // parallax (arcsec) + double rv = 0.0; // radial velocity (km/s, positive if receding) + /* + // Proper motion: RA/Dec derivatives, epoch J2000.0. + pmra = 536.23e-3 * DAS2R; + pr = atan2 ( pmra, cos(dc) ); + pd = 385.29e-3 * DAS2R; + // Parallax (arcsec) and recession speed (km/s). + px = 0.19495; + rv = -26.1;*/ + double ri, di, eo; + /* ICRS to CIRS (geocentric observer). */ + iauAtci13 ( rc, dc, pr, pd, px, rv, tt1, tt2, &ri, &di, &eo ); + reprd ( "ICRS -> CIRS:", ri, di ); + double rca, dca, eo1; + /* CIRS to ICRS (astrometric). */ + iauAtic13 ( ri, di, tt1, tt2, &rca, &dca, &eo1); + reprd ( "CIRS -> ICRSc:", rca, dca ); + /* ICRS to CIRS without PM + iauAtci13 ( rca, dca, 0.0, 0.0, 0.0, 0.0, tt1, tt2, &ri, &di, &eo ); + reprd ( "ICRSc -> CIRS (without PM):", ri, di ); */ + double ra, da; + /* Apparent place. */ + ra = iauAnp ( ri - eo ); + da = di; + reprd ( "geocentric apparent:", ra, da ); + slamap(rc, dc, pmra, pd, px, rv, 2000., mjd, &ra, &da); + reprd ( "geocentric apparent (sla):", ra, da ); + double ra2000, decl2000; + slaamp(ra, da, mjd, 2000.0, &ra2000, &decl2000); + reprd ( "apparent -> astrometric (sla):", ra2000, decl2000); + + double elong, phi, hm, phpa, tc, rh, wl, xp, yp, dut1; + /* Site longitude, latitude (radians) and height above the geoid (m). */ + iauAf2a ( '+', 41, 26, 26.45, &elong ); + iauAf2a ( '+', 43, 39, 12.69, &phi ); + hm = 2070.0; + /* Ambient pressure (HPa), temperature (C) and rel. humidity (frac). */ + phpa = 780.0; tc = -5.0; rh = 0.7; + /* Effective wavelength (microns) */ + wl = 0.55; + /* EOPs: polar motion in radians, UT1-UTC in seconds. */ + xp = 0.1074 * DAS2R; //polarX + yp = 0.2538 * DAS2R;//polarY + dut1 = 0.13026 ; // DUT1 + /* ICRS to observed. */ + double aob, zob, hob, dob, rob; + if ( iauAtco13 ( rc, dc, pr, + pd, px, rv, utc1, utc2, dut1, elong, phi, + hm, xp, yp, phpa, tc, rh, wl, &aob, &zob, + &hob, &dob, &rob, &eo ) ) return -1; + reprd ( "ICRS -> observed:", rob, dob ); + printf("A(bta)/Z: "); + radtodeg(aob); + printf("("); radtodeg(DPI-aob); + printf(")/"); radtodeg(zob); + printf("\n"); + if( iauAtoc13 ( "R", rob, dob, utc1, utc2, dut1, + elong, phi, hm, xp, yp, phpa, tc, rh, wl, &rca, &dca )) return -1; + reprd ( "observed -> ICRS:", rca, dca ); + + /* + * Given: + * RAP d geocentric apparent right ascension + * DAP d geocentric apparent declination + * DATE d UTC date/time (Modified Julian Date, JD-2400000.5) + * DUT d delta UT: UT1-UTC (UTC seconds) + * ELONGM d mean longitude of the observer (radians, east +ve) + * PHIM d mean geodetic latitude of the observer (radians) + * HM d observer's height above sea level (metres) + * XP d polar motion x-coordinate (radians) + * YP d polar motion y-coordinate (radians) + * TDK d local ambient temperature (K; std=273.15D0) + * PMB d local atmospheric pressure (mb; std=1013.25D0) + * RH d local relative humidity (in the range 0D0-1D0) + * WL d effective wavelength (micron, e.g. 0.55D0) + * TLR d tropospheric lapse rate (K/metre, e.g. 0.0065D0) + * + * Returned: + * AOB d observed azimuth (radians: N=0,E=90) + * ZOB d observed zenith distance (radians) + * HOB d observed Hour Angle (radians) + * DOB d observed Declination (radians) + * ROB d observed Right Ascension (radians) + */ + slaaop(ra, da, mjd, dut1, elong, phi, hm, xp, yp, tc+273., phpa, rh, wl, 0.0065, + &aob, &zob, &hob, &dob, &rob); + reprd ( "ICRS -> observed (sla):", rob, dob ); + printf("A(bta)/Z: "); + radtodeg(aob); + printf("("); radtodeg(DPI-aob); + printf(")/"); radtodeg(zob); + printf("\n"); + + //////////////////////////////////////////////////////////////////////////////////////////////// + // libNOVA + //////////////////////////////////////////////////////////////////////////////////////////////// + struct ln_equ_posn mean_position; + mean_position.ra = rc * ERFA_DR2D; // radians to degrees + mean_position.dec = dc * ERFA_DR2D; +/* + struct timeval tv; + struct timezone tz; + gettimeofday(&tv, &tz); // number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC) with microsecond precision + struct tm *utc_tm; + utc_tm = gmtime(&tv.tv_sec); + struct ln_date date; + date.seconds = utc_tm->tm_sec + ((double)tv.tv_usec / 1000000); + date.minutes = utc_tm->tm_min; + date.hours = utc_tm->tm_hour; + date.days = utc_tm->tm_mday; + date.months = utc_tm->tm_mon + 1; + date.years = utc_tm->tm_year + 1900; + double JNow = ln_get_julian_day(&date);*/ + double JNow = ln_get_julian_from_sys(); + struct ln_equ_posn propm={0,0}, apppl;//, equprec; + ln_get_apparent_posn(&mean_position, &propm, JNow, &apppl); + reprd ("geocentric apparent (NOVA):", apppl.ra*ERFA_DD2R, apppl.dec*ERFA_DD2R); + // Calculate the effects of precession on equatorial coordinates, between arbitary Jxxxx epochs. +/* + ln_get_equ_prec2(&mean_position, JD2000, JNow, &equprec); + reprd ("ln_get_equ_prec2 (NOVA):", equprec.ra*ERFA_DD2R, equprec.dec*ERFA_DD2R); + */ +/* + // ERFA + struct tm *ts; + ts = gmtime(&t); + int result = eraDtf2d ( "UTC", ts->tm_year+1900, ts->tm_mon+1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec, &utc1, &utc2 ); + if (result != 0) { + printf("eraDtf2d call failed\n"); + return 1; + } + // Make TT julian date for Atci13 call + result = eraUtctai( utc1, utc2, &tai1, &tai2 ); + if (result != 0) { + printf("eraUtctai call failed\n"); + return 1; + } + eraTaitt( tai1, tai2, &tt1, &tt2 ); + eraAtci13 ( rc, dc, pr, pd, px, rv, tt1, tt2, &ri, &di, &eo ); + reprd ( "geocentric apparent (ERFA):", eraAnp(ri - eo), di); +*/ + return 0; +} + diff --git a/cmakelists_/Makefile b/cmakelists_/Makefile deleted file mode 100644 index 7804b54..0000000 --- a/cmakelists_/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# run `make DEF=...` to add extra defines -PROGRAM := -LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all -SRCS := $(wildcard *.c) -DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111 -OBJDIR := mk -CFLAGS += -O2 -Wall -Wextra -Wno-trampolines -std=gnu99 -OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o)) -DEPS := $(OBJS:.o=.d) -CC = gcc -#CXX = g++ - - -all : $(OBJDIR) $(PROGRAM) - -debug: CFLAGS += -DEBUG -Werror -debug: all - -$(PROGRAM) : $(OBJS) - @echo -e "\t\tLD $(PROGRAM)" - $(CC) $(LDFLAGS) $(OBJS) -o $(PROGRAM) - -$(OBJDIR): - mkdir $(OBJDIR) - -ifneq ($(MAKECMDGOALS),clean) --include $(DEPS) -endif - -$(OBJDIR)/%.o: %.c - @echo -e "\t\tCC $<" - $(CC) -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ $< - -clean: - @echo -e "\t\tCLEAN" - @rm -f $(OBJS) $(DEPS) - @rmdir $(OBJDIR) 2>/dev/null || true - -xclean: clean - @rm -f $(PROGRAM) - -gentags: - CFLAGS="$(CFLAGS) $(DEFINES)" geany -g $(PROGRAM).c.tags *[hc] 2>/dev/null - -.PHONY: gentags clean xclean diff --git a/image_view_module/CMakeLists.txt b/image_view_module/CMakeLists.txt index 806fb3d..3fe300c 100644 --- a/image_view_module/CMakeLists.txt +++ b/image_view_module/CMakeLists.txt @@ -29,6 +29,7 @@ aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} IMSOURCES) find_package(PkgConfig REQUIRED) find_package(OpenGL REQUIRED) find_package(GLUT REQUIRED) +find_package(X11 REQUIRED) if(NOT GLUT_FOUND OR NOT OPENGL_FOUND) message("GLUT library not found, image view won't be available") @@ -143,7 +144,7 @@ else() ) endif(NOT DEFINED NOGETTEXT) endif(NOT DEFINED STANDALONE) -target_link_libraries(${IMLIB} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} -lm -lpthread) +target_link_libraries(${IMLIB} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${X11_LIBRARIES} -lm -lpthread) include_directories(${${IMLIB}_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIR} ${GLUT_INCLUDE_DIR}) link_directories(${${IMLIB}_LIBRARY_DIRS}) endif(NOT GLUT_FOUND OR NOT OPENGL_FOUND) diff --git a/image_view_module/imageview.c b/image_view_module/imageview.c index 529cd19..3cb8131 100644 --- a/image_view_module/imageview.c +++ b/image_view_module/imageview.c @@ -91,8 +91,10 @@ void createWindow(windowData *win){ win->zoom = 1. / win->Daspect; glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, win->Tex); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, win->image->w, win->image->h, 0, + GL_RGB, GL_UNSIGNED_BYTE, win->image->rawdata); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); @@ -100,8 +102,6 @@ void createWindow(windowData *win){ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, win->image->w, win->image->h, 0, - GL_RGB, GL_UNSIGNED_BYTE, win->image->rawdata); glDisable(GL_TEXTURE_2D); totWindows++; createMenu(win->GL_ID); @@ -236,10 +236,17 @@ void RedrawWindow(){ */ w /= 2.; h /= 2.; glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.0f); glVertex2f(-w, -h ); - glTexCoord2f(1.0f, 0.0f); glVertex2f( w, -h ); - glTexCoord2f(1.0f, 1.0f); glVertex2f( w, h ); - glTexCoord2f(0.0f, 1.0f); glVertex2f(-w, h ); +/* + glTexCoord2f(1.0f, 1.0f); glVertex2f( w, h ); // top right + glTexCoord2f(1.0f, 0.0f); glVertex2f( w, -h ); // bottom right + glTexCoord2f(0.0f, 0.0f); glVertex2f(-w, -h ); // bottom left + glTexCoord2f(0.0f, 1.0f); glVertex2f(-w, h ); // top left + */ + glTexCoord2f(1.0f, 1.0f); glVertex2f( -w, -h ); // top right + glTexCoord2f(1.0f, 0.0f); glVertex2f( -w, h ); // bottom right + glTexCoord2f(0.0f, 0.0f); glVertex2f(w, h ); // bottom left + glTexCoord2f(0.0f, 1.0f); glVertex2f(w, -h ); // top left + glEnd(); glDisable(GL_TEXTURE_2D); glFinish(); diff --git a/image_view_module/locale/ru/LC_MESSAGES/image_view_module.mo b/image_view_module/locale/ru/LC_MESSAGES/image_view_module.mo index 8431b67..b0e6d21 100644 Binary files a/image_view_module/locale/ru/LC_MESSAGES/image_view_module.mo and b/image_view_module/locale/ru/LC_MESSAGES/image_view_module.mo differ diff --git a/image_view_module/locale/ru/messages.po b/image_view_module/locale/ru/messages.po index 6caa9a1..05a5fb3 100644 --- a/image_view_module/locale/ru/messages.po +++ b/image_view_module/locale/ru/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-03-02 13:58+0300\n" +"POT-Creation-Date: 2020-01-23 12:32+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,41 +17,41 @@ msgstr "" "Content-Type: text/plain; charset=koi8-r\n" "Content-Transfer-Encoding: 8bit\n" -#: /home/eddy/tmp/image_view_module/macros.c:175 -msgid "No filename given!" -msgstr "" - -#: /home/eddy/tmp/image_view_module/macros.c:177 -#, c-format -msgid "Can't open %s for reading" -msgstr "" - -#: /home/eddy/tmp/image_view_module/macros.c:179 -#, c-format -msgid "Can't stat %s" -msgstr "" - -#: /home/eddy/tmp/image_view_module/macros.c:182 -msgid "Mmap error for input" -msgstr "" - -#: /home/eddy/tmp/image_view_module/macros.c:183 -msgid "Can't close mmap'ed file" -msgstr "" - -#: /home/eddy/tmp/image_view_module/macros.c:192 -msgid "Can't munmap" -msgstr "" - -#: /home/eddy/tmp/image_view_module/imageview.c:132 +#: /tmp/image_view_module/imageview.c:132 msgid "Error removing from list" msgstr "" -#: /home/eddy/tmp/image_view_module/imageview.c:362 +#: /tmp/image_view_module/imageview.c:369 msgid "Can't init mutex!" msgstr "" #. "Уже инициализировано!" -#: /home/eddy/tmp/image_view_module/imageview.c:389 +#: /tmp/image_view_module/imageview.c:396 msgid "Already initialized!" msgstr "" + +#: /tmp/image_view_module/macros.c:175 +msgid "No filename given!" +msgstr "" + +#: /tmp/image_view_module/macros.c:177 +#, c-format +msgid "Can't open %s for reading" +msgstr "" + +#: /tmp/image_view_module/macros.c:179 +#, c-format +msgid "Can't stat %s" +msgstr "" + +#: /tmp/image_view_module/macros.c:182 +msgid "Mmap error for input" +msgstr "" + +#: /tmp/image_view_module/macros.c:183 +msgid "Can't close mmap'ed file" +msgstr "" + +#: /tmp/image_view_module/macros.c:192 +msgid "Can't munmap" +msgstr "" diff --git a/image_view_module/locale/ru/ru.po b/image_view_module/locale/ru/ru.po index 43e1df6..a54ad9f 100644 --- a/image_view_module/locale/ru/ru.po +++ b/image_view_module/locale/ru/ru.po @@ -7,7 +7,7 @@ msgid "" msgstr "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" - "POT-Creation-Date: 2015-03-02 12:05+0300\n" + "POT-Creation-Date: 2020-01-23 12:32+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,41 +17,41 @@ msgstr "Project-Id-Version: PACKAGE VERSION\n" "Content-Transfer-Encoding: 8bit\n" #. "Уже инициализировано!" -#: /home/eddy/tmp/image_view_module/imageview.c:389 +#: /tmp/image_view_module/imageview.c:396 msgid "Already initialized!" msgstr "Уже инициализировано!" -#: /home/eddy/tmp/image_view_module/macros.c:183 +#: /tmp/image_view_module/macros.c:183 msgid "Can't close mmap'ed file" msgstr "Не могу закрыть mmap'нутый файл" -#: /home/eddy/tmp/image_view_module/imageview.c:362 +#: /tmp/image_view_module/imageview.c:369 msgid "Can't init mutex!" msgstr "Не могу инициировать взаимное исключение!" -#: /home/eddy/tmp/image_view_module/macros.c:192 +#: /tmp/image_view_module/macros.c:192 msgid "Can't munmap" msgstr "Не могу вызывать munmap" -#: /home/eddy/tmp/image_view_module/macros.c:177 +#: /tmp/image_view_module/macros.c:177 #, c-format msgid "Can't open %s for reading" msgstr "Не могу открыть %s для чтения" -#: /home/eddy/tmp/image_view_module/macros.c:179 +#: /tmp/image_view_module/macros.c:179 #, c-format msgid "Can't stat %s" msgstr "Не могу выполнить stat для %s" -#: /home/eddy/tmp/image_view_module/imageview.c:132 +#: /tmp/image_view_module/imageview.c:132 msgid "Error removing from list" msgstr "Ошибка удаления из списка" -#: /home/eddy/tmp/image_view_module/macros.c:182 +#: /tmp/image_view_module/macros.c:182 msgid "Mmap error for input" msgstr "Ошибка mmap для входных данных" -#: /home/eddy/tmp/image_view_module/macros.c:175 +#: /tmp/image_view_module/macros.c:175 msgid "No filename given!" msgstr "Не указано имя файла!" diff --git a/image_view_module/main.c b/image_view_module/main.c index 6a39fb4..c3946b9 100644 --- a/image_view_module/main.c +++ b/image_view_module/main.c @@ -50,11 +50,15 @@ void* change_image(void *data){ // DBG("refresh"); GLubyte *raw = win->image->rawdata; for(y = 0; y < h; y++){ + if(y<5){ + raw += w*3; continue; + } if(y%20 == 19){ raw += w*3; continue; } for(x = 0; x < w; x++){ + if(x==14){raw+=15;x+=4; continue;} if(x%20 != 19){ if(i < 80) raw[0]++; else if(i < 170) raw[1]++;