コード例 #1
0
ファイル: x34c.c プロジェクト: CronosProject/chronos
void initialize_colors( void )
{
    plscol0( 0, 255, 255, 255 );
    plscol0( 1, 0, 0, 0 );
    plscol0( 2, 255, 0, 0 );
    plscol0a( 3, 0, 0, 255, 0.3 );
}
コード例 #2
0
ファイル: plplot_driver.c プロジェクト: YingfangZhou/ert
static plplot_state_type * plplot_state_alloc( const void * init_arg ) {
  plplot_state_type * state = util_malloc( sizeof * state );
  state->stream     = 0;
  {
    const arg_pack_type * arg_pack = arg_pack_safe_cast_const( init_arg );
    state->filename                = util_alloc_string_copy( arg_pack_iget_const_ptr( arg_pack , 0) );
    state->device                  = util_alloc_string_copy( arg_pack_iget_const_ptr( arg_pack , 1) );
    
    plsstrm(state->stream);
    plsdev(state->device);    /* Can this be NULL?? */
    if (strcmp(state->device , "xwin") != 0)
      plsfnam(state->filename);
  }
  state->logx       = false;
  state->logy       = false;
  state->plbox_xopt = util_alloc_string_copy( PLOT_DEFAULT_PLBOX_XOPT );
  state->plbox_yopt = util_alloc_string_copy( PLOT_DEFAULT_PLBOX_YOPT );
  /** This color initialization must be here - do not really understand what for. */
  plscol0(WHITE, 255, 255, 255);
  plscol0(BLACK, 0, 0, 0);
  plfontld(0);
  //plinit();
  return state;
}
コード例 #3
0
/* basic "plot one line" atom */
static void plotOneLine(
    uint32_t numSamples,
    PLFLT *fx,
    LineDef *lineDef,
    bool plotPoints,		/* true: plot points */
    bool plotLine)			/* true: plot line */
{
    /* set drawing color - set the value for color map 0[1], then set it */
    const RGB *rgb = &plColors[lineDef->color];
    plscol0(1, rgb->r, rgb->g, rgb->b);
    plcol0(1);

    if(plotPoints) {
        plpoin(numSamples, fx, lineDef->fy, lineDef->pointCode);
    }
    if(plotLine) {
        plline(numSamples, fx, lineDef->fy);
    }
}
コード例 #4
0
ファイル: x31c.c プロジェクト: CronosProject/chronos
int
main( int argc, char *argv[] )
{
    PLFLT xmin0, xmax0, ymin0, ymax0, zxmin0, zxmax0, zymin0, zymax0;
    PLFLT xmin, xmax, ymin, ymax, zxmin, zxmax, zymin, zymax;
    PLFLT xmid, ymid, wx, wy;
    PLFLT mar0, aspect0, jx0, jy0, ori0;
    PLFLT mar, aspect, jx, jy, ori;
    PLINT win, level2, digmax, digits, compression1, compression2;
    PLFLT xp0, yp0;
    PLINT xleng0, yleng0, xoff0, yoff0;
    PLFLT xp1, yp1;
    PLINT xleng1, yleng1, xoff1, yoff1;
    PLFLT xp2, yp2;
    PLINT xleng2, yleng2, xoff2, yoff2;
    PLINT fam0, num0, bmax0;
    PLINT fam1, num1, bmax1;
    PLINT fam2, num2, bmax2;
    PLINT r0, g0, b0;
    PLFLT a0;
    PLINT r, g, b;
    PLFLT a;
    PLINT r1[] = { 0, 255 };
    PLINT g1[] = { 255, 0 };
    PLINT b1[] = { 0, 0 };
    PLFLT a1[] = { 1.0, 1.0 };
    int   status;
    char  fnam[256];

    // Parse and process command line arguments

    status = 0;

    (void) plparseopts( &argc, argv, PL_PARSE_FULL );

    // Test setting / getting familying parameters before plinit
    // Save values set by plparseopts to be restored later.
    plgfam( &fam0, &num0, &bmax0 );
    fam1  = 0;
    num1  = 10;
    bmax1 = 1000;
    plsfam( fam1, num1, bmax1 );

    // Retrieve the same values?
    plgfam( &fam2, &num2, &bmax2 );
    printf( "family parameters: fam, num, bmax = %d %d %d\n", fam2, num2, bmax2 );
    if ( fam2 != fam1 || num2 != num1 || bmax2 != bmax1 )
    {
        fputs( "plgfam test failed\n", stderr );
        status = 1;
    }
    // Restore values set initially by plparseopts.
    plsfam( fam0, num0, bmax0 );

    // Test setting / getting page parameters before plinit
    // Save values set by plparseopts to be restored later.
    plgpage( &xp0, &yp0, &xleng0, &yleng0, &xoff0, &yoff0 );
    xp1    = 200.;
    yp1    = 200.;
    xleng1 = 400;
    yleng1 = 200;
    xoff1  = 10;
    yoff1  = 20;
    plspage( xp1, yp1, xleng1, yleng1, xoff1, yoff1 );

    // Retrieve the same values?
    plgpage( &xp2, &yp2, &xleng2, &yleng2, &xoff2, &yoff2 );
    printf( "page parameters: xp, yp, xleng, yleng, xoff, yoff = %f %f %d %d %d %d\n", xp2, yp2, xleng2, yleng2, xoff2, yoff2 );
    if ( xp2 != xp1 || yp2 != yp1 || xleng2 != xleng1 || yleng2 != yleng1 ||
         xoff2 != xoff1 || yoff2 != yoff1 )
    {
        fputs( "plgpage test failed\n", stderr );
        status = 1;
    }
    // Restore values set initially by plparseopts.
    plspage( xp0, yp0, xleng0, yleng0, xoff0, yoff0 );

    // Test setting / getting compression parameter across plinit.
    compression1 = 95;
    plscompression( compression1 );

    // Initialize plplot
    plinit();

    // Test if device initialization screwed around with the preset
    // compression parameter.
    plgcompression( &compression2 );
    printf( "Output various PLplot parameters\n" );
    printf( "compression parameter = %d\n", compression2 );
    if ( compression2 != compression1 )
    {
        fputs( "plgcompression test failed\n", stderr );
        status = 1;
    }


    // Exercise plscolor, plscol0, plscmap1, and plscmap1a to make sure
    // they work without any obvious error messages.
    plscolor( 1 );
    plscol0( 1, 255, 0, 0 );
    plscmap1( r1, g1, b1, 2 );
    plscmap1a( r1, g1, b1, a1, 2 );

    plglevel( &level2 );
    printf( "level parameter = %d\n", level2 );
    if ( level2 != 1 )
    {
        fputs( "plglevel test failed.\n", stderr );
        status = 1;
    }

    pladv( 0 );

    xmin0 = 0.01;
    xmax0 = 0.99;
    ymin0 = 0.02;
    ymax0 = 0.49;
    plvpor( xmin0, xmax0, ymin0, ymax0 );
    plgvpd( &xmin, &xmax, &ymin, &ymax );
    printf( "plvpor: xmin, xmax, ymin, ymax = %f %f %f %f\n", xmin, xmax, ymin, ymax );
    if ( xmin != xmin0 || xmax != xmax0 || ymin != ymin0 || ymax != ymax0 )
    {
        fputs( "plgvpd test failed\n", stderr );
        status = 1;
    }
    xmid = 0.5 * ( xmin + xmax );
    ymid = 0.5 * ( ymin + ymax );

    xmin0 = 0.2;
    xmax0 = 0.3;
    ymin0 = 0.4;
    ymax0 = 0.5;
    plwind( xmin0, xmax0, ymin0, ymax0 );
    plgvpw( &xmin, &xmax, &ymin, &ymax );
    printf( "plwind: xmin, xmax, ymin, ymax = %f %f %f %f\n", xmin, xmax, ymin, ymax );
    if ( xmin != xmin0 || xmax != xmax0 || ymin != ymin0 || ymax != ymax0 )
    {
        fputs( "plgvpw test failed\n", stderr );
        status = 1;
    }

    // Get world coordinates for middle of viewport
    plcalc_world( xmid, ymid, &wx, &wy, &win );
    printf( "world parameters: wx, wy, win = %f %f %d\n", wx, wy, win );
    if ( fabs( wx - 0.5 * ( xmin + xmax ) ) > 1.0E-5 || fabs( wy - 0.5 * ( ymin + ymax ) ) > 1.0E-5 )
    {
        fputs( "plcalc_world test failed\n", stderr );
        status = 1;
    }

    // Retrieve and print the name of the output file (if any).
    // This goes to stderr not stdout since it will vary between tests and
    // we want stdout to be identical for compare test.
    plgfnam( fnam );
    if ( fnam[0] == '\0' )
    {
        printf( "No output file name is set\n" );
    }
    else
    {
        printf( "Output file name read\n" );
    }
    fprintf( stderr, "Output file name is %s\n", fnam );

    // Set and get the number of digits used to display axis labels
    // Note digits is currently ignored in pls[xyz]ax and
    // therefore it does not make sense to test the returned
    // value
    plsxax( 3, 0 );
    plgxax( &digmax, &digits );
    printf( "x axis parameters: digmax, digits = %d %d\n", digmax, digits );
    if ( digmax != 3 )
    {
        fputs( "plgxax test failed\n", stderr );
        status = 1;
    }

    plsyax( 4, 0 );
    plgyax( &digmax, &digits );
    printf( "y axis parameters: digmax, digits = %d %d\n", digmax, digits );
    if ( digmax != 4 )
    {
        fputs( "plgyax test failed\n", stderr );
        status = 1;
    }

    plszax( 5, 0 );
    plgzax( &digmax, &digits );
    printf( "z axis parameters: digmax, digits = %d %d\n", digmax, digits );
    if ( digmax != 5 )
    {
        fputs( "plgzax test failed\n", stderr );
        status = 1;
    }

    mar0    = 0.05;
    aspect0 = PL_NOTSET;
    jx0     = 0.1;
    jy0     = 0.2;
    plsdidev( mar0, aspect0, jx0, jy0 );
    plgdidev( &mar, &aspect, &jx, &jy );
    printf( "device-space window parameters: mar, aspect, jx, jy = %f %f %f %f\n", mar, aspect, jx, jy );
    if ( mar != mar0 || jx != jx0 || jy != jy0 )
    {
        fputs( "plgdidev test failed\n", stderr );
        status = 1;
    }

    ori0 = 1.0;
    plsdiori( ori0 );
    plgdiori( &ori );
    printf( "ori parameter = %f\n", ori );
    if ( ori != ori0 )
    {
        fputs( "plgdiori test failed\n", stderr );
        status = 1;
    }

    xmin0 = 0.1;
    ymin0 = 0.2;
    xmax0 = 0.9;
    ymax0 = 0.8;
    plsdiplt( xmin0, ymin0, xmax0, ymax0 );
    plgdiplt( &xmin, &ymin, &xmax, &ymax );
    printf( "plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f\n", xmin, ymin, xmax, ymax );
    if ( xmin != xmin0 || ymin != ymin0 || xmax != xmax0 || ymax != ymax0 )
    {
        fputs( "plgdiplt test failed\n", stderr );
        status = 1;
    }

    zxmin0 = 0.1;
    zymin0 = 0.1;
    zxmax0 = 0.9;
    zymax0 = 0.9;
    plsdiplz( zxmin0, zymin0, zxmax0, zymax0 );
    plgdiplt( &zxmin, &zymin, &zxmax, &zymax );
    printf( "zoomed plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f\n", zxmin, zymin, zxmax, zymax );
    if ( fabs( zxmin - ( xmin + ( xmax - xmin ) * zxmin0 ) ) > 1.0E-5 ||
         fabs( zymin - ( ymin + ( ymax - ymin ) * zymin0 ) ) > 1.0E-5 ||
         fabs( zxmax - ( xmin + ( xmax - xmin ) * zxmax0 ) ) > 1.0E-5 ||
         fabs( zymax - ( ymin + ( ymax - ymin ) * zymax0 ) ) > 1.0E-5 )
    {
        fputs( "plsdiplz test failed\n", stderr );
        status = 1;
    }

    r0 = 10;
    g0 = 20;
    b0 = 30;
    plscolbg( r0, g0, b0 );
    plgcolbg( &r, &g, &b );
    printf( "background colour parameters: r, g, b = %d %d %d\n", r, g, b );
    if ( r != r0 || g != g0 || b != b0 )
    {
        fputs( "plgcolbg test failed\n", stderr );
        status = 1;
    }

    r0 = 20;
    g0 = 30;
    b0 = 40;
    a0 = 0.5;
    plscolbga( r0, g0, b0, a0 );
    plgcolbga( &r, &g, &b, &a );
    printf( "background/transparency colour parameters: r, g, b, a = %d %d %d %f\n", r, g, b, a );
    if ( r != r0 || g != g0 || b != b0 || a != a0 )
    {
        fputs( "plgcolbga test failed\n", stderr );
        status = 1;
    }

    plend();

    exit( status );
}
コード例 #5
0
/*
 * Plot specified x/y coordinates, x as int32_t and y as float, with an arbitrary number
 * of separate lines, as lines and/or points.
 * Output is PDF file, location specified by 'fileName'.
 */
int plplotLines(
    PlplotSetup *setup,
    uint32_t numSamples,	/* size of ix[] and fy[] arrays */
    uint32_t numLines,		/* size of lineDef[] array */
    int32_t *ix,			/* numSamples */
    LineDef *lineDef,		/* numLines */
    const char *graphName,
    const char *fileName,
    bool plotPoints,		/* true: plot points */
    bool plotLine,			/* true: plot line */
    bool skipTrailZeroes)	/* don't plot zero Y values at end of graph */
{
    if(setup == NULL) {
        printf("***plplotLine: setup required\n");
        return -1;
    }

    char tmpFile[TEMP_FN_LEN];
    makeTempFile(tmpFile, TEMP_FN_LEN);

    PLFLT fx[numSamples];
    PLFLT minX = setup->minX;
    PLFLT maxX = setup->maxX;
    PLFLT minY = setup->minY;
    PLFLT maxY = setup->maxY;

    for(uint32_t dex=0; dex<numSamples; dex++) {
        fx[dex] = ix[dex];
    }

    const char *yName = "";
    if(setup->yAxisName) {
        yName = setup->yAxisName;
    }
    const char *xName = "";
    if(setup->xAxisName) {
        xName = setup->xAxisName;
    }

    plsdev ("psc");

    /* standard: background white, foreground (axes, labels, etc.) black */
    plscolbg(PLOT_WHITE);
    plscol0(1, PLOT_BLACK);

    plsfnam(tmpFile);
    plsdiori(1.0);						// portrait
    plinit();
    plenv(minX, maxX, minY, maxY, 0, 0);
    pllab(xName, yName, graphName);

    for(uint32_t dex=0; dex<numLines; dex++) {
        uint32_t thisSamples = numSamples;
        if(skipTrailZeroes) {
            while((lineDef[dex].fy[thisSamples-1] == 0.0) && (thisSamples > 0)) {
                thisSamples--;
            }
            if(thisSamples == 0) {
                printf("***plplotLines: Warning: line with all zeroes skipped\n");
                continue;
            }
        }
        plotOneLine(thisSamples, fx,  &lineDef[dex], plotPoints, plotLine);
    }

    plend();

    int ourRtn = psToPdf(tmpFile, fileName);
    unlink(tmpFile);
    return ourRtn;
}
コード例 #6
0
/*
 * Plot a histogram of prebinned data. X values are int32_t's, and the corresponding
 * Y values - the counts for each X - are uint32_t's.
 */
int plplotBins(
    uint32_t numBins,
    const int32_t *x,			/* numBins of X values, monotonically increasing */
    const uint32_t *y,			/* numBins of Y values for each associated X */
    const char *graphName,
    const char *fileName,
    const char *xAxisName,		/* optional */
    const char *yAxisName)		/* optional */
{
    char tmpFile[TEMP_FN_LEN];
    makeTempFile(tmpFile, TEMP_FN_LEN);

    PLINT totalBins = numBins + 2;

    /* PLFLT array of sample values */
    PLFLT *xf = (PLFLT *)malloc(totalBins * sizeof(PLFLT));

    /* these two will have Y values of zero */
    xf[0] = x[0] - 1;
    xf[totalBins - 1] = x[numBins-1] + 1;

    const int32_t *ip = x;
    PLFLT *op = xf + 1;
    for(uint32_t dex=0; dex<numBins; dex++) {
        *op++ = *ip++;
    }

    /* PLFLT array of bins */
    PLFLT *yf = (PLFLT *)malloc(totalBins * sizeof(PLFLT));
    yf[0] = 0.0;
    yf[totalBins - 1]  = 0.0;
    const uint32_t *uip = y;
    op = yf + 1;
    for(uint32_t dex=0; dex<numBins; dex++) {
        *op++ = *uip++;
    }

    /* get max Y value */
    uint32_t maxY = 0;
    uip = y;
    for(uint32_t dex=0; dex<numBins; dex++) {
        uint32_t currY = *uip++;
        if(currY > maxY) {
            maxY = currY;
        }
    }

    const char *yName = yAxisName ? yAxisName : "";
    const char *xName = xAxisName ? xAxisName : "";

#if	HIST_COLOR
    plsdev ("psc");
    plscolbg(255, 255, 255);			/* white background */
#else
    plsdev ("ps");
#endif
    plsfnam(tmpFile);
    plsdiori(1.0);						// portrait
    plinit();
    plenv(xf[0], xf[totalBins - 1], 0, maxY, 0, 0);

#if	HIST_COLOR
    /* can we alter colors of lines and the spaces inside the histograms? */
    plscolbg(255, 0, 0);				/* red background */
    plscol0(1, 255, 0, 0);				/* red foreground - no effect */
#endif

    pllab(xName, yName, graphName);

    plbin(totalBins, xf, yf, PL_BIN_CENTRED);
    plend();

    free(xf);
    free(yf);

    int ourRtn = psToPdf(tmpFile, fileName);
    unlink(tmpFile);
    return ourRtn;
}
コード例 #7
0
/*
 * Plot a histogram showing the number of occurences of each possible
 * value of 'samples'.
 */
int plplotHist(
    const int32_t *samples,
    uint32_t numSamples,
    const char *graphName,
    const char *fileName,
    const char *xAxisName,		/* optional */
    const char *yAxisName)		/* optional */
{
    char tmpFile[TEMP_FN_LEN];
    makeTempFile(tmpFile, TEMP_FN_LEN);

    /* First determine the range, i.e. the number of bins */
    int32_t minSamp = samples[0];
    int32_t maxSamp = samples[0];
    for(uint32_t dex=0; dex<numSamples; dex++) {
        int32_t s = samples[dex];
        if(s < minSamp) {
            minSamp = s;
        }
        if(s > maxSamp) {
            maxSamp = s;
        }
    }

    /* When we specify PL_BIN_CENTRED, the min and max values are half the normal width */
    minSamp--;
    maxSamp++;

    PLINT numBins = maxSamp - minSamp + 1;

    /* One array containing the sample values, x */
    PLFLT *x = (PLFLT *)malloc(numBins * sizeof(PLFLT));
    int32_t binNum = minSamp;
    for(uint32_t dex=0; dex<(uint32_t)numBins; dex++) {
        x[dex] = binNum++;
    }

    /* Now make and fill the bins proper */
    PLFLT *y = (PLFLT *)malloc(numBins * sizeof(PLFLT));
    for(uint32_t dex=0; dex<(uint32_t)numBins; dex++) {
        y[dex] = 0;
    }
    PLFLT maxY = 0.0;

    for(uint32_t dex=0; dex<numSamples; dex++) {
        int32_t s = samples[dex];
        PLFLT *yp = y + s - minSamp;
        *yp += 1.0;
        if(*yp > maxY) {
            maxY = *yp;
        }
    }

    const char *yName = yAxisName ? yAxisName : "";
    const char *xName = xAxisName ? xAxisName : "";

#if	HIST_COLOR
    plsdev ("psc");
    plscolor(1);
    plscolbg(255, 255, 255);			/* white background */
#else
    plsdev ("ps");
#endif
    plsfnam(tmpFile);
    plsdiori(1.0);						// portrait
    plinit();
    plenv(minSamp, maxSamp, 0, maxY, 0, 0);

#if	HIST_COLOR
    /* can we alter colors of lines and the spaces inside the histograms? */
    plscolbg(255, 0, 0);				/* red background */
    plscol0(1, 255, 0, 0);				/* red foreground - no effect */
#endif

    pllab(xName, yName, graphName);

    plbin(numBins, x, y, PL_BIN_CENTRED);
    plend();

    free(x);
    free(y);

    int ourRtn = psToPdf(tmpFile, fileName);
    unlink(tmpFile);
    return ourRtn;
}
コード例 #8
0
ファイル: plctrl.c プロジェクト: WenchaoLin/JAMg
void
c_plscolbg(PLINT r, PLINT g, PLINT b)
{
    plscol0(0, r, g, b);
}
コード例 #9
0
ファイル: sol_atmosmodel.c プロジェクト: grische/ProjectAtmos
int main() {                                                    
  
  // http://cdiac.ornl.gov/pns/current_ghg.html
  const double c_co2 = 390;
  const double c_n2o = 0.32;
  const double c_co = 0.1;
  const double c_ch4 = 1.775;
  const double c_o2 = 20.9e+4;
  
  
  const double cp=1004;  /* J/kg K */
  const double deltat=3600.0*4.0;  /* s */
  const double Ra=287; /* J/kg K */

  int timesteps = 0;
  int ilev=0;
  int ilyr=0;
  const int nlyr=20;  /* Number of Layers */
  const int nlev=nlyr+1;
  int instabil=FALSE;

  int status;
  
  
  

  const double deltap=PSURF/nlyr;
  const double kappa=Ra/cp;
  
  double *p=calloc(nlev,sizeof(double));
  double *T=calloc(nlyr,sizeof(double));
  double *theta=calloc(nlev,sizeof(double));
  double *plyr=calloc(nlyr,sizeof(double));
  double *z=calloc(nlev,sizeof(double));
  double *zlyr=calloc(nlyr,sizeof(double));
  double *deltazlyr=calloc(nlyr,sizeof(double));
  double *deltazlev=calloc(nlev,sizeof(double));
  double *h2o=calloc(nlyr,sizeof(double));
  double *o3=calloc(nlyr,sizeof(double));
  
  double ***dtaumol;
  double **wgt;
  double *wavelength;
  int nbnd=0;
  int *nch;
  int iv;
  int iq;
  
  double *tmplev=calloc(nlev, sizeof(double)); /* temporary vector with length lev */
  double *tmplyr=calloc(nlyr, sizeof(double)); /* temporary vector with length lyr */
  
  double *eup=calloc(nlev, sizeof(double));
  double *edn=calloc(nlev, sizeof(double));
  double *euptmp=calloc(nlev, sizeof(double));
  double *edntmp=calloc(nlev, sizeof(double));
  double *edirtmp=calloc(nlev, sizeof(double));
  double *enet=calloc(nlyr, sizeof(double));

  double *deltaTday=calloc(nlyr, sizeof(double));
  double *deltaT=calloc(nlyr, sizeof(double));
  
  //------------- Define variables for Rodents---------------//
  
  const double gr_albedo=0.3; /* 1 */
  
  const int mu_counterlimit = (int)(24.0 * 3600 / deltat);
  double* const mu_0 = calloc(mu_counterlimit, sizeof(double));
  int mu_counter;

  // --- start mu_0
  {
  double mu_weight = 0;

  for(mu_counter=0; mu_counter < mu_counterlimit; mu_counter++) {
    mu_0[mu_counter] = cos( 2.0*M_PI / mu_counterlimit * (mu_counter + mu_counter+1) / 2.0 );
    if(mu_0[mu_counter] > 0)
      mu_weight += mu_0[mu_counter];
  }
  // weight needs to be adjusted such that it is 0.5 for half of the steps (day-only)
  mu_weight = mu_weight / (mu_counterlimit/2.0 * 0.5);

  for(mu_counter=0; mu_counter < mu_counterlimit; mu_counter++) {
    mu_0[mu_counter] = mu_0[mu_counter] / mu_weight;
    printf("mu_0[%d] = %e\n", mu_counter, mu_0[mu_counter]);
  }
  mu_counter = 0;
  
  }
  // --- end mu_0
  
  double* S_0;
  double* omega_0=calloc(nlyr,sizeof(double));
  double* gassy=calloc(nlyr,sizeof(double));
  double* f=calloc(nlyr,sizeof(double));
  
  
  for(ilyr=0; ilyr<nlyr; ilyr++) {
   omega_0[ilyr] = 0.f;
   gassy[ilyr] = 0; //0.85f;
   f[ilyr] = 0; //0.8f;
  }
  
  {
    double *temp1, *temp2, *temp3;
    int temp4;
      status=read_4c_file("mstrnx.data/solar.dat", &temp1, &temp2, &temp3, &S_0, &temp4);
      if (status !=0) {
      printf("Error reading Solar.dat\n");
      return EXIT_FAILURE;
      }
      
      free(temp1);
      free(temp2);
      free(temp3);
  } 
  
  //--------------------- Plot color -------------------------//

#ifndef _NOPLOT
  plscolbg (255, 255, 255);   /* background color white */
  plscol0  (15, 0, 0, 0);     /* set color 15 to black  */
  plsdev ("xwin"); /* if not called, the user is asked! */
  plinit ();
  
  plssub(2,2);
#endif
  
  //--------------------- Calculate pressure for layers and levels -------------//

  for(ilev=0; ilev<nlev; ilev++) {                              /* Calculation of the Pressure at the Levels p[ilev] */
    p[ilev]=PSURF*ilev/(nlev-1);
  }
    
  for(ilyr=0; ilyr<nlyr; ilyr++) {                            /* Calculation of the Pressure in the Layers*/
    plyr[ilyr]= 0.5*(p[ilyr]+p[ilyr+1]);
  }
   
  
  //----------------------- Reading afglus ------------------------//
  
  {
    
    double *ztemp;
    double *ptemp;
    double *Ttemp;
    double *h2otemp;
    double *o3temp;

    int status;
    int ntemp;
    int itemp;
    unsigned int mintemp = 0;
    unsigned int mintemp2 = 0;
    
    status = read_5c_file("mstrnx.data/afglus.atm", &ztemp, &ptemp, &Ttemp, &h2otemp, &o3temp, &ntemp);
    if (status !=0) {
      printf("Error reading Temperature profile\n");
      return EXIT_FAILURE;
    }

    /*
      for (itemp=0; itemp<ntemp; itemp++) {
      printf("itemp = %d, ztemp = %f, ptemp = %f, Ttemp = %f, h2otemp = %f, o3temp = %f\n", itemp, ztemp[itemp], ptemp[itemp], Ttemp[itemp], h2otemp[itemp], o3temp[itemp]);
      }
    */  
    
    //-------------------- Interpolate T, h2o and o3 to layers --------------//
    
    for (ilyr=0; ilyr<nlyr; ilyr++) {
      // printf("ilev = %d, searching for %f\n", ilyr, plyr[ilyr]);
      for (itemp=0; itemp<ntemp; itemp++) {
	if ( abs(ptemp[mintemp]- plyr[ilyr])>abs(ptemp[itemp]-plyr[ilyr])) {
	  mintemp=itemp;
	}
      }
      if (ptemp[mintemp]<plyr[ilyr]) {
	mintemp2 = mintemp+1;
      }
      else {
	mintemp2 = mintemp-1;
      }
      // printf("\tmintemp  = %d,\tp = %f\n", mintemp, ptemp[mintemp]);
      // printf("\tmintemp2 = %d,\tp = %f\n", mintemp2, ptemp[mintemp2]);

      const double weight2 = abs(ptemp[mintemp]-plyr[ilyr]);
      const double weight1 = abs(ptemp[mintemp2]-plyr[ilyr]);
      const double norm = weight1 + weight2;
      
      /* T in levels?!?! */
      T[ilyr] = Ttemp[mintemp]*weight1 + Ttemp[mintemp2]*weight2;
      T[ilyr] /= norm;
      
      h2o[ilyr] = h2otemp[mintemp]*weight1 + h2otemp[mintemp2]*weight2;
      h2o[ilyr] /= norm;

      o3[ilyr] = o3temp[mintemp]*weight1 + o3temp[mintemp2]*weight2;
      o3[ilyr] /= norm;
    }
  }
  
  
  for (ilyr=0; ilyr<nlyr; ilyr++)  {
    printf("ilyr = %d, plyr = %f,\tT = %f,\th2o = %f,\to3 = %f\n", ilyr, plyr[ilyr], T[ilyr], h2o[ilyr], o3[ilyr]);
  }
  
  /* 
     for (ilyr=0; ilyr<nlyr; ilyr++)  {
     printf("T[%d] = %f\n", ilyr, T[ilyr]);
     }
     for (ilyr=0; ilyr<nlyr; ilyr++)  {
     printf("o3[%d] = %f\n", ilyr, o3[ilyr]);
     }
     for (ilyr=0; ilyr<nlyr; ilyr++)  {
     printf("h2o[%d] = %f\n", ilyr, h2o[ilyr]);
     }
  */
  
   
  
  
  //--------------------------------- Starting while-loop ----------------------------------//
  //----------------------------------------------------------------------------------------//
  
  while (timesteps*deltat<TIME_MAX) {
    // printf("\nNew time %d: T = %f\n", (int)(timesteps*deltat), T[nlyr-1]);
    timesteps++;
  
    for(ilev=0; ilev<nlev; ilev++) {                    /* Reseting edn, eup and enet */
      edn[ilev] = 0;
      eup[ilev] = 0;
      if(ilev < nlyr) //enet is defined for ilyr only
        enet[ilev]=0;
    }
    
    
    //--------------------- Calculate z ----------------------//
    
    for (ilyr=0;ilyr<nlyr; ilyr++) {                         /* z for layers */
      deltazlyr[ilyr]=(Ra*T[ilyr]*deltap)/(plyr[ilyr]*g);  
    }
      
    zlyr[nlyr-1]=0; //check this one time
    for (ilyr=nlyr-2; ilyr >= 0; ilyr--) {
      zlyr[ilyr]=zlyr[ilyr+1]+deltazlyr[ilyr];
    }
      
     
    for (ilev=0;ilev<nlev-1; ilev++) {                      /* z for levels */
      deltazlev[ilev]=(Ra*T[ilev]*deltap)/(plyr[ilev]*g);  
    }
      
    z[nlev-1]=0;
    for (ilev=nlev-2; ilev >= 0; ilev--) {
      z[ilev]=z[ilev+1]+deltazlev[ilev];
     
    }
      
      
      
    //--------------------- Use k-distribution ---------------------//
      
    /* mu_0 is defined for a 8-part cycle of the earth, i.e. a timestep of 3 hours! */
    if(++mu_counter == mu_counterlimit)
      mu_counter = 0;

    //calculate it every two days!
    if((timesteps-1) % 10 == 0)
      //warning, wavelength is in nm!
      status = ck_mstrnx (z, plyr, T, h2o, o3, nlev, /*lyrflag*/ 1, c_co2, c_n2o, c_co, c_ch4, c_o2, &dtaumol, &wgt, &wavelength, &nbnd, &nch);
    
    for(iv=0; iv<nbnd; iv++) {
      //printf("iv = %d, wavelength = %e, S0 = %e\n", iv, wavelength[iv], S_0[iv]);
	  
      
      //------------- Use schwarzschild and sum edn eup --------//
	
      
      for(iq=0; iq<nch[iv]; iq++) {
	schwarzschild2(dtaumol[iv][iq], T, nlev, T[nlyr-1], edntmp, euptmp, wavelength[iv]*1e-6,wavelength[iv+1]*1e-6, tmplev, tmplyr);	

	for(ilev=0; ilev<nlev; ilev++) {
	  edn[ilev] += edntmp[ilev]*wgt[iv][iq];
	  eup[ilev] += euptmp[ilev]*wgt[iv][iq];
	  //printf("ilev = %d, iv = %d of %d, iq = %d of %d, wgt = %e, edntmp = %e, euptmp = %e\n", ilev, iv, nbnd, iq, nch[iv], wgt[iv][iq], edntmp[ilev], euptmp[ilev]);
	}
	
	//------------------- Include Rodents---------------------//  
	if(mu_0[mu_counter] > 0) {
	  rodents_solar(nlyr, dtaumol[iv][iq], omega_0, gassy, f, S_0[iv], mu_0[mu_counter], gr_albedo, edntmp, euptmp, edirtmp);
	  
	  for(ilev=0; ilev<nlev; ilev++) {
	    edn[ilev] += (edntmp[ilev]+edirtmp[ilev])*wgt[iv][iq];
	    eup[ilev] += euptmp[ilev]*wgt[iv][iq];
	    //printf("ilev = %d, iv = %d of %d, iq = %d of %d, wgt = %e, edntmp = %e, euptmp = %e, edirtmp = %e\n", ilev, iv, nbnd, iq, nch[iv], wgt[iv][iq], edntmp[ilev], euptmp[ilev], edirtmp[ilev]);
	  }
	}
      }
    }
     
    //---------------- Calculate enet -----------------------// 
    
    for(ilyr=0; ilyr<nlyr-1; ilyr++) {
      enet[ilyr] = eup[ilyr+1] + edn[ilyr] - eup[ilyr] - edn[ilyr+1];
     
    }

    for (ilev=0; ilev<nlev; ilev++) {
      //printf("ilev = %d, eup = %f, edn = %f\n", ilev, eup[ilev], edn[ilev]);
    }

    //---------------- Calculate temperature gain per layer -----------//
    
    for (ilyr=0; ilyr<nlyr-1; ilyr++)  {
      deltaT[ilyr]=(enet[ilyr]*g*deltat)/((deltap*100.0)*cp);
      T[ilyr] +=deltaT[ilyr];
      //printf("dT[ilyr] = %f\n", ilyr, deltaT[ilyr]);
    }
  
    //----------------Calculate Temperature gain for ground layer ---------//
    
    deltaT[nlyr-1]=((edn[nlyr-1]-eup[nlyr-1])*g*deltat)/((deltap*100.0)*cp);
    T[nlyr-1] += deltaT[nlyr-1];


    //---------- Convert T to theta ------------//
    
    for (ilyr=0; ilyr<nlyr; ilyr++) {                           
      theta[ilyr]=pow(PSURF/plyr[ilyr], kappa)*T[ilyr];
      //printf("%d %f\n", ilyr, theta[ilyr]);
    }
    
    
    //------------ Convection -------------------//
    
    instabil = FALSE;
    
    for (ilyr=0; ilyr<nlyr;ilyr++) {                            /* Testing for Instability */
      if (theta[ilyr+1]>theta[ilyr]) {
	instabil = TRUE;
	break;
      }
    }

    if (instabil) {                                             /* Convection - Sorting of Layers according to theta */
      qsort (theta, nlyr, sizeof(double), sortfunc);
      //  printf ("Konvektion :-)\n");
    }
    
    for (ilyr=0; ilyr<nlyr; ilyr++) {                           /* Conversion from theta to T */
      T[ilyr] = theta[ilyr] /  (pow(PSURF/plyr[ilyr], kappa));

      //printf("%d %f\n", ilyr, theta[ilyr]);
    }

    
    //-------------------- Print every x timestep ------------//
    
    if(timesteps % (int)(10) == 0) {
      printf ("timestep %d\n", timesteps);

      /* Printing time in readable format
       * In order to remove days, hours or minutes
       * just add // in front of the appropriate line
       */
      int time = timesteps*deltat;
      printf("time ");
      printf("%dd = ", (int)(time / 3600 / 24));
      printf("%dh = ", (int)(time / 3600 ));
      printf("%dmin = ", (int)(time / 60 ));
      printf("%ds\n", time);

      printf(" Tsurf=%f\n", T[nlyr-1]);

      for (ilyr=0; ilyr<nlyr; ilyr++) {
	deltaTday[ilyr]=deltaT[ilyr]*86.4/2;
      }

      plotall(nlyr, T, plyr, zlyr, deltaTday);

      /* for (ilyr=0; ilyr<nlyr; ilyr++) { */
      /*   printf("ilyr %d, z=%f,  plyr=%f,theta=%f, T=%f\n", ilyr, z[ilyr], plyr[ilyr],theta[ilyr], T[ilyr]); */
      /* } */

      for (ilyr=0; ilyr<nlyr; ilyr++) {
      	printf("p%f, edn%f, eup%f, enet%f\n", p[ilyr], edn[ilyr], eup[ilyr], enet[ilyr]);
      }
      printf("p%f, edn%f, eup%f\n", p[ilyr], edn[ilyr], eup[ilyr]);
    }
   
  }                                     

  free(tmplyr);
  free(tmplev);
  //----------------- End of while-loop---------------------//
  
  printf("\nTime %d: T = %f\n", (int)(timesteps*deltat), T[nlyr-1]);
  for (ilyr=0; ilyr<nlyr; ilyr++) {
    printf("%d %f\n", ilyr, T[ilyr]);
  }

  printf("\nTsurf=%f\n", T[nlyr-1]);

  return 0;
}
コード例 #10
0
ファイル: plctrl.c プロジェクト: NikolaBorisov/racket
MZ_DLLEXPORT
void
c_plscolbg(PLINT r, PLINT g, PLINT b)
{
    plscol0(0, r, g, b);
}
コード例 #11
0
ファイル: x19c.c プロジェクト: HazenBabcock/PLplot
int
main( int argc, char **argv )
{
    PLFLT       minx, maxx, miny, maxy;
    PLFLT       x, y;
    //variables for the shapelib example
    const PLINT nbeachareas    = 2;
    const PLINT beachareas[]   = { 23, 24 };
    const PLINT nwoodlandareas = 94;
    PLINT       woodlandareas[94];
    const PLINT nshingleareas  = 22;
    const PLINT shingleareas[] = { 0, 1, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 217, 2424, 2425, 2426, 2427, 2428, 2491, 2577 };
    const PLINT ncragareas     = 2024;
    PLINT       cragareas[2024];
    const PLINT majorroads[] = { 33, 48, 71, 83, 89, 90, 101, 102, 111 };
    int         i;

// Parse and process command line arguments

    (void) plparseopts( &argc, argv, PL_PARSE_FULL );

// Longitude (x) and latitude (y)

    miny = -70;
    maxy = 80;

    plinit();

// Cartesian plots
// Most of world

    minx = -170;
    maxx = minx + 360;

    // Setup a custom latitude and longitude-based scaling function.
    plslabelfunc( geolocation_labeler, NULL );

    plcol0( 1 );
    plenv( minx, maxx, miny, maxy, 1, 70 );
    plmap( NULL, "usaglobe", minx, maxx, miny, maxy );

// The Americas

    minx = 190;
    maxx = 340;

    plcol0( 1 );
    plenv( minx, maxx, miny, maxy, 1, 70 );
    plmap( NULL, "usaglobe", minx, maxx, miny, maxy );

    // Clear the labeling function
    plslabelfunc( NULL, NULL );

// Polar, Northern hemisphere

    minx = 0;
    maxx = 360;

    plenv( -75., 75., -75., 75., 1, -1 );
    plmap( mapform19, "globe", minx, maxx, miny, maxy );

    pllsty( 2 );
    plmeridians( mapform19, 10.0, 10.0, 0.0, 360.0, -10.0, 80.0 );

// Polar, Northern hemisphere, this time with a PLplot-wide transform

    minx = 0;
    maxx = 360;

    plstransform( map_transform, NULL );

    pllsty( 1 );
    plenv( -75., 75., -75., 75., 1, -1 );
    // No need to set the map transform here as the global transform will be
    // used.
    plmap( NULL, "globe", minx, maxx, miny, maxy );

    pllsty( 2 );
    plmeridians( NULL, 10.0, 10.0, 0.0, 360.0, -10.0, 80.0 );

    // Show Baltimore, MD on the map
    plcol0( 2 );
    plssym( 0.0, 2.0 );
    x = -76.6125;
    y = 39.2902778;
    plpoin( 1, &x, &y, 18 );
    plssym( 0.0, 1.0 );
    plptex( -76.6125, 43.0, 0.0, 0.0, 0.0, "Baltimore, MD" );

    // For C, this is how the global transform is cleared
    plstransform( NULL, NULL );

    // An example using shapefiles. The shapefiles used are from Ordnance Survey, UK.
    // These were chosen because they provide shapefiles for small grid boxes which
    // are easilly manageable for this demo.

    pllsty( 1 );


    minx = 240570;
    maxx = 621109;
    miny = 87822;
    maxy = 722770;
    plscol0( 0, 255, 255, 255 );
    plscol0( 1, 0, 0, 0 );
    plscol0( 2, 150, 150, 150 );
    plscol0( 3, 0, 50, 200 );
    plscol0( 4, 50, 50, 50 );
    plscol0( 5, 150, 0, 0 );
    plscol0( 6, 100, 100, 255 );


    minx = 265000;
    maxx = 270000;
    miny = 145000;
    maxy = 150000;
    plscol0( 0, 255, 255, 255 ); //white
    plscol0( 1, 0, 0, 0 );       //black
    plscol0( 2, 255, 200, 0 );   //yelow for sand
    plscol0( 3, 60, 230, 60 );   // green for woodland
    plscol0( 4, 210, 120, 60 );  //brown for contours
    plscol0( 5, 150, 0, 0 );     //red for major roads
    plscol0( 6, 180, 180, 255 ); //pale blue for water
    plscol0( 7, 100, 100, 100 ); //pale grey for shingle or boulders
    plscol0( 8, 100, 100, 100 ); //dark grey for custom polygons - generally crags


    plcol0( 1 );
    plenv( minx, maxx, miny, maxy, 1, -1 );
    pllab( "", "", "Martinhoe CP, Exmoor National Park, UK (shapelib only)" );


    //Beach
    plcol0( 2 );
    plmapfill( NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, beachareas, nbeachareas );

    //woodland
    plcol0( 3 );
    for ( i = 0; i < nwoodlandareas; ++i )
        woodlandareas[i] = i + 218;
    plmapfill( NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, (PLINT_VECTOR) woodlandareas, nwoodlandareas );

    //shingle or boulders
    plcol0( 7 );
    plmapfill( NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, shingleareas, nshingleareas );

    //crags
    plcol0( 8 );
    for ( i = 0; i < ncragareas; ++i )
        cragareas[i] = i + 325;
    plmapfill( NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, (PLINT_VECTOR) cragareas, ncragareas );

    //draw contours, we need to separate contours from high/low coastline
    //draw_contours(pls, "ss/SS64_line", 433, 20, 4, 3, minx, maxx, miny, maxy );
    plcol0( 4 );
    plmapline( NULL, "ss/ss64ne_Height_Contours", minx, maxx, miny, maxy, NULL, 0 );

    //draw the sea and surface water
    plwidth( 0.0 );
    plcol0( 6 );
    plmapfill( NULL, "ss/ss64ne_Water_Area", minx, maxx, miny, maxy, NULL, 0 );
    plwidth( 2.0 );
    plmapfill( NULL, "ss/ss64ne_Water_Line", minx, maxx, miny, maxy, NULL, 0 );

    //draw the roads, first with black and then thinner with colour to give an
    //an outlined appearance
    plwidth( 5.0 );
    plcol0( 1 );
    plmapline( NULL, "ss/ss64ne_Road_Centreline", minx, maxx, miny, maxy, NULL, 0 );
    plwidth( 3.0 );
    plcol0( 0 );
    plmapline( NULL, "ss/ss64ne_Road_Centreline", minx, maxx, miny, maxy, NULL, 0 );
    plcol0( 5 );
    plmapline( NULL, "ss/ss64ne_Road_Centreline", minx, maxx, miny, maxy, majorroads, 9 );

    //draw buildings
    plwidth( 1.0 );
    plcol0( 1 );
    plmapfill( NULL, "ss/ss64ne_Building_Area", minx, maxx, miny, maxy, NULL, 0 );

    //labels
    plsfci( 0x80000100 );
    plschr( 0, 0.8 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "MARTINHOE CP", minx, maxx, miny, maxy, 202 );
    plschr( 0, 0.7 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Heale\nDown", minx, maxx, miny, maxy, 13 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "South\nDown", minx, maxx, miny, maxy, 34 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Martinhoe\nCommon", minx, maxx, miny, maxy, 42 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Woody Bay", minx, maxx, miny, maxy, 211 );
    plschr( 0, 0.6 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Mill Wood", minx, maxx, miny, maxy, 16 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Heale Wood", minx, maxx, miny, maxy, 17 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 1.0, "Bodley", minx, maxx, miny, maxy, 31 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.0, "Martinhoe", minx, maxx, miny, maxy, 37 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Woolhanger\nCommon", minx, maxx, miny, maxy, 60 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "West Ilkerton\nCommon", minx, maxx, miny, maxy, 61 );
    plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Caffyns\nHeanton\nDown", minx, maxx, miny, maxy, 62 );

    plend();
    exit( 0 );
}