void CheckOut(int CanopyRadAttOption, LAYER Veg, LAYER Soil, VEGTABLE *VType, SOILTABLE *SType, MAPSIZE *Map, TOPOPIX **TopoMap, VEGPIX **VegMap, SOILPIX **SoilMap) { int y, x, i, j; int *count = NULL, *scount = NULL; float a, b, l, Taud, Taub20, Taub40, Taub60, Taub80; int npixels; if (!(count = static_cast<int*>(calloc(Veg.NTypes, sizeof(int))))) { ReportError("Checkout", 1); } if (!(scount = static_cast<int *>(calloc(Soil.NTypes, sizeof(int))))) { ReportError("Checkout", 1); } for (y = 0; y < Map->NY; y++) { for (x = 0; x < Map->NX; x++) { if (INBASIN(TopoMap[y][x].Mask)) { if (VegMap[y][x].Veg < 1 || VegMap[y][x].Veg > Veg.NTypes) { printf("veg value %d out of range \n", VegMap[y][x].Veg); exit(-1); } count[VegMap[y][x].Veg - 1]++; if (SoilMap[y][x].Soil < 1 || SoilMap[y][x].Soil > Soil.NTypes) { printf("soil value %d out of range \n", SoilMap[y][x].Soil); exit(-1); } scount[SoilMap[y][x].Soil - 1]++; } } } i = 0; for (y = 0; y < Map->NY; y++) { for (x = 0; x < Map->NX; x++) { if (INBASIN(TopoMap[y][x].Mask)) { i = i + 1; } } } printf("\nBasin has %d active pixels \n", i); npixels = i; printf("\nThe following VEG types are in the current basin \n"); for (i = 0; i < Veg.NTypes; i++) { if (count[i] > 0) printf ("Class # %d of Type: %s has fraction basin area: %5.3f\n", i + 1, VType[i].Desc, (float) count[i] / (float) npixels); VType[i].TotalDepth = 0.0; for (y = 0; y < VType[i].NSoilLayers; y++) { VType[i].TotalDepth += VType[i].RootDepth[y]; } } printf("\nThe following SOIL types are in the current basin \n"); for (i = 0; i < Soil.NTypes; i++) if (scount[i] > 0) printf ("Class # %d of Type: %s has fraction basin area: %5.3f\n", i + 1, SType[i].Desc, (float) scount[i] / (float) npixels); printf("\nSome estimates for current vegetation specification\n"); for (i = 0; i < Veg.NTypes; i++) { if (count[i] > 0) { printf("\nVegetation Type: %s\n", VType[i].Desc); printf("2meter wind speed fraction of ref level %1.3f\n", VType[i].USnow); if (VType[i].OverStory) { for (j = 0; j < 12; j++) { if (fequal(VType[i].LAIMonthly[0][j], 0.0)) { printf("Overstory LAI must be > 0\n"); exit(-1); } } /* printf("Overstory LAI July %2.3f Effective LAI July %2.3f\n", VType[i].LAIMonthly[0][6]);*/ if (CanopyRadAttOption == VARIABLE) { a = VType[i].LeafAngleA; b = VType[i].LeafAngleB; l = VType[i].LAIMonthly[0][6] / VType[i].ClumpingFactor; if (l == 0) Taud = 1.0; else Taud = exp(-b * l) * ((1 - a * l) * exp(-a * l) + (a * l) * (a * l) * evalexpint(1, a * l)); Taub20 = exp(-l * (VType[i].LeafAngleA / 0.342 + VType[i].LeafAngleB)); Taub40 = exp(-l * (VType[i].LeafAngleA / 0.642 + VType[i].LeafAngleB)); Taub60 = exp(-l * (VType[i].LeafAngleA / 0.866 + VType[i].LeafAngleB)); Taub80 = exp(-l * (VType[i].LeafAngleA / 0.984 + VType[i].LeafAngleB)); printf("Solar Altitude 20 deg Tbeam %f Tdiff %f\n", Taub20, Taud); printf("Solar Altitude 40 deg Tbeam %f Tdiff %f\n", Taub40, Taud); printf("Solar Altitude 60 deg Tbeam %f Tdiff %f\n", Taub60, Taud); printf("Solar Altitude 80 deg Tbeam %f Tdiff %f\n", Taub80, Taud); } } } } for (y = 0; y < Map->NY; y++) { for (x = 0; x < Map->NX; x++) { if (INBASIN(TopoMap[y][x].Mask)) { if (SoilMap[y][x].Depth <= VType[VegMap[y][x].Veg - 1].TotalDepth) { printf("Error for class %d of Type %s \n", VegMap[y][x].Veg, VType[VegMap[y][x].Veg - 1].Desc); printf("%d %d Soil depth is %f, Root depth is %f \n", y,x,SoilMap[y][x].Depth, VType[VegMap[y][x].Veg - 1].TotalDepth); exit(-1); } } } } if (count) { free(count); } if (scount) { free(scount); } }
/***************************************************************************** InitNewMonth() At the start of a new month, read the new radiation files (diffuse and direct beam), and potentially a new LAI value. *****************************************************************************/ void InitNewMonth(TIMESTRUCT *Time, OPTIONSTRUCT *Options, MAPSIZE *Map, TOPOPIX **TopoMap, float **PrismMap, unsigned char ***ShadowMap, RADCLASSPIX **RadMap, INPUTFILES *InFiles, int NVegs, VEGTABLE *VType, int NStats, METLOCATION *Stat, char *Path) { const char *Routine = "InitNewMonth"; char FileName[MAXSTRING + 1]; char VarName[BUFSIZE + 1]; /* Variable name */ int i; int j; int y, x; float a, b, l; int NumberType; float *Array = NULL; unsigned char *Array1 = NULL; if (DEBUG) printf("Initializing new month\n"); /* If PRISM precipitation fields are being used to interpolate the observed precipitation fields, then read in the new months field */ if (Options->Prism == TRUE) { printf("reading in new PRISM field for month %d \n", Time->Current.Month); sprintf(FileName, "%s.%02d.%s", Options->PrismDataPath, Time->Current.Month, Options->PrismDataExt); GetVarName(205, 0, VarName); GetVarNumberType(205, &NumberType); if (!(Array = (float *) calloc(Map->NY * Map->NX, sizeof(float)))) ReportError((char *) Routine, 1); Read2DMatrix(FileName, Array, NumberType, Map->NY, Map->NX, 0); for (y = 0; y < Map->NY; y++) { for (x = 0; x < Map->NX; x++) { PrismMap[y][x] = Array[y * Map->NX + x]; } } free(Array); } if (Options->Shading == TRUE) { printf("reading in new shadow map for month %d \n", Time->Current.Month); sprintf(FileName, "%s.%02d.%s", Options->ShadingDataPath, Time->Current.Month, Options->ShadingDataExt); GetVarName(304, 0, VarName); GetVarNumberType(304, &NumberType); if (! (Array1 = (unsigned char *) calloc(Map->NY * Map->NX, sizeof(unsigned char)))) ReportError((char *) Routine, 1); for (i = 0; i < Time->NDaySteps; i++) { Read2DMatrix(FileName, Array1, NumberType, Map->NY, Map->NX, i, VarName); for (y = 0; y < Map->NY; y++) { for (x = 0; x < Map->NX; x++) { ShadowMap[i][y][x] = Array1[y * Map->NX + x]; } } } free(Array1); } printf("changing LAI, albedo and diffuse transmission parameters\n"); for (i = 0; i < NVegs; i++) { for (j = 0; j < VType[i].NVegLayers; j++) { VType[i].LAI[j] = VType[i].LAIMonthly[j][Time->Current.Month - 1]; VType[i].MaxInt[j] = VType[i].LAI[j] * VType[i].Fract[j] * LAI_WATER_MULTIPLIER; VType[i].Albedo[j] = VType[i].AlbedoMonthly[j][Time->Current.Month - 1]; } if (VType[i].OverStory) { a = VType[i].LeafAngleA; b = VType[i].LeafAngleB; l = VType[i].LAI[0] / VType[i].ClumpingFactor; if (l == 0) VType[i].Taud = 1.0; else VType[i].Taud = exp(-b * l) * ((1 - a * l) * exp(-a * l) + (a * l) * (a * l) * evalexpint(1, a * l)); } else { VType[i].Taud = 0.0; } } }