00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <grass/gis.h>
00030
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <unistd.h>
00034 #include <sys/stat.h>
00035 #include <math.h>
00036
00037 #ifdef __MINGW32__
00038 # define mkdir(name, mode) ((mkdir) (name))
00039 #endif
00040
00041
00042
00043
00044
00045
00046
00047 int G__make_location(
00048 char *location_name,
00049 struct Cell_head *wind,
00050 struct Key_Value *proj_info,
00051 struct Key_Value *proj_units,
00052 FILE *report_file )
00053
00054 {
00055 char path[2048];
00056 int out_stat;
00057
00058
00059 sprintf( path, "%s/%s", G_gisdbase(), location_name );
00060 if( mkdir( path, 0775 ) != 0 )
00061 return -1;
00062
00063
00064 sprintf( path, "%s/%s/%s", G_gisdbase(), location_name, "PERMANENT" );
00065 if( mkdir( path, 0775 ) != 0 )
00066 return -1;
00067
00068
00069 G__setenv( "LOCATION_NAME", location_name );
00070 G__setenv( "MAPSET", "PERMANENT" );
00071
00072
00073 G__put_window( wind, "", "DEFAULT_WIND" );
00074 G__put_window( wind, "", "WIND" );
00075
00076
00077 if( proj_info != NULL )
00078 {
00079 G__file_name( path, "", "PROJ_INFO", "PERMANENT" );
00080 G_write_key_value_file( path, proj_info, &out_stat );
00081 if( out_stat != 0 )
00082 return -2;
00083 }
00084
00085 if( proj_units != NULL )
00086 {
00087 G__file_name( path, "", "PROJ_UNITS", "PERMANENT" );
00088 G_write_key_value_file( path, proj_units, &out_stat );
00089 if( out_stat != 0 )
00090 return -2;
00091 }
00092
00093 return 0;
00094 }
00095
00096
00131 int G_make_location(
00132 char *location_name,
00133 struct Cell_head *wind,
00134 struct Key_Value *proj_info,
00135 struct Key_Value *proj_units,
00136 FILE *report_file )
00137
00138 {
00139 int err;
00140
00141 err = G__make_location( location_name, wind, proj_info, proj_units,
00142 report_file );
00143
00144 if( err == 0 )
00145 return 0;
00146
00147 if( err == -1 )
00148 {
00149 perror( "G_make_location" );
00150 }
00151
00152 G_fatal_error( "G_make_location failed." );
00153
00154 return 1;
00155 }
00156
00157
00158
00159
00160
00161
00175 int
00176 G_compare_projections( struct Key_Value *proj_info1,
00177 struct Key_Value *proj_units1,
00178 struct Key_Value *proj_info2,
00179 struct Key_Value *proj_units2 )
00180
00181 {
00182 char *proj1, *proj2;
00183
00184 if( proj_info1 == NULL && proj_info2 == NULL )
00185 return TRUE;
00186
00187
00188
00189
00190
00191 if( proj_info1 == NULL || proj_info2 == NULL)
00192 return -1;
00193
00194 proj1 = G_find_key_value("proj", proj_info1);
00195 proj2 = G_find_key_value("proj", proj_info2);
00196
00197 if( proj1 == NULL || proj2 == NULL || strcmp(proj1, proj2) )
00198 return -1;
00199
00200
00201
00202
00203
00204 if( proj_units1 == NULL && proj_units2 == NULL )
00205 return TRUE;
00206
00207 if( proj_units1 == NULL || proj_units2 == NULL)
00208 return -2;
00209
00210 {
00211 double a1=0, a2=0;
00212 if(G_find_key_value( "meters", proj_units1) != NULL)
00213 a1 = atof(G_find_key_value( "meters", proj_units1 ));
00214 if(G_find_key_value( "meters", proj_units2) != NULL)
00215 a2 = atof(G_find_key_value( "meters", proj_units2 ));
00216
00217 if ( a1 && a2 && ( fabs(a2-a1) > 0.000001 ) )
00218 return -2;
00219 }
00220
00221
00222
00223
00224
00225
00226 {
00227 double a1=0, a2=0;
00228 if(G_find_key_value( "a", proj_info1) != NULL)
00229 a1 = atof(G_find_key_value( "a", proj_info1 ));
00230 if(G_find_key_value( "a", proj_info2) != NULL)
00231 a2 = atof(G_find_key_value( "a", proj_info2 ));
00232
00233 if ( a1 && a2 && ( fabs(a2-a1) > 0.000001 ) )
00234 return -4;
00235 }
00236
00237
00238
00239
00240 if( !strcmp(proj1, "utm") && !strcmp(proj2, "utm")
00241 && atof(G_find_key_value( "zone", proj_info1 ))
00242 != atof(G_find_key_value( "zone", proj_info2 )) )
00243 return -5;
00244
00245
00246
00247
00248
00249 {
00250 char *x_0_1 = NULL, *x_0_2 = NULL;
00251
00252 x_0_1 = G_find_key_value( "x_0", proj_info1);
00253 x_0_2 = G_find_key_value( "x_0", proj_info2);
00254
00255 if ( x_0_1 && x_0_2 &&
00256 ( fabs(atof(x_0_1) - atof(x_0_2)) > 0.000001 ) )
00257 return -6;
00258 }
00259
00260
00261
00262
00263
00264 {
00265 char *y_0_1 = NULL, *y_0_2 = NULL;
00266
00267 y_0_1 = G_find_key_value( "y_0", proj_info1);
00268 y_0_2 = G_find_key_value( "y_0", proj_info2);
00269
00270 if ( y_0_1 && y_0_2 &&
00271 ( fabs(atof(y_0_1) - atof(y_0_2)) > 0.000001 ) )
00272 return -7;
00273 }
00274
00275
00276
00277
00278
00279 return TRUE;
00280 }