Back to index

radiance  4R0+20100331
Classes | Defines | Typedefs | Functions | Variables
resolu.h File Reference
#include <time.h>

Go to the source code of this file.

Classes

struct  RESOLU

Defines

#define XDECR   1
#define YDECR   2
#define YMAJOR   4
#define PIXSTANDARD   (YMAJOR|YDECR)
#define PIXSTDFMT   "-Y %d +X %d\n"
#define scanlen(rs)   ((rs)->rt & YMAJOR ? (rs)->xr : (rs)->yr)
#define numscans(rs)   ((rs)->rt & YMAJOR ? (rs)->yr : (rs)->xr)
#define RESOLU_BUFLEN   32
#define fputsresolu(rs, fp)   fputs(resolu2str(resolu_buf,rs),fp)
#define fgetsresolu(rs, fp)
#define fprtresolu(sl, ns, fp)   fprintf(fp,PIXSTDFMT,ns,sl)
#define fscnresolu(sl, ns, fp)   (fscanf(fp,PIXSTDFMT,ns,sl)==2)
#define isheadid(s)   headidval(NULL,s)
#define isformat(s)   formatval(NULL,s)
#define isdate(s)   dateval(NULL,s)
#define isgmt(s)   gmtval(NULL,s)
#define LATLONSTR   "LATLONG="
#define LLATLONSTR   8
#define islatlon(hl)   (!strncmp(hl,LATLONSTR,LLATLONSTR))
#define latlonval(ll, hl)
#define fputlatlon(lat, lon, fp)   fprintf(fp,"%s %.6f %.6f\n",LATLONSTR,lat,lon)

Typedefs

typedef int gethfunc (char *s, void *p)

Functions

void fputresolu (int ord, int sl, int ns, FILE *fp)
int fgetresolu (int *sl, int *ns, FILE *fp)
char * resolu2str (char *buf, RESOLU *rp)
int str2resolu (RESOLU *rp, char *buf)
void newheader (char *t, FILE *fp)
int headidval (char *r, char *s)
int dateval (time_t *t, char *s)
int gmtval (time_t *t, char *s)
void fputdate (time_t t, FILE *fp)
void fputnow (FILE *fp)
void printargs (int ac, char **av, FILE *fp)
int formatval (char *r, char *s)
void fputformat (char *s, FILE *fp)
int getheader (FILE *fp, gethfunc *f, void *p)
int globmatch (char *pat, char *str)
int checkheader (FILE *fin, char *fmt, FILE *fout)

Variables

char resolu_buf [RESOLU_BUFLEN]

Class Documentation

struct RESOLU

Definition at line 36 of file resolu.h.

Class Members
int rt
int xr
int yr

Define Documentation

#define fgetsresolu (   rs,
  fp 
)
Value:

Definition at line 51 of file resolu.h.

#define fprtresolu (   sl,
  ns,
  fp 
)    fprintf(fp,PIXSTDFMT,ns,sl)

Definition at line 55 of file resolu.h.

#define fputlatlon (   lat,
  lon,
  fp 
)    fprintf(fp,"%s %.6f %.6f\n",LATLONSTR,lat,lon)

Definition at line 69 of file resolu.h.

#define fputsresolu (   rs,
  fp 
)    fputs(resolu2str(resolu_buf,rs),fp)

Definition at line 50 of file resolu.h.

#define fscnresolu (   sl,
  ns,
  fp 
)    (fscanf(fp,PIXSTDFMT,ns,sl)==2)

Definition at line 56 of file resolu.h.

#define isdate (   s)    dateval(NULL,s)

Definition at line 61 of file resolu.h.

#define isformat (   s)    formatval(NULL,s)

Definition at line 60 of file resolu.h.

#define isgmt (   s)    gmtval(NULL,s)

Definition at line 62 of file resolu.h.

#define isheadid (   s)    headidval(NULL,s)

Definition at line 59 of file resolu.h.

#define islatlon (   hl)    (!strncmp(hl,LATLONSTR,LLATLONSTR))

Definition at line 66 of file resolu.h.

#define LATLONSTR   "LATLONG="

Definition at line 64 of file resolu.h.

#define latlonval (   ll,
  hl 
)
Value:
sscanf((hl)+LLATLONSTR, "%f %f", \
                                          &(ll)[0],&(ll)[1])

Definition at line 67 of file resolu.h.

#define LLATLONSTR   8

Definition at line 65 of file resolu.h.

#define numscans (   rs)    ((rs)->rt & YMAJOR ? (rs)->yr : (rs)->xr)

Definition at line 43 of file resolu.h.

#define PIXSTANDARD   (YMAJOR|YDECR)

Definition at line 32 of file resolu.h.

#define PIXSTDFMT   "-Y %d +X %d\n"

Definition at line 33 of file resolu.h.

#define RESOLU_BUFLEN   32

Definition at line 46 of file resolu.h.

#define scanlen (   rs)    ((rs)->rt & YMAJOR ? (rs)->xr : (rs)->yr)

Definition at line 42 of file resolu.h.

#define XDECR   1

Definition at line 27 of file resolu.h.

#define YDECR   2

Definition at line 28 of file resolu.h.

#define YMAJOR   4

Definition at line 29 of file resolu.h.


Typedef Documentation

typedef int gethfunc(char *s, void *p)

Definition at line 86 of file resolu.h.


Function Documentation

int checkheader ( FILE *  fin,
char *  fmt,
FILE *  fout 
)

Definition at line 319 of file header.c.

{
       struct check  cdat;
       char   *cp;

       cdat.fp = fout;
       cdat.fs[0] = '\0';
       if (getheader(fin, mycheck, &cdat) < 0)
              return(-1);
       if (!cdat.fs[0])
              return(0);
       for (cp = fmt; *cp; cp++)          /* check for globbing */
              if ((*cp == '?') | (*cp == '*')) {
                     if (globmatch(fmt, cdat.fs)) {
                            strcpy(fmt, cdat.fs);
                            return(1);
                     } else
                            return(-1);
              }
       return(strcmp(fmt, cdat.fs) ? -1 : 1);    /* literal match */
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dateval ( time_t *  t,
char *  s 
)

Definition at line 73 of file header.c.

{
       struct tm     tms;
       const char    *cp = TMSTR;

       while (*cp) if (*cp++ != *s++) return(0);
       while (isspace(*s)) s++;
       if (!*s) return(0);
       if (sscanf(s, "%d:%d:%d %d:%d:%d",
                     &tms.tm_year, &tms.tm_mon, &tms.tm_mday,
                     &tms.tm_hour, &tms.tm_min, &tms.tm_sec) != 6)
              return(0);
       if (tloc == NULL)
              return(1);
       tms.tm_mon--;
       tms.tm_year -= 1900;
       tms.tm_isdst = -1;   /* ask mktime() to figure out DST */
       *tloc = mktime(&tms);
       return(1);
}
int fgetresolu ( int *  sl,
int *  ns,
FILE *  fp 
)

Definition at line 41 of file resolu.c.

{
       RESOLU  rs;

       if (!fgetsresolu(&rs, fp))
              return(-1);
       if (rs.rt & YMAJOR) {
              *sl = rs.xr;
              *ns = rs.yr;
       } else {
              *sl = rs.yr;
              *ns = rs.xr;
       }
       return(rs.rt);
}

Here is the caller graph for this function:

int formatval ( char *  r,
char *  s 
)

Definition at line 170 of file header.c.

{
       const char  *cp = FMTSTR;

       while (*cp) if (*cp++ != *s++) return(0);
       while (isspace(*s)) s++;
       if (!*s) return(0);
       if (r == NULL) return(1);
       do
              *r++ = *s++;
       while(*s && !isspace(*s));
       *r = '\0';
       return(1);
}

Here is the caller graph for this function:

void fputdate ( time_t  t,
FILE *  fp 
)

Definition at line 124 of file header.c.

{
       struct tm     *tms;

       tms = localtime(&tv);
       if (tms != NULL)
              fprintf(fp, "%s %04d:%02d:%02d %02d:%02d:%02d\n", TMSTR,
                            tms->tm_year+1900, tms->tm_mon+1, tms->tm_mday,
                            tms->tm_hour, tms->tm_min, tms->tm_sec);
       tms = gmtime(&tv);
       if (tms != NULL)
              fprintf(fp, "%s %04d:%02d:%02d %02d:%02d:%02d\n", GMTSTR,
                            tms->tm_year+1900, tms->tm_mon+1, tms->tm_mday,
                            tms->tm_hour, tms->tm_min, tms->tm_sec);
}

Here is the caller graph for this function:

void fputformat ( char *  s,
FILE *  fp 
)

Definition at line 190 of file header.c.

{
       fputs(FMTSTR, fp);
       fputs(s, fp);
       putc('\n', fp);
}

Here is the caller graph for this function:

void fputnow ( FILE *  fp)

Definition at line 145 of file header.c.

{
       time_t tv;
       time(&tv);
       fputdate(tv, fp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fputresolu ( int  ord,
int  sl,
int  ns,
FILE *  fp 
)

Definition at line 22 of file resolu.c.

{
       RESOLU  rs;

       if ((rs.rt = ord) & YMAJOR) {
              rs.xr = sl;
              rs.yr = ns;
       } else {
              rs.xr = ns;
              rs.yr = sl;
       }
       fputsresolu(&rs, fp);
}

Here is the caller graph for this function:

int getheader ( FILE *  fp,
gethfunc f,
void *  p 
)

Definition at line 202 of file header.c.

{
       char  buf[MAXLINE];

       for ( ; ; ) {
              buf[MAXLINE-2] = '\n';
              if (fgets(buf, MAXLINE, fp) == NULL)
                     return(-1);
              if (buf[0] == '\n')
                     return(0);
#ifdef MSDOS
              if (buf[0] == '\r' && buf[1] == '\n')
                     return(0);
#endif
              if (buf[MAXLINE-2] != '\n') {
                     ungetc(buf[MAXLINE-2], fp); /* prevent false end */
                     buf[MAXLINE-2] = '\0';
              }
              if (f != NULL && (*f)(buf, p) < 0)
                     return(-1);
       }
}

Here is the caller graph for this function:

int globmatch ( char *  pat,
char *  str 
)

Definition at line 251 of file header.c.

{
       int    setmatch;

       do {
              switch (*p) {
              case '?':                   /* match any character */
                     if (!*s++)
                            return(0);
                     break;
              case '*':                   /* match any string */
                     while (p[1] == '*') p++;
                     do
                            if ( (p[1]=='?' || p[1]==*s) &&
                                          globmatch(p+1,s) )
                                   return(1);
                     while (*s++);
                     return(0);
              case '[':                   /* character set */
                     setmatch = *s == *++p;
                     if (!*p)
                            return(0);
                     while (*++p != ']') {
                            if (!*p)
                                   return(0);
                            if (*p == '-') {
                                   setmatch += p[-1] <= *s && *s <= p[1];
                                   if (!*++p)
                                          break;
                            } else
                                   setmatch += *p == *s;
                     }
                     if (!setmatch)
                            return(0);
                     s++;
                     break;
              case '\\':                  /* literal next */
                     p++;
              /* fall through */
              default:                    /* normal character */
                     if (*p != *s)
                            return(0);
                     s++;
                     break;
              }
       } while (*p++);
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gmtval ( time_t *  t,
char *  s 
)

Definition at line 99 of file header.c.

{
       struct tm     tms;
       const char    *cp = GMTSTR;

       while (*cp) if (*cp++ != *s++) return(0);
       while (isspace(*s)) s++;
       if (!*s) return(0);
       if (sscanf(s, "%d:%d:%d %d:%d:%d",
                     &tms.tm_year, &tms.tm_mon, &tms.tm_mday,
                     &tms.tm_hour, &tms.tm_min, &tms.tm_sec) != 6)
              return(0);
       if (tloc == NULL)
              return(1);
       tms.tm_mon--;
       tms.tm_year -= 1900;
       *tloc = timegm(&tms);
       return(1);
}
int headidval ( char *  r,
char *  s 
)

Definition at line 57 of file header.c.

{
       const char  *cp = HDRSTR;

       while (*cp) if (*cp++ != *s++) return(0);
       if (r == NULL) return(1);
       while (*s && !isspace(*s)) *r++ = *s++;
       *r = '\0';
       return(1);
}
void newheader ( char *  t,
FILE *  fp 
)

Definition at line 45 of file header.c.

{
       fputs(HDRSTR, fp);
       fputs(s, fp);
       putc('\n', fp);
}

Here is the caller graph for this function:

void printargs ( int  ac,
char **  av,
FILE *  fp 
)

Definition at line 156 of file header.c.

{
       while (ac-- > 0) {
              fputword(*av++, fp);
              fputc(ac ? ' ' : '\n', fp);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* resolu2str ( char *  buf,
RESOLU rp 
)

Definition at line 61 of file resolu.c.

{
       if (rp->rt&YMAJOR)
              sprintf(buf, "%cY %d %cX %d\n",
                            rp->rt&YDECR ? '-' : '+', rp->yr,
                            rp->rt&XDECR ? '-' : '+', rp->xr);
       else
              sprintf(buf, "%cX %d %cY %d\n",
                            rp->rt&XDECR ? '-' : '+', rp->xr,
                            rp->rt&YDECR ? '-' : '+', rp->yr);
       return(buf);
}
int str2resolu ( RESOLU rp,
char *  buf 
)

Definition at line 78 of file resolu.c.

{
       register char  *xndx, *yndx;
       register char  *cp;

       if (buf == NULL)
              return(0);
       xndx = yndx = NULL;
       for (cp = buf; *cp; cp++)
              if (*cp == 'X')
                     xndx = cp;
              else if (*cp == 'Y')
                     yndx = cp;
       if (xndx == NULL || yndx == NULL)
              return(0);
       rp->rt = 0;
       if (xndx > yndx) rp->rt |= YMAJOR;
       if (xndx[-1] == '-') rp->rt |= XDECR;
       if (yndx[-1] == '-') rp->rt |= YDECR;
       if ((rp->xr = atoi(xndx+1)) <= 0)
              return(0);
       if ((rp->yr = atoi(yndx+1)) <= 0)
              return(0);
       return(1);
}

Variable Documentation

Definition at line 18 of file resolu.c.