0

Found out GRD is a "gridded dataset file", but cannot see its contents using cat. I think it's in binary format, so it must be read in a different way. The problem is: only found examples in Fortran, R, MATLAB... I must convert the shell script below to PHP (that's only a partial code):

if test -s /path/${datemax}00tx.grd
then

# creating ctl file

echo DSET  /path/${datamax}00tx.grd >> $DIR/new-$customer.ctl
echo UNDEF  777.7   >> $DIR/new-$customer.ctl
echo TITLE CTL to view interpolated files >> $DIR/new-$customer.ctl
echo XDEF 176 LINEAR  -76 .25 >> $DIR/new-$customer.ctl
echo YDEF 160 LINEAR  -34 .25 >> $DIR/new-$customer.ctl
echo ZDEF 1  LINEAR  1 1  >> $DIR/new-$customer.ctl
echo TDEF 1  LINEAR 00Z01apr$yearmax 24HR >> $DIR/new-$customer.ctl
echo VARS 1 >> $DIR/new-$customer.ctl
echo maxval 0   99   Maximum Value>> $DIR/new-$customer.ctl
echo ENDVARS >> $DIR/new-$customer.ctl

echo MAXVAL

cat << eof | grads -bpc "$DIR/getvalues.gs" 
maxval
$customer
eof

fi

rm -f $DIR/new-$customer.ctl

Is it even possible to do this using another language like PHP, Java (my preferred one) or Python? This ugly script reminds me of Assembly.

Rasshu
  • 1,621
  • 5
  • 20
  • 46
  • 1
    If you already have a shell script that works why not just use it in PHP using `shell_exec` (or in Java via `Runtime.getRuntime().exec()`)? – apokryfos Jul 08 '16 at 14:47
  • 2
    Probably, yes. but we're not a code translation service. – Marc B Jul 08 '16 at 14:47
  • The aim is to abandon some 2004's scripts and redo them entirely in PHP - if possible. If not, guess the way is really reading them using shell_exec. – Rasshu Jul 08 '16 at 14:52
  • @rsb2097 There really is a question of cost-efficiency when it comes to re-writing things. If the existing scripts are hard/expensive to maintain (because they break a lot and they're in a language no one uses/knows anymore) then it's probably worth looking into the conversion. If not and they work then it's probably not worth it. – apokryfos Jul 08 '16 at 14:54
  • One option is using shell scripts in the case I posted, that is, anywhere it calls grads. So `shell_exec` is an alternative. – Rasshu Jul 08 '16 at 16:43
  • I'm almost done. Using the returns of `shell_exec` (only needed to read the file - fastest way right now) to build a table with data from the GRD files. Found out this link http://www.unidata.ucar.edu/software/thredds/current/netcdf-java/tutorial/ so I guess converting the files to NetCDF format is the way to go. – Rasshu Jul 11 '16 at 11:37

0 Answers0