Commit 7d539a8c1b98a7b2a1c90d95a08c3c526be2c89b

Authored by Elena.Budnik
1 parent 73625886

server side modifs

php/classes/FilesMgr.php
... ... @@ -120,15 +120,21 @@ class FilesMgr extends AmdaObjectMgr
120 120 return array('type' => $data_type, 'size' => $size, 'n_records' => $n_recs, 'units' => $units, 'fillvalue' => $fillval);
121 121 }
122 122  
123   - public function getCdfSampling()
124   - {
  123 + public function getCdfSampling() {
125 124 copy($this->fileName, "temp.cdf");
126 125 exec('cdfsamplingfromdata ', $results);
127 126 unlink("temp.cdf");
128 127  
129 128 return $results;
130 129 }
  130 +
  131 + public function getCdfSamplings() {
  132 + copy($this->fileName, "temp.cdf");
  133 + exec('cdfsamplingsfromdata ', $results);
  134 + unlink("temp.cdf");
131 135  
  136 + return $results;
  137 + }
132 138 /*
133 139 * CEF format processing
134 140 */
... ... @@ -594,22 +600,30 @@ class FilesMgr extends AmdaObjectMgr
594 600 }
595 601  
596 602  
597   - protected function createFile($format)
  603 + protected function createFile($format, $samplingType)
598 604 {
599 605 $newFile = $this->contentDom->createElement('file');
600 606 $newFile->setAttribute('xml:id', $this->fileId);
601 607 $newFile->setAttribute('name', $this->fileId);
602 608 $newFile->setAttribute('format', $format);
603   -
  609 +
  610 + $minSamp = $this->sampling;
  611 + $maxSamp = $this->maxSampling;
  612 +
604 613 switch ($format)
605 614 {
606 615 case "cdf":
607 616 $start_stop = explode(" ",$this->getCdfStartStop());
608   - $result = $this->getCdfSampling();
609   - //TODO process errors
610   - $minSamp = $result[count($result)-1];
611   - //TODO if min & max
612   - $maxSamp = $minSamp;
  617 + if ($minSamp < 0) {
  618 + if ($samplingType == 'constant') {
  619 + $result = $this->getCdfSampling();
  620 + //TODO process errors
  621 + $minSamp = $result[count($result)-1];
  622 + $maxSamp = $minSamp;
  623 + } else {
  624 + // $result = $this->getCdfSamplings();
  625 + }
  626 + }
613 627 break;
614 628 case "txt":
615 629 $start_stop = explode(" ",$this->reformatTxt());
... ... @@ -621,16 +635,14 @@ class FilesMgr extends AmdaObjectMgr
621 635 // Test if 'standard' meta exist in CEF
622 636 $cefMetaTest = $this->getCefStartStop();
623 637  
624   - if ($cefMetaTest != -1)
625   - {
  638 + if ($cefMetaTest != -1) {
626 639 $cefStartStop = explode("/",$cefMetaTest);
627 640 $start_stop[] = strtotime($cefStartStop[0]);
628 641 $start_stop[] = strtotime($cefStartStop[1]);
629 642 $result = $this->getCefSampling();
630 643 $minSamp = $result[count($result)-1];
631 644 }
632   - else
633   - {
  645 + else {
634 646 // no META data - so time processing
635 647 $timeInfo = $this->getCefTimeInfo();
636 648 $timeInfoArr = explode(" ", $timeInfo);
... ... @@ -644,8 +656,10 @@ class FilesMgr extends AmdaObjectMgr
644 656 case "vot" :
645 657 $start_stop = explode(" ",$this->getVotFileMgr()->getStartStop());
646 658 $samplings = $this->getVotFileMgr()->getSamplings();
647   - $minSamp = $samplings["minSampling"];
648   - $maxSamp = $samplings["maxSampling"];
  659 + if ($minSamp < 0) {
  660 + $minSamp = $samplings["minSampling"];
  661 + $maxSamp = $samplings["maxSampling"];
  662 + }
649 663 $desc = $this->getVotFileMgr()->getDescription();
650 664 break;
651 665 case "nc":
... ... @@ -655,11 +669,13 @@ class FilesMgr extends AmdaObjectMgr
655 669 return $ncInfo;
656 670 }
657 671 $ncInfoArr = explode("#",$ncInfo);
658   - $start_stop = explode(":",$ncInfoArr[0]);
659   - //TODO process errors
660   - $minSamp = $ncInfoArr[1];
661   - //TODO if min & max
662   - $maxSamp = $minSamp;
  672 + $start_stop = explode(":",$ncInfoArr[0]);
  673 + if ($minSamp < 0) {
  674 + //TODO process errors
  675 + $minSamp = $ncInfoArr[1];
  676 + //TODO if min & max
  677 + $maxSamp = $minSamp;
  678 + }
663 679 break;
664 680 default:
665 681 }
... ... @@ -1128,20 +1144,27 @@ class FilesMgr extends AmdaObjectMgr
1128 1144  
1129 1145 $format = $this->getFormat();
1130 1146  
1131   - if ($format === 'unknown')
1132   - {
  1147 + if ($format === 'unknown') {
1133 1148 unlink($this->fileName);
1134 1149 return array('success' => false, 'error' => 'Sorry, unknown format of '.$fileName);
1135 1150 }
1136 1151  
  1152 + // if sampling is defined by user
  1153 + if ($formats["samplingType"] == "manual") {
  1154 + $this->sampling = $formats["min_sampling"];
  1155 + if ($formats["max_sampling"])
  1156 + $this->maxSampling = $formats["max_sampling"];
  1157 + else
  1158 + $this->maxSampling = $this->sampling;
  1159 + }
  1160 +
  1161 +
1137 1162 if ($format == 'txt')
1138 1163 {
1139   - if ($formats["timeFormat"] == "user")
1140   - {
  1164 + if ($formats["timeFormat"] == "user") {
1141 1165 $res = $this->reformatTime($formats["nonStandard"], $formats["timeLength"], $formats["doy"]);
1142 1166  
1143   - if (!$res)
1144   - {
  1167 + if (!$res) {
1145 1168 unlink($this->fileName);
1146 1169 return array('success' => false, 'error' => 'can\'t reformat time');
1147 1170 }
... ... @@ -1149,60 +1172,54 @@ class FilesMgr extends AmdaObjectMgr
1149 1172 // check if file is not empty
1150 1173 $vars = $this->getTxtColNumber(false);
1151 1174  
1152   - if ($vars == -100)
1153   - {
  1175 + if ($vars == -100) {
1154 1176 return array('success' => false, 'error' => 'no such file');
1155 1177 }
1156 1178  
1157   - if ($vars == -1)
1158   - {
  1179 + if ($vars == -1) {
1159 1180 unlink($this->fileName);
1160 1181 return array('success' => false, 'error' => 'while reading file');
1161 1182 }
1162 1183  
1163   - if ($vars === 0)
1164   - {
  1184 + if ($vars === 0) {
1165 1185 unlink($this->fileName);
1166 1186 return array('success' => false, 'error' => 'file contains no data');
1167 1187 }
  1188 +
  1189 + // sampling is to be defined automatically
  1190 + if ($this->sampling < 0) {
  1191 + if ($formats["timeSampling"] == "constant") {
  1192 + $this->sampling = $this->getTxtSampling();
  1193 + $this->maxSampling = $this->sampling;
  1194 + }
  1195 + else {
  1196 + $samplings = $this->getTxtSamplings();
  1197 + $this->sampling = $samplings[0];
  1198 + $this->maxSampling = $samplings[1];
  1199 + }
1168 1200  
1169   - if ($formats["timeSampling"] == "constant")
1170   - {
1171   - $this->sampling = $this->getTxtSampling();
1172   - $this->maxSampling = $this->sampling;
1173   - }
1174   - else
1175   - {
1176   - $samplings = $this->getTxtSamplings();
1177   - $this->sampling = $samplings[0];
1178   - $this->maxSampling = $samplings[1];
  1201 + if ($this->sampling <= 0) {
  1202 + unlink($this->fileName);
  1203 + if ($this->sampling == -10) {
  1204 + return array('success' => false, 'error' => 'Sorry, can\'t process'.$fileName.PHP_EOL.'. Check if there are non numeric chars in the data');
  1205 + }
  1206 + return array('success' => false, 'error' => 'Sorry, can\'t process Time for '.$fileName.PHP_EOL.'. Check time format, start time (> 1970-01-01) or sampling time (>= 1s)');
  1207 + }
1179 1208 }
1180   -
1181   - if ($this->sampling <= 0)
1182   - {
1183   - unlink($this->fileName);
1184   - if ($this->sampling == -10)
1185   - {
1186   - return array('success' => false, 'error' => 'Sorry, can\'t process'.$fileName.PHP_EOL.'. Check if there are non numeric chars in the data');
1187   - }
1188   - return array('success' => false, 'error' => 'Sorry, can\'t process Time for '.$fileName.PHP_EOL.'. Check time format, start time (> 1970-01-01) or sampling time (>= 1s)');
1189   - }
1190 1209 }
1191 1210  
1192 1211 if ($format == 'nc')
1193 1212 {
1194 1213 $status = $this->reformatNcTime();
1195   - if ($status <= 0)
1196   - {
  1214 + if ($status <= 0) {
1197 1215 unlink($this->fileName);
1198 1216 return array('success' => false, 'error' => 'error '.$timeFormat.PHP_EOL.'Time Format problem');
1199 1217 }
1200 1218 }
1201 1219  
1202 1220 //create new file tag with all attributes and add it to the content DOM
1203   - $newFile = $this->createFile($format);
1204   - if (is_int($newFile) && ($newFile < 0))
1205   - {
  1221 + $newFile = $this->createFile($format, $formats["timeSampling"]);
  1222 + if (is_int($newFile) && ($newFile < 0)) {
1206 1223 unlink($this->fileName);
1207 1224 return array( 'success' => false, 'file' => $fileName);
1208 1225 }
... ... @@ -1218,8 +1235,8 @@ class FilesMgr extends AmdaObjectMgr
1218 1235 $mask->appendChild($newFile);
1219 1236  
1220 1237 $files = $mask->getElementsByTagName("file");
1221   - foreach ($files as $file)
1222   - {
  1238 +
  1239 + foreach ($files as $file) {
1223 1240 $starts[] = $file->getAttribute("start");
1224 1241 $stops[] = $file->getAttribute("stop");
1225 1242 }
... ... @@ -1230,8 +1247,7 @@ class FilesMgr extends AmdaObjectMgr
1230 1247 }
1231 1248 }
1232 1249 // no corresponding masks => add to fileList
1233   - if (!$isMask)
1234   - {
  1250 + if (!$isMask) {
1235 1251 $filesList = $this->contentDom->getElementById($this->contentRootId);
1236 1252 $filesList->appendChild($newFile);
1237 1253 }
... ... @@ -1241,8 +1257,7 @@ class FilesMgr extends AmdaObjectMgr
1241 1257 //if mask exists - add to data base
1242 1258 $myBaseManager = new BaseManager();
1243 1259 $mask = $myBaseManager->addFile($fileName);
1244   - if ($mask != null)
1245   - {
  1260 + if ($mask != null) {
1246 1261 $startstop = $myBaseManager->getStartStop($myBaseManager->getVi($mask));
1247 1262 $myParamMgr = new DerivedParamMgr('myDataParam');
1248 1263 $myParamMgr->updateMydata($mask,$startstop);
... ...
php/src/cdfsamplingfromdata.c
1   -/* $Id: timeResFromData.c,v 1.1 2010/08/31 10:32:55 budnik Exp $ */
  1 +/* $Id: cdf constant samplig from data $ */
2 2  
3   -/** @file timeResFromData.c
4   -* @brief Function to get CDAWEB dataset sampling times from data files
5   -*/
6 3 #include <stdio.h>
7 4 #include <stdlib.h>
8 5 #include <cdf.h>
... ... @@ -46,48 +43,18 @@ void cdf_handle_error(CDFstatus status)
46 43 exit(1);
47 44 }
48 45  
49   -void find_min(int* delta, int nRecs, int minFalse, int* minVal)
50   -{
51   - int i, n, min;
52   -
53   - n = 1;
54   - i = 0;
55   - while (abs(delta[i]) <= minFalse) i++;
56   - if (i < nRecs) {
57   - min = abs(delta[i]);
58   - // printf(" first MIN %d \n", min);
59   - for (i = 1; i < nRecs; i++) {
60   - // printf(" delta %d \n", delta[i]);
61   - if (delta[i] == min) n++;
62   - if (delta[i] < min && delta[i] > minFalse) {
63   - min = delta[i];
64   - n = 1;
65   - }
66   - }
67   - } else {
68   - min = -10;
69   - n = nRecs;
70   - }
71   -
72   - minVal[0] = min;
73   - minVal[1] = n;
74   - printf(" MIN %d %d\n", min, n);
75   -}
76   -
77 46 int main(int argc, char *argv[])
78 47 {
79   - long RecStart = 0, RecCount, RecInt = 1;
  48 + long RecStart = 0, RecCount = 2, RecInt = 1;
80 49 long indices[1] = {0}, intervals[1] = {1}, counts[1] = {1};
81 50 long varN = -1;
82 51 long datatype = 0, attrN, maxEntry;
83 52 CDFstatus cstatus; // CDF status code
84 53 CDFid id;
85 54 double *value;
86   - int *delta;
87 55 int i, minFalse = 0, numEnough;
88   - int min[2] = {0, 0};
89 56 char attrValue[300];
90   - float Sampling;
  57 + int sampling;
91 58 double epoch16[2], dbl_value, dbl_value_;
92 59 long year, month, day, hour, minute, sec, msec, mksec, nsec, psec;
93 60 long long *int_value;
... ... @@ -106,26 +73,27 @@ int main(int argc, char *argv[])
106 73 if ((cstatus = CDFlib(SELECT_, zVAR_, varN,
107 74 GET_, zVAR_DATATYPE_, &datatype, NULL_)) != CDF_OK)
108 75 cdf_handle_error (cstatus);
109   - // if (datatype == CDF_EPOCH16) break;
110 76 }
  77 +
111 78 fprintf(stdout,"DATATYPE %d %d\n", varN, datatype);
112 79 if ((cstatus = CDFlib(SELECT_, zVAR_, varN,
113 80 GET_, zVAR_MAXREC_, &CDFmaxRec, NULL_)) != CDF_OK)
114 81 cdf_handle_error (cstatus);
115 82  
116 83 fprintf(stdout,"Max Recs %d\n", CDFmaxRec+1);
117   - if (CDFmaxRec < 10) {
  84 +
  85 + if (CDFmaxRec < 3) {
118 86 fprintf(stdout," %d\n", badFile);
119 87 exit (0);
120 88 }
121 89  
122 90 if ( datatype == CDF_TIME_TT2000 ) {
123   - int_value = (long long *) malloc (sizeof(long long) * (CDFmaxRec+1));
  91 + int_value = (long long *) malloc (sizeof(long long) * (RecCount+1));
124 92 /******************* Get Epoch *************************/
125 93 if ((cstatus = CDFlib (SELECT_,
126 94 zVAR_, varN,
127 95 zVAR_RECNUMBER_, RecStart,
128   - zVAR_RECCOUNT_, CDFmaxRec+1,
  96 + zVAR_RECCOUNT_, RecCount + 1,
129 97 zVAR_RECINTERVAL_, RecInt,
130 98 zVAR_DIMINDICES_, indices,
131 99 zVAR_DIMCOUNTS_, counts,
... ... @@ -134,12 +102,12 @@ int main(int argc, char *argv[])
134 102 cdf_handle_error (cstatus);
135 103 }
136 104 else {
137   - value = (double *)malloc(sizeof(double)* (CDFmaxRec+1)*((datatype == CDF_EPOCH16)+1));
  105 + value = (double *)malloc(sizeof(double)* (RecCount + 1)*((datatype == CDF_EPOCH16)+1));
138 106 /******************* Get Epoch *************************/
139 107 if ((cstatus = CDFlib (SELECT_,
140 108 zVAR_, varN,
141 109 zVAR_RECNUMBER_, RecStart,
142   - zVAR_RECCOUNT_, CDFmaxRec+1,
  110 + zVAR_RECCOUNT_, RecCount + 1,
143 111 zVAR_RECINTERVAL_, RecInt,
144 112 zVAR_DIMINDICES_, indices,
145 113 zVAR_DIMCOUNTS_, counts,
... ... @@ -147,46 +115,35 @@ int main(int argc, char *argv[])
147 115 GET_, zVAR_HYPERDATA_, value, NULL_)) != CDF_OK)
148 116 cdf_handle_error (cstatus);
149 117 }
150   -
151 118  
152   -
153   - delta = (int *)malloc(sizeof(int)* CDFmaxRec);
154   - for (i = 1; i < CDFmaxRec+1; i++)
155   - {
  119 +
156 120 if (datatype == CDF_TIME_TT2000) {
157   - dbl_value_ = CDF_TT2000_to_UTC_EPOCH(int_value[i-1]);
158   - dbl_value = CDF_TT2000_to_UTC_EPOCH(int_value[i]);
159   - delta[i-1] = (int)(dbl_value - dbl_value_ + 50)/100;
  121 + dbl_value_ = CDF_TT2000_to_UTC_EPOCH(int_value[0]);
  122 + dbl_value = CDF_TT2000_to_UTC_EPOCH(int_value[1]);
  123 + sampling = (int)(dbl_value - dbl_value_ + 50)/100;
160 124 }
161 125 else {
162 126 if (datatype == CDF_EPOCH16) {
163   - epoch16[0] = value[2*(i-1)];
164   - epoch16[1] = value[2*(i-1)+1];
  127 + epoch16[0] = value[0];
  128 + epoch16[1] = value[1];
165 129 EPOCH16breakdown(epoch16, &year, &month, &day, &hour, &minute, &sec, &msec, &mksec, &nsec, &psec);
166   - value[i-1] = computeEPOCH(year, month, day, hour, minute, sec, msec);
167   - epoch16[0] = value[2*i];
168   - epoch16[1] = value[2*i+1];
  130 + value[0] = computeEPOCH(year, month, day, hour, minute, sec, msec);
  131 + epoch16[0] = value[2];
  132 + epoch16[1] = value[3];
169 133 EPOCH16breakdown(epoch16, &year, &month, &day, &hour, &minute, &sec, &msec, &mksec, &nsec, &psec);
170   - value[i] = computeEPOCH(year, month, day, hour, minute, sec, msec);
  134 + value[1] = computeEPOCH(year, month, day, hour, minute, sec, msec);
171 135 }
172   - delta[i-1] = (int)(value[i] - value[i-1] + 50)/100;
  136 + sampling = (int)(value[1] - value[0] + 50)/100;
173 137 }
174   - }
  138 +
175 139 // fprintf(stdout,"value %f\n", value[11]-value[10]);
176 140 if (datatype == CDF_TIME_TT2000) free(int_value);
177 141 else free(value);
178   - // fprintf(stdout,"delta %d\n", delta[0]);
179   - numEnough = CDFmaxRec/10;
180   - while (min[1] < numEnough) {
181   - fprintf(stdout,"minFalse %d\n", minFalse);
182   - find_min(delta, CDFmaxRec, minFalse, min);
183   - minFalse = min[0];
184   - }
  142 +
185 143  
186   - free(delta);
187 144 if ((cstatus = CDFlib(CLOSE_, CDF_, NULL_)) != CDF_OK)
188 145 cdf_handle_error (cstatus);
189 146  
190 147 // fprintf(stdout,"%d %f\n",min[1], (float)min[0]/100.0);
191   - fprintf(stdout,"%f\n",(float)min[0]/10.0);
  148 + fprintf(stdout,"%f\n",(float)sampling/10.0);
192 149 }
... ...
php/uploadFile.php
... ... @@ -117,11 +117,23 @@
117 117 $nonStd = $_POST['nonstd'] ? $_POST['nonstd'] : null;
118 118 $timeLength = $_POST['timelength'] ? $_POST['timelength'] : null;
119 119 $doy = isset($_POST['doy']) ? $_POST['doy'] : null;
  120 + $sampling = isset($_POST['smpl']) ? $_POST['smpl'] : null;
  121 + $min_sampling = isset($_POST['min_manual_sampling']) ? $_POST['min_manual_sampling'] : null;
  122 + $max_sampling = isset($_POST['max_manual_sampling']) ? $_POST['max_manual_sampling'] : null;
  123 +
  124 + if ($sampling == "auto" && $timeSmplg == "variable"
  125 + && (strtolower($fileFrmt) == "cdf" || strtolower($fileFrmt) == "nc")) {
  126 + $response = array('success' => false, 'error' => " : Auto-definition of variable sampling for $fileFrmt isn't implemented yet.
  127 + Use manual sampling definition");
  128 + die(json_encode($response));
  129 + }
  130 +
120 131 $sampData = isset($_POST['sampData']) ? $_POST['sampData'] : null;
121 132 $sampFileName = isset($_POST['sampFileName']) ? $_POST['sampFileName'] : null;
122 133  
123 134 $allFormats = array('fileFormat' => $fileFrmt, 'timeFormat' => $timeFrmt, 'doy' => $doy,
124   - 'timeSampling' => $timeSmplg, 'nonStandard' => $nonStd, 'timeLength' => $timeLength);
  135 + 'timeSampling' => $timeSmplg, 'nonStandard' => $nonStd, 'timeLength' => $timeLength,
  136 + 'samplingType' => $sampling, 'min_sampling' => $min_sampling, 'max_sampling' => $max_sampling);
125 137  
126 138 if ($_POST['filesrc'] == 'URL') $fromURL = true;
127 139 else $fromURL = false;
... ...