GRASS Programmer's Manual
6.4.2(2012)
|
00001 00002 /*- 00003 * Written by H. Mitasova, I. Kosinovsky, D. Gerdes Fall 1993 00004 * University of Illinois 00005 * US Army Construction Engineering Research Lab 00006 * Copyright 1993, H. Mitasova (University of Illinois), 00007 * I. Kosinovsky, (USA-CERL), and D.Gerdes (USA-CERL) 00008 * 00009 * modified by McCauley in August 1995 00010 * modified by Mitasova in August 1995 00011 * 00012 */ 00013 00014 #include <stdio.h> 00015 #include <math.h> 00016 #include <unistd.h> 00017 #include <grass/gis.h> 00018 00019 #include <grass/interpf.h> 00020 00021 int IL_write_temp_2d(struct interp_params *params, int ngstc, int nszc, int offset2 /* begin. and end. column, offset */ 00022 ) 00023 00024 /* 00025 * Writes az,adx,...,adxy into appropriate place (depending on ngstc, nszc 00026 * and offset) in corresponding temp file 00027 */ 00028 { 00029 int j; 00030 static FCELL *array_cell = NULL; 00031 00032 if (!array_cell) { 00033 00034 if (! 00035 (array_cell = 00036 (FCELL *) G_malloc(sizeof(FCELL) * params->nsizc + 1))) { 00037 fprintf(stderr, "Cannot allocate memory for array_cell\n"); 00038 return -1; 00039 } 00040 } 00041 if (params->Tmp_fd_z != NULL) { 00042 for (j = ngstc; j <= nszc; j++) 00043 array_cell[j - 1] = (FCELL) params->az[j]; 00044 if (fseek(params->Tmp_fd_z, (long)offset2, 0) == -1) { 00045 fprintf(stderr, "Cannot fseek elev offset2=%d\n", (int)offset2); 00046 return -1; 00047 } 00048 if (! 00049 (fwrite 00050 (array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1, 00051 params->Tmp_fd_z))) { 00052 fprintf(stderr, "Not enough disk space--cannot write files\n"); 00053 return -1; 00054 } 00055 } 00056 if (params->Tmp_fd_dx != NULL) { 00057 for (j = ngstc; j <= nszc; j++) 00058 if (!params->deriv) 00059 array_cell[j - 1] = (FCELL) params->adx[j]; 00060 else 00061 array_cell[j - 1] = (FCELL) (params->adx[j] * params->scik1); 00062 if (fseek(params->Tmp_fd_dx, (long)offset2, 0) == -1) { 00063 fprintf(stderr, "Cannot fseek slope\n"); 00064 return -1; 00065 } 00066 if (! 00067 (fwrite 00068 (array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1, 00069 params->Tmp_fd_dx))) { 00070 fprintf(stderr, "Not enough disk space--cannot write files\n"); 00071 return -1; 00072 } 00073 } 00074 if (params->Tmp_fd_dy != NULL) { 00075 for (j = ngstc; j <= nszc; j++) { 00076 if (!params->deriv) { 00077 if (params->ady[j] > 0. && params->ady[j] < 0.5) 00078 params->ady[j] = 360.; 00079 array_cell[j - 1] = (FCELL) params->ady[j]; 00080 } 00081 else 00082 array_cell[j - 1] = (FCELL) (params->ady[j] * params->scik1); 00083 } 00084 if (fseek(params->Tmp_fd_dy, (long)offset2, 0) == -1) { 00085 fprintf(stderr, "Cannot fseek aspect\n"); 00086 return -1; 00087 } 00088 if (! 00089 (fwrite 00090 (array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1, 00091 params->Tmp_fd_dy))) { 00092 fprintf(stderr, "Not enough disk space--cannot write files\n"); 00093 return -1; 00094 } 00095 } 00096 if (params->Tmp_fd_xx != NULL) { 00097 for (j = ngstc; j <= nszc; j++) { 00098 array_cell[j - 1] = (FCELL) (params->adxx[j] * params->scik1); 00099 } 00100 if (fseek(params->Tmp_fd_xx, (long)offset2, 0) == -1) { 00101 fprintf(stderr, "Cannot fseek pcurv\n"); 00102 return -1; 00103 } 00104 if (! 00105 (fwrite 00106 (array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1, 00107 params->Tmp_fd_xx))) { 00108 fprintf(stderr, "Not enough disk space--cannot write files\n"); 00109 return -1; 00110 } 00111 } 00112 if (params->Tmp_fd_yy != NULL) { 00113 for (j = ngstc; j <= nszc; j++) 00114 array_cell[j - 1] = (FCELL) (params->adyy[j] * params->scik2); 00115 if (fseek(params->Tmp_fd_yy, (long)offset2, 0) == -1) { 00116 fprintf(stderr, "Cannot fseek tcurv\n"); 00117 return -1; 00118 } 00119 if (! 00120 (fwrite 00121 (array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1, 00122 params->Tmp_fd_yy))) { 00123 fprintf(stderr, "Not enough disk space--cannot write files\n"); 00124 return -1; 00125 } 00126 } 00127 if (params->Tmp_fd_xy != NULL) { 00128 for (j = ngstc; j <= nszc; j++) 00129 array_cell[j - 1] = (FCELL) (params->adxy[j] * params->scik3); 00130 if (fseek(params->Tmp_fd_xy, (long)offset2, 0) == -1) { 00131 fprintf(stderr, "Cannot fseek mcurv\n"); 00132 return -1; 00133 } 00134 if (! 00135 (fwrite 00136 (array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1, 00137 params->Tmp_fd_xy))) { 00138 fprintf(stderr, "Not enough disk space--cannot write files\n"); 00139 return -1; 00140 } 00141 } 00142 return 1; 00143 }