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 "gis.h"
00030
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <unistd.h>
00034 #include <sys/stat.h>
00035
00036
00037
00038
00039
00040
00041
00042 int G__make_location(
00043 char *location_name,
00044 struct Cell_head *wind,
00045 struct Key_Value *proj_info,
00046 struct Key_Value *proj_units,
00047 FILE *report_file )
00048
00049 {
00050 char path[2048];
00051 int out_stat;
00052
00053
00054 sprintf( path, "%s/%s", G_gisdbase(), location_name );
00055 if( mkdir( path, 0775 ) != 0 )
00056 return -1;
00057
00058
00059 sprintf( path, "%s/%s/%s", G_gisdbase(), location_name, "PERMANENT" );
00060 if( mkdir( path, 0775 ) != 0 )
00061 return -1;
00062
00063
00064 G__setenv( "LOCATION_NAME", location_name );
00065 G__setenv( "MAPSET", "PERMANENT" );
00066
00067
00068 G__put_window( wind, "", "DEFAULT_WIND" );
00069 G__put_window( wind, "", "WIND" );
00070
00071
00072 if( proj_info != NULL )
00073 {
00074 G__file_name( path, "", "PROJ_INFO", "PERMANENT" );
00075 G_write_key_value_file( path, proj_info, &out_stat );
00076 if( out_stat != 0 )
00077 return -2;
00078 }
00079
00080 if( proj_units != NULL )
00081 {
00082 G__file_name( path, "", "PROJ_UNITS", "PERMANENT" );
00083 G_write_key_value_file( path, proj_units, &out_stat );
00084 if( out_stat != 0 )
00085 return -2;
00086 }
00087
00088 return 0;
00089 }
00090
00091 int G_make_location(
00092 char *location_name,
00093 struct Cell_head *wind,
00094 struct Key_Value *proj_info,
00095 struct Key_Value *proj_units,
00096 FILE *report_file )
00097
00098 {
00099 int err;
00100
00101 err = G__make_location( location_name, wind, proj_info, proj_units,
00102 report_file );
00103
00104 if( err == 0 )
00105 return 0;
00106
00107 if( err == -1 )
00108 {
00109 perror( "G_make_location" );
00110 }
00111
00112 G_fatal_error( "G_make_location failed." );
00113
00114 return 1;
00115 }
00116
00117
00118
00119
00120
00121
00122 int
00123 G_compare_projections( struct Key_Value *proj_info1,
00124 struct Key_Value *proj_units1,
00125 struct Key_Value *proj_info2,
00126 struct Key_Value *proj_units2 )
00127
00128 {
00129 char buf1[512], buf2[512];
00130
00131 if( proj_info1 == NULL && proj_info2 == NULL )
00132 return TRUE;
00133
00134
00135
00136
00137 if( G_find_key_value( "proj", proj_info1 ) != NULL
00138 && G_find_key_value( "meters", proj_units1 ) != NULL
00139 && atof(G_find_key_value( "meters", proj_units1 ))
00140 != atof(G_find_key_value( "meters", proj_units2 )) )
00141 return -1;
00142
00143
00144
00145
00146 if( proj_units1 != NULL && proj_units2 != NULL
00147 && G_find_key_value( "meters", proj_units1 ) != NULL
00148 && G_find_key_value( "meters", proj_units2 ) != NULL
00149 && atof(G_find_key_value( "meters", proj_units1 ))
00150 != atof(G_find_key_value( "meters", proj_units2 )) )
00151 return -2;
00152
00153
00154
00155
00156
00157
00158 {
00159 double a1=0, a2=0;
00160 if(G_find_key_value( "a", proj_info1) != NULL)
00161 a1 = atof(G_find_key_value( "a", proj_info1 ));
00162 if(G_find_key_value( "a", proj_info2) != NULL)
00163 a2 = atof(G_find_key_value( "a", proj_info2 ));
00164
00165 if ( a1 && a2 && ( abs(a2-a1) > 0.000001 ) )
00166 return -4;
00167 }
00168
00169
00170
00171
00172 {
00173 if( G_find_key_value( "proj", proj_info1 ) == "utm"
00174 && G_find_key_value( "proj", proj_info2 ) == "utm"
00175 && atof(G_find_key_value( "zone", proj_info1 ))
00176 != atof(G_find_key_value( "zone", proj_info2 )) )
00177 return -5;
00178 }
00179
00180
00181
00182
00183
00184 return TRUE;
00185 }