[GRASS-SVN] r30899 - in grass-addons/gipe: . r.out.vic
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Apr 7 23:38:31 EDT 2008
Author: ychemin
Date: 2008-04-07 23:38:31 -0400 (Mon, 07 Apr 2008)
New Revision: 30899
Added:
grass-addons/gipe/r.out.vic/
grass-addons/gipe/r.out.vic/Makefile
grass-addons/gipe/r.out.vic/description.html
grass-addons/gipe/r.out.vic/main.c
grass-addons/gipe/r.out.vic/veg_lib.c
Removed:
grass-addons/gipe/r.out.vic_mask/
grass-addons/gipe/r.out.vic_met/
grass-addons/gipe/r.out.vic_veg/
Log:
Merged all vic modules in one
Added: grass-addons/gipe/r.out.vic/Makefile
===================================================================
--- grass-addons/gipe/r.out.vic/Makefile (rev 0)
+++ grass-addons/gipe/r.out.vic/Makefile 2008-04-08 03:38:31 UTC (rev 30899)
@@ -0,0 +1,15 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.out.vic_met
+
+LIBES = $(GPROJLIB) $(GISLIB)
+DEPENDENCIES = $(GPROJDEP) $(GISDEP)
+EXTRA_INC = $(PROJINC)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+ifneq ($(USE_LARGEFILES),)
+ EXTRA_CFLAGS = -D_FILE_OFFSET_BITS=64
+endif
+
+default: cmd
Added: grass-addons/gipe/r.out.vic/description.html
===================================================================
--- grass-addons/gipe/r.out.vic/description.html (rev 0)
+++ grass-addons/gipe/r.out.vic/description.html 2008-04-08 03:38:31 UTC (rev 30899)
@@ -0,0 +1,42 @@
+<H2>DESCRIPTION</H2>
+
+<EM>r.out.vic</EM> creates a set of VIC hydrological model meteorological input ascii files.
+
+1 - Meteorological: Three time series of GIS data are needed: Precipitation (mm/d), Tmax(C) and Tmin(C).
+
+Files are $prefix_latitude_longitude.
+
+Format is:
+"%.2f %.2f %.2f\n"
+
+with:
+double precipitation
+double Tmax
+double Tmin
+
+This is an input to VIC (Variable Infiltration Capacity) in forcing/ of TEST example.
+
+
+2 - Vegetation: Filling only Land cover class, with only one class, and one standard root system. Option to add monthly LAI (12 maps).
+
+3 - Soil: Barely complete, it takes elevation data and lat/long, the rest is filled up with dummy soil data.
+
+
+<H2>NOTES</H2>
+
+<H2>TODO</H2>
+Soil files input creation is incomplete, a lot to do here.
+
+<H2>SEE ALSO</H2>
+
+<em>
+</em>
+
+
+<H2>AUTHORS</H2>
+
+Yann Chemin<BR>
+
+
+<p>
+<i>Last changed: $Date: 2008/03/23 09:39:55 $</i>
Added: grass-addons/gipe/r.out.vic/main.c
===================================================================
--- grass-addons/gipe/r.out.vic/main.c (rev 0)
+++ grass-addons/gipe/r.out.vic/main.c 2008-04-08 03:38:31 UTC (rev 30899)
@@ -0,0 +1,574 @@
+/****************************************************************************
+ *
+ * MODULE: r.out.vic
+ * AUTHOR(S): Yann Chemin - yann.chemin at gmail.com
+ * PURPOSE: Creates VIC input files:
+ * 1 - Meteorological:
+ * Three time series of GIS data are needed:
+ * Precipitation (mm/d), Tmax(C) and Tmin(C)
+ * 2 - Vegetation:
+ * Filling only Land cover class, with only one class,
+ * and one standard root system.
+ * Option to add monthly LAI (12 maps).
+ * 3 - Soil:
+ * Barely complete, it takes elevation data & lat/long,
+ * the rest is filled up with dummy soil data.
+ *
+ * COPYRIGHT: (C) 2008 by the GRASS Development Team
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ *****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/gprojects.h>
+#include <grass/glocale.h>
+
+/************************/
+/* daily one year is: */
+#define MAXFILES 366
+
+/************************/
+/* for vegeation: */
+int veglib(char *filename);
+
+int main(int argc, char *argv[])
+{
+ struct Cell_head cellhd; //region+header info
+ char *mapset; // mapset name
+ int nrows, ncols;
+ int row,col;
+
+ int not_ll=0;//if proj is not lat/long, it will be 1.
+ struct GModule *module;
+ struct Option *input1, *input2, *input3, *input4;
+ struct Option *input5, *input6;
+ struct Option *output1, *output2, *output3, *output4;
+
+ struct Flag *flag1;
+ struct History history; //metadata
+
+ struct pj_info iproj;
+ struct pj_info oproj;
+ /************************************/
+ /* FMEO Declarations*****************/
+ char *prcp_name;// input first time-series raster files names
+ char *tmax_name;// input second time_series raster files names
+ char *tmin_name;// input third time_series raster files names
+ char *landcover_name;// input raster name
+ char lai_name[12]; // input monthly raster files name
+ char *result1; //output file base name
+ char *result2; //output Soil file name
+ char *result3; //output Veg file name
+ char result_lat_long[50]; //output file name
+ //File Descriptors
+ int infd_prcp[MAXFILES], infd_tmax[MAXFILES], infd_tmin[MAXFILES];
+ int infd;
+ int infd_landcover, infd_lai[12];
+
+ int i=0,j=0;
+ double xp, yp;
+ double xmin, ymin;
+ double xmax, ymax;
+ double stepx,stepy;
+ double latitude, longitude;
+
+ void *inrast_prcp[MAXFILES];
+ void *inrast_tmax[MAXFILES];
+ void *inrast_tmin[MAXFILES];
+ void *inrast_elevation;
+ void *inrast_landcover;
+ void *inrast_lai[12];
+ RASTER_MAP_TYPE data_type_inrast_prcp[MAXFILES];
+ RASTER_MAP_TYPE data_type_inrast_tmax[MAXFILES];
+ RASTER_MAP_TYPE data_type_inrast_tmin[MAXFILES];
+ RASTER_MAP_TYPE data_type_inrast_elevation;
+ RASTER_MAP_TYPE data_type_inrast_landcover;
+ RASTER_MAP_TYPE data_type_inrast_lai[12];
+
+ /****************************************/
+ /* Meteorological maps */
+ FILE *f; // output ascii file
+ int grid_count; // grid cell count
+ double prcp[MAXFILES]; // Precipitation data
+ double tmax[MAXFILES]; // Tmax data
+ double tmin[MAXFILES]; // Tmin data
+ char **prcp_ptr; // pointer to get the input1->answers
+ char **tmax_ptr; // pointer to get the input2->answers
+ char **tmin_ptr; // pointer to get the input3->answers
+ int nfiles1, nfiles2, nfiles3, nfiles_shortest;// count no. input files
+ char **test1, **test2, **test3; // test number of input files
+ char **ptr1, **ptr2, **ptr3; // test number of input files
+ /****************************************/
+ /* Elevation map */
+ char *in;
+ FILE *g; // output soil ascii file
+ int process; // process grid cell switch
+ char *dummy_data1; // dummy data part 1
+ char *dummy_data2; // dummy data part 2
+ double elevation; // average evevation of grid cell
+ /************************************/
+ /* Vegetation map */
+ FILE *h; // output ascii file
+ char *dummy_data3; // dummy data part 1
+ char *dummy_data4; // dummy data part 2
+ double *lai[12]; // lAI data for each month
+ char **lai_ptr; // pointer to get the input2->answers
+ int nfiles; // count LAI input files
+ char **test, **ptr; // test number of LAI input files
+ /************************************/
+
+ G_gisinit(argv[0]);
+
+ module = G_define_module();
+ module->keywords = _("VIC, hydrology, precipitation, Tmax, Tmin, soil");
+ module->description = _("creates a meteorological ascii file for each non-null cell from 3 time series maps: precipitation, Tmax and Tmin. Also creates a dummy soil file from elevation.");
+
+ /* Define the different options */
+ input1 = G_define_standard_option(G_OPT_R_INPUT) ;
+ input1->key = _("prcp");
+ input1->multiple = YES;
+ input1->description=_("Names of the precipitation input maps");
+
+ input2 = G_define_standard_option(G_OPT_R_INPUT) ;
+ input2->key = _("tmax");
+ input2->multiple = YES;
+ input2->description=_("Names of the Tmax input maps");
+
+ input3 = G_define_standard_option(G_OPT_R_INPUT) ;
+ input3->key = _("tmin");
+ input3->multiple = YES;
+ input3->description=_("Names of the Tmin input maps");
+
+ input4 = G_define_standard_option(G_OPT_R_INPUT) ;
+ input4->key = _("dem");
+ input4->description=_("Name of the elevation input map");
+
+ input5 = G_define_standard_option(G_OPT_R_INPUT) ;
+ input5->key = _("landcover");
+ input5->description=_("Name of the land cover input map");
+
+ input6 = G_define_standard_option(G_OPT_R_INPUT) ;
+ input6->key = _("LAI");
+ input6->multiple = YES;
+ input6->required = NO;
+ input6->description=_("Name of the LAI input maps (12 of them!)");
+
+ output1 = G_define_option();
+ output1->key =_("output");
+ output1->description =_("Base Name of the output vic meteorological ascii files");
+ output1->answer =_("data_");
+
+ output2 = G_define_option() ;
+ output2->key =_("output_soil");
+ output2->description=_("Name of the output vic soil ascii file");
+ output2->answer =_("vic_soil.asc");
+
+ output3 = G_define_option() ;
+ output3->key =_("output");
+ output3->description=_("Name of the output vic vegetation ascii file");
+ output3->answer =_("vic_veg.asc");
+
+ output4 = G_define_option() ;
+ output4->key =_("veglib");
+ output4->required = NO;
+ output4->description=_("Name of a standard vegetation library file");
+ output4->answer =_("veglib");
+
+ flag1 = G_define_flag() ;
+ flag1->key = 'a';
+ flag1->description =_("append meteorological data if file already exists (useful if adding additional year of data)");
+ /********************/
+ if (G_parser(argc, argv))
+ exit (EXIT_FAILURE);
+
+ in = input4->answer;
+ landcover_name = input5->answer;
+ result1 = output1->answer;
+ result2 = output2->answer;
+ result3 = output3->answer;
+ /************************************************/
+ /* STANDARD VEGLIB CREATION HERE */
+ if(output4->answer)
+ veglib(output4->answer);
+
+ /************************************************/
+ /* LOADING TMAX TIME SERIES MAPS */
+ test1 = input1->answers;
+ for (ptr1 = test1, nfiles1 = 0; *ptr1 != NULL; ptr1++, nfiles1++)
+ ;
+ if (nfiles1 > MAXFILES){
+ G_fatal_error(_("Too many inputs1, change MAXFILES, recompile."));
+ }
+ prcp_ptr = input1->answers;
+ i=0;
+ for(; *prcp_ptr != NULL; prcp_ptr++){
+ prcp_name= *prcp_ptr;
+ mapset = G_find_cell2(prcp_name, "");
+ if (mapset == NULL)
+ G_fatal_error(_("cell file [%s] not found"), prcp_name);
+ data_type_inrast_prcp[i] = G_raster_map_type(prcp_name,mapset);
+ if ((infd_prcp[i] = G_open_cell_old (prcp_name,mapset)) < 0)
+ G_fatal_error (_("Cannot open cell file [%s]"), prcp_name);
+ if (G_get_cellhd (prcp_name, mapset, &cellhd) < 0)
+ G_fatal_error (_("Cannot read file header of [%s])"), prcp_name);
+ inrast_prcp[i] = G_allocate_raster_buf(data_type_inrast_prcp[i]);
+ i++;
+ }
+ nfiles1=i;
+ /************************************************/
+ /* LOADING TMAX TIME SERIES MAPS */
+ test2 = input2->answers;
+ for (ptr2 = test2, nfiles2 = 0; *ptr2 != NULL; ptr2++, nfiles2++)
+ ;
+ if (nfiles2 > MAXFILES){
+ G_fatal_error(_("Too many inputs2, change MAXFILES, recompile."));
+ }
+ tmax_ptr = input2->answers;
+ i=0;
+ for(; *tmax_ptr != NULL; tmax_ptr++){
+ tmax_name = *tmax_ptr;
+ mapset = G_find_cell2(tmax_name, "");
+ if (mapset == NULL)
+ G_fatal_error(_("cell file [%s] not found"), tmax_name);
+ data_type_inrast_tmax[i] = G_raster_map_type(tmax_name,mapset);
+ if ((infd_tmax[i] = G_open_cell_old (tmax_name,mapset)) < 0)
+ G_fatal_error (_("Cannot open cell file [%s]"),tmax_name);
+ if (G_get_cellhd (tmax_name, mapset, &cellhd) < 0)
+ G_fatal_error (_("Cannot read file header of [%s])"), tmax_name);
+ inrast_tmax[i] = G_allocate_raster_buf(data_type_inrast_tmax[i]);
+ i++;
+ }
+ nfiles2=i;
+ /************************************************/
+ /* LOADING TMIN TIME SERIES MAPS */
+ test3 = input3->answers;
+ for (ptr3 = test3, nfiles3 = 0; *ptr3 != NULL; ptr3++, nfiles3++)
+ ;
+ if (nfiles3 > MAXFILES){
+ G_fatal_error(_("Too many inputs3, change MAXFILES, recompile."));
+ }
+ tmin_ptr = input3->answers;
+ i=0;
+ for(; *tmin_ptr != NULL; tmin_ptr++){
+ tmin_name = *tmin_ptr;
+ mapset = G_find_cell2(tmin_name, "");
+ if (mapset == NULL)
+ G_fatal_error(_("cell file [%s] not found"), tmin_name);
+ data_type_inrast_tmin[i] = G_raster_map_type(tmin_name,mapset);
+ if ((infd_tmin[i] = G_open_cell_old (tmin_name,mapset)) < 0)
+ G_fatal_error (_("Cannot open cell file [%s]"), tmin_name);
+ if (G_get_cellhd (tmin_name, mapset, &cellhd) < 0)
+ G_fatal_error (_("Cannot read file header of [%s])"), tmin_name);
+ inrast_tmin[i] = G_allocate_raster_buf(data_type_inrast_tmin[i]);
+ i++;
+ }
+ nfiles3=i;
+ /************************************************/
+ if(nfiles1<=nfiles2||nfiles1<=nfiles3){
+ nfiles_shortest = nfiles1;
+ } else if (nfiles2<=nfiles1||nfiles2<=nfiles3){
+ nfiles_shortest = nfiles2;
+ } else {
+ nfiles_shortest = nfiles3;
+ }
+ /************************************************/
+ /* Load Elevation file */
+ mapset = G_find_cell2(in, "");
+ if (mapset == NULL) {
+ G_fatal_error(_("cell file [%s] not found"), in);
+ }
+ data_type_inrast_elevation = G_raster_map_type(in,mapset);
+ if ( (infd = G_open_cell_old (in,mapset)) < 0)
+ G_fatal_error (_("Cannot open cell file [%s]"), in);
+ if (G_get_cellhd (in, mapset, &cellhd) < 0)
+ G_fatal_error (_("Cannot read file header of [%s])"), in);
+ inrast_elevation = G_allocate_raster_buf(data_type_inrast_elevation);
+ /***************************************************/
+ /************************************************/
+ /* LOADING OPTIONAL LAI MONTHLY MAPS */
+ if (input6->answer){
+ test = input6->answers;
+ for (ptr = test, nfiles = 0; *ptr != NULL; ptr++, nfiles++)
+ ;
+ if (nfiles < 12)
+ G_fatal_error(_("The exact number of LAI input maps is 12"));
+ lai_ptr = input6->answers;
+ for(; *lai_ptr != NULL; lai_ptr++){
+ strcpy(lai_name,*lai_ptr);
+ }
+ for(i=0;i<12;i++){
+ mapset = G_find_cell2(&lai_name[i], "");
+ if (mapset == NULL) {
+ G_fatal_error(_("cell file [%s] not found"), lai_name[i]);
+ }
+ data_type_inrast_lai[i] = G_raster_map_type(&lai_name[i],mapset);
+ if ((infd_lai[i] = G_open_cell_old (&lai_name[i],mapset)) < 0)
+ G_fatal_error (_("Cannot open cell file [%s]"), lai_name[i]);
+ if (G_get_cellhd (&lai_name[i], mapset, &cellhd) < 0)
+ G_fatal_error (_("Cannot read file header of [%s])"), lai_name[i]);
+ inrast_lai[i] = G_allocate_raster_buf(data_type_inrast_lai[i]);
+ }
+ }
+ /************************************************/
+ /* LOADING REQUIRED LAND COVER MAP */
+ mapset = G_find_cell2(landcover_name, "");
+ if (mapset == NULL) {
+ G_fatal_error(_("cell file [%s] not found"), landcover_name);
+ }
+ data_type_inrast_landcover = G_raster_map_type(landcover_name,mapset);
+ if ( (infd_landcover = G_open_cell_old (landcover_name,mapset)) < 0)
+ G_fatal_error (_("Cannot open cell file [%s]"), landcover_name);
+ if (G_get_cellhd (landcover_name, mapset, &cellhd) < 0)
+ G_fatal_error (_("Cannot read file header of [%s])"), landcover_name);
+ inrast_landcover = G_allocate_raster_buf(data_type_inrast_landcover);
+ /***************************************************/
+ G_debug(3, "number of rows %d",cellhd.rows);
+
+ stepx=cellhd.ew_res;
+ stepy=cellhd.ns_res;
+
+ xmin=cellhd.west;
+ xmax=cellhd.east;
+ ymin=cellhd.south;
+ ymax=cellhd.north;
+
+ nrows = G_window_rows();
+ ncols = G_window_cols();
+
+ //Shamelessly stolen from r.sun !!!!
+ /* Set up parameters for projection to lat/long if necessary */
+ if ((G_projection() != PROJECTION_LL)) {
+ not_ll=1;
+ struct Key_Value *in_proj_info, *in_unit_info;
+ if ((in_proj_info = G_get_projinfo()) == NULL)
+ G_fatal_error(_("Can't get projection info of current location"));
+ if ((in_unit_info = G_get_projunits()) == NULL)
+ G_fatal_error(_("Can't get projection units of current location"));
+ if (pj_get_kv(&iproj, in_proj_info, in_unit_info) < 0)
+ G_fatal_error(_("Can't get projection key values of current location"));
+ G_free_key_value(in_proj_info);
+ G_free_key_value(in_unit_info);
+ /* Set output projection to latlong w/ same ellipsoid */
+ oproj.zone = 0;
+ oproj.meters = 1.;
+ sprintf(oproj.proj, "ll");
+ if ((oproj.pj = pj_latlong_from_proj(iproj.pj)) == NULL)
+ G_fatal_error(_("Unable to set up lat/long projection parameters"));
+ }//End of stolen from r.sun :P
+
+ /*Initialize grid cell process switch*/
+ g=fopen(result2,"w");
+ /*Initialize grid cell process switch*/
+ /*If =1 then process, if =0 then skip*/
+ process = 1;
+
+ /*Initialize grid cell count*/
+ grid_count = 1;
+ /*Initialize output file */
+ fprintf(g,"#RUN\tGRID\tLAT\tLNG\tINFILT\tDs\tDs_MAX\tWs\tC\tEXPT_1\tEXPT_2\tEXPT_3\tKsat_1\tKsat_2\tKsat_3\tPHI_1\tPHI_2\tPHI_3\tMOIST_1\tMOIST_2\tMOIST_3\tELEV\tDEPTH_1\tDEPTH_2\tDEPTH_3\tAVG_T\tDP\tBUBLE1\tBUBLE2\tBUBLE3\tQUARZ1\tQUARZ2\tQUARZ3\tBULKDN1\tBULKDN2\tBULKDN3\tPARTDN1\tPARTDN2\tPARTDN3\tOFF_GMT\tWcrFT1\tWcrFT2\tWcrFT3\tWpFT1\tWpFT2\tWpFT3\tZ0_SOIL\tZ0_SNOW\tPRCP\tRESM1\tRESM2\tRESM3\tFS_ACTV\tJULY_TAVG\n");
+
+ /*Initialize dummy data*/
+ dummy_data1 = "0.010\t1.e-4\t3.05\t0.93\t2\t4.0\t4.0\t4.0\t250.0\t250.0\t250.0\t-999\t-999\t-999\t0.4\t0.4\t0.4";
+ dummy_data2 = "0.1\t6.90\t2.000\t14.0\t4.0\t75.0\t75.0\t75.0\t0.24\t0.24\t0.24\t1306\t1367\t1367\t2650\t2650\t2650\t-6\t0.330\t0.330\t0.330\t0.133\t0.133\t0.133\t0.001\t0.010\t500\t0.02\t0.02\t0.02\t1\t18.665\n";
+
+ /*Initialize grid cell process switch*/
+ h=fopen(result1,"w");
+
+ /*Initialize dummy data*/
+ dummy_data3 = "0.10 0.1 1.00 0.65 0.50 0.25";
+ dummy_data4 = "0.312 0.413 0.413 0.413 0.413 0.488 0.975 1.150 0.625 0.312 0.312 0.312";
+
+ for (row = 0; row < nrows; row++){
+ DCELL d_prcp[MAXFILES];
+ DCELL d_tmax[MAXFILES];
+ DCELL d_tmin[MAXFILES];
+ DCELL d_elevation;
+ CELL c_landcover;
+ DCELL d_lai[12];
+ G_percent(row,nrows,2);
+ for(i=0;i<nfiles_shortest;i++){
+ if(G_get_raster_row(infd_prcp[i],inrast_prcp[i],row,data_type_inrast_prcp[i])<0)
+ G_fatal_error(_("Could not read from prcp<%d>"),i+1);
+ if(G_get_raster_row(infd_tmax[i],inrast_tmax[i],row,data_type_inrast_tmax[i])<0)
+ G_fatal_error(_("Could not read from tmax<%d>"),i+1);
+ if(G_get_raster_row(infd_tmin[i],inrast_tmin[i],row,data_type_inrast_tmin[i])<0)
+ G_fatal_error(_("Could not read from tmin<%d>"),i+1);
+ }
+ if(G_get_raster_row(infd,inrast_elevation,row,data_type_inrast_elevation)<0)
+ G_fatal_error(_("Could not read from <%s>"),in);
+ if(G_get_raster_row(infd_landcover,inrast_landcover,row,data_type_inrast_landcover)<0)
+ G_fatal_error(_("Could not read from <%s>"),landcover_name);
+ if(input6->answer){
+ for(i=0;i<12;i++){
+ if(G_get_raster_row(infd_lai[i],inrast_lai[i],row,data_type_inrast_lai[i])<0)
+ G_fatal_error(_("Could not read from <%s>"),lai_name[i]);
+ }
+ }
+ for (col=0; col < ncols; col++){
+ for(i=0;i<nfiles_shortest;i++){
+ /*Extract prcp time series data*/
+ switch(data_type_inrast_prcp[i]){
+ case CELL_TYPE:
+ d_prcp[i]= (double) ((CELL *) inrast_prcp[i])[col];
+ break;
+ case FCELL_TYPE:
+ d_prcp[i]= (double) ((FCELL *) inrast_prcp[i])[col];
+ break;
+ case DCELL_TYPE:
+ d_prcp[i]= (double) ((DCELL *) inrast_prcp[i])[col];
+ break;
+ }
+ /*Extract tmax time series data*/
+ switch(data_type_inrast_tmax[i]){
+ case CELL_TYPE:
+ d_tmax[i]= (double) ((CELL *) inrast_tmax[i])[col];
+ break;
+ case FCELL_TYPE:
+ d_tmax[i]= (double) ((FCELL *) inrast_tmax[i])[col];
+ break;
+ case DCELL_TYPE:
+ d_tmax[i]= (double) ((DCELL *) inrast_tmax[i])[col];
+ break;
+ }
+ /*Extract tmin time series data*/
+ switch(data_type_inrast_tmin[i]){
+ case CELL_TYPE:
+ d_tmin[i]= (double) ((CELL *) inrast_tmin[i])[col];
+ break;
+ case FCELL_TYPE:
+ d_tmin[i]= (double) ((FCELL *) inrast_tmin[i])[col];
+ break;
+ case DCELL_TYPE:
+ d_tmin[i]= (double) ((DCELL *) inrast_tmin[i])[col];
+ break;
+ }
+ }
+ /*Extract elevation data*/
+ switch(data_type_inrast_elevation){
+ case CELL_TYPE:
+ d_elevation = (double) ((CELL *) inrast_elevation)[col];
+ break;
+ case FCELL_TYPE:
+ d_elevation = (double) ((FCELL *) inrast_elevation)[col];
+ break;
+ case DCELL_TYPE:
+ d_elevation = ((DCELL *) inrast_elevation)[col];
+ break;
+ }
+ /*Extract landcover data*/
+ switch(data_type_inrast_landcover){
+ case CELL_TYPE:
+ c_landcover= (int) ((CELL *) inrast_landcover)[col];
+ break;
+ case FCELL_TYPE:
+ c_landcover= (int) ((FCELL *) inrast_landcover)[col];
+ break;
+ case DCELL_TYPE:
+ c_landcover= (int) ((DCELL *) inrast_landcover)[col];
+ break;
+ }
+ /*Extract lai monthly data*/
+ if(input6->answer){
+ for(i=0;i<12;i++){
+ switch(data_type_inrast_lai[i]){
+ case CELL_TYPE:
+ d_lai[i]= (double) ((CELL *) inrast_lai[i])[col];
+ break;
+ case FCELL_TYPE:
+ d_lai[i]= (double) ((FCELL *) inrast_lai[i])[col];
+ break;
+ case DCELL_TYPE:
+ d_lai[i]= (double) ((DCELL *) inrast_lai[i])[col];
+ break;
+ }
+ }
+ }
+ /*Extract lat/long data*/
+ latitude = ymax - ( row * stepy );
+ longitude = xmin + ( col * stepx );
+ if(not_ll){
+ if (pj_do_proj(&longitude, &latitude, &iproj, &oproj) < 0) {
+ G_fatal_error(_("Error in pj_do_proj"));
+ }
+ }else{
+ //Do nothing
+ }
+ if(G_is_d_null_value(&prcp[0])||
+ G_is_d_null_value(&d_tmax[0])||
+ G_is_d_null_value(&d_tmin[0])||
+ G_is_d_null_value(&d_elevation)||
+ G_is_c_null_value(&c_landcover)){
+ /* Do nothing */
+ } else {
+ /* Make the output .dat file name */
+ sprintf(result_lat_long,"%s%.4f%s%.4f",result1,latitude,"_",longitude);
+ /*Open new ascii file*/
+ if (flag1->answer){
+ /*Initialize grid cell in append mode*/
+ f=fopen(result_lat_long,"a");
+ } else {
+ /*Initialize grid cell in new file mode*/
+ f=fopen(result_lat_long,"w");
+ }
+ /*Print data into the file maps data if available*/
+ for(i=0;i<nfiles_shortest;i++){
+ fprintf(f,"%.2f %.2f %.2f\n", d_prcp[i], d_tmax[i], d_tmin[i]);
+ }
+ fclose(f);
+ /*Print to soil ascii file*/
+ fprintf(g,"%d\t%d\t%6.3f\t%7.3f\t%s\t%7.2f\t%s\n", process, grid_count, latitude, longitude, dummy_data1, d_elevation, dummy_data2);
+ /*Print to vegetation ascii file*/
+ /*Grid cell count and number of classes in that grid cell (=1)*/
+ fprintf(h,"%d 1\n", grid_count);
+ /*Class number, percentage that this class covers in the
+ * grid cell(=1.0, full grid cell)
+ * 3 root zones with depths of 10cm, 10cm and 1.0m
+ * for those 3 root zone depths, how much root in each (%)
+ * here we have 0.65, 0.50 and 0.25
+ * */
+ fprintf(h,"%d 1.0 %s\n", c_landcover, dummy_data1);
+ /*Load monthly LAI maps data if available*/
+ if(input6->answer){
+ fprintf(h,"%5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f\n", lai[0], lai[1], lai[2], lai[3], lai[4], lai[5], lai[6], lai[7], lai[8], lai[9], lai[10], lai[11]);
+ } else {
+ // fprintf(h,"%s\n", dummy_data4);
+ }
+ grid_count=grid_count+1;
+ }
+ }
+ }
+ G_message(_("Created %d VIC meteorological files"),grid_count);
+ G_message(_("Created %d VIC grid cells soil/vegetation definitions"),grid_count);
+ for(i=0;i<nfiles1;i++){
+ G_free (inrast_prcp[i]);
+ G_close_cell (infd_prcp[i]);
+ }
+ for(i=0;i<nfiles2;i++){
+ G_free (inrast_tmax[i]);
+ G_close_cell (infd_tmax[i]);
+ }
+ for(i=0;i<nfiles3;i++){
+ G_free (inrast_tmin[i]);
+ G_close_cell (infd_tmin[i]);
+ }
+ G_free (inrast_elevation);
+ G_close_cell (infd);
+ G_free (inrast_landcover);
+ G_close_cell (infd_landcover);
+ if(input6->answer){
+ for(i=0;i<12;i++){
+ G_free (inrast_lai[i]);
+ G_close_cell (infd_lai[i]);
+ }
+ }
+ fclose(h);
+ fclose(g);
+ exit(EXIT_SUCCESS);
+}
+
Added: grass-addons/gipe/r.out.vic/veg_lib.c
===================================================================
--- grass-addons/gipe/r.out.vic/veg_lib.c (rev 0)
+++ grass-addons/gipe/r.out.vic/veg_lib.c 2008-04-08 03:38:31 UTC (rev 30899)
@@ -0,0 +1,24 @@
+#include<stdio.h>
+#include<stdlib.h>
+
+int veglib(char *filename){
+
+ FILE *f;
+ f=fopen(filename,"w");
+
+ fprintf(f,"#Class OvrStry Rarc Rmin JAN-LAI FEB-LAI MAR-LAI APR-LAI MAY-LAI JUN-LAI JUL-LAI AUG-LAI SEP-LAI OCT-LAI NOV-LAI DEC-LAI JAN-ALB FEB_ALB MAR-ALB APR-ALB MAY-ALB JUN-ALB JUL-ALB AUG-ALB SEP-ALB OCT-ALB NOV-ALB DEC-ALB JAN-ROU FEB-ROU MAR-ROU APR-ROU MAY-ROU JUN-ROU JUL-ROU AUG-ROU SEP-ROU OCT-ROU NOV-ROU DEC-ROU JAN-DIS FEB-DIS MAR-DIS APR-DIS MAY-DIS JUN-DIS JUL-DIS AUG-DIS SEP-DIS OCT-DIS NOV-DIS DEC-DIS WIND_H RGL SolAtn WndAtn Trunk COMMENT\n\
+1 1 60.0 250. 3.400 3.400 3.500 3.700 4.000 4.400 4.400 4.300 4.200 3.700 3.500 3.400 0.12 0.12 0.12 0.12 0.12 0.12 0.12 0.12 0.12 0.12 0.12 0.12 1.476 1.476 1.476 1.476 1.476 1.476 1.476 1.476 1.476 1.476 1.476 1.476 8.04 8.04 8.04 8.04 8.04 8.04 8.04 8.04 8.04 8.04 8.04 8.04 50.0 30 0.5 0.5 0.2 Evergreen Needleleaf\n\
+2 1 60.0 250. 3.400 3.400 3.500 3.700 4.000 4.400 4.400 4.300 4.200 3.700 3.500 3.400 0.12 0.12 0.12 0.12 0.12 0.12 0.12 0.12 0.12 0.12 0.12 0.12 1.476 1.476 1.476 1.476 1.476 1.476 1.476 1.476 1.476 1.476 1.476 1.476 8.04 8.04 8.04 8.04 8.04 8.04 8.04 8.04 8.04 8.04 8.04 8.04 50.0 30 0.5 0.5 0.2 Evergreen Broadleaf\n\
+3 1 60.0 125. 1.680 1.520 1.680 2.900 4.900 5.000 5.000 4.600 3.440 3.040 2.160 2.000 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 50.0 30 0.5 0.5 0.2 Deciduous Needleleaf\n\
+4 1 60.0 125. 1.680 1.520 1.680 2.900 4.900 5.000 5.000 4.600 3.440 3.040 2.160 2.000 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 50.0 30 0.5 0.5 0.2 Deciduous Broadleaf\n\
+5 1 60.0 125. 1.680 1.520 1.680 2.900 4.900 5.000 5.000 4.600 3.440 3.040 2.160 2.000 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 50.0 50 0.5 0.5 0.2 Mixed Cover\n\
+6 1 60.0 125. 1.680 1.520 1.680 2.900 4.900 5.000 5.000 4.600 3.440 3.040 2.160 2.000 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 0.18 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 1.230 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 6.70 50.0 50 0.5 0.5 0.2 Woodland\n\
+7 0 40.0 125. 2.000 2.250 2.950 3.850 3.750 3.500 3.550 3.200 3.300 2.850 2.600 2.200 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.495 0.495 0.495 0.495 0.495 0.495 0.495 0.495 0.495 0.495 0.495 0.495 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 10 75. 0.5 0.5 0.2 Wooded Grasslands\n\
+8 0 50.0 135. 2.000 2.250 2.950 3.850 3.750 3.500 3.550 3.200 3.300 2.850 2.600 2.200 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.495 0.495 0.495 0.495 0.495 0.495 0.495 0.495 0.495 0.495 0.495 0.495 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 10 75. 0.5 0.5 0.2 Closed Shrublands\n\
+9 0 50.0 135. 2.000 2.250 2.950 3.850 3.750 3.500 3.550 3.200 3.300 2.850 2.600 2.200 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.19 0.495 0.495 0.495 0.495 0.495 0.495 0.495 0.495 0.495 0.495 0.495 0.495 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 10 75. 0.5 0.5 0.2 Open Shrublands\n\
+10 0 25.0 120. 2.000 2.250 2.950 3.850 3.750 3.500 3.550 3.200 3.300 2.850 2.600 2.200 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.0738 0.0738 0.0738 0.0738 0.0738 0.0738 0.0738 0.0738 0.0738 0.0738 0.0738 0.0738 0.402 0.402 0.402 0.402 0.402 0.402 0.402 0.402 0.402 0.402 0.402 0.402 10 100 0.5 0.5 0.2 Grasslands\n\
+11 0 25.0 120. 0.050 0.020 0.050 0.250 1.500 3.0000 4.500 5.0000 2.5000 0.500 0.050 0.020 0.10 0.10 0.10 0.10 0.20 0.20 0.20 0.20 0.20 0.10 0.10 0.10 0.006 0.006 0.006 0.006 0.012 0.062 0.123 0.185 0.215 0.215 0.006 0.006 0.034 0.034 0.034 0.034 0.067 0.335 0.670 1.005 1.173 1.173 0.034 0.034 10 100 0.5 0.5 0.2 Crop land (corn)\n");
+
+ fclose(f);
+ return;
+}
More information about the grass-commit
mailing list