Back to index

radiance  4R0+20100331
Defines | Functions | Variables
gensky.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include "color.h"

Go to the source code of this file.

Defines

#define PI   3.14159265358979323846
#define DOT(v1, v2)   (v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2])
#define S_CLEAR   1
#define S_OVER   2
#define S_UNIF   3
#define S_INTER   4
#define overcast   ((skytype==S_OVER)|(skytype==S_UNIF))
#define toupper(c)   ((c) & ~0x20) /* ASCII trick to convert case */

Functions

int jdate (int month, int day)
double stadj (int jd)
double sdec (int jd)
double salt (double sd, double st)
double sazi (double sd, double st)
double normsc ()
void computesky (void)
void printsky (void)
void printdefaults (void)
void userror (char *msg)
int cvthour (char *hs)
void printhead (register int ac, register char **av)
int main (int argc, argv)

Variables

static const char RCSid [] = "$Id: gensky.c,v 2.24 2006/07/26 17:15:11 greg Exp $"
double s_latitude
double s_longitude
double s_meridian
struct {
char zname [8]
float zmer
tzone []
int month
int day
double hour
int tsolar
double altitude
double azimuth
int skytype = S_CLEAR
int dosun = 1
double zenithbr = 0.0
int u_zenith = 0
double turbidity = 2.45
double gprefl = 0.2
double sundir [3]
double groundbr
double F2
double solarbr = 0.0
int u_solar = 0
char * progname
char errmsg [128]

Define Documentation

#define DOT (   v1,
  v2 
)    (v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2])

Definition at line 31 of file gensky.c.

#define overcast   ((skytype==S_OVER)|(skytype==S_UNIF))

Definition at line 38 of file gensky.c.

#define PI   3.14159265358979323846

Definition at line 28 of file gensky.c.

#define S_CLEAR   1

Definition at line 33 of file gensky.c.

#define S_INTER   4

Definition at line 36 of file gensky.c.

#define S_OVER   2

Definition at line 34 of file gensky.c.

#define S_UNIF   3

Definition at line 35 of file gensky.c.

#define toupper (   c)    ((c) & ~0x20) /* ASCII trick to convert case */

Definition at line 47 of file gensky.c.


Function Documentation

void computesky ( void  )
int cvthour ( char *  hs)

Definition at line 379 of file gensky.c.

{
       register char  *cp = hs;
       register int  i, j;

       if ( (tsolar = *cp == '+') ) cp++;        /* solar time? */
       while (isdigit(*cp)) cp++;
       if (*cp == ':')
              hour = atoi(hs) + atoi(++cp)/60.0;
       else {
              hour = atof(hs);
              if (*cp == '.') cp++;
       }
       while (isdigit(*cp)) cp++;
       if (!*cp)
              return(0);
       if (tsolar || !isalpha(*cp)) {
              fprintf(stderr, "%s: bad time format: %s\n", progname, hs);
              exit(1);
       }
       i = 0;
       do {
              for (j = 0; cp[j]; j++)
                     if (toupper(cp[j]) != tzone[i].zname[j])
                            break;
              if (!cp[j] && !tzone[i].zname[j]) {
                     s_meridian = tzone[i].zmer * (PI/180);
                     return(1);
              }
       } while (tzone[i++].zname[0]);

       fprintf(stderr, "%s: unknown time zone: %s\n", progname, cp);
       fprintf(stderr, "Known time zones:\n\t%s", tzone[0].zname);
       for (i = 1; tzone[i].zname[0]; i++)
              fprintf(stderr, " %s", tzone[i].zname);
       putc('\n', stderr);
       exit(1);
}

Here is the caller graph for this function:

int jdate ( int  month,
int  day 
)

Definition at line 25 of file sun.c.

{
       static short  mo_da[12] = {0,31,59,90,120,151,181,212,243,273,304,334};
       
       return(mo_da[month-1] + day);
}
int main ( int  argc,
argv   
)

Definition at line 103 of file gensky.c.

{
       int  got_meridian = 0;
       int  i;

       progname = argv[0];
       if (argc == 2 && !strcmp(argv[1], "-defaults")) {
              printdefaults();
              exit(0);
       }
       if (argc < 4)
              userror("arg count");
       if (!strcmp(argv[1], "-ang")) {
              altitude = atof(argv[2]) * (PI/180);
              azimuth = atof(argv[3]) * (PI/180);
              month = 0;
       } else {
              month = atoi(argv[1]);
              if (month < 1 || month > 12)
                     userror("bad month");
              day = atoi(argv[2]);
              if (day < 1 || day > 31)
                     userror("bad day");
              got_meridian = cvthour(argv[3]);
       }
       for (i = 4; i < argc; i++)
              if (argv[i][0] == '-' || argv[i][0] == '+')
                     switch (argv[i][1]) {
                     case 's':
                            skytype = S_CLEAR;
                            dosun = argv[i][0] == '+';
                            break;
                     case 'r':
                     case 'R':
                            u_solar = argv[i][1]=='R' ? -1 : 1;
                            solarbr = atof(argv[++i]);
                            break;
                     case 'c':
                            skytype = S_OVER;
                            break;
                     case 'u':
                            skytype = S_UNIF;
                            break;
                     case 'i':
                            skytype = S_INTER;
                            dosun = argv[i][0] == '+';
                            break;
                     case 't':
                            turbidity = atof(argv[++i]);
                            break;
                     case 'b':
                     case 'B':
                            u_zenith = argv[i][1]=='B' ? -1 : 1;
                            zenithbr = atof(argv[++i]);
                            break;
                     case 'g':
                            gprefl = atof(argv[++i]);
                            break;
                     case 'a':
                            s_latitude = atof(argv[++i]) * (PI/180);
                            break;
                     case 'o':
                            s_longitude = atof(argv[++i]) * (PI/180);
                            break;
                     case 'm':
                            if (got_meridian) {
                                   ++i;
                                   break;        /* time overrides */
                            }
                            s_meridian = atof(argv[++i]) * (PI/180);
                            break;
                     default:
                            sprintf(errmsg, "unknown option: %s", argv[i]);
                            userror(errmsg);
                     }
              else
                     userror("bad option");

       if (fabs(s_meridian-s_longitude) > 45*PI/180)
              fprintf(stderr,
       "%s: warning: %.1f hours btwn. standard meridian and longitude\n",
                     progname, (s_longitude-s_meridian)*12/PI);

       printhead(argc, argv);

       computesky();
       printsky();

       exit(0);
}

Here is the call graph for this function:

double normsc ( void  )
void printdefaults ( void  )
void printhead ( register int  ac,
register char **  av 
)

Definition at line 422 of file gensky.c.

{
       putchar('#');
       while (ac--) {
              putchar(' ');
              fputs(*av++, stdout);
       }
       putchar('\n');
}
void printsky ( void  )
double salt ( double  sd,
double  st 
)

Definition at line 57 of file sun.c.

{
       return( asin( sin(s_latitude) * sin(sd) -
                     cos(s_latitude) * cos(sd) * cos(st*(PI/12)) ) );
}

Here is the call graph for this function:

double sazi ( double  sd,
double  st 
)

Definition at line 68 of file sun.c.

{
       return( -atan2( cos(sd)*sin(st*(PI/12)),
                     -cos(s_latitude)*sin(sd) -
                     sin(s_latitude)*cos(sd)*cos(st*(PI/12)) ) );
}

Here is the call graph for this function:

double sdec ( int  jd)

Definition at line 48 of file sun.c.

{
       return( 0.4093 * sin( (2*PI/368) * (jd - 81) ) );
}

Here is the call graph for this function:

double stadj ( int  jd)

Definition at line 37 of file sun.c.

{
       return( 0.170 * sin( (4*PI/373) * (jd - 80) ) -
              0.129 * sin( (2*PI/355) * (jd - 8) ) +
              12 * (s_meridian - s_longitude) / PI );
}

Here is the call graph for this function:

void userror ( char *  msg)

Variable Documentation

double altitude

Definition at line 75 of file gensky.c.

double azimuth

Definition at line 75 of file gensky.c.

int day

Definition at line 72 of file gensky.c.

int dosun = 1

Definition at line 78 of file gensky.c.

char errmsg[128]

Definition at line 91 of file gensky.c.

double F2

Definition at line 86 of file gensky.c.

double gprefl = 0.2

Definition at line 82 of file gensky.c.

double groundbr

Definition at line 85 of file gensky.c.

double hour

Definition at line 73 of file gensky.c.

int month

Definition at line 72 of file gensky.c.

char* progname

Definition at line 90 of file gensky.c.

const char RCSid[] = "$Id: gensky.c,v 2.24 2006/07/26 17:15:11 greg Exp $" [static]

Definition at line 2 of file gensky.c.

double s_latitude

Definition at line 19 of file sun.c.

double s_longitude

Definition at line 20 of file sun.c.

double s_meridian

Definition at line 21 of file sun.c.

Definition at line 77 of file gensky.c.

double solarbr = 0.0

Definition at line 87 of file gensky.c.

double sundir[3]

Definition at line 84 of file gensky.c.

int tsolar

Definition at line 74 of file gensky.c.

double turbidity = 2.45

Definition at line 81 of file gensky.c.

struct { ... } tzone[]
int u_solar = 0

Definition at line 88 of file gensky.c.

int u_zenith = 0

Definition at line 80 of file gensky.c.

double zenithbr = 0.0

Definition at line 79 of file gensky.c.