1

I have 25 files with the same structure with 19 columns.

I want to open every file and copy from 3 to 19 column in other file using c shell.

The files is named like that:

2005090600
2005090603 
2005090606
2005090609
2005090612
2005090615
2005090618
2005090621
2005090624
2005090627
2005090630
2005090633
2005090636
2005090639
2005090642
2005090645
2005090648
2005090651
2005090654
2005090657
2005090660
2005090663
2005090666
2005090669
2005090672

The structure of every file look like this, but every file have 19 columns:

  23.78060      40.71370     288.82779       1.48891      78.58701    1021.$
  23.83990      40.71460     289.06360       1.67858      71.84100    1018.$
  23.89920      40.71550     289.40170       2.15609      67.67834    1020.$
  23.95850      40.71630     289.53516       2.74299      66.69261    1020.$
  24.01770      40.71720     289.19260       3.15175      70.89188    1017.$
  24.07700      40.71790     288.84558       3.48898      75.21935    1015.$
  24.13630      40.71870     288.67654       3.72929      77.41970    1018.$
  24.19560      40.71940     288.68100       3.91989      78.33372    1020.$
  24.25490      40.72010     288.74329       3.97584      77.75845    1020.$
  24.31410      40.72070     288.81891       3.83177      76.72694    1019.$
  24.37340      40.72130     288.86340       3.47986      75.53368    1018.$
  24.43270      40.72190     288.97015       2.86700      74.33279    1019.$
  24.49200      40.72250     289.07248       2.12211      73.56832    1020.$
  24.55130      40.72300     288.53864       1.39689      72.50629    1008.$
  24.61060      40.72350     287.37305       0.82412      75.36126     984.$
  24.66990      40.72390     287.01270       0.45068      78.88762     978.$
  24.72920      40.72430     288.14270       0.25516      81.30769     999.$
  24.78850      40.72470     288.97461       0.52074      79.94659    1019.$
  24.84770      40.72510     289.08139       1.04584      78.00870    1020.$

I want to open every file and paste content from 3 to 19 columns in another new file named grid_aladin.txt in the same directory.

Can I get example how to loop with cdo command on c shell every file and copy content in the file grid_aladin.txt

grid_aladin.txt look like this:

gridtype = latlon
xsize = 10612
ysize = 10612
xvals = 23.7806 23.8399 23.8992 23.9585 24.0177 24.077 24.1363 24.1956 24.2549 24.3141 24.3734 24.4327 24.492 24.5513 24.6106 24.6699 24.7292 24.7885 24.8477 24.907 24.9663 25.0256 25.0849 25.1442 25.2035 25.2628 25.3221 25.3814 25.4407$
yvals = 40.7137 40.7146 40.7155 40.7163 40.7172 40.7179 40.7187 40.7194 40.7201 40.7207 40.7213 40.7219 40.7225 40.723 40.7235 40.7239 40.7243 40.7247 40.7251 40.7254 40.7257 40.726 40.7262 40.7264 40.7266 40.7268 40.7269 40.727 40.727 $

My code on C shell:

# cdo: error while loading shared libraries: libQt5Core.so.5: cannot open shared object file
#gawk '{ print $3 }' 2005090672 | cdo -f nc input,grid_aladin.txt 2005090672_AT_.nc
#cdo chname,var1,air_temp 2005090672_AT_.nc 2005090672_AT.nc
#cdo -setattribute,air_temp@units="degC" -addc,-273.15 2005090672_AT.nc 2005090672_AT_.nc
#cdo -shifttime,72hour -settunits,hours -settaxis,2020-05-09,06:00,1hour 2005090672_AT_.nc 2005090672_AT.nc


#SET Dat_A="20050906"
#SET Yea_A="2020"
#SET Month_A="05"
#SET Day_A="09"
# files-25
hour_file=['00','03','06','09','12','15','18','21','24','27','30','33','36','39','42','45','48','51','54','57','60','63','6$
hour_number=[0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72]
# vars-10
var_name=['air_temp','w_speed','rel_hum','surf_ps','nebu','rain1','rain2','snow1','snow2','rglo']
var_fname=['AT','WS','RH','PS','NB','RR1','RR2','SN1','SN2','GR']
var_unit=['degC','m/s','%','Pas','0-1','mm','mm','mm','mm','W']
var_position=[3,4,5,6,14,15,16,17,18,19]

#loop on variables

#loop on files

gawk '{ print $${var_position} }' ${Dat_A}${hour_file} | cdo -f nc input,grid_aladin.txt ${Dat_A}${hour_file}_${var_fname}_$
cdo -setattribute,${var_name}@units="${var_unit}" -chname,var1,$var_name -shifttime,${hour_number}hour -settunits,hours \
    -settaxis,${Year_A}-${Month_A}-${Day_A},06:00,1hour ${Dat_A}${hour_file}_${var_fname}_.nc ${Dat_A}${hour_file}_${var_fn$
rm ${Dat_A}${hour_file}_${var_fname}_.nc

#end loop files

cdo -mergetime ${Dat_A}*_${var_fname}.nc ${Dat_A}_${var_fname}.nc

#end loop variables

cdo merge ${Dat_A}_*.nc ${Dat_A}.nc

#remap file

Can I get example how to loop this files and save the content in the grid_aladin.txt ?

kaylum
  • 13,833
  • 2
  • 22
  • 31
Pizhev Racing
  • 466
  • 1
  • 6
  • 23
  • 1
    why not just `awk '{print $3, $4, $5, .... $19}' *wildCardFileSpec* > aggregateFile.txt` (You may have to mess around with `awk -F\t` and/or `-v OFS="|"` or similar to get the fields working the way you want. See [awk tutorial](http://grymoire.com/Unix/Awk.html) for further details. Good luck. – shellter May 21 '20 at 14:46
  • I just want to put the files in array an use while or do while to get all content and put to another file – Pizhev Racing May 21 '20 at 15:53
  • Can I take some example with your comment ? – Pizhev Racing May 21 '20 at 15:59
  • Sorry, there is too much here to comprehend. I see at least 2 questions (*"open every file and paste content from 3 to 19 column..."* , and *"Can I get example how to loop with cdo command "*). Please simplify your problem by eliminating any use of variables that are strictly needed for your prolblem. I have given you a starter for `1:` and it looks like you have something for `2:` . `.....` – shellter May 21 '20 at 22:04
  • To simplify your Q you can reduce the size of the problem description. If a solutions will work for 2-3 variables and columns and lines of data, it will be easy to expand it to work for your full problem. Good luck. – shellter May 21 '20 at 22:06

0 Answers0